Skip to content

Commit 853e2da

Browse files
mrutland-armwilldeacon
authored andcommitted
arm64: perf: reject CHAIN events at creation time
Currently it's possible for a user to open CHAIN events arbitrarily, which we previously tried to rule out in commit: ca2b497 ("arm64: perf: Reject stand-alone CHAIN events for PMUv3") Which allowed the events to be opened, but prevented them from being scheduled by by using an arm_pmu::filter_match hook to reject the relevant events. The CHAIN event filtering in the arm_pmu::filter_match hook was silently removed in commit: bd27568 ("perf: Rewrite core context handling") As a result, it's now possible for users to open CHAIN events, and for these to be installed arbitrarily. Fix this by rejecting CHAIN events at creation time. This avoids the creation of events which will never count, and doesn't require using the dynamic filtering. Attempting to open a CHAIN event (0x1e) will now be rejected: | # ./perf stat -e armv8_pmuv3/config=0x1e/ ls | perf | | Performance counter stats for 'ls': | | <not supported> armv8_pmuv3/config=0x1e/ | | 0.002197470 seconds time elapsed | | 0.000000000 seconds user | 0.002294000 seconds sys Other events (e.g. CPU_CYCLES / 0x11) will open as usual: | # ./perf stat -e armv8_pmuv3/config=0x11/ ls | perf | | Performance counter stats for 'ls': | | 2538761 armv8_pmuv3/config=0x11/ | | 0.002227330 seconds time elapsed | | 0.002369000 seconds user | 0.000000000 seconds sys Fixes: bd27568 ("perf: Rewrite core context handling") Signed-off-by: Mark Rutland <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Ravi Bangoria <[email protected]> Cc: Will Deacon <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 61d0386 commit 853e2da

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

arch/arm64/kernel/perf_event.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,14 @@ static int __armv8_pmuv3_map_event(struct perf_event *event,
10631063
&armv8_pmuv3_perf_cache_map,
10641064
ARMV8_PMU_EVTYPE_EVENT);
10651065

1066+
/*
1067+
* CHAIN events only work when paired with an adjacent counter, and it
1068+
* never makes sense for a user to open one in isolation, as they'll be
1069+
* rotated arbitrarily.
1070+
*/
1071+
if (hw_event_id == ARMV8_PMUV3_PERFCTR_CHAIN)
1072+
return -EINVAL;
1073+
10661074
if (armv8pmu_event_is_64bit(event))
10671075
event->hw.flags |= ARMPMU_EVT_64BIT;
10681076

0 commit comments

Comments
 (0)