From patchwork Wed Dec 18 13:04:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13913621 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 1DA29E7718A for ; Wed, 18 Dec 2024 13:06:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA68C6B00A1; Wed, 18 Dec 2024 08:06:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A568B6B00A2; Wed, 18 Dec 2024 08:06:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8D0696B00A3; Wed, 18 Dec 2024 08:06:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 6DEFF6B00A1 for ; Wed, 18 Dec 2024 08:06:22 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 20595120DBA for ; Wed, 18 Dec 2024 13:06:22 +0000 (UTC) X-FDA: 82908102690.05.8A5AD29 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by imf17.hostedemail.com (Postfix) with ESMTP id E0CB14000F for ; Wed, 18 Dec 2024 13:05:55 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=DItOWe00; spf=pass (imf17.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.171 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=1734527150; a=rsa-sha256; cv=none; b=cR0Vi9PPPEizBMMqXD4rS9OEkvSsAaAfKFwFV4hPpfF5wx14Wh+p6hKFrMGaIDAhEV1xoM i4QdQ0dbWKOlUcbDYFAlmr943cUb/BCjoAFDXNfBQhdWJsfjTf4LNXVKTv4QTGgG8XCnJf loaGan5wHx6f0IVvLAYesXZ1n2AEqYQ= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=DItOWe00; spf=pass (imf17.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.171 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=1734527150; 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=3Ahoctd41Xu7L+7olWYCaTwfCpap8BqbvCHiRFQm2vo=; b=pSHFJ2LEH2BdkVNVh2UwpsbikYlDUyfPlsi2DpRYl+bbmKtuzEnAFRlc6ErHJmV+ViB6EY SbUQvmFw1kprVUFlXduZfC5DZ/+DCD1Ku4pYl6iNOgBn/cagzKlvMPqiiM6d17ZFs9Wo48 Gdi1wSk9c3OXT8PEVsQGY5xZGj1DdTg= Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2163dc5155fso55970815ad.0 for ; Wed, 18 Dec 2024 05:06:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1734527179; x=1735131979; 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=3Ahoctd41Xu7L+7olWYCaTwfCpap8BqbvCHiRFQm2vo=; b=DItOWe00Pgtn/JfwO1IHf/Ue+K0Noaq2L1AJKbaHwNjA4YnDKetok+8Syabl4WNSh0 He+ZfTEn0IVJQpq9+oI+k718o0BGmaasl1vcbGTtropCk/B5F7T7Y6odYOlcB0owRGAV RIrNy9Tejk3SjAr5OtP5bDxqiZkKPOMtjSNjk1h4R7aD4tvazP7YWwy7rgay3k5vulk2 SjQA6VVW+Jt/OYom8ikYoVE/bTNsmJHBbMsN8XYx9Hw1QnhxQV7XlwFu1QgUa2/508f4 5nz0lQVvLIeBgNGrKWACJ1s4a30kGHStM4XRcUKH83uQMrK0Czbl+ChD51rB5mgcoKWf qryg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734527179; x=1735131979; 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=3Ahoctd41Xu7L+7olWYCaTwfCpap8BqbvCHiRFQm2vo=; b=WeO5D2Du4JRwM85Nk09BihtXy+Ndxp36X3AAPXp2VNJcAmWp1Ofsk9eMtmoXIMxp9J 8G1H3EU9zNkyNn0Ms9amUkvgs23R6/gMU2uPgJvMyndsUNFovz1ou/kXe03RBOCP5kWo ec3Dd1YE49yDWF7b64WQ/p4gGhdLWj8JvQUKAx7xJyHhHciHZB5m+vCAt/Bc9jIiegSb qmhp2LUmFRyPlnPWIihPI5ZbFlI6eX0R9GSeDnGqxticegHcMdeCq0Hv4gqYaqCf5kXi Zl/07lg0EV3kqlduYLTlKBTnmERhUdCkRAOmXvjpY3qeYENP/2X97pdxl5raiIwcXMoU 0clA== X-Gm-Message-State: AOJu0Yy7Q4aUPrEn0b+tIMZTrc0f6TV858HZaSPddEwDxq1bnG7enRrM 8sWVeztDSNoZmvEFHyzXcplt2PD+8ntdz1VmNuRfAWUPOkrChX5fqXI65Z7SL9Y= X-Gm-Gg: ASbGncui3tgP2W4RXrS4U5m7FcG9LVN8Hfng59NJ4IHRWFitbZqYHBCw/RMQ6DRS5pf FYbEVHOKs2zR5Z2p+pDSlpaK2uER+VXu0tBn1NdVGcvy7QXSeXGePYUeiPO94c/T6ZZGLHA65wx JhLBzByp4c26QE9nNCaTsTQ0ogiYU0ZXSwZ6Jay0sR0TmMC9cCuONoGi+50mnpbCKJnWsRLZ+lw 321sibh/ZpOCcDHUGypiUNlls8PVsiEqt2kGMhdijFEwQ3D0HP/r3ybLn0shkZXK5p5CvUgRb17 LpOXt/TFGiDUkOHKPNxrVQ== X-Google-Smtp-Source: AGHT+IErwrhCem5fzBI6a6wl06mNTQ9yKVlkmz7hDOEqq4HxfcsAp66u7+2R+nQ/CreR8BGTw2JG1g== X-Received: by 2002:a17:902:f646:b0:216:393b:23c9 with SMTP id d9443c01a7336-218d71fd765mr39074785ad.29.1734527178847; Wed, 18 Dec 2024 05:06:18 -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.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Dec 2024 05:06: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, vishal.moola@gmail.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Qi Zheng , linux-s390@vger.kernel.org Subject: [PATCH v2 10/15] s390: pgtable: also move pagetable_dtor() of PxD to __tlb_remove_table() Date: Wed, 18 Dec 2024 21:04:46 +0800 Message-Id: <0a6caf8305409173b5d41dccb6ecd46460cf9c1c.1734526570.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-Queue-Id: E0CB14000F X-Stat-Signature: jxp5za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c3q2vVgC39d2iCRdSfSf/qduDEqVtY1cwqAVsjGluzjRl21RyfrqYA7zkV6DNP2+9HWCiKTDVeFTGxEJk1bTfo51mviCmBRCtTRwHs2p2EKkEMaes3wDqw/hot871fvYJyAMg+vf63l8GmC+mJPlYWXvlzkGWG8IfDXnqQxhT+GHFuIBScZp36wnUnmun6k7HSKemiu3h9VwYIxo2SsIO3rIG0kaUeZaGK8+w7YhOtJEVYIShk/gXaq/w0MrWvGc2IyP+RaDgVKRcKMIyFG9LVfdXv6RonhhqmYKTctzlhyeCdMqcZAxAm3LiZ+TWKpPPJBVGdf/KII+ktQSira32mlR7q8M0uHg1sIpAM86U84CgRPgCt1QjJzgROH7PQ9jrWyQd/v3L0kVSAWNvS8KNP8Qs0Irpd5/MG8oNj8bnPI84MzYVZVRNknc7CGJ2QijlA9e/ImD33h2DnxQNlAOcXVNDBYfNGqI0bpGPGa8b5yjscRUWXRDnPr X-Bogosity: Ham, tests=bogofilter, spamicity=0.000814, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: In s390, the pagetable_dtor() of PTE has long been moved to __tlb_remove_table(). So similarly, also move the pagetable_dtor() of PMD|PUD|P4D to __tlb_remove_table(). This prevents the use-after-free problem where the ptlock is freed immediately but the page table pages is freed later via RCU. By the way, rename pagetable_pte_dtor_free() to pagetable_dtor_free(). Signed-off-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) Cc: linux-s390@vger.kernel.org --- arch/s390/include/asm/tlb.h | 3 --- arch/s390/mm/pgalloc.c | 14 ++++---------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/arch/s390/include/asm/tlb.h b/arch/s390/include/asm/tlb.h index 74b6fba4c2ee3..79df7c0932c56 100644 --- a/arch/s390/include/asm/tlb.h +++ b/arch/s390/include/asm/tlb.h @@ -102,7 +102,6 @@ static inline void pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd, { if (mm_pmd_folded(tlb->mm)) return; - pagetable_dtor(virt_to_ptdesc(pmd)); __tlb_adjust_range(tlb, address, PAGE_SIZE); tlb->mm->context.flush_mm = 1; tlb->freed_tables = 1; @@ -122,7 +121,6 @@ static inline void pud_free_tlb(struct mmu_gather *tlb, pud_t *pud, { if (mm_pud_folded(tlb->mm)) return; - pagetable_dtor(virt_to_ptdesc(pud)); tlb->mm->context.flush_mm = 1; tlb->freed_tables = 1; tlb->cleared_p4ds = 1; @@ -141,7 +139,6 @@ static inline void p4d_free_tlb(struct mmu_gather *tlb, p4d_t *p4d, { if (mm_p4d_folded(tlb->mm)) return; - pagetable_dtor(virt_to_ptdesc(p4d)); __tlb_adjust_range(tlb, address, PAGE_SIZE); tlb->mm->context.flush_mm = 1; tlb->freed_tables = 1; diff --git a/arch/s390/mm/pgalloc.c b/arch/s390/mm/pgalloc.c index 569de24d33761..c73b89811a264 100644 --- a/arch/s390/mm/pgalloc.c +++ b/arch/s390/mm/pgalloc.c @@ -180,7 +180,7 @@ unsigned long *page_table_alloc(struct mm_struct *mm) return table; } -static void pagetable_pte_dtor_free(struct ptdesc *ptdesc) +static void pagetable_dtor_free(struct ptdesc *ptdesc) { pagetable_dtor(ptdesc); pagetable_free(ptdesc); @@ -190,20 +190,14 @@ void page_table_free(struct mm_struct *mm, unsigned long *table) { struct ptdesc *ptdesc = virt_to_ptdesc(table); - pagetable_pte_dtor_free(ptdesc); + pagetable_dtor_free(ptdesc); } void __tlb_remove_table(void *table) { struct ptdesc *ptdesc = virt_to_ptdesc(table); - struct page *page = ptdesc_page(ptdesc); - if (compound_order(page) == CRST_ALLOC_ORDER) { - /* pmd, pud, or p4d */ - pagetable_free(ptdesc); - return; - } - pagetable_pte_dtor_free(ptdesc); + pagetable_dtor_free(ptdesc); } #ifdef CONFIG_TRANSPARENT_HUGEPAGE @@ -211,7 +205,7 @@ static void pte_free_now(struct rcu_head *head) { struct ptdesc *ptdesc = container_of(head, struct ptdesc, pt_rcu_head); - pagetable_pte_dtor_free(ptdesc); + pagetable_dtor_free(ptdesc); } void pte_free_defer(struct mm_struct *mm, pgtable_t pgtable)