Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm: pgtable: introduce generic __tlb_remove_table()

Several architectures (arm, arm64, riscv and x86) define exactly the same
__tlb_remove_table(), just introduce generic __tlb_remove_table() to
eliminate these duplications.

The s390 __tlb_remove_table() is nearly the same, so also make s390
__tlb_remove_table() version generic.

Link: https://lkml.kernel.org/r/ea372633d94f4d3f9f56a7ec5994bf050bf77e39.1736317725.git.zhengqi.arch@bytedance.com
Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com>
Reviewed-by: Kevin Brodsky <kevin.brodsky@arm.com>
Acked-by: Andreas Larsson <andreas@gaisler.com> [sparc]
Acked-by: Alexander Gordeev <agordeev@linux.ibm.com> [s390]
Acked-by: Arnd Bergmann <arnd@arndb.de> [asm-generic]
Cc: Alexandre Ghiti <alex@ghiti.fr>
Cc: Alexandre Ghiti <alexghiti@rivosinc.com>
Cc: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jann Horn <jannh@google.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Mike Rapoport (Microsoft) <rppt@kernel.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vishal Moola (Oracle) <vishal.moola@gmail.com>
Cc: Will Deacon <will@kernel.org>
Cc: Yu Zhao <yuzhao@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Qi Zheng and committed by
Andrew Morton
2dccdf70 5550b3c5

