Skip to content

Commit b186219

Browse files
Suzuki K. Poulosewildea01
authored andcommitted
drivers: cci: reject groups spanning multiple HW PMUs
The perf core implicitly rejects events spanning multiple HW PMUs, as in these cases the event->ctx will differ. However this validation is performed after pmu::event_init() is called in perf_init_event(), and thus pmu::event_init() may be called with a group leader from a different HW PMU. The CCI PMU driver does not take this fact into account, and assumes that the any other hardware event belongs to the CCI. There are two issues with it : 1) It is wrong and we should reject such groups. 2) Validation allocates an temporary idx for this non-cci event, which leads to wrong calculation of the counter availability, and eventually lesser number of events in the group. This patch updates the CCI PMU driver to first test for and reject events from other PMUs, which is the right thing to do. Cc: Will Deacon <will.deacon@arm.com> Acked-by: Mark Rutland <mark.rutland@arm.com> Acked-by: Peter Ziljstra (Intel) <peterz@infradead.org> Signed-off-by: Suzuki K. Poulose <suzuki.poulose@arm.com> Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent 06e5801 commit b186219

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

‎drivers/bus/arm-cci.c‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -660,12 +660,21 @@ static void cci_pmu_del(struct perf_event *event, int flags)
660660
}
661661

662662
static int
663-
validate_event(struct cci_pmu_hw_events *hw_events,
664-
struct perf_event *event)
663+
validate_event(struct pmu *cci_pmu,
664+
struct cci_pmu_hw_events *hw_events,
665+
struct perf_event *event)
665666
{
666667
if (is_software_event(event))
667668
return 1;
668669

670+
/*
671+
* Reject groups spanning multiple HW PMUs (e.g. CPU + CCI). The
672+
* core perf code won't check that the pmu->ctx == leader->ctx
673+
* until after pmu->event_init(event).
674+
*/
675+
if (event->pmu != cci_pmu)
676+
return 0;
677+
669678
if (event->state < PERF_EVENT_STATE_OFF)
670679
return 1;
671680

@@ -687,15 +696,15 @@ validate_group(struct perf_event *event)
687696
.used_mask = CPU_BITS_NONE,
688697
};
689698

690-
if (!validate_event(&fake_pmu, leader))
699+
if (!validate_event(event->pmu, &fake_pmu, leader))
691700
return -EINVAL;
692701

693702
list_for_each_entry(sibling, &leader->sibling_list, group_entry) {
694-
if (!validate_event(&fake_pmu, sibling))
703+
if (!validate_event(event->pmu, &fake_pmu, sibling))
695704
return -EINVAL;
696705
}
697706

698-
if (!validate_event(&fake_pmu, event))
707+
if (!validate_event(event->pmu, &fake_pmu, event))
699708
return -EINVAL;
700709

701710
return 0;

0 commit comments

Comments
 (0)