Skip to content

Commit 27c68c2

Browse files
namhyungPeter Zijlstra
authored and
Peter Zijlstra
committed
perf/x86: Fix lockdep warning in for_each_sibling_event() on SPR
On SPR, the load latency event needs an auxiliary event in the same group to work properly. There's a check in intel_pmu_hw_config() for this to iterate sibling events and find a mem-loads-aux event. The for_each_sibling_event() has a lockdep assert to make sure if it disabled hardirq or hold leader->ctx->mutex. This works well if the given event has a separate leader event since perf_try_init_event() grabs the leader->ctx->mutex to protect the sibling list. But it can cause a problem when the event itself is a leader since the event is not initialized yet and there's no ctx for the event. Actually I got a lockdep warning when I run the below command on SPR, but I guess it could be a NULL pointer dereference. $ perf record -d -e cpu/mem-loads/uP true The code path to the warning is: sys_perf_event_open() perf_event_alloc() perf_init_event() perf_try_init_event() x86_pmu_event_init() hsw_hw_config() intel_pmu_hw_config() for_each_sibling_event() lockdep_assert_event_ctx() We don't need for_each_sibling_event() when it's a standalone event. Let's return the error code directly. Fixes: f3c0eba ("perf: Add a few assertions") Reported-by: Greg Thelen <[email protected]> Signed-off-by: Namhyung Kim <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected]
1 parent 06c2afb commit 27c68c2

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

arch/x86/events/intel/core.c

+7
Original file line numberDiff line numberDiff line change
@@ -3993,6 +3993,13 @@ static int intel_pmu_hw_config(struct perf_event *event)
39933993
struct perf_event *leader = event->group_leader;
39943994
struct perf_event *sibling = NULL;
39953995

3996+
/*
3997+
* When this memload event is also the first event (no group
3998+
* exists yet), then there is no aux event before it.
3999+
*/
4000+
if (leader == event)
4001+
return -ENODATA;
4002+
39964003
if (!is_mem_loads_aux_event(leader)) {
39974004
for_each_sibling_event(sibling, leader) {
39984005
if (is_mem_loads_aux_event(sibling))

0 commit comments

Comments
 (0)