Skip to content

Commit 1862de6

Browse files
ouptonjannau
authored andcommitted
arm64: Enable IMP DEF PMUv3 traps on Apple M2
Apple M2 CPUs support IMPDEF traps of the PMUv3 sysregs, allowing a hypervisor to virtualize an architectural PMU for a VM. Flip the appropriate bit in HACR_EL2 on supporting hardware. Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
1 parent 615ca25 commit 1862de6

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

arch/arm64/kernel/cpu_errata.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,37 @@ has_neoverse_n1_erratum_1542419(const struct arm64_cpu_capabilities *entry,
194194
return is_midr_in_range(midr, &range) && has_dic;
195195
}
196196

197+
static const struct midr_range impdef_pmuv3_cpus[] = {
198+
MIDR_ALL_VERSIONS(MIDR_APPLE_M2_BLIZZARD),
199+
MIDR_ALL_VERSIONS(MIDR_APPLE_M2_AVALANCHE),
200+
MIDR_ALL_VERSIONS(MIDR_APPLE_M2_BLIZZARD_PRO),
201+
MIDR_ALL_VERSIONS(MIDR_APPLE_M2_AVALANCHE_PRO),
202+
MIDR_ALL_VERSIONS(MIDR_APPLE_M2_BLIZZARD_MAX),
203+
MIDR_ALL_VERSIONS(MIDR_APPLE_M2_AVALANCHE_MAX),
204+
{},
205+
};
206+
207+
static bool has_impdef_pmuv3(const struct arm64_cpu_capabilities *entry, int scope)
208+
{
209+
u64 dfr0 = read_sanitised_ftr_reg(SYS_ID_AA64DFR0_EL1);
210+
unsigned int pmuver;
211+
212+
if (!is_kernel_in_hyp_mode())
213+
return false;
214+
215+
pmuver = cpuid_feature_extract_unsigned_field(dfr0,
216+
ID_AA64DFR0_EL1_PMUVer_SHIFT);
217+
if (pmuver != ID_AA64DFR0_EL1_PMUVer_IMP_DEF)
218+
return false;
219+
220+
return is_midr_in_range_list(read_cpuid_id(), impdef_pmuv3_cpus);
221+
}
222+
223+
static void cpu_enable_impdef_pmuv3_traps(const struct arm64_cpu_capabilities *__unused)
224+
{
225+
sysreg_clear_set_s(SYS_HACR_EL2, 0, BIT(56));
226+
}
227+
197228
#ifdef CONFIG_ARM64_WORKAROUND_REPEAT_TLBI
198229
static const struct arm64_cpu_capabilities arm64_repeat_tlbi_list[] = {
199230
#ifdef CONFIG_QCOM_FALKOR_ERRATUM_1009
@@ -786,6 +817,13 @@ const struct arm64_cpu_capabilities arm64_errata[] = {
786817
ERRATA_MIDR_RANGE_LIST(erratum_ac03_cpu_38_list),
787818
},
788819
#endif
820+
{
821+
.desc = "Apple IMPDEF PMUv3 Traps",
822+
.capability = ARM64_WORKAROUND_PMUV3_IMPDEF_TRAPS,
823+
.type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM,
824+
.matches = has_impdef_pmuv3,
825+
.cpu_enable = cpu_enable_impdef_pmuv3_traps,
826+
},
789827
{
790828
}
791829
};

0 commit comments

Comments
 (0)