git: 19135e372ff1 - stable/13 - arm64: Fix finding the pmc event ID

Mitchell Horne mhorne at FreeBSD.org
Thu Jul 29 15:25:16 UTC 2021


The branch stable/13 has been updated by mhorne:

URL: https://cgit.FreeBSD.org/src/commit/?id=19135e372ff1627d2337f3014ee0bfe2e178d00a

commit 19135e372ff1627d2337f3014ee0bfe2e178d00a
Author:     Andrew Turner <andrew at FreeBSD.org>
AuthorDate: 2021-04-01 14:38:09 +0000
Commit:     Mitchell Horne <mhorne at FreeBSD.org>
CommitDate: 2021-07-29 15:00:37 +0000

    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)
---
 sys/dev/hwpmc/hwpmc_arm64.c | 4 +++-
 sys/dev/hwpmc/hwpmc_arm64.h | 1 -
 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' */


More information about the dev-commits-src-all mailing list