Skip to content

Commit

Permalink
perf/smmuv3: Validate group size
Browse files Browse the repository at this point in the history
Ensure that a group will actually fit into the available counters.

Signed-off-by: Robin Murphy <[email protected]>
Signed-off-by: Will Deacon <[email protected]>
  • Loading branch information
rmurphy-arm authored and willdeacon committed Aug 27, 2019
1 parent d91cc2f commit 33e84ea
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions drivers/perf/arm_smmuv3_pmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ static int smmu_pmu_event_init(struct perf_event *event)
struct smmu_pmu *smmu_pmu = to_smmu_pmu(event->pmu);
struct device *dev = smmu_pmu->dev;
struct perf_event *sibling;
int group_num_events = 1;
u16 event_id;

if (event->attr.type != event->pmu->type)
Expand All @@ -347,18 +348,23 @@ static int smmu_pmu_event_init(struct perf_event *event)
}

/* Don't allow groups with mixed PMUs, except for s/w events */
if (event->group_leader->pmu != event->pmu &&
!is_software_event(event->group_leader)) {
dev_dbg(dev, "Can't create mixed PMU group\n");
return -EINVAL;
if (!is_software_event(event->group_leader)) {
if (event->group_leader->pmu != event->pmu)
return -EINVAL;

if (++group_num_events > smmu_pmu->num_counters)
return -EINVAL;
}

for_each_sibling_event(sibling, event->group_leader) {
if (sibling->pmu != event->pmu &&
!is_software_event(sibling)) {
dev_dbg(dev, "Can't create mixed PMU group\n");
if (is_software_event(sibling))
continue;

if (sibling->pmu != event->pmu)
return -EINVAL;

if (++group_num_events > smmu_pmu->num_counters)
return -EINVAL;
}
}

hwc->idx = -1;
Expand Down

0 comments on commit 33e84ea

Please sign in to comment.