From patchwork Wed Dec 18 13:04:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13913629 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1FD7AE77188 for ; Wed, 18 Dec 2024 13:06:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=hRj0wkIcDyLmKPONLgLEnODGJVOQ/lxkeDhrLguGMRU=; b=4qPPbcP49AeizdwVHhbF3VgVWV EMFQjhdhMGc8L7OgctgMHndYzEkQU/jFtS7i88FAjUSf6Zk1yOUSH9GBmKPGP9xrf4EE/fF7d6teV B5OewhXjyzxFN4Fj4GLBhWYYSpyYYGX9My/9vsMZk7MqVXs07HfdunyLYSAMxEmhH3FjbuvPFCWpJ Wm1WA15MeXREp9znDFeHmwesd8iLYVhpCOzQ7pZLPWNMCI0ufLxhlGh3nWwUkVbyOijrgOHV265N0 /z71RiaLi3f1DiOC0JG8e32DLfKJFigMCKQ2EZKmNmrMiehUUrWVX6xlggUGadrMK7Ak8poaLR7sH fJhw4Mlw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tNtl9-0000000Gfpx-3N52; Wed, 18 Dec 2024 13:06:39 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tNtk3-0000000GfPv-2HxV for linux-arm-kernel@lists.infradead.org; Wed, 18 Dec 2024 13:05:32 +0000 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-2165cb60719so52142595ad.0 for ; Wed, 18 Dec 2024 05:05:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1734527130; x=1735131930; darn=lists.infradead.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=hRj0wkIcDyLmKPONLgLEnODGJVOQ/lxkeDhrLguGMRU=; b=LmGok5mH8h4uu9Sbv1qxhkDZb5TWayVEUzC4hqFKkyOnkHYVXIZus1KclqcyclYibJ JFrcvpgWyNflh4eq9GEyaOR5kCvakJP/5tzz/wHUQJAsv6//ArQtqcfvaZjiE1cZbMkw ZR0Ma0byzzQxWdcccFBgPKBTyhfclfmD+II/hDXG665EBlrn5xEhiKrV6Gtk8vyE+vsU pVUo2v5jXQFUCHuZ8KSOmC7cxQaQeU4Kt3E5tEmNlHWoFelhWu0PI1BhflN77HsVarC8 /R3Mzt2aFKN+TNK0C1lY+oHtI96QTCLRb30xAbnApaFIAledNC/IXxLHwLN3Whr33zSX neFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734527130; x=1735131930; 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=hRj0wkIcDyLmKPONLgLEnODGJVOQ/lxkeDhrLguGMRU=; b=oYajCy7u+W7l9jlfMxX6uepAdJff5bCt7SDHFXKQYklUq2QGoUk1zNbFNt0pFb2L+0 C4LEDBW/RPs17ZccSb0js3uENz3IJd+CCgpuISlqRMDsSHLqoGE2CiJ3YmevoGRDErz/ yBBGELFdCVdADMK1+ErGxEbjzs4Zbs9ERrVb4RzGsl6V9LiDL0vvFmnj1tmqWdpREGr/ UIWDFUscdCpNxCUkGDO1u9bGnj4LXCcqhBiPH2oPhukiXRDSyUTyKzURAkNqGlXOFU1C SULyZ5qP3Y2SlNvO7cdpUaxDst/Raebx9ch/8QPOcJ5/pO5g8zeHgFEMEM6OBAJtkDdz yekQ== X-Forwarded-Encrypted: i=1; AJvYcCX2s8kBmTzR17GITl9NMimwDJgMithmLD3bK/i2+AJIOMWvFqWwDV7qiegOz3kxbvHiiVrZyCTeRVePFyyFLzZq@lists.infradead.org X-Gm-Message-State: AOJu0YxeU29Gu1g77ieR49Afm5K929SqgR38pPKbDtUOdetN2bRfS4Dg o8/4/fksyYcAdJkMegjz2UVi+LUPotfuyZnRqL7PYKlN4nIvC8ElVV4lFod590g= X-Gm-Gg: ASbGncvt5Gatw8P5pZjvRCaKqFh3ftkwc9BoJsL7o+nTr91qAC4H/+JelS6OLZdrmGV mgCjxpSnb6+vHkVIZ7EYo5Mnk4KLWP70GYtcDC6Aew2GY9u1A2VSWR2rpqWco+fdJ5QuWoMsHyN MINz2HiFmmEu0FlznsF1DGdSRtg/G/nDRUoduiXynqh8CFmqBWdP5Wnd+duIahSQ2dkKa+Y9DbE Y8vISzUEEMeAimTNU2IAqZ1mtkfnhpIfnDen32Nj/Eu4pML4nFxxYeSsmqakbIQBGpbgZ468P0R kns6grWAlROu94v2Y5pO5Q== X-Google-Smtp-Source: AGHT+IEbMQUiOWkQtVsukFUm2ZLuTFY97EKfs/PZuqMM+WxRQxlasXxPYQ7Z03KXqwqNdfJrdRWLVA== X-Received: by 2002:a17:902:e5ca:b0:215:4394:40b5 with SMTP id d9443c01a7336-218d724abe7mr34796235ad.43.1734527130325; Wed, 18 Dec 2024 05:05:30 -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.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Dec 2024 05:05:29 -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 03/15] arm64: pgtable: use mmu gather to free p4d level page table Date: Wed, 18 Dec 2024 21:04:39 +0800 Message-Id: X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241218_050531_581344_84B3EF4C X-CRM114-Status: GOOD ( 10.19 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Like other levels of page tables, also use mmu gather mechanism to free p4d level page table. Signed-off-by: Qi Zheng Originally-by: Peter Zijlstra (Intel) Cc: linux-arm-kernel@lists.infradead.org --- arch/arm64/include/asm/pgalloc.h | 2 -- arch/arm64/include/asm/tlb.h | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/pgalloc.h b/arch/arm64/include/asm/pgalloc.h index 679c530549327..58cc260b6bee8 100644 --- a/arch/arm64/include/asm/pgalloc.h +++ b/arch/arm64/include/asm/pgalloc.h @@ -100,8 +100,6 @@ static inline void p4d_free(struct mm_struct *mm, p4d_t *p4d) if (pgtable_l5_enabled()) __p4d_free(mm, p4d); } - -#define __p4d_free_tlb(tlb, p4d, addr) p4d_free((tlb)->mm, p4d) #else static inline void __pgd_populate(pgd_t *pgdp, phys_addr_t p4dp, pgdval_t prot) { diff --git a/arch/arm64/include/asm/tlb.h b/arch/arm64/include/asm/tlb.h index a947c6e784ed2..445282cde9afb 100644 --- a/arch/arm64/include/asm/tlb.h +++ b/arch/arm64/include/asm/tlb.h @@ -111,4 +111,18 @@ static inline void __pud_free_tlb(struct mmu_gather *tlb, pud_t *pudp, } #endif +#if CONFIG_PGTABLE_LEVELS > 4 +static inline void __p4d_free_tlb(struct mmu_gather *tlb, p4d_t *p4dp, + unsigned long addr) +{ + struct ptdesc *ptdesc = virt_to_ptdesc(p4dp); + + if (!pgtable_l5_enabled()) + return; + + pagetable_p4d_dtor(ptdesc); + tlb_remove_ptdesc(tlb, ptdesc); +} +#endif + #endif From patchwork Wed Dec 18 13:04:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13913630 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6DEE4E77187 for ; Wed, 18 Dec 2024 13:07:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=qA0mhWnXo6upWemI3POPEc6VJyAkyxFJggkOB6WNq2k=; b=fQxfwvdfLluDs+z0GeQ5T5GdzP UbJoMJzuhmmZ566uA2EYlOHRmRiFGHsE/m5EXx4XBBK9PgGpsCyNx2gId0v9Ls3d+KAeyClieZ1av XHh+u4e7VUTC64FA0x3ns+bW1D81+bnYERJTW0sut6L5hnc0gjqZs5Dx12pDe/ncKS5hIYMFLiVgh ASj1IIE2wmoFHy0jCzWTVhiQLzZL+W/Ma6atW4Zx5gEwcm9BMcfWjbBAFO/EjxGKMeo/6SKqsaj0Z O8JdKw67idmd2XK0aQApgLaDfM6gciXoyJIfyFfs4NlGXqVYnOxUKdAfnipL5PO+EUca784XBVszB DwNfLaug==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tNtmE-0000000Gg6F-1iao; Wed, 18 Dec 2024 13:07:46 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tNtkO-0000000GfXv-2eBV for linux-arm-kernel@lists.infradead.org; Wed, 18 Dec 2024 13:05:53 +0000 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-2163b0c09afso57214305ad.0 for ; Wed, 18 Dec 2024 05:05:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1734527152; x=1735131952; darn=lists.infradead.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=qA0mhWnXo6upWemI3POPEc6VJyAkyxFJggkOB6WNq2k=; b=M5QqjEAhefXNTprv4JTnbEwTcAApd0sUcEVldqSHy1Y0euYTt7ngdYMJCTR+oA0QPD UR5ryzfTHNT1uomZypYAfg53zrr0340s9dZi/5+MP4N4OA9/gHJ7JrzKAbva6N3xos8Z 9Bq/8R2lg0TeUE3ACemB2GMvfluS4vQO6w82vEy6em2yyZ97Vk2ZxM0iJofE3ZTn1Fk0 oU1qVbI0CE0voLu1ZgI+KIYt6aRGftwxI/SlaSUEebmolbws0drefW144yZRgCXyauFh OT6yxdVg+3QrBlrW+Qb8oG6V805065jAJU3ZGr8l8QJrIc/7Q8Li8HvampeHlXim1rpZ Czqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734527152; x=1735131952; 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=qA0mhWnXo6upWemI3POPEc6VJyAkyxFJggkOB6WNq2k=; b=rAkahHjF4genzUm1MFLYyc+aBXYmRKK3rOK9fs22KGQLJyKgA3RAKVcTTCiXzpiqgn 1nvAqMU8MQMJX88A8i38BJbyrEi40xY4aCDepCWwyHkcNS51Vjycsv7tYFb0iq8d1oQH csatssRnc8Exfkfnr68k0QWpZeu9NB0zKTBWO0cVK5bCy0WsWz36bZMlllAVscml5xmf G1qljErbjmdydmf0U5mQBq5p6WccJXROc/RQw7lrqRyf9Ak791gC1kFZVbY5LqOghWJM PriSSLq/eUFCSC16VIlF4wmjQ2AAeU9PQPFDEn2Wx94yStOryq2kHjLgYy+hx0+M6pAl mnoA== X-Forwarded-Encrypted: i=1; AJvYcCVBxX8hriGJuOMsGDElTFN/wg81+JlvbQEPNHTqQ3bBG0OykjEXIQd+yDLw8gAG/nAXqslnpJT5Z3uXWLsvT+n+@lists.infradead.org X-Gm-Message-State: AOJu0YzzvWZEAFjWjuk6NfkgaBdiHxfYTXJvjH4/Qm3TKCb0nqv4fPmD h+fd7h/6hSv/tew7n6lNA/Q5D5omP5rK6Af4vbIU82uRh5idw6wVtB52ZIx8zzM= X-Gm-Gg: ASbGnctQDen/akihVbrKLlm7duLuOg6pR1rqyXJZnr79pNFZ2z315GCO+MOpA/wR4x6 BbhaDJowgHB28bUFHIRTM9XtkaqleOkD8KuMgHFaNRhvHOMAcrqmiRDkup3QWBV9lGbSNFOqapP m/fvaBXrS7zEuugNl6vJ0hm/jH91JTMOVDOJoAdwPIr+8i/4FhcDOb6+h9aWJJUdT8x1UQMmpcA sGoxUKNGsehfj8ot5pphFrpCdaLO/sWNMavRHY29FKbVzdpGB5pmD9/569IMGq0aa5NSRsZvRJY e6GRk4DhS/CqrlXAs6qZRQ== X-Google-Smtp-Source: AGHT+IFdeNYkaToIEDdUvkBTd8lP/0QrRZpL4HARu9WlaN/FvfyhXaaWSW9JhSu0jLr2tRkQ6EUdVw== X-Received: by 2002:a17:902:f68d:b0:215:b058:289c with SMTP id d9443c01a7336-218d70fe050mr36430515ad.8.1734527152123; Wed, 18 Dec 2024 05:05:52 -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.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Dec 2024 05:05:51 -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 06/15] arm: pgtable: move pagetable_dtor() to __tlb_remove_table() Date: Wed, 18 Dec 2024 21:04:42 +0800 Message-Id: X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241218_050552_666377_DF83683B X-CRM114-Status: GOOD ( 11.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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/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 } 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: 13913631 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DEF98E77188 for ; Wed, 18 Dec 2024 13:09:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=0nJ0bdEaVLB0+13gaCQHdoBfFkuXXT3Pqta7GOjv8Bo=; b=jvIaB2wWUQEGs3Xhb5fwwVRlCu TY6wQed54lNNHVQm8S3/LSIAokRC4+SLfG4TuLz0tMnuz9lUIgNisLaQ7CueY0c6hrBIxipOlzSd6 XzkkBfxSsk/8CB5Yc4rbxrp2nVIjDsxgjxhA4h8UwmX2ulgxCIG9MPQYpqJBkCvgUXUi4w0v96MGa 03KwjsRdMiQC4jhQV8OpmzI0zDq/Royj2qozL08ggeEly5MUL6VAHngJe2onDS2yBNE0kG0FZiCrv LJikx/7k5NNgZsZS8VivgLm11M5E0v0/ZCQWFgZt8wwxQEUYzNKpi550HJrrqTSK9uPqqlEaSMLat UGRiNe0A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tNtnI-0000000GgKZ-0MnR; Wed, 18 Dec 2024 13:08:52 +0000 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tNtkV-0000000GfaM-0vNk for linux-arm-kernel@lists.infradead.org; Wed, 18 Dec 2024 13:06:00 +0000 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-2163dc5155fso55965855ad.0 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=lists.infradead.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=TGifs1C29YB8qB1pcTlGhI08D2dPJf9zCxR0+Zrr8DKBC5Jb6XnPDABFQ9vJNpaZ25 yH8uHOe8Ml5f3cyS7lBOcfZE4uIqziiK0xwVd5lng2EY91FyjizTW7PF4Qj/0RD8jj24 aHtxGywQ8DkIvgbzG3NiZevu/rip+q+UZtndxjTp4Hmn4r/zTKkB7CQZQaNTjUMqTXBu kW2NnnjHmzVtYc0+JFu1wfH70WHfklIR++NtBRFoO5KcT5jYhjNz5BxaLgfI1iavJ4eZ 9EgBtgJ+q/7M6eLZrYjgpL00u9DHlzgF3yNV3WE2/h0ZPm7zNDXSuEvI13nzz3EHP/RD 1JuA== 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=ZgFdMP8LLbEWm2WolY/S0HvhaSiMX3u+vYqHmfqVEax6k+c7c8Ccdq0rIIAq5I4J11 M0FbS8P49lm/gSDFgsBi5g1rdiryB1AXusRHSwgO3Xxx7gVQpfLbMSFcWvu8MHHVg11+ 8E+gufEisk0UdjVSbvoSHWWiZR8FdSU82ow9vxWZaEGanP2GUiHrP30NSRkxaU7dUlbF J2tKGkcr1SAquBaKRX/ElSRC/9g1lCBRgbBOjr9kZEauuIxrhzgJg9Wz8TPvj3wnOsvu 7Uhf8DUv5NdzZPGw0709SCZZdDH0/SSkqABBb+FQdBNy/KVBMd7nkhpzUmNts7GHcM6S tGMA== X-Forwarded-Encrypted: i=1; AJvYcCU6B7skshilmgRC9S8COPdSe3s/rp5+CrZdQRObcWqkj7a29m/1MKr/aJcP4cqTHZVNZz5wKvpiIpCgdwohz5w/@lists.infradead.org X-Gm-Message-State: AOJu0Yy03RcDCSgV8Bxq1w89GjxBFlhdBTPd/BJ5hUCfWnjp71kbB073 onTy/FgtyvLUJSsSera8KBq0mrKTrpiP5KtGFF1e+9AnyPK4nU0mSi8L9PxU+pM= X-Gm-Gg: ASbGncv/UN0rsHdC6d70TGG21gjeiSZkI9YlvBz0i5o1YfGnwCt64XDz6uGluwRo+JP qdaKig6RYEF0ChqZqiUdfyBkzLyykb0nwjbimIsQjvuYjUbsBVRyp5bbzKXynG2hwgVf/1CkZvM PyrrziZSAU3WEIz1ziKw9WB3qwAhmMztkT2OXY6WihhZcFtUb2bjnA2roi6KcBjZQmbhkSFrpUV wB+MgesaHh9CmAfkAGFzjoM5uvY/BE7MGRkaRHvU3zx89i971wd023JJJuieRY7OthEvnZM4065 vl1wGmKCXOA1w55QVLOmAg== 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241218_050559_260149_2F2BC5FB X-CRM114-Status: GOOD ( 11.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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