From patchwork Wed Dec 18 13:04:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13913618 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 E80E0E77188 for ; Wed, 18 Dec 2024 13:06:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7BF466B009B; Wed, 18 Dec 2024 08:06:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7716D6B009C; Wed, 18 Dec 2024 08:06:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 637546B009D; Wed, 18 Dec 2024 08:06:02 -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 44DBC6B009B for ; Wed, 18 Dec 2024 08:06:02 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id F1EE41A0DF4 for ; Wed, 18 Dec 2024 13:06:01 +0000 (UTC) X-FDA: 82908101598.26.64A41D5 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf06.hostedemail.com (Postfix) with ESMTP id 9B3BE180020 for ; Wed, 18 Dec 2024 13:05:37 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Jfc3Ci6w; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf06.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734527144; a=rsa-sha256; cv=none; b=7CH311fyoTvQimLtFpDcC1CQvcOY0DpAT0iEF5d6hSVrwFooNO4Pz+mwxK6+vy3J867jGx W7vTb2kH7GO9ulvc5Kd7dfdYKejHZvYSOzQsChWS/bR5DVQa69HaIBrIWLLRmRkzMHOqdF s8XBSWwB8jvT1wJdV+1znBS78J2O72g= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Jfc3Ci6w; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf06.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.175 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=1734527144; 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=0nJ0bdEaVLB0+13gaCQHdoBfFkuXXT3Pqta7GOjv8Bo=; b=q6rpj5tOUadcdxb/ebFIm+k/AwiHULmZDCDwSUNsmGPf20hzUP2C+2FfFvtlrNYkIJnCN4 0ovwrDgLq2f0JYQ3GYrT1+tFEHar1Imqqa4XaN+ps2bVbyVtj8tJmN98fpyahbWRt6ioPr G/vWJpKf4YI6AkNZKgl7Dc6CeWXwqk0= Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2164b1f05caso59754215ad.3 for ; Wed, 18 Dec 2024 05:05:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1734527159; x=1735131959; 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=0nJ0bdEaVLB0+13gaCQHdoBfFkuXXT3Pqta7GOjv8Bo=; b=Jfc3Ci6wSEL8FZ55c+t9fBBxQes8GUkXt3DIvrDVK3J1IWQQfzDk1o9v97ROA1tpqO q/GF0Si0QuTEm52tnMM5fuGWDrDu+o9NgVfISBaXnTe6by93ljDurXuYBikyN6LkbQbM DK3QDzWGPs3RavUbrjObAWeVzFc7U85lP5A0KYwaGKSK/aNGItFcUqj59FSjmhrpc49W BFU9TeoNssCUHad1ew63uGRdQzUZpw5/KwFzrOoIzbkchjhJGaYHNg5Ez3sFzqh7P7gB y5a/UzaABXayxQU4Sm5UtAyzF09kmMUlE/wgJ4+e8Ek9pwji/UZKegVPyt9sPI4crS78 0t7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734527159; x=1735131959; 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=0nJ0bdEaVLB0+13gaCQHdoBfFkuXXT3Pqta7GOjv8Bo=; b=mvSLJuiQZC+q6uH2faF4HGB1lsaPHC3mpjsKgTl9zB7tbvVWQnzho/YvpLAgjD+n6t JAOi4IGZhPEHxjQ8zNrMOvtNleQBILitjpHyugRuC2rT54ePe1r6EjzwO8NZsn81iha6 d0dq2Piv7LuQo6mOicOi0CdYJZuav0kHWrn5/h8wy3dDCbuptMWlxO9FMaj4j2z5qfmv bLqb/YE3zazg3YNSdFbu3nIyaa8Kwwb5sADfOXrECpOancPDoYGp+FH0zpPEIW+HKV19 SoEK6nUjdsI7MxkWEppoNx+dpnJgT5Ayv+I11Ct/W0DjcTaK2kEGvoV+xeIMIyi+zWfN jnsA== X-Gm-Message-State: AOJu0YzQOfwnKT56TLqVTZ9dJt7mp41Tt7SmyHMApwxgBOqU6RkfpC+x pI/rflOmpQu4OtNgNssxGwunIAc5Sj4gou5Zn25AP5S+GgvHEm0NKo2Yukvxhyw= X-Gm-Gg: ASbGncuK+L9+8mcHn3WKaOADjyRss7AIPf0XvaL7dNbHmpv7L4ShQU4Jv4JYHVmpKB2 iT3XxS2bNTTTYbcNvkreyQkDvKwQtdmm2HSu/H5LciAN6K6ABEIeBJZabina/9A8nRjpcufBacw GGiQD+SW7oPAs+wCJ0vf/RrlHvhsvrk+2r39M6fLHYFT1T/hKYmBrpw4+0fO3Quc/18FWOVyQOK pxBisVWFJU1vLDfSS346TZX3qovj3hTiWYp9X9ix2o6mIHVEtmRjYDRjO0VsUz6P0XpVJnGyitx DqeNXwX7ZjCsq+fkNYqNgQ== X-Google-Smtp-Source: AGHT+IFH9P+x/Mfn/YDKtSKvkH1s3GazvpYiwIZf55I8HG6lzpeJuaV9oSxqUwHwuTwe8mBCoFXtDw== X-Received: by 2002:a17:903:41cf:b0:216:4dfe:3ebd with SMTP id d9443c01a7336-218d725ebd2mr32859975ad.50.1734527158730; Wed, 18 Dec 2024 05:05:58 -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.05.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Dec 2024 05:05:58 -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-arm-kernel@lists.infradead.org Subject: [PATCH v2 07/15] arm64: pgtable: move pagetable_dtor() to __tlb_remove_table() Date: Wed, 18 Dec 2024 21:04:43 +0800 Message-Id: <634f0236b4b4effc528b06e108b7bda51cd0ea2c.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-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 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OXa8vVJxPMD1f7zjPMPkBc9MPayYMt5aBRd9598KeJsxt5Xo3jopxqmVoOHmhDAGDfDS8y+ZP6P7nfbKANGfXCcRVTUpvaiok/WiJ6JFzKQVN/8vvCW4hbhk79d2bWTn68Rjitt+bt9oIF2AHN7Ka1iCXNclZwAAYMIPB3MegAaH0I/HNhodVwzFbTxWLCOZZj8L2fJTxnycpS08UWYUQb0Wq7k+jEmxbXMOi5oGju0sRjLgctM/lBcDkFWpYCtCMqJY4kI0ONKy+4bhKUppe0ttYauRl9shEv7DEFWQC4/e5uFMbx6zjYHPrbLO1+jI3xsK7RdxbM9gBKKPaG2ZswpfCpKRCj7zoEN7wppwtzkgk3Og538Y6VsTYoAK9pnlZdmPBRduy3eB3kWVY0M85Vvu7+Kmu216zdtq7HIbz7a0ogN8N5xxqsZRvUC/Msyr+BBMvGT1g0Il/hivXetkq8cY3ngcBkuMmqf4eObuGUQ3g= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000249, 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 Suggested-by: Peter Zijlstra (Intel) Cc: linux-arm-kernel@lists.infradead.org --- arch/arm64/include/asm/tlb.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/arch/arm64/include/asm/tlb.h b/arch/arm64/include/asm/tlb.h index 408d0f36a8a8f..93591a80b5bfb 100644 --- a/arch/arm64/include/asm/tlb.h +++ b/arch/arm64/include/asm/tlb.h @@ -9,11 +9,13 @@ #define __ASM_TLB_H #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); } #define tlb_flush tlb_flush @@ -82,7 +84,6 @@ static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte, { struct ptdesc *ptdesc = page_ptdesc(pte); - pagetable_dtor(ptdesc); tlb_remove_ptdesc(tlb, ptdesc); } @@ -92,7 +93,6 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmdp, { struct ptdesc *ptdesc = virt_to_ptdesc(pmdp); - pagetable_dtor(ptdesc); tlb_remove_ptdesc(tlb, ptdesc); } #endif @@ -106,7 +106,6 @@ static inline void __pud_free_tlb(struct mmu_gather *tlb, pud_t *pudp, if (!pgtable_l4_enabled()) return; - pagetable_dtor(ptdesc); tlb_remove_ptdesc(tlb, ptdesc); } #endif @@ -120,7 +119,6 @@ static inline void __p4d_free_tlb(struct mmu_gather *tlb, p4d_t *p4dp, if (!pgtable_l5_enabled()) return; - pagetable_dtor(ptdesc); tlb_remove_ptdesc(tlb, ptdesc); } #endif