From patchwork Wed Jan 8 06:57:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13930205 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81AC8E77188 for ; Wed, 8 Jan 2025 07:02:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 206E66B00AC; Wed, 8 Jan 2025 02:02:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 190B76B00AD; Wed, 8 Jan 2025 02:02:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F24FD6B00AE; Wed, 8 Jan 2025 02:02:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C4EB66B00AC for ; Wed, 8 Jan 2025 02:02:56 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 7D1F81C6375 for ; Wed, 8 Jan 2025 07:02:56 +0000 (UTC) X-FDA: 82983392352.02.EFC7213 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf29.hostedemail.com (Postfix) with ESMTP id 9BB0D120005 for ; Wed, 8 Jan 2025 07:02:54 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=iPm1oOcP; spf=pass (imf29.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.182 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736319774; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=DKWQZ+PEOlL8JpVZj7ISn1dZhyFPgkd436O3CmTW6X0=; b=46zjkv2VkNPmgMH1x7N+T/be1iMOI/xkepwZUBgzlqdiAPgGMJpjRKdbl/JWSun89/TJUm v3uqUGdW6SXDRLPB/YYUMWHLKQHkQzBbxGAg8AwbLsQdA+evgnoGnfEYcpB794zgLRAxUD OxmyfI+cLlNw3gEeUDGyNmr/T12a8Ms= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736319774; a=rsa-sha256; cv=none; b=yQdgRF1+Bs/v3LWEhKSXmr3uG1yo1b204fW0tpK1FbuEEw4aLHGF1Es+17ZHg0BaLJxk4Q v8m20XXkgVMqgv8q6jANngoJ14c87M8rI4Btm7cORMpkGwCRUTRXJDxVxdPA7+F68MSV+4 Wj8iTT2wSBukOWn39xHs4IvdBo/YkaM= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=iPm1oOcP; spf=pass (imf29.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.182 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-21628b3fe7dso235491125ad.3 for ; Tue, 07 Jan 2025 23:02:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1736319773; x=1736924573; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DKWQZ+PEOlL8JpVZj7ISn1dZhyFPgkd436O3CmTW6X0=; b=iPm1oOcPUUFsTsRXhia/aDGFdaOQNrecIL9AhdM3fEemFxHgjOkVvKwm2qVx0DLWde 5vS2NiIcYtPmPP38HzUmcbBwnYxmydozjlUj+C+gJUa6sz5i/zip0nLUmagjFZnmZiJF e29TsxGTckxvLNfkOQ9Q7MrJVKgkRU9tl0WNNyfQ+zNmLj+lF53xS5g9OHHqxsAILz2E FiZ/uczKDCNRNs25apvvjDgHcmeZdEM5vlbitH/QTAIGnhqyVTjZ4xsBjAurDN2W/wEH KbqMcU0AzmV+l2BI4cKOa0W9XnAC/lpZlNPlEDyu1VOnsLA9TWu+jgY6y+ncUQ4p+Zzd JW2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736319773; x=1736924573; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DKWQZ+PEOlL8JpVZj7ISn1dZhyFPgkd436O3CmTW6X0=; b=f0pl5Rsm0zycmHasg0mekKLni2QHLVA9NkAXScmnAU+5iU3Ogw7DPNRJ7JIm9ImP9t l8KcsAOOyvVSgnfTk9OUXJ8D/i166bSURjhNNAmvHznZ4YglNhj8yi2oXMkChVmvwHQ8 XBTIc6HAvmIWYfYF4uIXK6zpBXAV8emSMGCLBbzjpeMg4aeCTUau3fXE42SbR/6zcZto R7vqec2jqWP7rujXJTniaz6vdF4idXd07sbWuhJ5Jfymxi4mqYqMlpqLDTK+vuzvwvHr t2CtjK6ADSBWXt//rum48qEb0Bf6bICCi3ioiRBzUbykwtLpQuSBnmpepj8SaVm7Mrtb EgBw== X-Gm-Message-State: AOJu0YzbHN32y11l3iS8g3s6w6YFo+Np1KUqRs7dBlmSgID3QM6Ajwko g7dr10crwqCoUWx8z0VhQHfBPAlFezWHx8LyERX6k3rk2fLOsIon1n205U1soVM= X-Gm-Gg: ASbGncvND0wolmE8wgomsS2jpGe0PExV1T+21YKoLA+xIABRGqNX30gvGhMwFrgqknL ofG0nv96aR1r8jBz0Bo5NGeesgPZosOQSoJ3rUHwXUzw+kztglbzQj1bNZY1Fa0qyqH0+DyLcIX VM8Zq3ib2iaesrMg1YxK1G/0tbO0J94lYZlkNMjtJ1okt4qu947Zwhk8KGp1/vHP0qZvZnU/hXE bWI2kSpwnveqUoJzVLhvvJrsUn6SCPzsmymJ5by3khHOMtWNtvGRbtYrCC+a4HfOduSUAVcLOeV BTJEbIUKIfRi3qE1lfn1eRyQBBg= X-Google-Smtp-Source: AGHT+IHGzG078/xZKjf5ni4u4VqQSEqesUDiW4uhWhxryubYr9zfzyAKAXvb8eE6PvXFj9EqVM5aSQ== X-Received: by 2002:a17:903:244a:b0:211:fcad:d6ea with SMTP id d9443c01a7336-21a83fcf7a9mr28371525ad.45.1736319773330; Tue, 07 Jan 2025 23:02:53 -0800 (PST) Received: from C02DW0BEMD6R.bytedance.net ([139.177.225.244]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dca023a3sm320067275ad.250.2025.01.07.23.02.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 23:02:52 -0800 (PST) From: Qi Zheng To: peterz@infradead.org, agordeev@linux.ibm.com, kevin.brodsky@arm.com, alex@ghiti.fr, andreas@gaisler.com, palmer@dabbelt.com, tglx@linutronix.de, david@redhat.com, jannh@google.com, hughd@google.com, yuzhao@google.com, willy@infradead.org, muchun.song@linux.dev, vbabka@kernel.org, lorenzo.stoakes@oracle.com, akpm@linux-foundation.org, rientjes@google.com, vishal.moola@gmail.com, arnd@arndb.de, will@kernel.org, aneesh.kumar@kernel.org, npiggin@gmail.com, dave.hansen@linux.intel.com, rppt@kernel.org, ryan.roberts@arm.com Cc: linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, linux-arch@vger.kernel.org, linux-csky@vger.kernel.org, linux-hexagon@vger.kernel.org, loongarch@lists.linux.dev, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-openrisc@vger.kernel.org, linux-sh@vger.kernel.org, linux-um@lists.infradead.org, Qi Zheng Subject: [PATCH v5 14/17] mm: pgtable: introduce generic __tlb_remove_table() Date: Wed, 8 Jan 2025 14:57:30 +0800 Message-Id: X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 9BB0D120005 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: ezibb9wqc6utp9bbqnibun5f3k1ix4i4 X-HE-Tag: 1736319774-705189 X-HE-Meta: U2FsdGVkX19rVotVmL+KNF637Ve/Dc5oO+LKqpBbNHd1SQbXXxCVR1Rj62HGtyFO4z5Dku3MwB6xDpwbZegEEB0djGIHuKSryR4/Ig+z8IzKYtM1onQTJn1upRskyXqZPjZ2FX9QWxErBqSEKEo97iJSg79W9YNFHObMjKJsfRPXY+1Fx37ElLHLYK2c8KO465KSv4jbywgjv9jGZNizbLWr4+jgSY7DF1VGD22Glq8nSAgIsk8UPqkddMmxrk2Q0KuxbROW1m09JDszz9eh+/LVjmVL24tWq0WPBnAyg7CIOQJYNPIieYlZVjfNX7VHl6UjfZSkhb1vKUBwABbpLZoFEkI6ZqerLdMsL4aSm8s5c3f+rvjzPU+/eJhNg8RUWP4TuTAQKDsQccIKwUTSRx2fwP1bHZqDcHO13jzsC+4UjARaq+0sHm9sehr9wBUsxmDJeB0MCCpt7vwiNVDHXYFcQ3Fb1FRfqiJ/cU5UQRL4CBOX93vQ4kk2kIHVvFtUyKUilh9gR5rCAWI43hkjB5Q6paLQkGTINUSOlCleuXl/DzV2hhXkQbtSNhaJzC8rKrKaWpt0O680sdbgbR8cUpXoktfuMiOogo1ZjE4rF3Ukjr3dxwDsIowq/4aPPrSuB7x+B2IcnVVy6zrLxDKnbWaPeSh7A0tElWeC8VFl5Vj7uhN4Zn6NBUwGD/1uhGBSTvBc+GBdqrok0ZwTxipyBXTdf2PAVZ/hBFNxWi7DveBeDKEa4RmKc69vdGkMVhI0T/tP6ilENUbJteI64M5MdkWwEqHFLYOyDpi8cH7SWV4kj1goFgD95/j0rnZJBnMumeYsTu4GTNw2cOPxixxi5NbPhA+0+EpjenLzoeq3gRM+0EVZDi4+m2D+ZsAe1bVgtXp637NemgdfMpr+uHe7tH+3afd+x2pgdGlZxyMn06HavbRfaFcdPeznzDr5go1GFPLXXUJNrM5CHBFrDC1 g0j9TilI 088lVeAua3KatiFRd9nrOomJzX+VfXSU4iC09U1+JKPsc4Q2P4RAZgLFf/61u7W0sF7/hzOMH2Dcedi1CEki9RwebwkkCQmc3YmpsRTRcDywA/jj7EAkIIpDqcBywvBNg36PFJPFArOD/3qx2irxiESv6y4kscs+2yCG+M2dgRv6sPf0x1tQzMbsVmwsNzJUi/1d3EOOLGG2mRIB2mWpKyUpoKZfeBckjcMe5rs9H5LaRB73latttJnzWpk/A9omJLFkod8C9OCjNDwvvxjHkNRNuNogIVgvE3+31Bj6fpJ9xZFfE1i5KpwyAa7TDwNsYpCDHTANG3M4G1evLSXmx5j7MQgrFeWhoGki+i/BKfLtfvUpT29tWiZncosp/q564CWFkZugqIBKXmgWC9BubjrPdH45UZohHjUwdUJUxxWHOvaqhdYizPDTeYPhyIGzstzRSCmPRms15K0RTgsN4N8Z7EjSd+Pa6LCHx9VAjVtGJ7y3qH+16Uf68zqc+4EbgKnFIiInAaDr+8kZJLrfW4z/00ScDM22wi877yTLg1jGji0/eJKPGGqBl0GZo/LRRMBZg X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 Reviewed-by: Kevin Brodsky Acked-by: Andreas Larsson # sparc Acked-by: Alexander Gordeev # s390 Acked-by: Arnd Bergmann # asm-generic --- 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_64.h | 1 + arch/x86/include/asm/tlb.h | 17 ----------------- include/asm-generic/tlb.h | 15 +++++++++++++-- 9 files changed, 19 insertions(+), 59 deletions(-) diff --git a/arch/arm/include/asm/tlb.h b/arch/arm/include/asm/tlb.h index 59854c6b97bc5..b8eebdb598631 100644 --- a/arch/arm/include/asm/tlb.h +++ b/arch/arm/include/asm/tlb.h @@ -27,15 +27,6 @@ #else /* !CONFIG_MMU */ #include - -static inline void __tlb_remove_table(void *_table) -{ - struct ptdesc *ptdesc = (struct ptdesc *)_table; - - pagetable_dtor(ptdesc); - pagetable_free(ptdesc); -} - #include static inline void diff --git a/arch/arm64/include/asm/tlb.h b/arch/arm64/include/asm/tlb.h index 93591a80b5bfb..8d762607285cc 100644 --- a/arch/arm64/include/asm/tlb.h +++ b/arch/arm64/include/asm/tlb.h @@ -10,13 +10,6 @@ #include -static inline void __tlb_remove_table(void *_table) -{ - struct ptdesc *ptdesc = (struct ptdesc *)_table; - - pagetable_dtor(ptdesc); - pagetable_free(ptdesc); -} #define tlb_flush tlb_flush static void tlb_flush(struct mmu_gather *tlb); diff --git a/arch/powerpc/include/asm/tlb.h b/arch/powerpc/include/asm/tlb.h index 1ca7d4c4b90db..2058e8d3e0138 100644 --- a/arch/powerpc/include/asm/tlb.h +++ b/arch/powerpc/include/asm/tlb.h @@ -37,6 +37,7 @@ extern void tlb_flush(struct mmu_gather *tlb); */ #define tlb_needs_table_invalidate() radix_enabled() +#define __HAVE_ARCH_TLB_REMOVE_TABLE /* Get the generic bits... */ #include diff --git a/arch/riscv/include/asm/tlb.h b/arch/riscv/include/asm/tlb.h index ded8724b3c4f7..50b63b5c15bd8 100644 --- a/arch/riscv/include/asm/tlb.h +++ b/arch/riscv/include/asm/tlb.h @@ -10,18 +10,6 @@ struct mmu_gather; static void tlb_flush(struct mmu_gather *tlb); -#ifdef CONFIG_MMU - -static inline void __tlb_remove_table(void *table) -{ - struct ptdesc *ptdesc = (struct ptdesc *)table; - - pagetable_dtor(ptdesc); - pagetable_free(ptdesc); -} - -#endif /* CONFIG_MMU */ - #define tlb_flush tlb_flush #include diff --git a/arch/s390/include/asm/tlb.h b/arch/s390/include/asm/tlb.h index d5b27a2445c96..f39f8c4723f15 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 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)); } /* @@ -142,7 +141,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)); } 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/arch/sparc/include/asm/tlb_64.h b/arch/sparc/include/asm/tlb_64.h index 3037187482db7..1a6e694418e39 100644 --- a/arch/sparc/include/asm/tlb_64.h +++ b/arch/sparc/include/asm/tlb_64.h @@ -33,6 +33,7 @@ void flush_tlb_pending(void); #define tlb_needs_table_invalidate() (false) #endif +#define __HAVE_ARCH_TLB_REMOVE_TABLE #include #endif /* _SPARC64_TLB_H */ diff --git a/arch/x86/include/asm/tlb.h b/arch/x86/include/asm/tlb.h index f64730be5ad67..3858dbf75880e 100644 --- a/arch/x86/include/asm/tlb.h +++ b/arch/x86/include/asm/tlb.h @@ -20,23 +20,6 @@ static inline void tlb_flush(struct mmu_gather *tlb) flush_tlb_mm_range(tlb->mm, start, end, stride_shift, tlb->freed_tables); } -/* - * While x86 architecture in general requires an IPI to perform 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 (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) -{ - struct ptdesc *ptdesc = (struct ptdesc *)table; - - pagetable_dtor(ptdesc); - pagetable_free(ptdesc); -} - #ifdef CONFIG_PT_RECLAIM static inline void __tlb_remove_table_one_rcu(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 */