Skip to content

Commit d86564a

Browse files
Peter Zijlstratorvalds
authored andcommitted
mm/tlb, x86/mm: Support invalidating TLB caches for RCU_TABLE_FREE
Jann reported that x86 was missing required TLB invalidates when he hit the !*batch slow path in tlb_remove_table(). This is indeed the case; RCU_TABLE_FREE does not provide TLB (cache) invalidates, the PowerPC-hash where this code originated and the Sparc-hash where this was subsequently used did not need that. ARM which later used this put an explicit TLB invalidate in their __p*_free_tlb() functions, and PowerPC-radix followed that example. But when we hooked up x86 we failed to consider this. Fix this by (optionally) hooking tlb_remove_table() into the TLB invalidate code. NOTE: s390 was also needing something like this and might now be able to use the generic code again. [ Modified to be on top of Nick's cleanups, which simplified this patch now that tlb_flush_mmu_tlbonly() really only flushes the TLB - Linus ] Fixes: 9e52fc2 ("x86/mm: Enable RCU based page table freeing (CONFIG_HAVE_RCU_TABLE_FREE=y)") Reported-by: Jann Horn <jannh@google.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Rik van Riel <riel@surriel.com> Cc: Nicholas Piggin <npiggin@gmail.com> Cc: David Miller <davem@davemloft.net> Cc: Will Deacon <will.deacon@arm.com> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: stable@kernel.org Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent a6f5720 commit d86564a

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

arch/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,9 @@ config HAVE_ARCH_JUMP_LABEL
362362
config HAVE_RCU_TABLE_FREE
363363
bool
364364

365+
config HAVE_RCU_TABLE_INVALIDATE
366+
bool
367+
365368
config ARCH_HAVE_NMI_SAFE_CMPXCHG
366369
bool
367370

arch/x86/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ config X86
181181
select HAVE_PERF_REGS
182182
select HAVE_PERF_USER_STACK_DUMP
183183
select HAVE_RCU_TABLE_FREE
184+
select HAVE_RCU_TABLE_INVALIDATE if HAVE_RCU_TABLE_FREE
184185
select HAVE_REGS_AND_STACK_ACCESS_API
185186
select HAVE_RELIABLE_STACKTRACE if X86_64 && (UNWINDER_FRAME_POINTER || UNWINDER_ORC) && STACK_VALIDATION
186187
select HAVE_STACKPROTECTOR if CC_HAS_SANE_STACKPROTECTOR

mm/memory.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,21 @@ bool __tlb_remove_page_size(struct mmu_gather *tlb, struct page *page, int page_
330330
* See the comment near struct mmu_table_batch.
331331
*/
332332

333+
/*
334+
* If we want tlb_remove_table() to imply TLB invalidates.
335+
*/
336+
static inline void tlb_table_invalidate(struct mmu_gather *tlb)
337+
{
338+
#ifdef CONFIG_HAVE_RCU_TABLE_INVALIDATE
339+
/*
340+
* Invalidate page-table caches used by hardware walkers. Then we still
341+
* need to RCU-sched wait while freeing the pages because software
342+
* walkers can still be in-flight.
343+
*/
344+
tlb_flush_mmu_tlbonly(tlb);
345+
#endif
346+
}
347+
333348
static void tlb_remove_table_smp_sync(void *arg)
334349
{
335350
/* Simply deliver the interrupt */
@@ -366,6 +381,7 @@ void tlb_table_flush(struct mmu_gather *tlb)
366381
struct mmu_table_batch **batch = &tlb->batch;
367382

368383
if (*batch) {
384+
tlb_table_invalidate(tlb);
369385
call_rcu_sched(&(*batch)->rcu, tlb_remove_table_rcu);
370386
*batch = NULL;
371387
}
@@ -378,11 +394,13 @@ void tlb_remove_table(struct mmu_gather *tlb, void *table)
378394
if (*batch == NULL) {
379395
*batch = (struct mmu_table_batch *)__get_free_page(GFP_NOWAIT | __GFP_NOWARN);
380396
if (*batch == NULL) {
397+
tlb_table_invalidate(tlb);
381398
tlb_remove_table_one(table);
382399
return;
383400
}
384401
(*batch)->nr = 0;
385402
}
403+
386404
(*batch)->tables[(*batch)->nr++] = table;
387405
if ((*batch)->nr == MAX_TABLE_BATCH)
388406
tlb_table_flush(tlb);

0 commit comments

Comments
 (0)