Fixup page directory freeing
Subsystems (11)
v4 cover Fixup page directory freeing
This is a repost of patch series from Peter with the arch specific changes except ppc64 dropped. ppc64 changes are added here because we are redoing the patch series on top of ppc64 changes. This makes it easy to backport these changes. Only the first 2 patches need to be backported to stable.
The thing is, on anything SMP, freeing page directories should observe the exact same order as normal page freeing:
1) unhook page/directory
2) TLB invalidate
3) free page/directory
Without this, any concurrent page-table walk could end up with a Use-after-Free. This is esp. trivial for anything that has software page-table walkers (HAVE_FAST_GUP / software TLB fill) or the hardware caches partial page-walks (ie. caches page directories).
Even on UP this might give issues since mmu_gather is preemptible these days. An interrupt or preempted task accessing user pages might stumble into the free page if the hardware caches page directories.
This patch series fixup ppc64 and add generic MMU_GATHER changes to support the conversion of other architectures. I haven't added patches w.r.t other architecture because they are yet to be acked.
Changes from V3:
* Added Cc:stable for first two patches
* Explained why we have sparc related changes in patch 2
Aneesh Kumar K.V (1):
powerpc/mmu_gather: Enable RCU_TABLE_FREE even for !SMP case
Peter Zijlstra (8):
mm/mmu_gather: Invalidate TLB correctly on batch allocation failure
and flush
asm-generic/tlb: Avoid potential double flush asm-gemeric/tlb: Remove stray function declarations asm-generic/tlb: Add missing CONFIG symbol asm-generic/tlb: Rename HAVE_RCU_TABLE_FREE asm-generic/tlb: Rename HAVE_MMU_GATHER_PAGE_SIZE asm-generic/tlb: Rename HAVE_MMU_GATHER_NO_GATHER asm-generic/tlb: Provide MMU_GATHER_TABLE_FREE
arch/Kconfig | 13 +- arch/arm/Kconfig | 2 +- arch/arm/include/asm/tlb.h | 4 - arch/arm64/Kconfig | 2 +- arch/powerpc/Kconfig | 5 +- arch/powerpc/include/asm/book3s/32/pgalloc.h | 8 -- arch/powerpc/include/asm/book3s/64/pgalloc.h | 2 - arch/powerpc/include/asm/nohash/pgalloc.h | 8 -- arch/powerpc/include/asm/tlb.h | 11 ++ arch/powerpc/mm/book3s64/pgtable.c | 7 - arch/s390/Kconfig | 4 +- arch/sparc/Kconfig | 3 +- arch/sparc/include/asm/tlb_64.h | 9 ++ arch/x86/Kconfig | 2 +- arch/x86/include/asm/tlb.h | 4 +- include/asm-generic/tlb.h | 120 ++++++++++------- mm/gup.c | 2 +- mm/mmu_gather.c | 134 +++++++++++++------ 18 files changed, 207 insertions(+), 133 deletions(-)
Signature · 1 line
2.24.1
PATCH v4 1/9 powerpc/mmu_gather: Enable RCU_TABLE_FREE even for !SMP case
A follow up patch is going to make sure we correctly invalidate page walk cache before we free page table pages. In order to keep things simple enable RCU_TABLE_FREE even for !SMP so that we don't have to fixup the !SMP case differently in the followup patch
!SMP case is right now broken for radix translation w.r.t page walk cache flush. We can get interrupted in between page table free and that would imply we have page walk cache entries pointing to tables which got freed already.
--- arch/powerpc/Kconfig | 2 +- arch/powerpc/include/asm/book3s/32/pgalloc.h | 8 -------- arch/powerpc/include/asm/book3s/64/pgalloc.h | 2 -- arch/powerpc/include/asm/nohash/pgalloc.h | 8 -------- arch/powerpc/mm/book3s64/pgtable.c | 7 ------- 5 files changed, 1 insertion(+), 26 deletions(-)
arch/powerpc/Kconfig +1 -1
@@ -222,7 +222,7 @@ config PPC select HAVE_HARDLOCKUP_DETECTOR_PERF if PERF_EVENTS && HAVE_PERF_EVENTS_NMI && !HAVE_HARDLOCKUP_DETECTOR_ARCH select HAVE_PERF_REGS select HAVE_PERF_USER_STACK_DUMP - select HAVE_RCU_TABLE_FREE if SMP + select HAVE_RCU_TABLE_FREE select HAVE_RCU_TABLE_NO_INVALIDATE if HAVE_RCU_TABLE_FREE select HAVE_MMU_GATHER_PAGE_SIZE select HAVE_REGS_AND_STACK_ACCESS_API
arch/powerpc/include/asm/book3s/32/pgalloc.h +0 -8
@@ -49,7 +49,6 @@ static inline void pgtable_free(void *table, unsigned index_size)#define get_hugepd_cache_index (x) (x) -#ifdef CONFIG_SMP static inline void pgtable_free_tlb (struct mmu_gather *tlb,void *table,int shift) {
@@ -66,13 +65,6 @@ static inline void __tlb_remove_table(void *_table)pgtable_free (table, shift); } -#else -static inline void pgtable_free_tlb (struct mmu_gather *tlb, -void *table,int shift) -{ -pgtable_free (table, shift); -} -#endif static inline void __pte_free_tlb (struct mmu_gather *tlb,pgtable_t table,unsigned long address)
arch/powerpc/include/asm/book3s/64/pgalloc.h +0 -2
@@ -19,9 +19,7 @@ extern struct vmemmap_backing *vmemmap_list;extern pmd_t *pmd_fragment_alloc (struct mm_struct *,unsigned long );extern void pmd_fragment_free (unsigned long *);extern void pgtable_free_tlb (struct mmu_gather *tlb,void *table,int shift); -#ifdef CONFIG_SMP extern void __tlb_remove_table (void *_table); -#endif void pte_frag_destroy (void *pte_frag);static inline pgd_t *radix__pgd_alloc (struct mm_struct *mm)
arch/powerpc/include/asm/nohash/pgalloc.h +0 -8
@@ -46,7 +46,6 @@ static inline void pgtable_free(void *table, int shift)#define get_hugepd_cache_index (x) (x) -#ifdef CONFIG_SMP static inline void pgtable_free_tlb (struct mmu_gather *tlb,void *table,int shift) {unsigned long pgf = (unsigned long )table;
@@ -64,13 +63,6 @@ static inline void __tlb_remove_table(void *_table)pgtable_free (table, shift); } -#else -static inline void pgtable_free_tlb (struct mmu_gather *tlb,void *table,int shift) -{ -pgtable_free (table, shift); -} -#endif -static inline void __pte_free_tlb (struct mmu_gather *tlb,pgtable_t table,unsigned long address) {
arch/powerpc/mm/book3s64/pgtable.c +0 -7
@@ -378,7 +378,6 @@ static inline void pgtable_free(void *table, int index) } } -#ifdef CONFIG_SMP void pgtable_free_tlb (struct mmu_gather *tlb,void *table,int index) {unsigned long pgf = (unsigned long )table;
@@ -395,12 +394,6 @@ void __tlb_remove_table(void *_table)return pgtable_free (table, index); } -#else -void pgtable_free_tlb (struct mmu_gather *tlb,void *table,int index) -{ -return pgtable_free (table, index); -} -#endif #ifdef CONFIG_PROC_FS atomic_long_t direct_pages_count[MMU_PAGE_COUNT ];
Signature · 1 line
2.24.1
Re: [PATCH v4 1/9] powerpc/mmu_gather: Enable RCU_TABLE_FREE even for !SMP case
Quoted 8 lines · Aneesh Kumar K.V
A follow up patch is going to make sure we correctly invalidate page walk cache before we free page table pages. In order to keep things simple enable
RCU_TABLE_FREEeven for !SMP so that we don't have to fixup the !SMP case differently in the followup patch!SMP case is right now broken for radix translation w.r.t page walk cache flush. We can get interrupted in between page table free and that would imply we have page walk cache entries pointing to tables which got freed already.
For the archives, both our platforms that run on Power9 force SMP on in Kconfig, so the !SMP case is unlikely to be a problem for anyone in practice, unless they've hacked their kernel to build it !SMP.
Quoted 10 lines
Cc <[email protected]>Signed-off-by Aneesh Kumar K.V <[email protected]>--- arch/powerpc/Kconfig | 2 +- arch/powerpc/include/asm/book3s/32/pgalloc.h | 8 -------- arch/powerpc/include/asm/book3s/64/pgalloc.h | 2 -- arch/powerpc/include/asm/nohash/pgalloc.h | 8 -------- arch/powerpc/mm/book3s64/pgtable.c | 7 ------- 5 files changed, 1 insertion(+), 26 deletions(-)
cheers
Quoted 106 lines
arch/powerpc/Kconfig +1
-1@@ -222,7 +222,7 @@ config PPC select HAVE_HARDLOCKUP_DETECTOR_PERF if PERF_EVENTS && HAVE_PERF_EVENTS_NMI && !HAVE_HARDLOCKUP_DETECTOR_ARCH select HAVE_PERF_REGS select HAVE_PERF_USER_STACK_DUMP - select HAVE_RCU_TABLE_FREE if SMP + select HAVE_RCU_TABLE_FREE select HAVE_RCU_TABLE_NO_INVALIDATE if HAVE_RCU_TABLE_FREE select HAVE_MMU_GATHER_PAGE_SIZE select HAVE_REGS_AND_STACK_ACCESS_APIarch/powerpc/include/asm/book3s/32/pgalloc.h +0
-8@@ -49,7 +49,6 @@ static inline void pgtable_free(void *table, unsigned index_size)#define get_hugepd_cache_index (x) (x) -#ifdef CONFIG_SMP static inline void pgtable_free_tlb (struct mmu_gather *tlb,void *table,int shift) {@@ -66,13 +65,6 @@ static inline void __tlb_remove_table(void *_table)pgtable_free (table, shift); } -#else -static inline void pgtable_free_tlb (struct mmu_gather *tlb, -void *table,int shift) -{ -pgtable_free (table, shift); -} -#endif static inline void __pte_free_tlb (struct mmu_gather *tlb,pgtable_t table,unsigned long address)arch/powerpc/include/asm/book3s/64/pgalloc.h +0
-2@@ -19,9 +19,7 @@ extern struct vmemmap_backing *vmemmap_list;extern pmd_t *pmd_fragment_alloc (struct mm_struct *,unsigned long );extern void pmd_fragment_free (unsigned long *);extern void pgtable_free_tlb (struct mmu_gather *tlb,void *table,int shift); -#ifdef CONFIG_SMP extern void __tlb_remove_table (void *_table); -#endif void pte_frag_destroy (void *pte_frag);static inline pgd_t *radix__pgd_alloc (struct mm_struct *mm)arch/powerpc/include/asm/nohash/pgalloc.h +0
-8@@ -46,7 +46,6 @@ static inline void pgtable_free(void *table, int shift)#define get_hugepd_cache_index (x) (x) -#ifdef CONFIG_SMP static inline void pgtable_free_tlb (struct mmu_gather *tlb,void *table,int shift) {unsigned long pgf = (unsigned long )table;@@ -64,13 +63,6 @@ static inline void __tlb_remove_table(void *_table)pgtable_free (table, shift); } -#else -static inline void pgtable_free_tlb (struct mmu_gather *tlb,void *table,int shift) -{ -pgtable_free (table, shift); -} -#endif -static inline void __pte_free_tlb (struct mmu_gather *tlb,pgtable_t table,unsigned long address) {arch/powerpc/mm/book3s64/pgtable.c +0
-7@@ -378,7 +378,6 @@ static inline void pgtable_free(void *table, int index) } } -#ifdef CONFIG_SMP void pgtable_free_tlb (struct mmu_gather *tlb,void *table,int index) {unsigned long pgf = (unsigned long )table;@@ -395,12 +394,6 @@ void __tlb_remove_table(void *_table)return pgtable_free (table, index); } -#else -void pgtable_free_tlb (struct mmu_gather *tlb,void *table,int index) -{ -return pgtable_free (table, index); -} -#endif #ifdef CONFIG_PROC_FS atomic_long_t direct_pages_count[MMU_PAGE_COUNT ];Signature · 1 line
2.24.1
PATCH v4 2/9 mm/mmu_gather: Invalidate TLB correctly on batch allocation failure and flush
In reply to Aneesh Kumar K.VFrom: Peter Zijlstra <[email protected]>
Architectures for which we have hardware walkers of Linux page table should flush TLB on mmu gather batch allocation failures and batch flush. Some architectures like POWER supports multiple translation modes (hash and radix) and in the case of POWER only radix translation mode needs the above TLBI. This is because for hash translation mode kernel wants to avoid this extra flush since there are no hardware walkers of linux page table. With radix translation, the hardware also walks linux page table and with that, kernel needs to make sure to TLB invalidate page walk cache before page table pages are freed.
More details in
commit: d86564a2f085 ("mm/tlb, x86/mm: Support invalidating TLB caches for RCU_TABLE_FREE")
The changes to sparc are to make sure we keep the old behavior since we are now removing HAVE_RCU_TABLE_NO_INVALIDATE. The default value for tlb_needs_table_invalidate is to always force an invalidate and sparc can avoid the table invalidate. Hence we define tlb_needs_table_invalidate to false for sparc architecture.
--- arch/Kconfig | 3 --- arch/powerpc/Kconfig | 1 - arch/powerpc/include/asm/tlb.h | 11 +++++++++++ arch/sparc/Kconfig | 1 - arch/sparc/include/asm/tlb_64.h | 9 +++++++++ include/asm-generic/tlb.h | 22 +++++++++++++++------- mm/mmu_gather.c | 16 ++++++++-------- 7 files changed, 43 insertions(+), 20 deletions(-)
arch/Kconfig +0 -3
@@ -396,9 +396,6 @@ config HAVE_ARCH_JUMP_LABEL_RELATIVE config HAVE_RCU_TABLE_FREE bool -config HAVE_RCU_TABLE_NO_INVALIDATE - bool - config HAVE_MMU_GATHER_PAGE_SIZE bool
arch/powerpc/Kconfig +0 -1
@@ -223,7 +223,6 @@ config PPC select HAVE_PERF_REGS select HAVE_PERF_USER_STACK_DUMP select HAVE_RCU_TABLE_FREE - select HAVE_RCU_TABLE_NO_INVALIDATE if HAVE_RCU_TABLE_FREE select HAVE_MMU_GATHER_PAGE_SIZE select HAVE_REGS_AND_STACK_ACCESS_API select HAVE_RELIABLE_STACKTRACE if PPC_BOOK3S_64 && CPU_LITTLE_ENDIAN
arch/powerpc/include/asm/tlb.h +11 -0
@@ -26,6 +26,17 @@#define tlb_flush tlb_flushextern void tlb_flush (struct mmu_gather *tlb); +/* +* book3s: +* Hash does not use the linux page-tables, so we can avoid +* the TLB invalidate for page-table freeing, Radix otoh does use the +* page-tables and needs the TLBI. +* +* nohash: +* We still do TLB invalidate in the __pte_free_tlb routine before we +* add the page table pages to mmu gather table batch. +*/ +#define tlb_needs_table_invalidate () radix_enabled()/* Get the generic bits... */ #include <asm-generic/tlb.h>
arch/sparc/Kconfig +0 -1
@@ -65,7 +65,6 @@ config SPARC64 select HAVE_KRETPROBES select HAVE_KPROBES select HAVE_RCU_TABLE_FREE if SMP - select HAVE_RCU_TABLE_NO_INVALIDATE if HAVE_RCU_TABLE_FREE select HAVE_MEMBLOCK_NODE_MAP select HAVE_ARCH_TRANSPARENT_HUGEPAGE select HAVE_DYNAMIC_FTRACE
arch/sparc/include/asm/tlb_64.h +9 -0
@@ -28,6 +28,15 @@ void flush_tlb_pending(void);#define __tlb_remove_tlb_entry (tlb, ptep, address) do { } while (0)#define tlb_flush (tlb) flush_tlb_pending() +/* +* SPARC64's hardware TLB fill does not use the Linux page-tables +* and therefore we don't need a TLBI when freeing page-table pages. +*/ + +#ifdef CONFIG_HAVE_RCU_TABLE_FREE +#define tlb_needs_table_invalidate () (false) +#endif +#include <asm-generic/tlb.h> #endif /* _SPARC64_TLB_H */
include/asm-generic/tlb.h +15 -7
@@ -137,13 +137,6 @@* When used, an architecture is expected to provide __tlb_remove_table() * which does the actual freeing of these pages. * -* HAVE_RCU_TABLE_NO_INVALIDATE -* -* This makes HAVE_RCU_TABLE_FREE avoid calling tlb_flush_mmu_tlbonly() before -* freeing the page-table pages. This can be avoided if you use -* HAVE_RCU_TABLE_FREE and your architecture does _NOT_ use the Linux -* page-tables natively. -* * MMU_GATHER_NO_RANGE * * Use this if your architecture lacks an efficient flush_tlb_range().
@@ -189,8 +182,23 @@ struct mmu_table_batch {extern void tlb_remove_table (struct mmu_gather *tlb,void *table); +/* +* This allows an architecture that does not use the linux page-tables for +* hardware to skip the TLBI when freeing page tables. +*/ +#ifndef tlb_needs_table_invalidate +#define tlb_needs_table_invalidate () (true) +#endif + +#else + +#ifdef tlb_needs_table_invalidate +#error tlb_needs_table_invalidate() requires HAVE_RCU_TABLE_FREE#endif +#endif /* CONFIG_HAVE_RCU_TABLE_FREE */ + +#ifndef CONFIG_HAVE_MMU_GATHER_NO_GATHER /* * If we can't allocate a page to make a big batch of page pointers
mm/mmu_gather.c +8 -8
@@ -102,14 +102,14 @@ bool __tlb_remove_page_size(struct mmu_gather *tlb, struct page *page, int page_*/ static inline void tlb_table_invalidate (struct mmu_gather *tlb) { -#ifndef CONFIG_HAVE_RCU_TABLE_NO_INVALIDATE -/* -* Invalidate page-table caches used by hardware walkers. Then we still -* need to RCU-sched wait while freeing the pages because software -* walkers can still be in-flight. -*/ -tlb_flush_mmu_tlbonly (tlb); -#endif +if (tlb_needs_table_invalidate ()) { +/* +* Invalidate page-table caches used by hardware walkers. Then +* we still need to RCU-sched wait while freeing the pages +* because software walkers can still be in-flight. +*/ +tlb_flush_mmu_tlbonly (tlb); + } }static void tlb_remove_table_smp_sync (void *arg)
Signature · 1 line
2.24.1
Re: [PATCH v4 2/9] mm/mmu_gather: Invalidate TLB correctly on batch allocation failure and flush
Quoted 15 lines · Aneesh Kumar K.V
From: Peter Zijlstra <[email protected]>
Architectures for which we have hardware walkers of Linux page table should flush TLB on mmu gather batch allocation failures and batch flush. Some architectures like POWER supports multiple translation modes (hash and radix) and in the case of POWER only radix translation mode needs the above TLBI. This is because for hash translation mode kernel wants to avoid this extra flush since there are no hardware walkers of linux page table. With radix translation, the hardware also walks linux page table and with that, kernel needs to make sure to TLB invalidate page walk cache before page table pages are freed.
More details in
commit:d86564a2f085("mm/tlb, x86/mm: Support invalidating TLB caches forRCU_TABLE_FREE")
Quoted 8 lines
The changes to sparc are to make sure we keep the old behavior since we are now removing
HAVE_RCU_TABLE_NO_INVALIDATE. The default value fortlb_needs_table_invalidateis to always force an invalidate and sparc can avoid the table invalidate. Hence we definetlb_needs_table_invalidateto false for sparc architecture.Cc <[email protected]>Fixes a46cc7a90fd8 ("powerpc/mm/radix: Improve TLB/PWC flushes")
Which went into v4.14, so I like to use:
Quoted 11 lines
Signed-off-by Peter Zijlstra (Intel) <[email protected]Signed-off-by Aneesh Kumar K.V <[email protected]>--- arch/Kconfig | 3 --- arch/powerpc/Kconfig | 1 - arch/powerpc/include/asm/tlb.h | 11 +++++++++++ arch/sparc/Kconfig | 1 - arch/sparc/include/asm/tlb_64.h | 9 +++++++++ include/asm-generic/tlb.h | 22 +++++++++++++++------- mm/mmu_gather.c | 16 ++++++++-------- 7 files changed, 43 insertions(+), 20 deletions(-)
cheers
Quoted 151 lines
arch/Kconfig +0
-3@@ -396,9 +396,6 @@ config HAVE_ARCH_JUMP_LABEL_RELATIVE config HAVE_RCU_TABLE_FREE bool -config HAVE_RCU_TABLE_NO_INVALIDATE - bool - config HAVE_MMU_GATHER_PAGE_SIZE boolarch/powerpc/Kconfig +0
-1@@ -223,7 +223,6 @@ config PPC select HAVE_PERF_REGS select HAVE_PERF_USER_STACK_DUMP select HAVE_RCU_TABLE_FREE - select HAVE_RCU_TABLE_NO_INVALIDATE if HAVE_RCU_TABLE_FREE select HAVE_MMU_GATHER_PAGE_SIZE select HAVE_REGS_AND_STACK_ACCESS_API select HAVE_RELIABLE_STACKTRACE if PPC_BOOK3S_64 && CPU_LITTLE_ENDIANarch/powerpc/include/asm/tlb.h +11
-0@@ -26,6 +26,17 @@#define tlb_flush tlb_flushextern void tlb_flush (struct mmu_gather *tlb); +/* +* book3s: +* Hash does not use the linux page-tables, so we can avoid +* the TLB invalidate for page-table freeing, Radix otoh does use the +* page-tables and needs the TLBI. +* +* nohash: +* We still do TLB invalidate in the __pte_free_tlb routine before we +* add the page table pages to mmu gather table batch. +*/ +#define tlb_needs_table_invalidate () radix_enabled()/* Get the generic bits... */ #include <asm-generic/tlb.h> arch/sparc/Kconfig +0
-1@@ -65,7 +65,6 @@ config SPARC64 select HAVE_KRETPROBES select HAVE_KPROBES select HAVE_RCU_TABLE_FREE if SMP - select HAVE_RCU_TABLE_NO_INVALIDATE if HAVE_RCU_TABLE_FREE select HAVE_MEMBLOCK_NODE_MAP select HAVE_ARCH_TRANSPARENT_HUGEPAGE select HAVE_DYNAMIC_FTRACEarch/sparc/include/asm/tlb_64.h +9
-0@@ -28,6 +28,15 @@ void flush_tlb_pending(void);#define __tlb_remove_tlb_entry (tlb, ptep, address) do { } while (0)#define tlb_flush (tlb) flush_tlb_pending() +/* +* SPARC64's hardware TLB fill does not use the Linux page-tables +* and therefore we don't need a TLBI when freeing page-table pages. +*/ + +#ifdef CONFIG_HAVE_RCU_TABLE_FREE +#define tlb_needs_table_invalidate () (false) +#endif +#include <asm-generic/tlb.h> #endif /* _SPARC64_TLB_H */ include/asm-generic/tlb.h +15
-7@@ -137,13 +137,6 @@* When used, an architecture is expected to provide __tlb_remove_table() * which does the actual freeing of these pages. * -* HAVE_RCU_TABLE_NO_INVALIDATE -* -* This makes HAVE_RCU_TABLE_FREE avoid calling tlb_flush_mmu_tlbonly() before -* freeing the page-table pages. This can be avoided if you use -* HAVE_RCU_TABLE_FREE and your architecture does _NOT_ use the Linux -* page-tables natively. -* * MMU_GATHER_NO_RANGE * * Use this if your architecture lacks an efficient flush_tlb_range(). @@ -189,8 +182,23 @@ struct mmu_table_batch {extern void tlb_remove_table (struct mmu_gather *tlb,void *table); +/* +* This allows an architecture that does not use the linux page-tables for +* hardware to skip the TLBI when freeing page tables. +*/ +#ifndef tlb_needs_table_invalidate +#define tlb_needs_table_invalidate () (true) +#endif + +#else + +#ifdef tlb_needs_table_invalidate +#error tlb_needs_table_invalidate() requires HAVE_RCU_TABLE_FREE#endif +#endif /* CONFIG_HAVE_RCU_TABLE_FREE */ + +#ifndef CONFIG_HAVE_MMU_GATHER_NO_GATHER /* * If we can't allocate a page to make a big batch of page pointers mm/mmu_gather.c +8
-8@@ -102,14 +102,14 @@ bool __tlb_remove_page_size(struct mmu_gather *tlb, struct page *page, int page_*/ static inline void tlb_table_invalidate (struct mmu_gather *tlb) { -#ifndef CONFIG_HAVE_RCU_TABLE_NO_INVALIDATE -/* -* Invalidate page-table caches used by hardware walkers. Then we still -* need to RCU-sched wait while freeing the pages because software -* walkers can still be in-flight. -*/ -tlb_flush_mmu_tlbonly (tlb); -#endif +if (tlb_needs_table_invalidate ()) { +/* +* Invalidate page-table caches used by hardware walkers. Then +* we still need to RCU-sched wait while freeing the pages +* because software walkers can still be in-flight. +*/ +tlb_flush_mmu_tlbonly (tlb); + } }static void tlb_remove_table_smp_sync (void *arg)Signature · 1 line
2.24.1
PATCH v4 3/9 asm-generic/tlb: Avoid potential double flush
In reply to Aneesh Kumar K.VFrom: Peter Zijlstra <[email protected]>
Aneesh reported that:
tlb_flush_mmu() tlb_flush_mmu_tlbonly() tlb_flush() <-- #1 tlb_flush_mmu_free() tlb_table_flush() tlb_table_invalidate() tlb_flush_mmu_tlbonly() tlb_flush() <-- #2
does two TLBIs when tlb->fullmm, because __tlb_reset_range() will not clear tlb->end in that case.
Observe that any caller to __tlb_adjust_range() also sets at least one of the tlb->freed_tables || tlb->cleared_p* bits, and those are unconditionally cleared by __tlb_reset_range().
Change the condition for actually issuing TLBI to having one of those bits set, as opposed to having tlb->end != 0.
--- include/asm-generic/tlb.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
include/asm-generic/tlb.h +6 -1
@@ -402,7 +402,12 @@ tlb_update_vma_flags(struct mmu_gather *tlb, struct vm_area_struct *vma) { }static inline void tlb_flush_mmu_tlbonly (struct mmu_gather *tlb) { -if (!tlb->end) +/* +* Anything calling __tlb_adjust_range() also sets at least one of +* these bits. +*/ +if (!(tlb->freed_tables || tlb->cleared_ptes || tlb->cleared_pmds || + tlb->cleared_puds || tlb->cleared_p4ds))return ;tlb_flush (tlb);
Signature · 1 line
2.24.1
Re: [PATCH v4 3/9] asm-generic/tlb: Avoid potential double flush
Quoted 16 lines · Aneesh Kumar K.V
From: Peter Zijlstra <[email protected]>
Aneesh reported that:
tlb_flush_mmu() tlb_flush_mmu_tlbonly() tlb_flush() <-- #1 tlb_flush_mmu_free() tlb_table_flush() tlb_table_invalidate() tlb_flush_mmu_tlbonly() tlb_flush() <-- #2does two TLBIs when
tlb->fullmm, because__tlb_reset_range()will not cleartlb->endin that case.
Quoted 7 lines
Observe that any caller to
__tlb_adjust_range()also sets at least one of thetlb->freed_tables|| tlb->cleared_p* bits, and those are unconditionally cleared by__tlb_reset_range().Change the condition for actually issuing TLBI to having one of those bits set, as opposed to having
tlb->end!= 0.
We should possibly get this to stable too along with the first two patches. I am not quiet sure if this will qualify for a stable backport. Hence avoided adding Cc:[email protected]
Quoted 26 lines
Reported-by "Aneesh Kumar K.V" <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>Signed-off-by Aneesh Kumar K.V <[email protected]>--- include/asm-generic/tlb.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)include/asm-generic/tlb.h +6
-1@@ -402,7 +402,12 @@ tlb_update_vma_flags(struct mmu_gather *tlb, struct vm_area_struct *vma) { }static inline void tlb_flush_mmu_tlbonly (struct mmu_gather *tlb) { -if (!tlb->end) +/* +* Anything calling __tlb_adjust_range() also sets at least one of +* these bits. +*/ +if (!(tlb->freed_tables || tlb->cleared_ptes || tlb->cleared_pmds || + tlb->cleared_puds || tlb->cleared_p4ds))return ;tlb_flush (tlb);
Andrew Morton
maintainerRe: [PATCH v4 3/9] asm-generic/tlb: Avoid potential double flush
Quoted 21 lines · On Thu, 16 Jan 2020 12:19:59 +0530 "Aneesh Kumar K.V"…
Quoted 20 lines · Aneesh Kumar K.V
From: Peter Zijlstra <[email protected]>
Aneesh reported that:
tlb_flush_mmu() tlb_flush_mmu_tlbonly() tlb_flush() <-- #1 tlb_flush_mmu_free() tlb_table_flush() tlb_table_invalidate() tlb_flush_mmu_tlbonly() tlb_flush() <-- #2does two TLBIs when
tlb->fullmm, because__tlb_reset_range()will not cleartlb->endin that case.Observe that any caller to
__tlb_adjust_range()also sets at least one of thetlb->freed_tables|| tlb->cleared_p* bits, and those are unconditionally cleared by__tlb_reset_range().
Quoted 8 lines
Quoted 3 lines
Change the condition for actually issuing TLBI to having one of those bits set, as opposed to having
tlb->end!= 0.We should possibly get this to stable too along with the first two patches. I am not quiet sure if this will qualify for a stable backport. Hence avoided adding Cc:[email protected]
I'm not seeing any description of the user-visible runtime effects. Always needed, especially for -stable, please.
It appears to be a small performance benefit? If that benefit was "large" and measurements were presented then that would be something we might wish to backport.
PATCH v4 4/9 asm-gemeric/tlb: Remove stray function declarations
In reply to Aneesh Kumar K.VFrom: Peter Zijlstra <[email protected]>
We removed the actual functions a while ago.
--- include/asm-generic/tlb.h | 4 ---- 1 file changed, 4 deletions(-)
include/asm-generic/tlb.h +0 -4
@@ -285,11 +285,7 @@ struct mmu_gather {#endif }; -void arch_tlb_gather_mmu (struct mmu_gather *tlb, -struct mm_struct *mm,unsigned long start,unsigned long end);void tlb_flush_mmu (struct mmu_gather *tlb); -void arch_tlb_finish_mmu (struct mmu_gather *tlb, -unsigned long start,unsigned long end,bool force); static inline void __tlb_adjust_range(struct mmu_gather *tlb, unsigned long address,
Signature · 1 line
2.24.1
PATCH v4 5/9 asm-generic/tlb: Add missing CONFIG symbol
In reply to Aneesh Kumar K.VFrom: Peter Zijlstra <[email protected]>
Without this the symbol will not actually end up in .config files.
--- arch/Kconfig | 3 +++ 1 file changed, 3 insertions(+)
arch/Kconfig +3 -0
@@ -399,6 +399,9 @@ config HAVE_RCU_TABLE_FREE config HAVE_MMU_GATHER_PAGE_SIZE bool +config MMU_GATHER_NO_RANGE + bool + config HAVE_MMU_GATHER_NO_GATHER bool
Signature · 1 line
2.24.1
PATCH v4 6/9 asm-generic/tlb: Rename HAVE_RCU_TABLE_FREE
In reply to Aneesh Kumar K.VFrom: Peter Zijlstra <[email protected]>
Towards a more consistent naming scheme.
--- arch/Kconfig | 2 +- arch/arm/Kconfig | 2 +- arch/arm/include/asm/tlb.h | 2 +- arch/arm64/Kconfig | 2 +- arch/powerpc/Kconfig | 2 +- arch/s390/Kconfig | 2 +- arch/sparc/Kconfig | 2 +- arch/sparc/include/asm/tlb_64.h | 2 +- arch/x86/Kconfig | 2 +- arch/x86/include/asm/tlb.h | 4 ++-- include/asm-generic/tlb.h | 10 +++++----- mm/gup.c | 2 +- mm/mmu_gather.c | 8 ++++---- 13 files changed, 21 insertions(+), 21 deletions(-)
arch/Kconfig +1 -1
@@ -393,7 +393,7 @@ config HAVE_ARCH_JUMP_LABEL config HAVE_ARCH_JUMP_LABEL_RELATIVE bool -config HAVE_RCU_TABLE_FREE +config MMU_GATHER_RCU_TABLE_FREE bool config HAVE_MMU_GATHER_PAGE_SIZE
arch/arm/Kconfig +1 -1
@@ -102,7 +102,7 @@ config ARM select HAVE_PERF_EVENTS select HAVE_PERF_REGS select HAVE_PERF_USER_STACK_DUMP - select HAVE_RCU_TABLE_FREE if SMP && ARM_LPAE + select MMU_GATHER_RCU_TABLE_FREE if SMP && ARM_LPAE select HAVE_REGS_AND_STACK_ACCESS_API select HAVE_RSEQ select HAVE_STACKPROTECTOR
arch/arm/include/asm/tlb.h +1 -1
@@ -37,7 +37,7 @@ static inline void __tlb_remove_table(void *_table)#include <asm-generic/tlb.h> -#ifndef CONFIG_HAVE_RCU_TABLE_FREE +#ifndef CONFIG_MMU_GATHER_RCU_TABLE_FREE #define tlb_remove_table (tlb, entry) tlb_remove_page(tlb, entry)#endif
arch/arm64/Kconfig +1 -1
@@ -162,7 +162,7 @@ config ARM64 select HAVE_PERF_USER_STACK_DUMP select HAVE_REGS_AND_STACK_ACCESS_API select HAVE_FUNCTION_ARG_ACCESS_API - select HAVE_RCU_TABLE_FREE + select MMU_GATHER_RCU_TABLE_FREE select HAVE_RSEQ select HAVE_STACKPROTECTOR select HAVE_SYSCALL_TRACEPOINTS
arch/powerpc/Kconfig +1 -1
@@ -222,7 +222,7 @@ config PPC select HAVE_HARDLOCKUP_DETECTOR_PERF if PERF_EVENTS && HAVE_PERF_EVENTS_NMI && !HAVE_HARDLOCKUP_DETECTOR_ARCH select HAVE_PERF_REGS select HAVE_PERF_USER_STACK_DUMP - select HAVE_RCU_TABLE_FREE + select MMU_GATHER_RCU_TABLE_FREE select HAVE_MMU_GATHER_PAGE_SIZE select HAVE_REGS_AND_STACK_ACCESS_API select HAVE_RELIABLE_STACKTRACE if PPC_BOOK3S_64 && CPU_LITTLE_ENDIAN
arch/s390/Kconfig +1 -1
@@ -169,7 +169,7 @@ config S390 select HAVE_OPROFILE select HAVE_PCI select HAVE_PERF_EVENTS - select HAVE_RCU_TABLE_FREE + select MMU_GATHER_RCU_TABLE_FREE select HAVE_REGS_AND_STACK_ACCESS_API select HAVE_RELIABLE_STACKTRACE select HAVE_RSEQ
arch/sparc/Kconfig +1 -1
@@ -64,7 +64,7 @@ config SPARC64 select HAVE_FUNCTION_GRAPH_TRACER select HAVE_KRETPROBES select HAVE_KPROBES - select HAVE_RCU_TABLE_FREE if SMP + select MMU_GATHER_RCU_TABLE_FREE select HAVE_MEMBLOCK_NODE_MAP select HAVE_ARCH_TRANSPARENT_HUGEPAGE select HAVE_DYNAMIC_FTRACE
arch/sparc/include/asm/tlb_64.h +1 -1
@@ -33,7 +33,7 @@ void flush_tlb_pending(void);* and therefore we don't need a TLBI when freeing page-table pages. */ -#ifdef CONFIG_HAVE_RCU_TABLE_FREE +#ifdef CONFIG_MMU_GATHER_RCU_TABLE_FREE #define tlb_needs_table_invalidate () (false)#endif
arch/x86/Kconfig +1 -1
@@ -200,7 +200,7 @@ config X86 select HAVE_PCI select HAVE_PERF_REGS select HAVE_PERF_USER_STACK_DUMP - select HAVE_RCU_TABLE_FREE if PARAVIRT + select MMU_GATHER_RCU_TABLE_FREE if PARAVIRT select HAVE_REGS_AND_STACK_ACCESS_API select HAVE_RELIABLE_STACKTRACE if X86_64 && (UNWINDER_FRAME_POINTER || UNWINDER_ORC) && STACK_VALIDATION select HAVE_FUNCTION_ARG_ACCESS_API
arch/x86/include/asm/tlb.h +2 -2
@@ -29,8 +29,8 @@ static inline void tlb_flush(struct mmu_gather *tlb)* shootdown, enablement code for several hypervisors overrides * .flush_tlb_others hook in pv_mmu_ops and implements it by issuing * a hypercall. To keep software pagetable walkers safe in this case we -* switch to RCU based table free (HAVE_RCU_TABLE_FREE). See the comment -* below 'ifdef CONFIG_HAVE_RCU_TABLE_FREE' in include/asm-generic/tlb.h +* switch to RCU based table free (MMU_GATHER_RCU_TABLE_FREE). See the comment +* below 'ifdef CONFIG_MMU_GATHER_RCU_TABLE_FREE' in include/asm-generic/tlb.h * for more details. */ static inline void __tlb_remove_table (void *table)
include/asm-generic/tlb.h +5 -5
@@ -126,7 +126,7 @@* This ensures we call tlb_flush() every time tlb_change_page_size() actually * changes the size and provides mmu_gather::page_size to tlb_flush(). * -* HAVE_RCU_TABLE_FREE +* MMU_GATHER_RCU_TABLE_FREE * * This provides tlb_remove_table(), to be used instead of tlb_remove_page() * for page directores (__p*_free_tlb()). This provides separate freeing of
@@ -142,7 +142,7 @@* Use this if your architecture lacks an efficient flush_tlb_range(). */ -#ifdef CONFIG_HAVE_RCU_TABLE_FREE +#ifdef CONFIG_MMU_GATHER_RCU_TABLE_FREE /* * Semi RCU freeing of the page directories. *
@@ -193,10 +193,10 @@ extern void tlb_remove_table(struct mmu_gather *tlb, void *table);#else #ifdef tlb_needs_table_invalidate -#error tlb_needs_table_invalidate() requires HAVE_RCU_TABLE_FREE +#error tlb_needs_table_invalidate() requires MMU_GATHER_RCU_TABLE_FREE#endif -#endif /* CONFIG_HAVE_RCU_TABLE_FREE */ +#endif /* CONFIG_MMU_GATHER_RCU_TABLE_FREE */ #ifndef CONFIG_HAVE_MMU_GATHER_NO_GATHER
@@ -235,7 +235,7 @@ extern bool __tlb_remove_page_size(struct mmu_gather *tlb, struct page *page,struct mmu_gather {struct mm_struct *mm; -#ifdef CONFIG_HAVE_RCU_TABLE_FREE +#ifdef CONFIG_MMU_GATHER_RCU_TABLE_FREE struct mmu_table_batch *batch;#endif
mm/gup.c +1 -1
@@ -1729,7 +1729,7 @@ EXPORT_SYMBOL(get_user_pages_unlocked);* Before activating this code, please be aware that the following assumptions * are currently made: * -* *) Either HAVE_RCU_TABLE_FREE is enabled, and tlb_remove_table() is used to +* *) Either MMU_GATHER_RCU_TABLE_FREE is enabled, and tlb_remove_table() is used to * free pages containing page tables or TLB flushing requires IPI broadcast. * * *) ptes can be read atomically by the architecture.
mm/mmu_gather.c +4 -4
@@ -91,7 +91,7 @@ bool __tlb_remove_page_size(struct mmu_gather *tlb, struct page *page, int page_#endif /* HAVE_MMU_GATHER_NO_GATHER */ -#ifdef CONFIG_HAVE_RCU_TABLE_FREE +#ifdef CONFIG_MMU_GATHER_RCU_TABLE_FREE /* * See the comment near struct mmu_table_batch.
@@ -173,11 +173,11 @@ void tlb_remove_table(struct mmu_gather *tlb, void *table) tlb_table_flush(tlb); } -#endif /* CONFIG_HAVE_RCU_TABLE_FREE */ +#endif /* CONFIG_MMU_GATHER_RCU_TABLE_FREE */ static void tlb_flush_mmu_free (struct mmu_gather *tlb) { -#ifdef CONFIG_HAVE_RCU_TABLE_FREE +#ifdef CONFIG_MMU_GATHER_RCU_TABLE_FREE tlb_table_flush (tlb);#endif #ifndef CONFIG_HAVE_MMU_GATHER_NO_GATHER
@@ -220,7 +220,7 @@ void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, tlb->batch_count =0 ;#endif -#ifdef CONFIG_HAVE_RCU_TABLE_FREE +#ifdef CONFIG_MMU_GATHER_RCU_TABLE_FREE tlb->batch =NULL ;#endif #ifdef CONFIG_HAVE_MMU_GATHER_PAGE_SIZE
Signature · 1 line
2.24.1
kbuild test robot
build botRe: [PATCH v4 6/9] asm-generic/tlb: Rename HAVE_RCU_TABLE_FREE
I love your patch! Yet something to improve:
Hi "Aneesh,
I love your patch! Yet something to improve:
[auto build test ERROR on powerpc/next]
[also build test ERROR on asm-generic/master sparc/master linus/master v5.5-rc6 next-20200117] [cannot apply to sparc-next/master]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Aneesh-Kumar-K-V/Fixup-page-directory-freeing/20200117-131601 base: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next config: sparc64-allnoconfig (attached as .config) compiler: sparc64-linux-gcc (GCC) 7.5.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.5.0 make.cross ARCH=sparc64
If you fix the issue, kindly add following tag
All errors (new ones prefixed by >>):
mm/mmu_gather.c: In function 'tlb_remove_table_one':
>> mm/mmu_gather.c:130:2: error: implicit declaration of function '__tlb_remove_table'; did you mean 'tlb_remove_table'? [-Werror=implicit-function-declaration]
__tlb_remove_table(table);
^~~~~~~~~~~~~~~~~~
tlb_remove_tablecc1: some warnings being treated as errors
vim +130 mm/mmu_gather.c
196d9d8bb71dea Peter Zijlstra 2018-09-03 119
196d9d8bb71dea Peter Zijlstra 2018-09-03 120 static void tlb_remove_table_one(void *table)
196d9d8bb71dea Peter Zijlstra 2018-09-03 121 {
196d9d8bb71dea Peter Zijlstra 2018-09-03 122 /*
196d9d8bb71dea Peter Zijlstra 2018-09-03 123 * This isn't an RCU grace period and hence the page-tables cannot be
196d9d8bb71dea Peter Zijlstra 2018-09-03 124 * assumed to be actually RCU-freed.
196d9d8bb71dea Peter Zijlstra 2018-09-03 125 *
196d9d8bb71dea Peter Zijlstra 2018-09-03 126 * It is however sufficient for software page-table walkers that rely on
196d9d8bb71dea Peter Zijlstra 2018-09-03 127 * IRQ disabling. See the comment near struct mmu_table_batch.
196d9d8bb71dea Peter Zijlstra 2018-09-03 128 */
196d9d8bb71dea Peter Zijlstra 2018-09-03 129 smp_call_function(tlb_remove_table_smp_sync, NULL, 1);196d9d8bb71dea Peter Zijlstra 2018-09-03 @130 __tlb_remove_table(table);196d9d8bb71dea Peter Zijlstra 2018-09-03 131 }196d9d8bb71dea Peter Zijlstra 2018-09-03 132
:::::: The code at line 130 was first introduced by commit
:::::: 196d9d8bb71deaa2d1c7170c88a2f1a318363047 mm/memory: Move mmu_gather and TLB invalidation code into its own file
:::::: TO: Peter Zijlstra <[email protected]>
:::::: CC: Will Deacon <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org Intel Corporation
Re: [PATCH v4 6/9] asm-generic/tlb: Rename HAVE_RCU_TABLE_FREE
In reply to Aneesh Kumar K.VQuoted 6 lines · Aneesh Kumar K.V
From: Peter Zijlstra <[email protected]>
Towards a more consistent naming scheme.
Signed-off-by Peter Zijlstra (Intel) <[email protected]>Signed-off-by Aneesh Kumar K.V <[email protected]>
...
arch/sparc/Kconfig config SPARC64 · line 70
Quoted 13 lines
arch/sparc/Kconfig +1
-1@@ -64,7 +64,7 @@ config SPARC64 select HAVE_FUNCTION_GRAPH_TRACER select HAVE_KRETPROBES select HAVE_KPROBES - select HAVE_RCU_TABLE_FREE if SMP + select MMU_GATHER_RCU_TABLE_FREE select HAVE_MEMBLOCK_NODE_MAP select HAVE_ARCH_TRANSPARENT_HUGEPAGE select HAVE_DYNAMIC_FTRACE
This resulted in build failure reported by kbuild test robot. Can we fold the below change
arch/sparc/Kconfig +1 -1
@@ -64,7 +64,7 @@ config SPARC64 select HAVE_FUNCTION_GRAPH_TRACER select HAVE_KRETPROBES select HAVE_KPROBES - select MMU_GATHER_RCU_TABLE_FREE + select MMU_GATHER_RCU_TABLE_FREE if SMP select HAVE_MEMBLOCK_NODE_MAP select HAVE_ARCH_TRANSPARENT_HUGEPAGE select HAVE_DYNAMIC_FTRACE
We should handle that drop of SMP in a separate patch if needed.
-aneesh
PATCH v4 7/9 asm-generic/tlb: Rename HAVE_MMU_GATHER_PAGE_SIZE
In reply to Aneesh Kumar K.VFrom: Peter Zijlstra <[email protected]>
Towards a more consistent naming scheme.
--- arch/Kconfig | 2 +- arch/powerpc/Kconfig | 2 +- include/asm-generic/tlb.h | 9 ++++++--- mm/mmu_gather.c | 4 ++-- 4 files changed, 10 insertions(+), 7 deletions(-)
arch/Kconfig +1 -1
@@ -396,7 +396,7 @@ config HAVE_ARCH_JUMP_LABEL_RELATIVE config MMU_GATHER_RCU_TABLE_FREE bool -config HAVE_MMU_GATHER_PAGE_SIZE +config MMU_GATHER_PAGE_SIZE bool config MMU_GATHER_NO_RANGE
arch/powerpc/Kconfig +1 -1
@@ -223,7 +223,7 @@ config PPC select HAVE_PERF_REGS select HAVE_PERF_USER_STACK_DUMP select MMU_GATHER_RCU_TABLE_FREE - select HAVE_MMU_GATHER_PAGE_SIZE + select MMU_GATHER_PAGE_SIZE select HAVE_REGS_AND_STACK_ACCESS_API select HAVE_RELIABLE_STACKTRACE if PPC_BOOK3S_64 && CPU_LITTLE_ENDIAN select HAVE_SYSCALL_TRACEPOINTS
include/asm-generic/tlb.h +6 -3
@@ -121,11 +121,14 @@* * Additionally there are a few opt-in features: * -* HAVE_MMU_GATHER_PAGE_SIZE +* MMU_GATHER_PAGE_SIZE * * This ensures we call tlb_flush() every time tlb_change_page_size() actually * changes the size and provides mmu_gather::page_size to tlb_flush(). * +* This might be useful if your architecture has size specific TLB +* invalidation instructions. +* * MMU_GATHER_RCU_TABLE_FREE * * This provides tlb_remove_table(), to be used instead of tlb_remove_page()
@@ -279,7 +282,7 @@ struct mmu_gather {struct mmu_gather_batch local;struct page *__pages[MMU_GATHER_BUNDLE ]; -#ifdef CONFIG_HAVE_MMU_GATHER_PAGE_SIZE +#ifdef CONFIG_MMU_GATHER_PAGE_SIZE unsigned int page_size;#endif #endif
@@ -435,7 +438,7 @@ static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)static inline void tlb_change_page_size (struct mmu_gather *tlb,unsigned int page_size) { -#ifdef CONFIG_HAVE_MMU_GATHER_PAGE_SIZE +#ifdef CONFIG_MMU_GATHER_PAGE_SIZE if (tlb->page_size && tlb->page_size != page_size) {if (!tlb->fullmm && !tlb->need_flush_all)tlb_flush_mmu (tlb);
mm/mmu_gather.c +2 -2
@@ -69,7 +69,7 @@ bool __tlb_remove_page_size(struct mmu_gather *tlb, struct page *page, int page_VM_BUG_ON (!tlb->end); -#ifdef CONFIG_HAVE_MMU_GATHER_PAGE_SIZE +#ifdef CONFIG_MMU_GATHER_PAGE_SIZE VM_WARN_ON (tlb->page_size != page_size);#endif
@@ -223,7 +223,7 @@ void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm,#ifdef CONFIG_MMU_GATHER_RCU_TABLE_FREE tlb->batch =NULL ;#endif -#ifdef CONFIG_HAVE_MMU_GATHER_PAGE_SIZE +#ifdef CONFIG_MMU_GATHER_PAGE_SIZE tlb->page_size =0 ;#endif
Signature · 1 line
2.24.1
PATCH v4 8/9 asm-generic/tlb: Rename HAVE_MMU_GATHER_NO_GATHER
In reply to Aneesh Kumar K.VFrom: Peter Zijlstra <[email protected]>
Towards a more consistent naming scheme.
--- arch/Kconfig | 2 +- arch/s390/Kconfig | 2 +- include/asm-generic/tlb.h | 14 ++++++++++++-- mm/mmu_gather.c | 10 +++++----- 4 files changed, 19 insertions(+), 9 deletions(-)
arch/Kconfig +1 -1
@@ -402,7 +402,7 @@ config MMU_GATHER_PAGE_SIZE config MMU_GATHER_NO_RANGE bool -config HAVE_MMU_GATHER_NO_GATHER +config MMU_GATHER_NO_GATHER bool config ARCH_HAVE_NMI_SAFE_CMPXCHG
arch/s390/Kconfig +1 -1
@@ -163,7 +163,7 @@ config S390 select HAVE_PERF_USER_STACK_DUMP select HAVE_MEMBLOCK_NODE_MAP select HAVE_MEMBLOCK_PHYS_MAP - select HAVE_MMU_GATHER_NO_GATHER + select MMU_GATHER_NO_GATHER select HAVE_MOD_ARCH_SPECIFIC select HAVE_NOP_MCOUNT select HAVE_OPROFILE
include/asm-generic/tlb.h +12 -2
@@ -143,6 +143,16 @@* MMU_GATHER_NO_RANGE * * Use this if your architecture lacks an efficient flush_tlb_range(). +* +* MMU_GATHER_NO_GATHER +* +* If the option is set the mmu_gather will not track individual pages for +* delayed page free anymore. A platform that enables the option needs to +* provide its own implementation of the __tlb_remove_page_size() function to +* free pages. +* +* This is useful if your architecture already flushes TLB entries in the +* various ptep_get_and_clear() functions. */ #ifdef CONFIG_MMU_GATHER_RCU_TABLE_FREE
@@ -202,7 +212,7 @@ extern void tlb_remove_table(struct mmu_gather *tlb, void *table);#endif /* CONFIG_MMU_GATHER_RCU_TABLE_FREE */ -#ifndef CONFIG_HAVE_MMU_GATHER_NO_GATHER +#ifndef CONFIG_MMU_GATHER_NO_GATHER /* * If we can't allocate a page to make a big batch of page pointers * to work on, then just handle a few from the on-stack structure.
@@ -277,7 +287,7 @@ struct mmu_gather {unsigned int batch_count; -#ifndef CONFIG_HAVE_MMU_GATHER_NO_GATHER +#ifndef CONFIG_MMU_GATHER_NO_GATHER struct mmu_gather_batch *active;struct mmu_gather_batch local;struct page *__pages[MMU_GATHER_BUNDLE ];
mm/mmu_gather.c +5 -5
@@ -11,7 +11,7 @@#include <asm/pgalloc.h> #include <asm/tlb.h> -#ifndef CONFIG_HAVE_MMU_GATHER_NO_GATHER +#ifndef CONFIG_MMU_GATHER_NO_GATHER static bool tlb_next_batch (struct mmu_gather *tlb) {
@@ -89,7 +89,7 @@ bool __tlb_remove_page_size(struct mmu_gather *tlb, struct page *page, int page_ return false; } -#endif /* HAVE_MMU_GATHER_NO_GATHER */ +#endif /* MMU_GATHER_NO_GATHER */ #ifdef CONFIG_MMU_GATHER_RCU_TABLE_FREE
@@ -180,7 +180,7 @@ static void tlb_flush_mmu_free(struct mmu_gather *tlb)#ifdef CONFIG_MMU_GATHER_RCU_TABLE_FREE tlb_table_flush (tlb);#endif -#ifndef CONFIG_HAVE_MMU_GATHER_NO_GATHER +#ifndef CONFIG_MMU_GATHER_NO_GATHER tlb_batch_pages_flush (tlb);#endif }
@@ -211,7 +211,7 @@ void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm,/* Is it from 0 to ~0? */ tlb->fullmm = !(start | (end+1 )); -#ifndef CONFIG_HAVE_MMU_GATHER_NO_GATHER +#ifndef CONFIG_MMU_GATHER_NO_GATHER tlb->need_flush_all =0 ; tlb->local.next =NULL ; tlb->local.nr =0 ;
@@ -271,7 +271,7 @@ void tlb_finish_mmu(struct mmu_gather *tlb,tlb_flush_mmu (tlb); -#ifndef CONFIG_HAVE_MMU_GATHER_NO_GATHER +#ifndef CONFIG_MMU_GATHER_NO_GATHER tlb_batch_list_free (tlb);#endif dec_tlb_flush_pending (tlb->mm);
Signature · 1 line
2.24.1
PATCH v4 9/9 asm-generic/tlb: Provide MMU_GATHER_TABLE_FREE
In reply to Aneesh Kumar K.VFrom: Peter Zijlstra <[email protected]>
As described in the comment, the correct order for freeing pages is:
1) unhook page
2) TLB invalidate page
3) free page
This order equally applies to page directories.
Currently there are two correct options:
- use tlb_remove_page(), when all page directores are full pages and there are no futher contraints placed by things like software walkers (HAVE_FAST_GUP).
- use MMU_GATHER_RCU_TABLE_FREE and tlb_remove_table() when the architecture does not do IPI based TLB invalidate and has HAVE_FAST_GUP (or software TLB fill).
This however leaves architectures that don't have page based directories but don't need RCU in a bind. For those, provide MMU_GATHER_TABLE_FREE, which provides the independent batching for directories without the additional RCU freeing.
--- arch/Kconfig | 5 ++ arch/arm/include/asm/tlb.h | 4 -- include/asm-generic/tlb.h | 72 +++++++++++----------- mm/mmu_gather.c | 120 +++++++++++++++++++++++++++---------- 4 files changed, 130 insertions(+), 71 deletions(-)
arch/Kconfig +5 -0
@@ -393,8 +393,12 @@ config HAVE_ARCH_JUMP_LABEL config HAVE_ARCH_JUMP_LABEL_RELATIVE bool +config MMU_GATHER_TABLE_FREE + bool + config MMU_GATHER_RCU_TABLE_FREE bool + select MMU_GATHER_TABLE_FREE config MMU_GATHER_PAGE_SIZE bool
@@ -404,6 +408,7 @@ config MMU_GATHER_NO_RANGE config MMU_GATHER_NO_GATHER bool + depends on MMU_GATHER_TABLE_FREE config ARCH_HAVE_NMI_SAFE_CMPXCHG bool
arch/arm/include/asm/tlb.h +0 -4
@@ -37,10 +37,6 @@ static inline void __tlb_remove_table(void *_table)#include <asm-generic/tlb.h> -#ifndef CONFIG_MMU_GATHER_RCU_TABLE_FREE -#define tlb_remove_table (tlb, entry) tlb_remove_page(tlb, entry) -#endif -static inline void __pte_free_tlb (struct mmu_gather *tlb,pgtable_t pte,unsigned long addr) {
include/asm-generic/tlb.h +37 -35
110 lines not on this page · raw message
mm/mmu_gather.c +88 -32
173 lines not on this page · raw message
Signature · 1 line
2.24.1