On Mon, Dec 30, 2024 at 05:07:48PM +0800, Qi Zheng wrote: > 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. > > Signed-off-by: Qi Zheng <zhengqi.arch@xxxxxxxxxxxxx> > --- > arch/arm/include/asm/tlb.h | 9 --------- > arch/arm64/include/asm/tlb.h | 7 ------- > arch/powerpc/include/asm/tlb.h | 1 + > arch/riscv/include/asm/tlb.h | 12 ------------ > arch/s390/include/asm/tlb.h | 9 ++++----- > arch/s390/mm/pgalloc.c | 7 ------- > arch/sparc/include/asm/tlb_32.h | 1 + > arch/sparc/include/asm/tlb_64.h | 1 + > arch/x86/include/asm/tlb.h | 17 ----------------- > include/asm-generic/tlb.h | 15 +++++++++++++-- > 10 files changed, 20 insertions(+), 59 deletions(-) ... > diff --git a/arch/s390/include/asm/tlb.h b/arch/s390/include/asm/tlb.h > index 79df7c0932c56..da4a7d175f69c 100644 > --- a/arch/s390/include/asm/tlb.h > +++ b/arch/s390/include/asm/tlb.h > @@ -22,7 +22,6 @@ > * Pages used for the page tables is a different story. FIXME: more > */ > > -void __tlb_remove_table(void *_table); > static inline void tlb_flush(struct mmu_gather *tlb); > static inline bool __tlb_remove_page_size(struct mmu_gather *tlb, > struct page *page, bool delay_rmap, int page_size); > @@ -87,7 +86,7 @@ static inline void pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte, > tlb->cleared_pmds = 1; > if (mm_alloc_pgste(tlb->mm)) > gmap_unlink(tlb->mm, (unsigned long *)pte, address); > - tlb_remove_ptdesc(tlb, pte); > + tlb_remove_ptdesc(tlb, virt_to_ptdesc(pte)); > } > > /* > @@ -106,7 +105,7 @@ static inline void pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd, > tlb->mm->context.flush_mm = 1; > tlb->freed_tables = 1; > tlb->cleared_puds = 1; > - tlb_remove_ptdesc(tlb, pmd); > + tlb_remove_ptdesc(tlb, virt_to_ptdesc(pmd)); > } > > /* > @@ -124,7 +123,7 @@ static inline void pud_free_tlb(struct mmu_gather *tlb, pud_t *pud, > tlb->mm->context.flush_mm = 1; > tlb->freed_tables = 1; > tlb->cleared_p4ds = 1; > - tlb_remove_ptdesc(tlb, pud); > + tlb_remove_ptdesc(tlb, virt_to_ptdesc(pud)); > } > > /* > @@ -142,7 +141,7 @@ static inline void p4d_free_tlb(struct mmu_gather *tlb, p4d_t *p4d, > __tlb_adjust_range(tlb, address, PAGE_SIZE); > tlb->mm->context.flush_mm = 1; > tlb->freed_tables = 1; > - tlb_remove_ptdesc(tlb, p4d); > + tlb_remove_ptdesc(tlb, virt_to_ptdesc(p4d)); > } > > #endif /* _S390_TLB_H */ > diff --git a/arch/s390/mm/pgalloc.c b/arch/s390/mm/pgalloc.c > index c73b89811a264..3e002dea6278f 100644 > --- a/arch/s390/mm/pgalloc.c > +++ b/arch/s390/mm/pgalloc.c > @@ -193,13 +193,6 @@ void page_table_free(struct mm_struct *mm, unsigned long *table) > pagetable_dtor_free(ptdesc); > } > > -void __tlb_remove_table(void *table) > -{ > - struct ptdesc *ptdesc = virt_to_ptdesc(table); > - > - pagetable_dtor_free(ptdesc); > -} > - > #ifdef CONFIG_TRANSPARENT_HUGEPAGE > static void pte_free_now(struct rcu_head *head) > { ... > diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h > index 709830274b756..69de47c7ef3c5 100644 > --- a/include/asm-generic/tlb.h > +++ b/include/asm-generic/tlb.h > @@ -153,8 +153,9 @@ > * > * Useful if your architecture has non-page page directories. > * > - * When used, an architecture is expected to provide __tlb_remove_table() > - * which does the actual freeing of these pages. > + * When used, an architecture is expected to provide __tlb_remove_table() or > + * use the generic __tlb_remove_table(), which does the actual freeing of these > + * pages. > * > * MMU_GATHER_RCU_TABLE_FREE > * > @@ -207,6 +208,16 @@ struct mmu_table_batch { > #define MAX_TABLE_BATCH \ > ((PAGE_SIZE - sizeof(struct mmu_table_batch)) / sizeof(void *)) > > +#ifndef __HAVE_ARCH_TLB_REMOVE_TABLE > +static inline void __tlb_remove_table(void *table) > +{ > + struct ptdesc *ptdesc = (struct ptdesc *)table; > + > + pagetable_dtor(ptdesc); > + pagetable_free(ptdesc); > +} > +#endif > + > extern void tlb_remove_table(struct mmu_gather *tlb, void *table); > > #else /* !CONFIG_MMU_GATHER_HAVE_TABLE_FREE */ For s390: Acked-by: Alexander Gordeev <agordeev@xxxxxxxxxxxxx> Thanks!