[RFC PATCH v3 04/16] arm64: Introduce CPU SPE feature

Alexandru Elisei alexandru.elisei at arm.com
Tue Oct 27 13:26:53 EDT 2020


Detect Statistical Profiling Extension (SPE) support using the cpufeatures
framework. The presence of SPE is reported via the ARM64_SPE capability.

The feature will be necessary for emulating SPE in KVM, because KVM needs
that all CPUs have SPE hardware to avoid scheduling a VCPU on a CPU without
support. For this reason, the feature type ARM64_CPUCAP_SYSTEM_FEATURE has
been selected to disallow hotplugging a CPU which doesn't support SPE.

Signed-off-by: Alexandru Elisei <alexandru.elisei at arm.com>
---
 arch/arm64/include/asm/cpucaps.h |  3 ++-
 arch/arm64/kernel/cpufeature.c   | 24 ++++++++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/include/asm/cpucaps.h b/arch/arm64/include/asm/cpucaps.h
index 42868dbd29fd..10fd094d9a5b 100644
--- a/arch/arm64/include/asm/cpucaps.h
+++ b/arch/arm64/include/asm/cpucaps.h
@@ -65,7 +65,8 @@
 #define ARM64_HAS_ARMv8_4_TTL			55
 #define ARM64_HAS_TLB_RANGE			56
 #define ARM64_MTE				57
+#define ARM64_SPE				58
 
-#define ARM64_NCAPS				58
+#define ARM64_NCAPS				59
 
 #endif /* __ASM_CPUCAPS_H */
diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
index dcc165b3fc04..4a0f4dc53824 100644
--- a/arch/arm64/kernel/cpufeature.c
+++ b/arch/arm64/kernel/cpufeature.c
@@ -1278,6 +1278,18 @@ has_useable_cnp(const struct arm64_cpu_capabilities *entry, int scope)
 	return has_cpuid_feature(entry, scope);
 }
 
+static bool __maybe_unused
+has_usable_spe(const struct arm64_cpu_capabilities *entry, int scope)
+{
+	u64 pmbidr;
+
+	if (!has_cpuid_feature(entry, scope))
+		return false;
+
+	pmbidr = read_sysreg_s(SYS_PMBIDR_EL1);
+	return !(pmbidr & BIT(SYS_PMBIDR_EL1_P_SHIFT));
+}
+
 /*
  * This check is triggered during the early boot before the cpufeature
  * is initialised. Checking the status on the local CPU allows the boot
@@ -2003,6 +2015,18 @@ static const struct arm64_cpu_capabilities arm64_features[] = {
 		.min_field_value = 1,
 		.cpu_enable = cpu_enable_cnp,
 	},
+#endif
+#ifdef CONFIG_ARM_SPE_PMU
+	{
+		.desc = "Statistical Profiling Extension (SPE)",
+		.capability = ARM64_SPE,
+		.type = ARM64_CPUCAP_SYSTEM_FEATURE,
+		.matches = has_usable_spe,
+		.sys_reg = SYS_ID_AA64DFR0_EL1,
+		.sign = FTR_UNSIGNED,
+		.field_pos = ID_AA64DFR0_PMSVER_SHIFT,
+		.min_field_value = 1,
+	},
 #endif
 	{
 		.desc = "Speculation barrier (SB)",
-- 
2.29.1




More information about the linux-arm-kernel mailing list