From patchwork Sat Dec 14 09:02:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13908436 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 23E8EE77180 for ; Sat, 14 Dec 2024 09:05:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B12586B00A4; Sat, 14 Dec 2024 04:05:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AC13E6B00A5; Sat, 14 Dec 2024 04:05:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 989786B00A6; Sat, 14 Dec 2024 04:05:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 7A12C6B00A4 for ; Sat, 14 Dec 2024 04:05:21 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 340AD121CEB for ; Sat, 14 Dec 2024 09:05:21 +0000 (UTC) X-FDA: 82892979792.06.9614977 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by imf28.hostedemail.com (Postfix) with ESMTP id 5985DC000C for ; Sat, 14 Dec 2024 09:04:49 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=VWjaccTh; spf=pass (imf28.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.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=1734167091; 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=tGOtYoMgWgj4YJiYefYK2aPYu+m8suzmBGDTS71l9lQ=; b=n24ZNhRI1q8R8DgeJEWDGhY89wtmeu02TXO/uiXuraMQB4zpaXtrqE6FFydYzecHyicQg4 lR/b6BmQa/55TotCzTLowbXfsEaZ6v82sVc9p/cHw+mg5JCIh9gqV8BRiwnsyDTRL7nOhC fDvslmF1JfDdVxQ1iT9vJCWbdfDk9I4= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=VWjaccTh; spf=pass (imf28.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734167091; a=rsa-sha256; cv=none; b=cx9Ys1lSH8k/5sucMVkC2uRBMaBVx3t7mbs9j74j/qNicImhWdzs1IODEMEVDhtSD07g7p 6ThzMKMC0mRysSrGbGj7xGcv9xIWWAkkOpIv+yu1+p0pjW6t5tzCu8X4Y13FErgUtlBRHB sYjfxaP/3GCzhp4/yQvIiZy1snWRBXI= Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2166022c5caso20755565ad.2 for ; Sat, 14 Dec 2024 01:05:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1734167118; x=1734771918; 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=tGOtYoMgWgj4YJiYefYK2aPYu+m8suzmBGDTS71l9lQ=; b=VWjaccThzyC8QDvOjlc8o0T7TEPSf+LhcSNDYWH5CaN7d0r+lzLvXQH2SFnDgYqTzP d9ZQw84EQiBVPKohdSfpTNtrADBBolWMxDp8CIGl7yxa/VDhqgCxkWvQpz0o3+A0mYx3 g4aUJ0ztbJX1gv30nB0aQ8ay172cCJImK7or2V1I8I1NNLH2vSiuC5WQzXwdafgiyow6 VFKU/g9B9DMUWAa/ACa1vDisqNMVeOL/91fkewu5fVsqu7njUoZKZ3/B+1STDM0ciQze cIGMG+wUaqFWldfrIPMj3YUWs6wMNbSHqSMesFBsmhmqYMtfmLOc35bcyhFygbMxYOD9 Ws+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734167118; x=1734771918; 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=tGOtYoMgWgj4YJiYefYK2aPYu+m8suzmBGDTS71l9lQ=; b=nSVCsad/A0EbhfC9MLrki1gBV3EjyxNuLZnthz4wyN/Ib/OB4UwKOEu892qj3rId5d iEu+DgK3VlD/R4J7o2O3U8KTI0lcYgX25H3LOm3Q+XBz+Lk94brNfUdlkoYqyADhj7Yf 4MuJw5jS4jbWv8cDL5YAITE7nXP7Nq0VSpZBnfwUWGtl2wUe6psxx4C5W3s97RqQ2Rus qQ1yvnwoE0L2Ap7sKKgbfLELEKgpteU7eoBFWd+RuuKr2F4+aYUUxtoCZiryZaQ1qPd1 WphKAOBF9s6AN1a9f2mqquSjPmQiTa8qEy0BsJCPFxVxAjCHkKam3Bli4xRBOgI+EiJg KjCg== X-Gm-Message-State: AOJu0YwzF9QD9+kMJp3IxlJuM1zgixAeyXxSJuBHML6GwZUFV5+pUG5Z 3JGLN2R6Ty/mPejdP2cNPAPqwd+eua1c29yS8iSecpIWn1T3poKRxZI2xhfyQ8w= X-Gm-Gg: ASbGncvhK2PlPH2ZvUaZ4NTjetPhcIhmzjZLf4np0gD7wQKaLTRpcFqnKJXFtr/UO4F eVrvbY/JqJIUhLMElk6FBTvSYLfXe2+4uN09PrKSYe7FmxKtisZjSHlr3GKzeF1xkixAXC0sp5p LI7qht0QVMrhcgMPbn/cvNR3M/axY98GM0JIjrlribdhcUs/4rjccErnbZ6VREj7yBlRkhInEh9 HsCHwnoRDiZy0E8PgFoYgRZYruOgE3dfkfR66gqcBVvdtN1kcNzqAgMVVlWdEjkpjPSLrEOHemN iyApIFiJle0kMUGUlimNpTrrFZV1uw== X-Google-Smtp-Source: AGHT+IGZK6CYdPWEqKPfkUj35U2xxEx7kipqiMJDua7xnmtA6POZpy/3kuQaFLc+awGAy7moPmF5qQ== X-Received: by 2002:a17:902:d481:b0:216:4b66:1f1f with SMTP id d9443c01a7336-21892a7c538mr78074805ad.54.1734167118105; Sat, 14 Dec 2024 01:05:18 -0800 (PST) Received: from C02DW0BEMD6R.bytedance.net ([2409:8a28:f4f:a9a4:5d46:4ef0:daa9:1db8]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-801d5a90ba0sm905731a12.16.2024.12.14.01.05.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Dec 2024 01:05:17 -0800 (PST) From: Qi Zheng To: peterz@infradead.org, 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 Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Qi Zheng Subject: [PATCH 11/12] mm: pgtable: introduce generic __tlb_remove_table() Date: Sat, 14 Dec 2024 17:02:57 +0800 Message-Id: <271e58cd4ab808c4f402539b76d5916924e2bc6f.1734164094.git.zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 5985DC000C X-Rspam-User: X-Stat-Signature: yzwn6c61ca9u4b58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6e803wB37aCYrV6ObFfjo7lshOYwIQJEEnxVlNze/9WXISx/uyHefQMttjQodOjJsI/MkADFIRbuClHFdE03Ye5NvJm7b1rnShCdR9jrqBucc0oeEEXrlv0oNBGjLY07HdKvA2GWL/+TWEGYNadHxLa33Yxqr9RdRk5SmatdlJw0kTSn48x9JwFVwlnsP39HFanKbdG13nkw8kN/LnXTW6OBHFgYzFe8vIfCYuIojeAnjT2IMrczfvYHhNhxcQeTwlsEbtictG0Ou6vgdUQ3DCVN1Cb/IEqfnxHUGY3JwSNmIkfodPu0KhxB7Jtj3tZqhWMpdcHVvJMbLkBWJ3mCSG5ZYqBi2+KF5OrLboElUop8/KV9eXO2tMw== 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, s390 and x86) define exactly the same __tlb_remove_table(), just introduce generic __tlb_remove_table() to eliminate these duplications. 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 | 1 - 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, 16 insertions(+), 55 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..7052780740349 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); 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..939a813023d7e 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 */