From patchwork Mon Dec 23 09:41:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13918682 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 9999AE7718B for ; Mon, 23 Dec 2024 09:46:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2C5146B00B1; Mon, 23 Dec 2024 04:46:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 274126B00B2; Mon, 23 Dec 2024 04:46:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0EDCB6B00B3; Mon, 23 Dec 2024 04:46:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E007D6B00B1 for ; Mon, 23 Dec 2024 04:46:43 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 90A6980FF7 for ; Mon, 23 Dec 2024 09:46:43 +0000 (UTC) X-FDA: 82925742438.01.36F7874 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf11.hostedemail.com (Postfix) with ESMTP id 0AF0E40008 for ; Mon, 23 Dec 2024 09:46:06 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Khlz2XCR; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf11.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734947184; a=rsa-sha256; cv=none; b=JrAWM7YI627Q+UYL1CHEEtVA/Rit+prNwrBeEpYxGWQU2ynqrhmh4RvJl1Y/0UF3j1yB0U FGQ391dDp6SULfyCpT9rWrOokT2XsgLuOnGbmdaPHVwf38oKNgMhS8piP6OvpFIUclJj5p 6Y7Q74tgpFhkoutrTyoGKbBAMhG0H+Q= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Khlz2XCR; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf11.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734947184; 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=/Vy7m3PQdTp9s3cHn2TFUEZi29ZbV6wwwxQw/bfJltk=; b=WlJVcxjP3q9YgD0uk1gwarSWwZx1ARfYLjLUHcqRzQkFTy6GYQmaPKL5vXubj5lCQNNN/y 55XycPXLYTttWay0UlT9S7DFr2S10ckYujpcZFyT1JNpT9MsA8jnmuPRdtIXCAH/ZtyVuT QOoapbrPeR5UJlKbuYnBRE3cuTVvwmk= Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-725f2f79ed9so3110666b3a.2 for ; Mon, 23 Dec 2024 01:46:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1734947200; x=1735552000; 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=/Vy7m3PQdTp9s3cHn2TFUEZi29ZbV6wwwxQw/bfJltk=; b=Khlz2XCRf3nkaxHH8ouK5t8qZHaEIiygKtMtUEAOug/mM9Y+lMtqky45dxir3e+Lzl yGLiwr5A6zGSWVD1LfOb29DifgQTU3fKUX09ze95uM3MlKkhAu2OLNDZPjHVLF8z6Ql4 P63gM9cntJUY8DUMZId4jv21feAdgXKTsDd7dRyiWlLOOvbPzV6pmjaVRkHYtZnZxZGX 9sd3VcHYp4JbOVicUICaGB4C4Jct3tLWv6xsteWSiYRqMYF+EY4crU0+S3fJaR+gsmSs mLA6yUzme1zumWpZVvaqHXre7o5FFqZC6FtZoWysyW8CtOMegcjjCMZs9FHdyF0QyehE 7RPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734947200; x=1735552000; 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=/Vy7m3PQdTp9s3cHn2TFUEZi29ZbV6wwwxQw/bfJltk=; b=hn0dpV+cGd5PG/PSlBwgjkg+OoEOJUc9w+WaVNvcV1iiQPdCNAdXQifEloGJ1EtodO jvoiWV11GClv+Bwr3Zm5TKLqtbr/Htk8YoOPVP26XwU7MG4B1yD2ZqR0VhTxfeIR+Gt/ 5Hd8WFAR88R1QqYYRBIjo2B8efsulfJx39fN5yhLy4XdT7cbt9RGi4gQG0MOdUb/TLXH BGltrvaS5aScvbPx06uHPd3kuPsmco/tHUGYRSrhQeBKxzkizgsW7aHNNQybbTRnkjgk z1DAQAduTgObztfd84HxJjagxuLnh3NkRrOZI/bLtfsqGVyOLhGHrvMKqXFabIN/YyBj HtgQ== X-Gm-Message-State: AOJu0YxSNKaeab4kxf+fQWxAWLjI2G0xl0hnks0e6f+IL3sL/3ooQL87 qanC+jS2NovemQMHwtl4eEEXYucruJBDKEMmtIhxOeCImfgThnh+ymwyNqNG0uA= X-Gm-Gg: ASbGncs89KuQgOzfRtDtNtLeHTAYu5vf6WTNz5Hx0B2FBfUVsze3ERAzyGt2v5xx8Oa TN/K4jtQiE7R0/exQs1Tj547MKEW+LR9rje/B4tjKpUulDSDDLUNWANTLJppUVRpIvjcvMt8ZAp tRGEfjso0AJBHwuPJtsFaMLzc3OmTT64q+rTrQ/jwc7RFf602bjCw/cPLkxq0k02sjRrBTCRhe7 wZ6ryYIB4sdmbLgvSnlNaA8bqwscMVhDIKeQFCgop++kfaSCLa8zDdscA0e1FhuO4KswTKfsaBo 3bYHd9SqvHgXqlFAdUPPiA== X-Google-Smtp-Source: AGHT+IHTlP+hesMysY/dnyw4k1T/aSGpJ0FSxzWG+ektln9VxnC2FaHlf9zeRwOgabkwOIXU2HSkPg== X-Received: by 2002:a05:6a00:2407:b0:729:597:4faa with SMTP id d2e1a72fcca58-72abde9c004mr15027146b3a.16.1734947200520; Mon, 23 Dec 2024 01:46:40 -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.46.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Dec 2024 01:46:40 -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 17/17] mm: pgtable: introduce generic pagetable_dtor_free() Date: Mon, 23 Dec 2024 17:41:03 +0800 Message-Id: <3ade33c5049f465dc2f0b95edc2d68c80f2048c9.1734945104.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-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 0AF0E40008 X-Stat-Signature: ttsoogj3pwcxhokibta9n7hy6bcc8a8z X-HE-Tag: 1734947166-282867 X-HE-Meta: U2FsdGVkX1/n2SHVUs+xoIQxrYdZPmIOgLopFmK/8a5cuYKKFUe4h5H0zD/7lJy9qN5g9LRJX72n6NcJGmQgzoseNDbWWl6dkoH5YigRyHznQr4BjalpaEyPSbogMCHQYdMq+7KQTiUm+IIX1g3sKMjU0jWlXa55QmzJ9kVto1qj7sS8rXFYx5EWlRuRFwMXztNV5nnXZqKwVo5k7QqKaoxh/PT2GA0xeOb6Ns7ZiWyYp5GEEUESiJQ3Z7IDFFR+tN4J7ScRR73lhjScxqEiIQxdUtGCcF+zk8HHQt19MYwDG4SZd1CaaBzTa065u1x/gpHuMsy6dMXzSYMAYeXrMWnouSOQ79l3639VtcvuSs3biLDjILwT9bdbkcBYkt1ycvzLwjujCFG91+ZLFlP8erFNQCJn7LmyAv4/ObaKYzPB2gHoRhksKlrfQB6lsT7dSfBxfAC35krRruhCFCCKaaaPfWyJ00HeVBi2L3zpxUfCG/x6JLpRDgiaAKRfVdeC+kp2AuKWn7tFuR84rUTaKAtUrQ87+H/74KViyRfP1OvWsT6a2/xg3NZ/RfY0Uzm05A05ps4RMxWUqeYk7piXSWbdWoom8TMUtRoXLdn/Px26tlLR5gSh5OAYuD3AlYv9o+G8G0dOZZANtMp2X28dfV8JxbCKVDeRYM0JC5d+4kE6qKdFfHQxsmQ4aftxcOcYDTUsfwCHHXlEPyOJezh8XkPkIFQtYA0MPB/u/+csxilOy9FBcXN9gdC1HI4aJ7RvBx9AM3DyyF136yZKfUneYh3wtCPLn8Y8fkC19zWb10BSv1QUrn8u3lAMAM1v4o25+V6oygAj+tGxno9uE26cONDcWbAp+tkXIVd7JvKny35Bao3G9G9aDX8flatUtyyEd9vcokg5hI86PkoDd3iN3c+5KCMevysxHC9k1iwnwT9GUeIbd2jetZQ+EUxjp1oOVziPXN44/BjrwPxlvzz ZhI3usxI Hv9KcXqfrjtkw7imiEJb1BcTCmmesjggKT6u3VT24SDRWAOsfzAOYj+bOasSfUahFxygTanoh2MRV3cBesljf7zLVUlDuKTmfAUHML4oIAImlJdF/JD9wBJtNnSIDNMpvijLhyE03Bv/Pb1ooukvOhRPsKknosUpdB6vTeMzmOrVnqEpY5/VwvR+jMIrTd7Dvr2fxeoY1MSh267zegptp6jZf8C/yupasotZfySCguUS0WkgpnoL3jLQuFB0Tm40lK0cNpv/WIf/ZIMgTMvwlAceYhqLMkciaSlH80kDeNZpm04eh7iDXL5hXOEVnMWxvKI0dyOkJjo28xqEBBVIkc/leMWJr56fnsK5C1Eo3Et41U5VtrygK1la4TKPdR8FpUjtiUAUSlJ99kIeRFk+mAu1O7CTM+g9GMNybJGSr9Pu4f51oM7/jMVCzkXRFiIpjLdSqjYS2+qU867QTMdLK40raSJVCiT7kg1hq+oC+T9pktcvpUFJo8ly1JpYuhEjpzIOwXi2+FbvaF0zHrdrej59ySaTVcYBgAXdt X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The pte_free(), pmd_free(), __pud_free() and __p4d_free() in asm-generic/pgalloc.h and the generic __tlb_remove_table() are basically the same, so let's introduce pagetable_dtor_free() to deduplicate them. In addition, the pagetable_dtor_free() in s390 actually does the same thing, so let's s390 also calls generic pagetable_dtor_free(). Signed-off-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) --- arch/s390/mm/pgalloc.c | 18 ++++++------------ include/asm-generic/pgalloc.h | 23 ++++------------------- include/asm-generic/tlb.h | 5 +---- include/linux/mm.h | 8 ++++++++ 4 files changed, 19 insertions(+), 35 deletions(-) diff --git a/arch/s390/mm/pgalloc.c b/arch/s390/mm/pgalloc.c index 3e002dea6278f..1e0727be48eaf 100644 --- a/arch/s390/mm/pgalloc.c +++ b/arch/s390/mm/pgalloc.c @@ -180,32 +180,26 @@ unsigned long *page_table_alloc(struct mm_struct *mm) return table; } -static void pagetable_dtor_free(struct ptdesc *ptdesc) -{ - pagetable_dtor(ptdesc); - pagetable_free(ptdesc); -} - void page_table_free(struct mm_struct *mm, unsigned long *table) { - struct ptdesc *ptdesc = virt_to_ptdesc(table); + struct page *page = virt_to_page(table); - pagetable_dtor_free(ptdesc); + pagetable_dtor_free(page); } #ifdef CONFIG_TRANSPARENT_HUGEPAGE static void pte_free_now(struct rcu_head *head) { - struct ptdesc *ptdesc = container_of(head, struct ptdesc, pt_rcu_head); + struct page *page = container_of(head, struct page, rcu_head); - pagetable_dtor_free(ptdesc); + pagetable_dtor_free(page); } void pte_free_defer(struct mm_struct *mm, pgtable_t pgtable) { - struct ptdesc *ptdesc = virt_to_ptdesc(pgtable); + struct page *page = virt_to_page(pgtable); - call_rcu(&ptdesc->pt_rcu_head, pte_free_now); + call_rcu(&page->rcu_head, pte_free_now); /* * THPs are not allowed for KVM guests. Warn if pgste ever reaches here. * Turn to the generic pte_free_defer() version once gmap is removed. diff --git a/include/asm-generic/pgalloc.h b/include/asm-generic/pgalloc.h index 4afb346eae255..7d327889df306 100644 --- a/include/asm-generic/pgalloc.h +++ b/include/asm-generic/pgalloc.h @@ -107,10 +107,7 @@ static inline pgtable_t pte_alloc_one_noprof(struct mm_struct *mm) */ static inline void pte_free(struct mm_struct *mm, struct page *pte_page) { - struct ptdesc *ptdesc = page_ptdesc(pte_page); - - pagetable_dtor(ptdesc); - pagetable_free(ptdesc); + pagetable_dtor_free(pte_page); } @@ -150,11 +147,7 @@ static inline pmd_t *pmd_alloc_one_noprof(struct mm_struct *mm, unsigned long ad #ifndef __HAVE_ARCH_PMD_FREE static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd) { - struct ptdesc *ptdesc = virt_to_ptdesc(pmd); - - BUG_ON((unsigned long)pmd & (PAGE_SIZE-1)); - pagetable_dtor(ptdesc); - pagetable_free(ptdesc); + pagetable_dtor_free(virt_to_page(pmd)); } #endif @@ -199,11 +192,7 @@ static inline pud_t *pud_alloc_one_noprof(struct mm_struct *mm, unsigned long ad static inline void __pud_free(struct mm_struct *mm, pud_t *pud) { - struct ptdesc *ptdesc = virt_to_ptdesc(pud); - - BUG_ON((unsigned long)pud & (PAGE_SIZE-1)); - pagetable_dtor(ptdesc); - pagetable_free(ptdesc); + pagetable_dtor_free(virt_to_page(pud)); } #ifndef __HAVE_ARCH_PUD_FREE @@ -245,11 +234,7 @@ static inline p4d_t *p4d_alloc_one_noprof(struct mm_struct *mm, unsigned long ad static inline void __p4d_free(struct mm_struct *mm, p4d_t *p4d) { - struct ptdesc *ptdesc = virt_to_ptdesc(p4d); - - BUG_ON((unsigned long)p4d & (PAGE_SIZE-1)); - pagetable_dtor(ptdesc); - pagetable_free(ptdesc); + pagetable_dtor_free(virt_to_page(p4d)); } #ifndef __HAVE_ARCH_P4D_FREE diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h index 583e95568f52b..ef25169523602 100644 --- a/include/asm-generic/tlb.h +++ b/include/asm-generic/tlb.h @@ -211,10 +211,7 @@ struct mmu_table_batch { #ifndef __HAVE_ARCH_TLB_REMOVE_TABLE static inline void __tlb_remove_table(void *table) { - struct ptdesc *ptdesc = page_ptdesc((struct page *)table); - - pagetable_dtor(ptdesc); - pagetable_free(ptdesc); + pagetable_dtor_free(table); } #endif diff --git a/include/linux/mm.h b/include/linux/mm.h index cad11fa10c192..cd078d51f47c7 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3001,6 +3001,14 @@ static inline void pagetable_dtor(struct ptdesc *ptdesc) lruvec_stat_sub_folio(folio, NR_PAGETABLE); } +static inline void pagetable_dtor_free(void *table) +{ + struct ptdesc *ptdesc = page_ptdesc((struct page *)table); + + pagetable_dtor(ptdesc); + pagetable_free(ptdesc); +} + static inline bool pagetable_pte_ctor(struct ptdesc *ptdesc) { struct folio *folio = ptdesc_folio(ptdesc);