From patchwork Mon Dec 23 09:40:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13918678 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 6C2FAE7718E for ; Mon, 23 Dec 2024 09:45:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 02C2C6B00A9; Mon, 23 Dec 2024 04:45:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F1E036B00AA; Mon, 23 Dec 2024 04:45:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D705D6B00AB; Mon, 23 Dec 2024 04:45:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id B81666B00A9 for ; Mon, 23 Dec 2024 04:45:52 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 73575B0E4E for ; Mon, 23 Dec 2024 09:45:52 +0000 (UTC) X-FDA: 82925741304.05.552E6D0 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by imf16.hostedemail.com (Postfix) with ESMTP id 08F70180005 for ; Mon, 23 Dec 2024 09:45:11 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=j6AcRjsT; spf=pass (imf16.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.178 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=1734947107; 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=m/+0uIvp7xUeTeFwO63TH1y++vtASeDM7X35qnuktEM=; b=cdquzrE/2FidJLZM0Nv8p6+Nks5h0y4ogRPz22Ck/xTA+rypYWe6NrmvcmghVjq8DwP4Ce DXCA9hc04Feq/0zQRBp9Q7zDwGavNXtHx6M5jL5EXgV3xEeRg1W3ruLMtWk9f7WQ4dBnqN O1jzYo15RgfOxMQ2rfWQFCejVVBAuAY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734947107; a=rsa-sha256; cv=none; b=HSZesyqxNkUnU9Hcf1Kc02uMJNxuw+sFmpB/s0d7l/E6rkQKgy1k6v2TDsZON7xDQ8SHot aUD062Ph5r9T9l9QnV8EI6o65aQzyLzJZgv7VILh/jP8ioPHdhX58PLjdTHwvYGkRjJmgP oQsK4lqjsggtsnP9z5Fxc+Vp2oT1h0E= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=j6AcRjsT; spf=pass (imf16.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-725abf74334so3355155b3a.3 for ; Mon, 23 Dec 2024 01:45:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1734947149; x=1735551949; 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=m/+0uIvp7xUeTeFwO63TH1y++vtASeDM7X35qnuktEM=; b=j6AcRjsTn9rFqV2PiJleqg5FPeoMP/eDhe0W07PJvVLYIOgcpM8cIvWAAOxCwkWmZK aQOkp+kqqPVpV2BnfYlt4ASt7UBokbJ0XH1qbeRfTg3xW/bwQOCey8nyLEkfP8qVPFcD 6u/DFiCbQPm87df/VyRrzK1M3gM5aWXTZnpnUt08ppN5cGpB5MO4ZFQpYyOlUtGit+2j G+GgBuVkZLDPG+bmlc1m0EmbIsm11C/YfOSbJm/g1ry5lFprSmQhbRIWZC6scCoPu4wA EQYfLmqyyq82CBaW8t71Yv4Dt/QzsKYeCE01/rkUdy9Nj6/9CRAB1VzeaOpNxqECi84W j/UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734947149; x=1735551949; 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=m/+0uIvp7xUeTeFwO63TH1y++vtASeDM7X35qnuktEM=; b=HNJhqQqqgbb02mxdCGKtkKoeGDOWaEk2kFf7idOGrKwTUGDAy2IYQXFEmzs5uvRhx9 MshKB2oytK+CHP8Ob/nJhSKN9nhtHtxX7vwNSDsTrKSeia8KDkJPvDRItZS6IPq49Qjz F1leCu9mh5jSKQy/xKc+MgK/f2PxuLymuIV+HUG4udXiE9Uk1zh9QOkjeCsGRZ1DOUMd EhMOm77aXNAcIoaYhExkl8hoiJV8imrNc+2e6HRgILHssMkg5PCh0ETsIFtaddU66Uzm QWn9dpFWV6ijyS0s3u328Y1U4trzSARCEuDMFIjGqRCpBCai8ftL2/OT/z4MgehGLJ3D 7Wpg== X-Gm-Message-State: AOJu0Yyexh9TRg8ux3SC7UX66xOUxZRBLDIbr0mE1dmDEIhNXYD8EqTZ 7/SxZ+ZdxPGEwxJ3/ztFjkBW/eIUNlWQEOpeI3hu5n6IvS5Sp5ny/JB9JAYvpv4= X-Gm-Gg: ASbGncvvvLYA/VBfJdg6AX9b3EIiepGv/HaOJhQPLmCQUryKpLrHlM4HuaBUMfz/JGm JZdQe6ir9xkp1eylBfeEOsmVQ6OJRUjak8r+V6va+d2SYHFNvUigzS/9l75NfuZSFKBh1gUPqBm jIJ8le0Vt6EZXnG5cVuZQV/OuisHSgJH0L4wbayywMQKMCp6NyiaGisMtQAFepO89/YaiNOzj1T CxpIJICLQT2UuvwTtfIUvGnk6nPH3BMK8cKpTma1+lkhDUkzNmoY6jsdQcYXlyE4HSsXRAKn+fb SpCbolDeW0JjYJIrh7GFOw== X-Google-Smtp-Source: AGHT+IHlutX536vagq2BMCvNjirBm1uJlF1dzaH3GgOc0ZHj3lAXm7kK/AuGYqDlsmkXqpl9hOqJ3g== X-Received: by 2002:a05:6a00:92a4:b0:728:e1f9:b680 with SMTP id d2e1a72fcca58-72abdd7ac89mr17103004b3a.6.1734947149240; Mon, 23 Dec 2024 01:45:49 -0800 (PST) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.150]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72aad8486c6sm7468309b3a.85.2024.12.23.01.45.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Dec 2024 01:45:48 -0800 (PST) From: Qi Zheng To: peterz@infradead.org, agordeev@linux.ibm.com, kevin.brodsky@arm.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 v3 13/17] mm: pgtable: introduce generic __tlb_remove_table() Date: Mon, 23 Dec 2024 17:40:59 +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: 08F70180005 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: y4qdgguiu6tz8a4zzs3fza3gx19c9rxy X-HE-Tag: 1734947111-469715 X-HE-Meta: U2FsdGVkX1/XT2GGsRy9gwTnO5UVAUO4Ax5neAYgsyUXN1OEFPTDfyhRRus+NNMnfN2f4xlmk0WZQseFqCliU/hnCd/SugI12sfpkEJiueCOa5/+cuUKv/y17QuxO0Lj0SK8cOASorVeG7QP2oZsi51FF0YZoBAJTmwWIAnaM6w+sZnja626ppmoEf4xA2pjchqsdKVEOcChjV43R5n2Bl3TRRahUkakfvRqQ1PLczG13vJege1IUVOokpb8V4CDXgBdsKbT9DZTWJt/BwEAcH8omQj3G9DWDRrMQxe+zO0CvPqHel8mxxF0OXICsikgQglbdCVQMD4E6sK4y9yYd+Mm5P4qnrvs/L4rGB14pGQVGWliWnW68Wa4aKDxV0a8aUpaH6ZmJZ7Mqnd74EBwSRo+K3ddV9NIBjn0OvfKu96Q1+gaOrEbq0ThvqDUrWyP03J4QZjYxPwt3Y80xhk2D3ayfyTjaF5bQn/QjjQuWEPmOsUbM/ziQlsy8AGRb4seIoOjtqk77VCp1YfMm9mYhhlJmRGuIx8rEbsXuil3w/ANasNA6Ko/jcJ6o1DHM1PCEg51GTZ7xiGYRLEZLhDv89vOTTzXSquEu9vIrP0/1hgYEFDvp8Wwb5xRXLZ6JhTzDETcz8V15WELPztXzbPPfkMNPl6haruxgo8hk4jj3notIU1UK1b/qqPHsSjPAxaGstaR+vt4PkNEkTI0yPGjXjCNx0JYoSaVggVbYFVoeLfvax6XBwG9vwl5tEIlhVEa3/AJVXtPWnTR7ZjTOgFydmGjUy/4exS+odGZ2n5jjEUQrs3JsxPJTi5cvKy6FoG56ZsBCEltHESU5P2aAYSMqBWwjLnXVSFV6jMXi7+92w/+wTLaWcLs6jx7lKcJ/pBNgRFkm/8pJxmwpt+hQXEXJdNpi26bRNMp4cDxp11gHE6yOJnjxGqvTjOiZIpdoAH38f8DcQCbzO1tTmj3fRd fFzoDCyZ SGm2OM0E+CIhr9FMskBf564KxDxnEyk88JT0WdD36mH0NQfTccyjYxE40ddLd8tHS135980n491DNgjXcnXh4wpD1H4ga3z3/buOZAlpf9pdudoVMS1RO06UGTi2mSj/NYmzZ8kQUOLaRqMMoBpuBLNcKcSHZ5jzGw64WmIyxBUYZd8mBUO6IdIqZDq/m/C8CPqGOk4cjWlfOp02FyHo37Z6i+7/bAWbx4KU7or3X80lhilp6QrW6rem2iRZsB4ouo3sFF/e16j1Xn6alqlv1uLjAU09Y31DDYwmhULBTdbtdxWVFBx0EEKzPRz2tDjNj0AIek4phCzO7hmi0jTa85QTtrQAIQoMRn9M3bMWlvD9dAAUicUmeJoAzhVUweD5txs1zvxUlJNqQn9Zca1fDvL7CDJQ+xgIaKkMK5qfnp4lk8RFm2JV8SghxQ2wV6mxvFzHCCNiDG+K5nG9rD+AanEL18A== 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 --- 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/arm/include/asm/tlb.h b/arch/arm/include/asm/tlb.h index 264ab635e807a..ea4fbe7b17f6f 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 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/arch/sparc/include/asm/tlb_32.h b/arch/sparc/include/asm/tlb_32.h index 5cd28a8793e39..910254867dfbd 100644 --- a/arch/sparc/include/asm/tlb_32.h +++ b/arch/sparc/include/asm/tlb_32.h @@ -2,6 +2,7 @@ #ifndef _SPARC_TLB_H #define _SPARC_TLB_H +#define __HAVE_ARCH_TLB_REMOVE_TABLE #include #endif /* _SPARC_TLB_H */ 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 */