From mboxrd@z Thu Jan 1 00:00:00 1970 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 6FD0BCD3439 for ; Tue, 5 May 2026 16:08:32 +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:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=iHXcZFw+wF4OYpI6Cnw8uZJYrQ+MXVIiKcx2ZKYmuA0=; b=Voc31j7sVRunYv7QrLvJHYpqH/ k9GwdfBoIzJpIuzAyc8EUzERJ0ZhcyafrtCf7PKD6jiz+WC05BaR8WxdNOcPZjjGmpDYEZbY9ct8v +PXqdZJGo0Xugiw06N/RmouyEwp0c8xTlI3/XskJlOTxM0JR4u0e3CpyvXXD2bXxbAHY5Lt/37j9J COoIrDvBkAaitfwt34nJh3JKLvcNz7Jx3JIalEu2D0nx4a5LHHW6sb8IIH5zKPvqaLX1hY4CoPHGm 3QyO02N+elBOG86vY+SyS0rDCOQkuDS8kfNVY5RFe0RE6YEiFJ9xesYCInsDMHMYqtaXhHu5iLDG0 JGtzrK1w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1wKIJs-0000000GnsH-0mSi; Tue, 05 May 2026 16:08:24 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1wKIJq-0000000GnpL-3Tlz for linux-arm-kernel@bombadil.infradead.org; Tue, 05 May 2026 16:08:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Sender:Reply-To:Content-ID:Content-Description; bh=iHXcZFw+wF4OYpI6Cnw8uZJYrQ+MXVIiKcx2ZKYmuA0=; b=Aim1+pBrD4SYk9zCPAINCboCL1 1eJLOlHIWrgRY9wrtmTxN4JwsFMr8F8R3wkiDaDkxiTpSbP0wOLHF1Fa7N9FobgB0I5+ca+YotApW Zd+0bJnWHgtDlKaLHkdFvaRtEOsC4dZnyj9SFmOxeqfmw7Mp8kJd3r/k0seC7PIlR+Gr7v/FQRc6H 4iK3TObavuRprfs9+xWe7edKI/0MeV0zdPcvPqGOLybCpQcrJiyHzrM9vXSpCdq2HB3lhNri4K6Qp HmafMw+umjsZ6jxw32DVg9asfqihipJ5vVbR5T9Iu+ctZW8nW+oB6ZA5GPj0lgmyvdRjhkw50E29H JuA1H5EA==; Received: from foss.arm.com ([217.140.110.172]) by desiato.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1wKIJl-0000000Dz4D-2md6 for linux-arm-kernel@lists.infradead.org; Tue, 05 May 2026 16:08:21 +0000 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 C866E2681; Tue, 5 May 2026 09:08:10 -0700 (PDT) Received: from localhost.localdomain (e123572-lin.cambridge.arm.com [10.1.194.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 101713F763; Tue, 5 May 2026 09:08:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1777997296; bh=v82/1vPoSQuONG3WsQV7YwA6orY4PDGaaB1P1kQ48kU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=fIdM1FwSO2f6XGsJKrkG/VYHmwB0LijHUxa41oHHt+eexYWn/zSHVvFdi/WjIj5TC CKZbYJoEfEIPR0koypxMh7V++i2dVvWf/FB6mx+sHP3u1WjdfYY0GYSO1UNahW+wOC owgcTiwx2aUZTy4OMoYhxFACve5A/xPX1cLP8fHQ= From: Kevin Brodsky Date: Tue, 05 May 2026 17:06:05 +0100 Subject: [PATCH RFC v7 16/24] arm64: kpkeys: Implement arch_supports_kpkeys_early() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260505-kpkeys-v7-16-20c0bdd97197@arm.com> References: <20260505-kpkeys-v7-0-20c0bdd97197@arm.com> In-Reply-To: <20260505-kpkeys-v7-0-20c0bdd97197@arm.com> To: linux-hardening@vger.kernel.org Cc: Kevin Brodsky , Andrew Morton , Andy Lutomirski , Catalin Marinas , Dave Hansen , "David Hildenbrand (Arm)" , Ira Weiny , Jann Horn , Jeff Xu , Joey Gouly , Kees Cook , Linus Walleij , Marc Zyngier , Mark Brown , Matthew Wilcox , Maxwell Bland , "Mike Rapoport (IBM)" , Peter Zijlstra , Pierre Langlois , Quentin Perret , Rick Edgecombe , Ryan Roberts , Will Deacon , Yang Shi , Yeoreum Yun , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, x86@kernel.org, Lorenzo Stoakes , Thomas Gleixner , Vlastimil Babka X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1777997220; l=1883; i=kevin.brodsky@arm.com; s=20260427; h=from:subject:message-id; bh=v82/1vPoSQuONG3WsQV7YwA6orY4PDGaaB1P1kQ48kU=; b=erbWwshOH5eSYbyBEexjjPp8WQMR4JDB9K29Hi1KltLPQNM9epNdeZRtpkGDFf1Qo50ePQwea Ds0xvNYDolDBUJxj2MoI7xnIpoGZ7cxQVtj2651ujEYLpq5wrnulAVd X-Developer-Key: i=kevin.brodsky@arm.com; a=ed25519; pk=N2QG+eJKrvkNovwhhwJhnJ4+ScVfsGCHldmqLfcMTFs= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260505_170818_151863_AF254E0E X-CRM114-Status: GOOD ( 13.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 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. 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 4de51f8d92cb..8722e9e62702 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -1078,6 +1078,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 7dad3532cacf..ea915f78936b 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, int ctx) -- 2.51.2