From patchwork Wed Dec 18 13:04:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13913622 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 40615E77187 for ; Wed, 18 Dec 2024 13:06:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C2D7B6B00A3; Wed, 18 Dec 2024 08:06:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BDCC46B00A4; Wed, 18 Dec 2024 08:06:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A56E36B00A5; Wed, 18 Dec 2024 08:06:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 859406B00A3 for ; Wed, 18 Dec 2024 08:06:28 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 4216BAEAE9 for ; Wed, 18 Dec 2024 13:06:28 +0000 (UTC) X-FDA: 82908102186.08.1FB8A22 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by imf14.hostedemail.com (Postfix) with ESMTP id 32301100018 for ; Wed, 18 Dec 2024 13:05:50 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=cAkCU5VO; spf=pass (imf14.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=1734527151; 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=8jrhRkH9wk2k8zCLxFmzwNce2I+voVuTloSZdpUGAUc=; b=mKbE/kmLq4v6gNt2sZpjX82p2w2vT3oTUI7MyOyILRJMFdeMyEHnhjjYYMLVmRllWBAnxh qAJs7KMGBsyqlAv6QkcYbGKebT/vFMgMbdA3woIUrGkuqAhQhvQj7rwxHCUgfTCDCccKJS t5ERYzDZcs8nzmHJEf5QQ8XZxkK4/Yc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734527151; a=rsa-sha256; cv=none; b=VWqa6OmEZAlNC5Gt0mUs4YTQqivOGlLJTUNSLZzpw/0qo95SdHY2sBM5RQNz0h59zeQooT UtLf6SGHIY/5hqYbqMaTIXRlKe3jkJjn1oxzBsvCSeuJVm1B7PvIbgU4JN4PUsjC+s066D HNveCo+a8FipUe19exvCQNoYRds1JYk= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=cAkCU5VO; spf=pass (imf14.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 Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-21670dce0a7so71224075ad.1 for ; Wed, 18 Dec 2024 05:06:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1734527185; x=1735131985; 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=8jrhRkH9wk2k8zCLxFmzwNce2I+voVuTloSZdpUGAUc=; b=cAkCU5VOlwetxhCDm3sUnfzA27zreh1uALPTRuDuqiHhknsd9yuVYDl4TzlkHe7kj0 lrqKgOtHdJqIkkOna3QlPJD0bxbJZQVVkDWb3dRKNETXXZ/ikRLyDzKUHuPDGNGlunia Ou6IbPh81MayxQojeopfWetTL+51mq7epg1MEFlLBYFUf3cOneHouQ4uzkMKexV6l5sO oeuKzWGgk5BSNzHeADgrhWuQJF6wOSaGp6UUsJpZLGQeg9aAYlAQV3Mus6pAYfDhAm4r Q7Dpr2kfewqdYo/yZEguEWvlce5ErGkmWUfN6ls1zAqqJWyQMQYkaR/bssmlCETe4zUS TYHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734527185; x=1735131985; 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=8jrhRkH9wk2k8zCLxFmzwNce2I+voVuTloSZdpUGAUc=; b=NgIoI+zvFJA4VFOXnZIBTROEsPAjjUssC+2DMCOxCkBdnqYzTJ5iCsb8XKFmVGOOvJ oJhUcUDHRPGrTa1InZ6VVVpR6D1TcmbQ+bSLm8zk2E5rwk74XtzwXCHumCycJhw3MLBV T9PQsjkT6C2rI2SGP7oaXyru8TXlTQ04boqHNgG7uzVcVeeJGte3nYBoL4LmYVh25aAV 2CxOvGmwpfxg0kgohoMjcrRJiFSsN2s9afu2xpp/qOQM8JT6gY8v38p9lIhFmH6Zc9dp 3yPtjX0Aw1FJqsu37om1DU+iuDJskJ02fWxrIe3QGUlIlWtlwjUXIzaqnpjvQib6xzS1 PE8w== X-Gm-Message-State: AOJu0Yxp4SwniDuv+T3LWsiDT5+dwowy2gggFk3o6eJelRWPeE14LkS/ qswho4fmFpXKkd7fViWrq83zzJDJ0PO7EdECRAFmgO0Aq9p5UsKx9YfI5fwkn80= X-Gm-Gg: ASbGncvlhmwmKgrbXbTtcaD3XRFBwGtjP/UOLvRpKGCoE9IDgf/4M5sI+SOkdrAp2Um D2ggN24tw2LL3AF9FC/CGRYgwf0ldTlcwhtabzPOKvGEKG2Cyn7QzGIZM3FC9A3fgywh6PZJQyt l/pxEoIkRMSvRSOil8OYFZWZvGDPJkmwXngyTqAm6lRz6cPX02VBBErSRL9WwNiQG2FkDz5tioY Z/CTbaV+DkLTOWvMvB87pDdOGtPuCoORb6CGUqLcJOdsjmE+KAMt6YJkW0DxeNR1tmZW4t+ogX8 W/zSkKsfGEiywVDJyMH9eQ== X-Google-Smtp-Source: AGHT+IG/JUNAlV4GKtrGOWzVqsVky2vkpSpLF0iAE0qU7NCcidXao7F2hMgn6AIs6nUdS2ae8ITLQQ== X-Received: by 2002:a17:903:1105:b0:216:6769:9ee7 with SMTP id d9443c01a7336-218d7247707mr40539125ad.41.1734527185019; Wed, 18 Dec 2024 05:06:25 -0800 (PST) Received: from C02DW0BEMD6R.bytedance.net ([139.177.225.238]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-218a1db755dsm75751825ad.42.2024.12.18.05.06.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Dec 2024 05:06:24 -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, vishal.moola@gmail.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Qi Zheng Subject: [PATCH v2 11/15] mm: pgtable: introduce generic __tlb_remove_table() Date: Wed, 18 Dec 2024 21:04:47 +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: 32301100018 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: 4xpibazqcycjezgccym1brqnq48o7pj8 X-HE-Tag: 1734527150-935905 X-HE-Meta: U2FsdGVkX19nBaNZaXb09HX652QOS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1NgzCpCOny+HQFJlJkRiVOrLZ0P+iNTGWcy2xkELOmcT8s2BaWN8h5KooTsuUs6zSZ/fDRryyOfXQ3+jYKsUgDcOoqE82GMdPWdOayGLiX+LP5DX4lUhFKwnqsR6Qk7ZI+QiIrm28JZQTu7HoDYb3cZZkn+7q6d0dtPP21IDYkwMxanEBpzk2Rj26U3FqOhktko62NeLwF2A68ZHpbOH4tPQMipFhyeieG3FqYLtRfBQf5vzIZmA8AXG7lmj+vr0fMLZIY9zQtXJt+xWC6AdhpaZOdVDfCB4U4QxUVooYFftZYWoxUJ8XoF5MpXsf0dpZjJViGOHWyfppik7AT8H5P2T5YTyUWTJryG79G5fzeiw== 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..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 */