[Patch v2 03/16] perf/x86/intel: Guard leader sibling walk on nr_siblings
From: Dapeng Mi
Date: Mon Nov 30 2026 - 19:45:37 EST
The leader event's ctx mutex is only held before calling
pmu->event_init() for sibling events, not for a newly-created group
leader.
The branch counters walk in intel_pmu_hw_config() calls
for_each_sibling_event() on the leader itself. At that point,
leader->ctx is not yet initialized, so the lockdep assertion in
for_each_sibling_event() can trigger WARN_ON_ONCE(), and the access to
leader->ctx is unsafe.
This loop is unnecessary when the event is the group leader, because the
leader has no siblings yet. Guard the iteration with leader->nr_siblings
before calling for_each_sibling_event().
Fixes: 33744916196b ("perf/x86/intel: Support branch counters logging")
Signed-off-by: Dapeng Mi <dapeng1.mi@xxxxxxxxxxxxxxx>
---
arch/x86/events/intel/core.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index e91b5fea5708..9fae7d83a6b4 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -5048,9 +5048,11 @@ static int intel_pmu_hw_config(struct perf_event *event)
return -EINVAL;
leader->hw.flags |= PERF_X86_EVENT_BRANCH_COUNTERS;
- for_each_sibling_event(sibling, leader) {
- if (intel_set_branch_counter_constr(sibling, &num))
- return -EINVAL;
+ if (leader->nr_siblings) {
+ for_each_sibling_event(sibling, leader) {
+ if (intel_set_branch_counter_constr(sibling, &num))
+ return -EINVAL;
+ }
}
/* event isn't installed as a sibling yet. */
--
2.34.1