Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

arm_pmu: Validate single/group leader events

In the case where there is only a cycle counter available (i.e.
PMCR_EL0.N is 0) and an event other than CPU cycles is opened, the open
should fail as the event can never possibly be scheduled. However, the
event validation when an event is opened is skipped when the group
leader is opened. Fix this by always validating the group leader events.

Reported-by: Al Grant <al.grant@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Rob Herring <robh@kernel.org>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Link: https://lore.kernel.org/r/20220408203330.4014015-1-robh@kernel.org
Cc: <stable@vger.kernel.org>
Signed-off-by: Will Deacon <will@kernel.org>

authored by

Rob Herring and committed by
Will Deacon
e5c23779 d02b4dd8

+4 -6
+4 -6
drivers/perf/arm_pmu.c
··· 400 400 if (!validate_event(event->pmu, &fake_pmu, leader)) 401 401 return -EINVAL; 402 402 403 + if (event == leader) 404 + return 0; 405 + 403 406 for_each_sibling_event(sibling, leader) { 404 407 if (!validate_event(event->pmu, &fake_pmu, sibling)) 405 408 return -EINVAL; ··· 492 489 local64_set(&hwc->period_left, hwc->sample_period); 493 490 } 494 491 495 - if (event->group_leader != event) { 496 - if (validate_group(event) != 0) 497 - return -EINVAL; 498 - } 499 - 500 - return 0; 492 + return validate_group(event); 501 493 } 502 494 503 495 static int armpmu_event_init(struct perf_event *event)