Skip to content

Commit 6487c96

Browse files
brooniectmarinas
authored andcommitted
arm64/cpufeature: Runtime detection of Guarded Control Stack (GCS)
Add a cpufeature for GCS, allowing other code to conditionally support it at runtime. Reviewed-by: Thiago Jung Bauermann <[email protected]> Reviewed-by: Catalin Marinas <[email protected]> Signed-off-by: Mark Brown <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent ff5181d commit 6487c96

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

arch/arm64/include/asm/cpufeature.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,12 @@ static inline bool system_supports_poe(void)
838838
alternative_has_cap_unlikely(ARM64_HAS_S1POE);
839839
}
840840

841+
static inline bool system_supports_gcs(void)
842+
{
843+
return IS_ENABLED(CONFIG_ARM64_GCS) &&
844+
alternative_has_cap_unlikely(ARM64_HAS_GCS);
845+
}
846+
841847
int do_emulate_mrs(struct pt_regs *regs, u32 sys_reg, u32 rt);
842848
bool try_emulate_mrs(struct pt_regs *regs, u32 isn);
843849

arch/arm64/kernel/cpufeature.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ static const struct arm64_ftr_bits ftr_id_aa64pfr0[] = {
291291
};
292292

293293
static const struct arm64_ftr_bits ftr_id_aa64pfr1[] = {
294+
ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_GCS),
295+
FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR1_EL1_GCS_SHIFT, 4, 0),
294296
ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SME),
295297
FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR1_EL1_SME_SHIFT, 4, 0),
296298
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)
23582360
}
23592361
#endif
23602362

2363+
#ifdef CONFIG_ARM64_GCS
2364+
static void cpu_enable_gcs(const struct arm64_cpu_capabilities *__unused)
2365+
{
2366+
/* GCSPR_EL0 is always readable */
2367+
write_sysreg_s(GCSCRE0_EL1_nTR, SYS_GCSCRE0_EL1);
2368+
}
2369+
#endif
2370+
23612371
/* Internal helper functions to match cpu capability type */
23622372
static bool
23632373
cpucap_late_cpu_optional(const struct arm64_cpu_capabilities *cap)
@@ -2889,6 +2899,16 @@ static const struct arm64_cpu_capabilities arm64_features[] = {
28892899
.cpu_enable = cpu_enable_poe,
28902900
ARM64_CPUID_FIELDS(ID_AA64MMFR3_EL1, S1POE, IMP)
28912901
},
2902+
#endif
2903+
#ifdef CONFIG_ARM64_GCS
2904+
{
2905+
.desc = "Guarded Control Stack (GCS)",
2906+
.capability = ARM64_HAS_GCS,
2907+
.type = ARM64_CPUCAP_SYSTEM_FEATURE,
2908+
.cpu_enable = cpu_enable_gcs,
2909+
.matches = has_cpuid_feature,
2910+
ARM64_CPUID_FIELDS(ID_AA64PFR1_EL1, GCS, IMP)
2911+
},
28922912
#endif
28932913
{},
28942914
};

arch/arm64/tools/cpucaps

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ HAS_EVT
2929
HAS_FPMR
3030
HAS_FGT
3131
HAS_FPSIMD
32+
HAS_GCS
3233
HAS_GENERIC_AUTH
3334
HAS_GENERIC_AUTH_ARCH_QARMA3
3435
HAS_GENERIC_AUTH_ARCH_QARMA5

0 commit comments

Comments
 (0)