@@ -316,21 +316,44 @@ static u64 arm_spe_event_to_pmscr(struct perf_event *event)
static void arm_spe_pmu_set_pmscr(struct perf_event *event)
{
struct perf_event_attr *attr = &event->attr;
- u64 reg = 0;
+ u64 pmscr_el1, pmscr_el12;
- reg = arm_spe_event_to_pmscr(event);
- if (!attr->exclude_user)
- reg |= PMSCR_EL1x_E0SPE;
+ pmscr_el1 = pmscr_el12 = arm_spe_event_to_pmscr(event);
+
+ /*
+ * Map the exclude_* descision to ELx according to
+ * Documentation/arch/arm64/perf.rst.
+ */
+ if (is_kernel_in_hyp_mode()) {
+ if (!attr->exclude_kernel && !attr->exclude_host)
+ pmscr_el1 |= PMSCR_EL1x_E1SPE;
- if (!attr->exclude_kernel)
- reg |= PMSCR_EL1x_E1SPE;
+ if (!attr->exclude_kernel && !attr->exclude_guest)
+ pmscr_el12 |= PMSCR_EL1x_E1SPE;
+
+ if (!attr->exclude_user && !attr->exclude_host) {
+ pmscr_el1 |= PMSCR_EL1x_E0SPE;
+ pmscr_el12 |= PMSCR_EL1x_E0SPE;
+ }
+ } else {
+ if (!attr->exclude_kernel)
+ pmscr_el1 |= PMSCR_EL1x_E1SPE;
+
+ if (!attr->exclude_user)
+ pmscr_el1 |= PMSCR_EL1x_E0SPE;
+ }
isb();
- write_sysreg_s(reg, SYS_PMSCR_EL1);
+ write_sysreg_s(pmscr_el1, SYS_PMSCR_EL1);
+ if (is_kernel_in_hyp_mode())
+ write_sysreg_s(pmscr_el12, SYS_PMSCR_EL12);
}
static void arm_spe_pmu_clr_pmscr(void)
{
+ if (is_kernel_in_hyp_mode())
+ write_sysreg_s(0, SYS_PMSCR_EL12);
+
write_sysreg_s(0, SYS_PMSCR_EL1);
isb();
}