From patchwork Sat Dec 14 09:02:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13908435 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 7ABAFE7716A for ; Sat, 14 Dec 2024 09:05:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 125996B00A2; Sat, 14 Dec 2024 04:05:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0FEF36B00A3; Sat, 14 Dec 2024 04:05:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F085D6B00A4; Sat, 14 Dec 2024 04:05:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id D07716B00A2 for ; Sat, 14 Dec 2024 04:05:12 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 88399161989 for ; Sat, 14 Dec 2024 09:05:12 +0000 (UTC) X-FDA: 82892979666.22.212D075 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by imf01.hostedemail.com (Postfix) with ESMTP id 79CB640007 for ; Sat, 14 Dec 2024 09:04:50 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=RPEIBTOh; spf=pass (imf01.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=1734167082; 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=eMqrm4pkcrZJ7adK/0JGqqs1dXiKNR49XOWaF/ar7JI=; b=pS0jwXQkq7pGzeuA6zxtd4BXgGEHm82ZM4dllaPIRlYQeJ4tDuytUpbeFD8Fg9KqyFTmd5 VxcHuFjf0VDmGNvjz9Eyhhf/JXCzgkeaPcoV9kNIZlKtFk/fDWpOd4NNAwkAUBFB8k3XGB gidBEfIMMC4wfCnbWyqi7QJ3oBSFu4g= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734167082; a=rsa-sha256; cv=none; b=aFNGIn/mLE9W1BqmVj+cyBojdjH73C+HezOc8H08B7y368kit5Want+wH9CGxnvnnnk0XI Z3fI9tC2jmDKOs/gGXVpueHRGASd+hOJ+gFv65PZtLBK2KGHeoCW8z/mOfO+eaUUE8CNIK 6vJXvqpwQdsCYBZtfmLHDrfEAUZ1+h8= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=RPEIBTOh; spf=pass (imf01.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-725dac69699so2193755b3a.0 for ; Sat, 14 Dec 2024 01:05:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1734167109; x=1734771909; 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=eMqrm4pkcrZJ7adK/0JGqqs1dXiKNR49XOWaF/ar7JI=; b=RPEIBTOhCNZJ3DeRtgiTdcA0JvaZ52asqSAbZ6slDLNprGO4GjhR9p7LQv/zjbKRfs BO6m4fSp/Hb5ikG1JNSufRvl4vLiNLOw1rLukMTmaxiXNZ6ozfn0akUzsf8iFM/8dQ2v rMzf9n1KeWnTa5Tw4WHyD9geBVkNBeuDNl0fsNxRPiNUzmbyZPEf8PIFUl6WBg+l1ZF/ T5xQueWcSZ1eOxOWuAR5vf1KzQneWAQtmMQJRrNKhHqiIAdkHVgK0+zkBMA1ZbzfFEnF cgOo0ag7FhKs2LoHe4ZP3Ni8FOwZJ4RT/UmZISYeYb5bq4Ks4tR3nsH0NK5S25jj9rUl A/Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734167109; x=1734771909; 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=eMqrm4pkcrZJ7adK/0JGqqs1dXiKNR49XOWaF/ar7JI=; b=XwNnRwid/N7qZGDLK8HzshP6UsTLg+l3Kt2jcpoh+P2vcVdgLIH+jHsq44jVo2x5MH N7Owm18IE8t7w/nOynQj300UxPuisBhd6J19FYePe2E9XKTvC04L9+czpVAUhdyHhikS ErdQt7AU14bS7vzn3MYst7MGsnVy7FlnX0LDgu0nCCR/PNa/fzo5/7mUq9vHwSMsJj5J vZ//IZ5md75imp3RqOQYS4iM65AoxKSmOdO2RVJv3A0jHuiY8yjZzydeS+jM0YiYVUtP BHEgmgYATI6xOLzkWteR4vDqhXmAb1zOJaXhxxFMW/tfITjwwQCZCoKMm21ZC3i3Y3lM 3o/A== X-Gm-Message-State: AOJu0Yz7kpWuaEBFutkhJus6j08BXY9DfU0jpm5aVRViDHuCJQhVrJhy Dfoyf0Bmf66giQ7VoXsoE1iicmUviWvJu8fdBpR5nUJCkY9QfKPSeC1Y+hsAsXQ= X-Gm-Gg: ASbGncsgfTWp2fewnA6PEzfQtxG8KwS1PWV27AiXBTdkeEmv+1Q6n7TdFacRlehVIcg jxgVZ4H/rG5XDeQ9jLX4enxWYU4C/QYl+U4AGpNZama2DP9hGieuPRO9DkzdU3/N3XOOFrHAFpJ 4B+SSYJybOm+u2VTPlRBXbWDRWIyl0U6dK5s2ou9QxzihlwVb4TizaVSv/zcCWhjFlCPXDLlksM dCFfO+hs30n0YMKYPq4y0WFOwGEfJzendMcSis56E39eQUsWqIQV0ALd6gaH3lVux5xqZiQSu3q Mvg71dN9mB3r6CLIT1cZeoi+Pjeszg== X-Google-Smtp-Source: AGHT+IE/1mbbP4uNRetgOIypjg2bvSDj3GWH/cGEc/xqzPLinfL2kdCDxCigFtQu4L9Hg/0wQ4NEdw== X-Received: by 2002:a05:6a20:a123:b0:1e1:96d9:a7db with SMTP id adf61e73a8af0-1e1dfbfc129mr8345681637.4.1734167109554; Sat, 14 Dec 2024 01:05:09 -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.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Dec 2024 01:05:08 -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 , linux-s390@vger.kernel.org Subject: [PATCH 10/12] s390: pgtable: also move pagetable_dtor() of PxD to __tlb_remove_table() Date: Sat, 14 Dec 2024 17:02:56 +0800 Message-Id: <1e87efe43e9b8b679384e947dd8503715dd9faf0.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-Que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EA zJotF70Z Cj1TfmsmsiaBLSjRks5LGwqdOrvD1DgrPcl4JyLiF3K2FeT8Uin5Dxhn/g82m++SwHynl24pXTIG70VysjvLpnrmFmBizZgWdlE6L1gSHsdfPbQr1a+LNR7H+XifErlsKIk7N05Z5tBJS0V/lDeBGX7aO/UUnWRhuS+1zXeKo5CN9hmSt5r6+QkjJLWTIYtJLbsYXBS0bSmqbvIRZadcaYdXjBUl/UoZpLZTL7+qi3scuVNOMVg73ht8AHSBh2ZO1EZ+ssfMRfkWsWCZNR4QqLNlBRZBgNiOn+3Iza9NkpxZ+4jhVBzAqV2fpDR2t6SSncPitk9VD5Oyat7uD/ZCsm1wpCrYwpx2R4uqGbP+zku1OLonyv1jREsaCTOxmELrbRG0FxWm+YgpheO8= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000066, 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 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)