aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Turner <andrew@FreeBSD.org>2021-04-01 14:38:09 +0000
committerMitchell Horne <mhorne@FreeBSD.org>2021-07-29 15:00:37 +0000
commit19135e372ff1627d2337f3014ee0bfe2e178d00a (patch)
treeb517c026c8613c752c3ff7fee5fd019fb9187e91
parent90ffac35b778564d1b4cb8ec7d2ff92ccc8e56dd (diff)
downloadsrc-19135e372ff1627d2337f3014ee0bfe2e178d00a.tar.gz
src-19135e372ff1627d2337f3014ee0bfe2e178d00a.zip
arm64: Fix finding the pmc event ID
The lower pmc event bits were masked off to find the PMC event ID. The doesn't work when there are more events. Switch it to use the offser relative to the first event while also checking the ID is in the expected range. Reviewed by: gnn, ray Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D29600 (cherry picked from commit 24b2f4ea49229618c5608846acfc10be2eb0d567)
-rw-r--r--sys/dev/hwpmc/hwpmc_arm64.c4
-rw-r--r--sys/dev/hwpmc/hwpmc_arm64.h1
2 files changed, 3 insertions, 2 deletions
diff --git a/sys/dev/hwpmc/hwpmc_arm64.c b/sys/dev/hwpmc/hwpmc_arm64.c
index 49375219a485..050f861a74fe 100644
--- a/sys/dev/hwpmc/hwpmc_arm64.c
+++ b/sys/dev/hwpmc/hwpmc_arm64.c
@@ -181,7 +181,9 @@ arm64_allocate_pmc(int cpu, int ri, struct pmc *pm,
}
pe = a->pm_ev;
- config = (pe & EVENT_ID_MASK);
+ config = (uint32_t)pe - PMC_EV_ARMV8_FIRST;
+ if (config > (PMC_EV_ARMV8_LAST - PMC_EV_ARMV8_FIRST))
+ return (EINVAL);
pm->pm_md.pm_arm64.pm_arm64_evsel = config;
PMCDBG2(MDP, ALL, 2, "arm64-allocate ri=%d -> config=0x%x", ri, config);
diff --git a/sys/dev/hwpmc/hwpmc_arm64.h b/sys/dev/hwpmc/hwpmc_arm64.h
index f0d43aa58ef8..fb7637a39c60 100644
--- a/sys/dev/hwpmc/hwpmc_arm64.h
+++ b/sys/dev/hwpmc/hwpmc_arm64.h
@@ -40,7 +40,6 @@
#define ARMV8_RELOAD_COUNT_TO_PERFCTR_VALUE(R) (-(R))
#define ARMV8_PERFCTR_VALUE_TO_RELOAD_COUNT(P) (-(P))
-#define EVENT_ID_MASK 0xFF
#ifdef _KERNEL
/* MD extension for 'struct pmc' */