[PATCH 10/19] perf/arm-ni: Improve event validation
Robin Murphy
robin.murphy at arm.com
Thu Aug 14 03:01:02 AEST 2025
Although it is entirely benign for arm_ni_val_count_event() to count
any old hardware leader/sibling as an NI event (perf core will still
ultimately reject the cross-PMU group), it would still be nicer if it
didn't. Stop trying to special-case software events and simply skip any
event which doesn't belong to our PMU. Similarly drop the early return
paths since they can almost never actually return early.
Signed-off-by: Robin Murphy <robin.murphy at arm.com>
---
drivers/perf/arm-ni.c | 29 +++++++++++++----------------
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/drivers/perf/arm-ni.c b/drivers/perf/arm-ni.c
index 1615a0564031..d6b683a0264e 100644
--- a/drivers/perf/arm-ni.c
+++ b/drivers/perf/arm-ni.c
@@ -271,40 +271,37 @@ static void arm_ni_pmu_disable(struct pmu *pmu)
}
struct arm_ni_val {
+ const struct pmu *pmu;
unsigned int evcnt;
unsigned int ccnt;
};
-static bool arm_ni_val_count_event(struct perf_event *evt, struct arm_ni_val *val)
+static void arm_ni_val_count_event(struct perf_event *evt, struct arm_ni_val *val)
{
- if (is_software_event(evt))
- return true;
-
- if (NI_EVENT_TYPE(evt) == NI_PMU) {
- val->ccnt++;
- return val->ccnt <= 1;
+ if (evt->pmu == val->pmu) {
+ if (NI_EVENT_TYPE(evt) == NI_PMU)
+ val->ccnt++;
+ else
+ val->evcnt++;
}
-
- val->evcnt++;
- return val->evcnt <= NI_NUM_COUNTERS;
}
static int arm_ni_validate_group(struct perf_event *event)
{
struct perf_event *sibling, *leader = event->group_leader;
- struct arm_ni_val val = { 0 };
+ struct arm_ni_val val = { .pmu = event->pmu };
if (leader == event)
return 0;
arm_ni_val_count_event(event, &val);
- if (!arm_ni_val_count_event(leader, &val))
+ arm_ni_val_count_event(leader, &val);
+ for_each_sibling_event(sibling, leader)
+ arm_ni_val_count_event(sibling, &val);
+
+ if (val.evcnt > NI_NUM_COUNTERS || val.ccnt > 1)
return -EINVAL;
- for_each_sibling_event(sibling, leader) {
- if (!arm_ni_val_count_event(sibling, &val))
- return -EINVAL;
- }
return 0;
}
--
2.39.2.101.g768bb238c484.dirty
More information about the Linuxppc-dev
mailing list