+19 -59
-9
arch/arm/include/asm/tlb.h
··· 27 27 #else /* !CONFIG_MMU */ 28 28 29 29 #include <asm/tlbflush.h> 30 - 31 - static inline void __tlb_remove_table(void *_table) 32 - { 33 - struct ptdesc *ptdesc = (struct ptdesc *)_table; 34 - 35 - pagetable_dtor(ptdesc); 36 - pagetable_free(ptdesc); 37 - } 38 - 39 30 #include <asm-generic/tlb.h> 40 31 41 32 static inline void
-7
arch/arm64/include/asm/tlb.h
··· 10 10 11 11 #include <linux/pagemap.h> 12 12 13 - static inline void __tlb_remove_table(void *_table) 14 - { 15 - struct ptdesc *ptdesc = (struct ptdesc *)_table; 16 - 17 - pagetable_dtor(ptdesc); 18 - pagetable_free(ptdesc); 19 - } 20 13 21 14 #define tlb_flush tlb_flush 22 15 static void tlb_flush(struct mmu_gather *tlb);
+1
arch/powerpc/include/asm/tlb.h
··· 37 37 */ 38 38 #define tlb_needs_table_invalidate() radix_enabled() 39 39 40 + #define __HAVE_ARCH_TLB_REMOVE_TABLE 40 41 /* Get the generic bits... */ 41 42 #include <asm-generic/tlb.h> 42 43
-12
arch/riscv/include/asm/tlb.h
··· 10 10 11 11 static void tlb_flush(struct mmu_gather *tlb); 12 12 13 - #ifdef CONFIG_MMU 14 - 15 - static inline void __tlb_remove_table(void *table) 16 - { 17 - struct ptdesc *ptdesc = (struct ptdesc *)table; 18 - 19 - pagetable_dtor(ptdesc); 20 - pagetable_free(ptdesc); 21 - } 22 - 23 - #endif /* CONFIG_MMU */ 24 - 25 13 #define tlb_flush tlb_flush 26 14 #include <asm-generic/tlb.h> 27 15
+4 -5
arch/s390/include/asm/tlb.h
··· 22 22 * Pages used for the page tables is a different story. FIXME: more 23 23 */ 24 24 25 - void __tlb_remove_table(void *_table); 26 25 static inline void tlb_flush(struct mmu_gather *tlb); 27 26 static inline bool __tlb_remove_page_size(struct mmu_gather *tlb, 28 27 struct page *page, bool delay_rmap, int page_size); ··· 86 87 tlb->cleared_pmds = 1; 87 88 if (mm_alloc_pgste(tlb->mm)) 88 89 gmap_unlink(tlb->mm, (unsigned long *)pte, address); 89 - tlb_remove_ptdesc(tlb, pte); 90 + tlb_remove_ptdesc(tlb, virt_to_ptdesc(pte)); 90 91 } 91 92 92 93 /* ··· 105 106 tlb->mm->context.flush_mm = 1; 106 107 tlb->freed_tables = 1; 107 108 tlb->cleared_puds = 1; 108 - tlb_remove_ptdesc(tlb, pmd); 109 + tlb_remove_ptdesc(tlb, virt_to_ptdesc(pmd)); 109 110 } 110 111 111 112 /* ··· 123 124 __tlb_adjust_range(tlb, address, PAGE_SIZE); 124 125 tlb->mm->context.flush_mm = 1; 125 126 tlb->freed_tables = 1; 126 - tlb_remove_ptdesc(tlb, p4d); 127 + tlb_remove_ptdesc(tlb, virt_to_ptdesc(p4d)); 127 128 } 128 129 129 130 /* ··· 141 142 tlb->mm->context.flush_mm = 1; 142 143 tlb->freed_tables = 1; 143 144 tlb->cleared_p4ds = 1; 144 - tlb_remove_ptdesc(tlb, pud); 145 + tlb_remove_ptdesc(tlb, virt_to_ptdesc(pud)); 145 146 } 146 147 147 148
-7
arch/s390/mm/pgalloc.c
··· 193 193 pagetable_dtor_free(ptdesc); 194 194 } 195 195 196 - void __tlb_remove_table(void *table) 197 - { 198 - struct ptdesc *ptdesc = virt_to_ptdesc(table); 199 - 200 - pagetable_dtor_free(ptdesc); 201 - } 202 - 203 196 #ifdef CONFIG_TRANSPARENT_HUGEPAGE 204 197 static void pte_free_now(struct rcu_head *head) 205 198 {
+1
arch/sparc/include/asm/tlb_64.h
··· 33 33 #define tlb_needs_table_invalidate() (false) 34 34 #endif 35 35 36 + #define __HAVE_ARCH_TLB_REMOVE_TABLE 36 37 #include <asm-generic/tlb.h> 37 38 38 39 #endif /* _SPARC64_TLB_H */
-17
arch/x86/include/asm/tlb.h
··· 20 20 flush_tlb_mm_range(tlb->mm, start, end, stride_shift, tlb->freed_tables); 21 21 } 22 22 23 - /* 24 - * While x86 architecture in general requires an IPI to perform TLB 25 - * shootdown, enablement code for several hypervisors overrides 26 - * .flush_tlb_others hook in pv_mmu_ops and implements it by issuing 27 - * a hypercall. To keep software pagetable walkers safe in this case we 28 - * switch to RCU based table free (MMU_GATHER_RCU_TABLE_FREE). See the comment 29 - * below 'ifdef CONFIG_MMU_GATHER_RCU_TABLE_FREE' in include/asm-generic/tlb.h 30 - * for more details. 31 - */ 32 - static inline void __tlb_remove_table(void *table) 33 - { 34 - struct ptdesc *ptdesc = (struct ptdesc *)table; 35 - 36 - pagetable_dtor(ptdesc); 37 - pagetable_free(ptdesc); 38 - } 39 - 40 23 #ifdef CONFIG_PT_RECLAIM 41 24 static inline void __tlb_remove_table_one_rcu(struct rcu_head *head) 42 25 {
+13 -2
include/asm-generic/tlb.h
··· 153 153 * 154 154 * Useful if your architecture has non-page page directories. 155 155 * 156 - * When used, an architecture is expected to provide __tlb_remove_table() 157 - * which does the actual freeing of these pages. 156 + * When used, an architecture is expected to provide __tlb_remove_table() or 157 + * use the generic __tlb_remove_table(), which does the actual freeing of these 158 + * pages. 158 159 * 159 160 * MMU_GATHER_RCU_TABLE_FREE 160 161 * ··· 207 206 208 207 #define MAX_TABLE_BATCH \ 209 208 ((PAGE_SIZE - sizeof(struct mmu_table_batch)) / sizeof(void *)) 209 + 210 + #ifndef __HAVE_ARCH_TLB_REMOVE_TABLE 211 + static inline void __tlb_remove_table(void *table) 212 + { 213 + struct ptdesc *ptdesc = (struct ptdesc *)table; 214 + 215 + pagetable_dtor(ptdesc); 216 + pagetable_free(ptdesc); 217 + } 218 + #endif 210 219 211 220 extern void tlb_remove_table(struct mmu_gather *tlb, void *table); 212 221