]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
arm64/cpufeature: Runtime detection of Guarded Control Stack (GCS)
authorMark Brown <broonie@kernel.org>
Tue, 1 Oct 2024 22:58:51 +0000 (23:58 +0100)
committerCatalin Marinas <catalin.marinas@arm.com>
Fri, 4 Oct 2024 11:04:35 +0000 (12:04 +0100)
Add a cpufeature for GCS, allowing other code to conditionally support it
at runtime.

Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20241001-arm64-gcs-v13-12-222b78d87eee@kernel.org
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
arch/arm64/include/asm/cpufeature.h
arch/arm64/kernel/cpufeature.c
arch/arm64/tools/cpucaps

index 3d261cc123c1e22ac7bc9cfcde463624c76b2084..69470795f5d2aa4487fe04df0fe21fdaad79573d 100644 (file)
@@ -838,6 +838,12 @@ static inline bool system_supports_poe(void)
                alternative_has_cap_unlikely(ARM64_HAS_S1POE);
 }
 
+static inline bool system_supports_gcs(void)
+{
+       return IS_ENABLED(CONFIG_ARM64_GCS) &&
+               alternative_has_cap_unlikely(ARM64_HAS_GCS);
+}
+
 int do_emulate_mrs(struct pt_regs *regs, u32 sys_reg, u32 rt);
 bool try_emulate_mrs(struct pt_regs *regs, u32 isn);
 
index 718728a85430fad5151b73fa213a510efac3f834..d1e758e99e0a70e120ed5b53f862b15fac66da44 100644 (file)
@@ -291,6 +291,8 @@ static const struct arm64_ftr_bits ftr_id_aa64pfr0[] = {
 };
 
 static const struct arm64_ftr_bits ftr_id_aa64pfr1[] = {
+       ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_GCS),
+                      FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR1_EL1_GCS_SHIFT, 4, 0),
        ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SME),
                       FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR1_EL1_SME_SHIFT, 4, 0),
        ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR1_EL1_MPAM_frac_SHIFT, 4, 0),
@@ -2358,6 +2360,14 @@ static void cpu_enable_poe(const struct arm64_cpu_capabilities *__unused)
 }
 #endif
 
+#ifdef CONFIG_ARM64_GCS
+static void cpu_enable_gcs(const struct arm64_cpu_capabilities *__unused)
+{
+       /* GCSPR_EL0 is always readable */
+       write_sysreg_s(GCSCRE0_EL1_nTR, SYS_GCSCRE0_EL1);
+}
+#endif
+
 /* Internal helper functions to match cpu capability type */
 static bool
 cpucap_late_cpu_optional(const struct arm64_cpu_capabilities *cap)
@@ -2889,6 +2899,16 @@ static const struct arm64_cpu_capabilities arm64_features[] = {
                .cpu_enable = cpu_enable_poe,
                ARM64_CPUID_FIELDS(ID_AA64MMFR3_EL1, S1POE, IMP)
        },
+#endif
+#ifdef CONFIG_ARM64_GCS
+       {
+               .desc = "Guarded Control Stack (GCS)",
+               .capability = ARM64_HAS_GCS,
+               .type = ARM64_CPUCAP_SYSTEM_FEATURE,
+               .cpu_enable = cpu_enable_gcs,
+               .matches = has_cpuid_feature,
+               ARM64_CPUID_FIELDS(ID_AA64PFR1_EL1, GCS, IMP)
+       },
 #endif
        {},
 };
index eedb5acc21ed98bfaaaaa6badcd9a266308ace8e..867d25d4a45a7ff9057185626c722c4bfdc43e5b 100644 (file)
@@ -29,6 +29,7 @@ HAS_EVT
 HAS_FPMR
 HAS_FGT
 HAS_FPSIMD
+HAS_GCS
 HAS_GENERIC_AUTH
 HAS_GENERIC_AUTH_ARCH_QARMA3
 HAS_GENERIC_AUTH_ARCH_QARMA5