From patchwork Sat Dec 14 09:02:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13908431 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 B0226E7716A for ; Sat, 14 Dec 2024 09:04:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 40B646B0099; Sat, 14 Dec 2024 04:04:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3BD9D6B009A; Sat, 14 Dec 2024 04:04:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 23C1C6B009B; Sat, 14 Dec 2024 04:04:35 -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 012846B0099 for ; Sat, 14 Dec 2024 04:04:34 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id AF4A44544B for ; Sat, 14 Dec 2024 09:04:34 +0000 (UTC) X-FDA: 82892978112.24.D8EED19 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by imf20.hostedemail.com (Postfix) with ESMTP id E56781C0004 for ; Sat, 14 Dec 2024 09:04:04 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="NL8vPA6/"; spf=pass (imf20.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.172 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=1734167052; 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=12IiSMzMVIlfwdGc3SnaXSwRS1fKZAvHGusKFMV1b3k=; b=HXmPMOCliMpduGsIcmPThYmsHdzbWyXZpQFY0UMt68G9L5juYUF+6eUIkjgV0SzOzXheCz FzSf4f4sr6u7ppj13Omo8ghQn4T0/p29+as5GTO+bIuMgUqOtuW83QfQXazAzSzveuJKgR YlMSVVMK692bJ0Z1YCxDlR3q3pFTDtk= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="NL8vPA6/"; spf=pass (imf20.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.172 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=1734167052; a=rsa-sha256; cv=none; b=Id7PfEiFdcMPNH4u7dvEmA7AmnOIXXbEFjjU+QHn726Ll7Up6wvqlIVPBOGch3+PjUMaFh dx2HZU25mUKAZZGL5bDxSBXR7/IW7HsF+kbLHcnmqCRe2BeskeaBjM1WBGeI+ISTOfFnJA vPz5xIrzSE/sTnn+cBDOYczJ7JUvfLM= Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-72739105e02so2791527b3a.0 for ; Sat, 14 Dec 2024 01:04:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1734167072; x=1734771872; 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=12IiSMzMVIlfwdGc3SnaXSwRS1fKZAvHGusKFMV1b3k=; b=NL8vPA6/SotHPoWdVX/wBdgx87rt74vnuIUE7aHH/6NuU8C2lD97oftTzHkF26A5GA ajvvHkYUIKAY2u1n8AlxE/UGriJk3SYugYIcq6/iB/KPulxSU5DtKMFlgfaHiAzsVV2i anGblsrRp+vDq7giXBcbKMZcbsjiTk40Ye4uff1g8CKPWf9dP7fXxGmoe1DeohbxP9BC bxQeLRZhVQyMpTbJXdosMNEWDb8+/wacvqPJZZjFM3Vz2rnR1gfjoom4QcgwHaopb+NS 9oZgtB19uDG7+Pb+sDagKJOBeXjOIZudbi1HEbqoTH6mYUF6pwlskkZSA3wEidhJ2afa +dZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734167072; x=1734771872; 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=12IiSMzMVIlfwdGc3SnaXSwRS1fKZAvHGusKFMV1b3k=; b=IeRJ+BiyumCU6X6Z4gQDzTqNDhMHDQZb/PYW8tKTg7RqWipo4OPoPc8bzzWNVw8poN 3skEAVvtBsKR2w3VYY4VHQx77A7HUU9YSeiG5QYlUGtR+Os0/iP3myYS+Ct3CgDE8xmR jW1jCvzataJ6Z+iVQrTYO9GTe56JuU/GmeYwk0x63OIfff1Tgs/ngunPyb0BSTFKSUOp hER/cZ9wqkeZrYVhB7mUhImCmhMp2vxfxWATiwDdeLiQHE2OXaUO5jskqND/vQdpf8cC b+SxOBz/ydKrHmFCjrmJnOPPKNdhd5uPwQYoZcUSnJVaK00SedaakrtKBAZaDnXqJLBd HIaw== X-Gm-Message-State: AOJu0YxyDAyHwriEfGe8hI29hfNzPqnKGIFN9hWvWm2mFNpJ6AERHjs6 3wqOnHjKxfGVBC8kcnQa6la45Z4gQtKVn4VCYkU2R1kDHBh2iw56GXr06seoKw4= X-Gm-Gg: ASbGncsjqIPkbg5SOv0r59Eo5jJI8RVBLYJF1sdiM5obI4wvtmXwNX5VHi29WSIj9JA S/4Zil2TQVVWSmXnlalcvzU1ePoEUV4mmchryq7Xa/coEV7uexBn+9XZxrFc/KUiNfVHJ94a7jA ZWSuB8ymlmDdwfB2mzJYJ+yxbhhE/J/L81zUKx3qZJViPrqFx2Vz/UkkKP9JVPQBjEtcXK1F1E4 u6jm7ijyftetlBwUeLN+Xx5i+HBSBwexQNJSC5e22zMo+iDxdTzHmCmpeEQ7QEnHKi51IpSJX9D LK8ywXLyYP/TiXBMHRBcknwPJPGxRA== X-Google-Smtp-Source: AGHT+IFvnXDbPrP66UsHi9s8CFtvVszYyEfjge+aAOFm/P/L2638kVYMzofXCSp9Xlrusy3CzYMSYA== X-Received: by 2002:a05:6a21:33a0:b0:1e0:d796:b079 with SMTP id adf61e73a8af0-1e1dfd55614mr8533024637.17.1734167071820; Sat, 14 Dec 2024 01:04:31 -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.04.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Dec 2024 01:04:31 -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-arm-kernel@lists.infradead.org Subject: [PATCH 06/12] arm: pgtable: move pagetable_dtor() to __tlb_remove_table() Date: Sat, 14 Dec 2024 17:02:52 +0800 Message-Id: <59fd7e0364e8dd293132d81b91b28694e70263e2.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-Queue-Id: E56781C0004 X-Rspamd-Server: rspam12 X-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dSiI+RhVYxiylbVaFVPGZAHKilQcYYEfRmsKPtjIxojzW8l8ELtg8w1M/gru5f1+S6YM1H2odO2qTVL1mqsPbHpWDBCj+IfOzIRyTxOLUM1HOdk9jGtjirmUF8a8XA+1OFlyEAhNycw3897BkhnCIOvnbvY/SAxAsVvd0WKYnplkryYcgjyIkr9jIQWIx6kvXo9nQCql+pzckLyfOwNxN0jxgqBwZfrxrnxQEbMOl8epsa63Bv9vgdBexk/McOUSnczwrzjwSgTdu9U4R61ekwemsNUB3Nt3XRygIEjPufqT1kaFcQcwf5yGN/vHgQvZhkP2BBgoJv04++DrcXS4jb1dFseGtJYmG2FHr6yy5fV4+WnEhdgIdYWmzwEu4ZlbPglRgxkYnWoOIjcodGuh97tYhr76vmI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.001711, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Move pagetable_dtor() to __tlb_remove_table(), so that ptlock and page table pages can be freed together (regardless of whether RCU is used). This prevents the use-after-free problem where the ptlock is freed immediately but the page table pages is freed later via RCU. Page tables shouldn't have swap cache, so use pagetable_free() instead of free_page_and_swap_cache() to free page table pages. Signed-off-by: Qi Zheng Cc: linux-arm-kernel@lists.infradead.org --- arch/arm/include/asm/tlb.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/arch/arm/include/asm/tlb.h b/arch/arm/include/asm/tlb.h index ef79bf1e8563f..264ab635e807a 100644 --- a/arch/arm/include/asm/tlb.h +++ b/arch/arm/include/asm/tlb.h @@ -26,12 +26,14 @@ #else /* !CONFIG_MMU */ -#include #include static inline void __tlb_remove_table(void *_table) { - free_page_and_swap_cache((struct page *)_table); + struct ptdesc *ptdesc = (struct ptdesc *)_table; + + pagetable_dtor(ptdesc); + pagetable_free(ptdesc); } #include @@ -41,8 +43,6 @@ __pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte, unsigned long addr) { struct ptdesc *ptdesc = page_ptdesc(pte); - pagetable_dtor(ptdesc); - #ifndef CONFIG_ARM_LPAE /* * With the classic ARM MMU, a pte page has two corresponding pmd @@ -61,7 +61,6 @@ __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmdp, unsigned long addr) #ifdef CONFIG_ARM_LPAE struct ptdesc *ptdesc = virt_to_ptdesc(pmdp); - pagetable_dtor(ptdesc); tlb_remove_ptdesc(tlb, ptdesc); #endif }