The group validation here has a few issues to fix: firstly, failing to count the group leader or the event being opened itself. Secondly it appears wrong not to count disabled sibling events given that they could be enabled later. Finally there's the subtlety that we should avoid racy access to the sibling list when the event is its own group leader.
Signed-off-by: Robin Murphy <robin.mur...@arm.com> --- drivers/iommu/intel/perfmon.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/intel/perfmon.c b/drivers/iommu/intel/perfmon.c index 75f493bcb353..c3a1ac14cb2b 100644 --- a/drivers/iommu/intel/perfmon.c +++ b/drivers/iommu/intel/perfmon.c @@ -258,21 +258,25 @@ static int iommu_pmu_validate_group(struct perf_event *event) { struct iommu_pmu *iommu_pmu = iommu_event_to_pmu(event); struct perf_event *sibling; - int nr = 0; + int nr = 1; + if (event == event->group_leader) + return 0; /* * All events in a group must be scheduled simultaneously. * Check whether there is enough counters for all the events. */ - for_each_sibling_event(sibling, event->group_leader) { - if (!is_iommu_pmu_event(iommu_pmu, sibling) || - sibling->state <= PERF_EVENT_STATE_OFF) - continue; + if (is_iommu_pmu_event(iommu_pmu, event->group_leader)) + ++nr; - if (++nr > iommu_pmu->num_cntr) - return -EINVAL; + for_each_sibling_event(sibling, event->group_leader) { + if (is_iommu_pmu_event(iommu_pmu, sibling)) + ++nr; } + if (nr > iommu_pmu->num_cntr) + return -EINVAL; + return 0; } -- 2.39.2.101.g768bb238c484.dirty