From nobody Tue Dec 2 02:19:22 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 770F933FE05 for ; Wed, 19 Nov 2025 13:00:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763557231; cv=none; b=IPVMTOKYEKC0WMjC1jTTMe8pXeBmfNNR3pdknlL/LIghqjYVjqWFIDQnMO8YYms/uurjijWwoy12eX3H1/GNzKrrvlT6Lwr8tIMJd6aiHcviWooLa+dvzHm7Y43vquyICrgqAN6bkXqXr8GKgzj/ahi78fC7PB17K4T3kcY3K6c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763557231; c=relaxed/simple; bh=bE+ZoNx2TOJvLKnwZ0aMvCaPhirTLXIJl7XC3mgVuUA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Ztg4eicoRX32/+EIQoDIZA5c+hTpKezWzVrbEFfvPY2A78tr+GW/Lt+wHId0dnBKz6KXOfEWzgXHszxdkTG31gY5gRs+LR67uo5R5v1UFPmV0adGnl5GA1QNp0y9TvJ0VG721KIeUmv+UIunvBFqkCMUSkgBZ1WDv36aOVxqHLg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 13E93FEC; Wed, 19 Nov 2025 05:00:21 -0800 (PST) Received: from e123572-lin.arm.com (e123572-lin.cambridge.arm.com [10.1.194.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0D6143F66E; Wed, 19 Nov 2025 05:00:26 -0800 (PST) From: Kevin Brodsky To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Kevin Brodsky , Catalin Marinas , "Christoph Lameter (Ampere)" , David Hildenbrand , Dev Jain , D Scott Phillips , Ryan Roberts , Will Deacon , Yang Shi Subject: [PATCH] arm64: mm: Simplify check in arch_kfence_init_pool() Date: Wed, 19 Nov 2025 13:00:16 +0000 Message-ID: <20251119130016.283216-1-kevin.brodsky@arm.com> X-Mailer: git-send-email 2.51.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" TL;DR: checking force_pte_mapping() in arch_kfence_init_pool() is sufficient Commit ce2b3a50ad92 ("arm64: mm: Don't sleep in split_kernel_leaf_mapping() when in atomic context") recently added an arm64 implementation of arch_kfence_init_pool() to ensure that the KFENCE pool is PTE-mapped. Assuming that the pool was not initialised early, block splitting is necessary if the linear mapping is not fully PTE-mapped, in other words if force_pte_mapping() is false. arch_kfence_init_pool() currently makes another check: whether BBML2-noabort is supported, i.e. whether we are *able* to split block mappings. This check is however unnecessary, because force_pte_mapping() is always true if KFENCE is enabled and BBML2-noabort is not supported. This must be the case by design, since KFENCE requires PTE-mapped pages in all cases. We can therefore remove that check. The situation is different in split_kernel_leaf_mapping(), as that function is called unconditionally regardless of the configuration. If BBML2-noabort is not supported, it cannot do anything and bails out. If force_pte_mapping() is true, there is nothing to do and it also bails out, but these are independent checks. Commit 53357f14f924 ("arm64: mm: Tidy up force_pte_mapping()") grouped these checks into a helper, split_leaf_mapping_possible(). This isn't so helpful as only split_kernel_leaf_mapping() should check both. Revert the parts of that commit that introduced the helper, reintroducing the more accurate comments in split_kernel_leaf_mapping(). Signed-off-by: Kevin Brodsky Reviewed-by: Ryan Roberts --- Apologies for not suggesting this during the review cycle of [1], I'm late to the party... [1] https://lore.kernel.org/all/20251106160945.3182799-1-ryan.roberts@arm.c= om/ --- Cc: Catalin Marinas Cc: Christoph Lameter (Ampere) Cc: David Hildenbrand Cc: Dev Jain Cc: D Scott Phillips Cc: Ryan Roberts Cc: Will Deacon Cc: Yang Shi --- arch/arm64/mm/mmu.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 2ba01dc8ef82..866cc889bb61 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -720,18 +720,6 @@ static inline bool force_pte_mapping(void) return rodata_full || arm64_kfence_can_set_direct_map() || is_realm_world= (); } =20 -static inline bool split_leaf_mapping_possible(void) -{ - /* - * !BBML2_NOABORT systems should never run into scenarios where we would - * have to split. So exit early and let calling code detect it and raise - * a warning. - */ - if (!system_supports_bbml2_noabort()) - return false; - return !force_pte_mapping(); -} - static DEFINE_MUTEX(pgtable_split_lock); =20 int split_kernel_leaf_mapping(unsigned long start, unsigned long end) @@ -739,11 +727,22 @@ int split_kernel_leaf_mapping(unsigned long start, un= signed long end) int ret; =20 /* - * Exit early if the region is within a pte-mapped area or if we can't - * split. For the latter case, the permission change code will raise a - * warning if not already pte-mapped. + * !BBML2_NOABORT systems should not be trying to change permissions on + * anything that is not pte-mapped in the first place. Just return early + * and let the permission change code raise a warning if not already + * pte-mapped. */ - if (!split_leaf_mapping_possible() || is_kfence_address((void *)start)) + if (!system_supports_bbml2_noabort()) + return 0; + + /* + * If the region is within a pte-mapped area, there is no need to try to + * split. Additionally, CONFIG_DEBUG_PAGEALLOC and CONFIG_KFENCE may + * change permissions from atomic context so for those cases (which are + * always pte-mapped), we must not go any further because taking the + * mutex below may sleep. + */ + if (force_pte_mapping() || is_kfence_address((void *)start)) return 0; =20 /* @@ -1042,7 +1041,7 @@ bool arch_kfence_init_pool(void) int ret; =20 /* Exit early if we know the linear map is already pte-mapped. */ - if (!split_leaf_mapping_possible()) + if (force_pte_mapping()) return true; =20 /* Kfence pool is already pte-mapped for the early init case. */ base-commit: 6a23ae0a96a600d1d12557add110e0bb6e32730c --=20 2.51.2