From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794240114; b=2TahMaDvFPC0lG8o8kAXpYMNlrcoi/BMVwUTxUJ606ST9NHN+it/SMV7OsDMSSsg2b+A emfi3qcmYiZghRELeJxuQqAjm+kOepKFT9PCVi3E9+mqWla/c6ocPb+h8KilsWd7U9LFb fg5b8G5Vqjja32xDKQJfSahTsk9xY7rmFzbXEcdEYfYVmB4M4+OmM23D7e8zJmOUBM3+6 XQqOF+IsL+VuxfooucSyRMUIjd2plnkZdnw/N0MiEu6euAQiVFMve6G2XX89b/2LX9rmb 6z8cX0DFWG+F1n1e6h6Ovv7R6GL+FSvW280SYFFEdP1zVT+iLJMWNCh0k5VR1a5clKA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794240114; h=DMARC-Filter:Received:Received:DKIM-Signature:From:Date:Subject: MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id: References:In-Reply-To:To:Cc:X-Mailer:X-Developer-Signature: X-Developer-Key; bh=I20sRd/PRulOIZRhd+UEj/sasH6pZnvh1x/HC0d3HPs=; b=rQsSRhOum8QtCQoLkBAhkA6UOIyc0Wil/h8KZ0d2ebuTGLMhYgb1di0oTAnyjXvR4PTu 75b+HjVR8CAzvWK8pRw1K0qwLF/osMV5MMo4EfW6rF2XH2GQp/KMxdE8JDWIg38kPAafB BpoCIBa1wc5lxYeAc6iAm8zRyyH43INX+TLASpN2Hi8Yz/rKRYH9JuS14Y4EqyFo5Dbob vCDHZvymhLKeAGVizzXuSE8Onl3kw7H//OOMGFJoiMKc6+hWtEzaBux2Ocvc6m5DYVNlh dJrkUKw9KxXhruvAJo6oitt+o1ygUghi8BuPfGC1LmQhpcI1gU36Fh9rQ9LR/qOOFnQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=lTHZ+qb8; arc=none smtp.remote-ip=217.140.110.172 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D3F49606EE87; Mon, 9 Nov 2026 16:01:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D3F49606EE87 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=lTHZ+qb8 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 160072F; Mon, 9 Nov 2026 08:01:50 -0800 (PST) Received: from localhost.localdomain (e123572-lin.cambridge.arm.com [10.2.208.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 39EAA3F632; Mon, 9 Nov 2026 08:01:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1794240113; bh=x0fs4aL6amulindDHORyceQYe6RPCjEvCe7RN43wDF8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=lTHZ+qb8Lpb5MdGoi5c6jMxnW2x0nCEFq0oX1jDx8IG7OVlTjwulAINb2xlF9ymah cOQTnqS9PT61Dl+Oidh19ri+5GXv0wrMFklaMGMHgi2oS6TrL60lyr61AtTCJHAc81 G76uWFAfR8qpm0XbXv4dpBu0AcJao1wvunC2ofCU= From: Kevin Brodsky Date: Mon, 09 Nov 2026 15:58:40 +0000 Subject: [PATCH RFC v10 15/22] arm64: kpkeys: Implement arch_supports_kpkeys_early() X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261109-kpkeys-v10-15-aa6c4d9603bc@arm.com> References: <20261109-kpkeys-v10-0-aa6c4d9603bc@arm.com> In-Reply-To: <20261109-kpkeys-v10-0-aa6c4d9603bc@arm.com> To: linux-hardening@vger.kernel.org Cc: Kevin Brodsky , Andrew Morton , Ard Biesheuvel , Andy Lutomirski , Catalin Marinas , Dave Hansen , "David Hildenbrand (Arm)" , Jann Horn , Jeff Xu , Joey Gouly , Kees Cook , Linu Cherian , Linus Walleij , Marc Zyngier , Mark Brown , Matthew Wilcox , Maxwell Bland , "Mike Rapoport (IBM)" , Peter Zijlstra , Pierre Langlois , =?utf-8?q?Pierre-Cl=C3=A9ment_Tosi?= , Quentin Perret , Rick Edgecombe , Ryan Roberts , Vlastimil Babka , Will Deacon , Yang Shi , Yeoreum Yun , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, x86@kernel.org, Ira Weiny , Lorenzo Stoakes , Thomas Gleixner X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1794240029; l=1943; i=kevin.brodsky@arm.com; s=20260427; h=from:subject:message-id; bh=x0fs4aL6amulindDHORyceQYe6RPCjEvCe7RN43wDF8=; b=GI39UyqJq4/O0CdszPupFvOqE4Y/AHbk7Ja0HguyPHLzW9XAa/I3Sv7T0zG456AtmVEcUY1Ez gJM++4wBYmHC2L1Cg92cXl5qVHAPKbZNyE9HaVOaJcos0Hph2srQROE X-Developer-Key: i=kevin.brodsky@arm.com; a=ed25519; pk=N2QG+eJKrvkNovwhhwJhnJ4+ScVfsGCHldmqLfcMTFs= We need to check if the kpkeys_hardened_pgtables feature is going to be enabled very early during boot, to decide how to set up the linear map and how to allocate early page tables. This happens even before boot CPU features are detected. Implement the arch_supports_kpkeys_early() helper by directly checking if the boot CPU supports POE, if it is called before boot CPU features are detected. It may also be called later, in which case we simply check the POE feature. Reviewed-by: Yeoreum Yun Signed-off-by: Kevin Brodsky --- arch/arm64/include/asm/cpufeature.h | 12 ++++++++++++ arch/arm64/include/asm/kpkeys.h | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index e3c8a1493dc8..062d444da4ea 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -1114,6 +1114,18 @@ static inline bool cpu_has_lpa2(void) #endif } +static inline bool cpu_has_poe(void) +{ + u64 mmfr3; + + if (!IS_ENABLED(CONFIG_ARM64_POE)) + return false; + + mmfr3 = read_sysreg_s(SYS_ID_AA64MMFR3_EL1); + return cpuid_feature_extract_unsigned_field(mmfr3, + ID_AA64MMFR3_EL1_S1POE_SHIFT); +} + #endif /* __ASSEMBLER__ */ #endif diff --git a/arch/arm64/include/asm/kpkeys.h b/arch/arm64/include/asm/kpkeys.h index 4f9bdb369b47..70d85b0d69d6 100644 --- a/arch/arm64/include/asm/kpkeys.h +++ b/arch/arm64/include/asm/kpkeys.h @@ -21,6 +21,13 @@ static inline bool arch_supports_kpkeys(void) return system_supports_poe(); } +static inline bool arch_supports_kpkeys_early(void) +{ + /* POE is a boot feature */ + return boot_capabilities_finalized() ? + system_supports_poe() : cpu_has_poe(); +} + #ifdef CONFIG_ARM64_POE static inline u64 por_set_kpkeys_context(u64 por, enum kpkeys_ctx ctx) -- 2.56.0