Skip to content

Commit 652884f

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
perf: Add a bit of paranoia
Add a few WARN()s to catch things that should never happen. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Linus Torvalds <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 8f4bf4b commit 652884f

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

kernel/events/core.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,8 @@ static void perf_group_attach(struct perf_event *event)
12751275
if (group_leader == event)
12761276
return;
12771277

1278+
WARN_ON_ONCE(group_leader->ctx != event->ctx);
1279+
12781280
if (group_leader->group_flags & PERF_GROUP_SOFTWARE &&
12791281
!is_software_event(event))
12801282
group_leader->group_flags &= ~PERF_GROUP_SOFTWARE;
@@ -1296,6 +1298,10 @@ static void
12961298
list_del_event(struct perf_event *event, struct perf_event_context *ctx)
12971299
{
12981300
struct perf_cpu_context *cpuctx;
1301+
1302+
WARN_ON_ONCE(event->ctx != ctx);
1303+
lockdep_assert_held(&ctx->lock);
1304+
12991305
/*
13001306
* We can have double detach due to exit/hot-unplug + close.
13011307
*/
@@ -1380,6 +1386,8 @@ static void perf_group_detach(struct perf_event *event)
13801386

13811387
/* Inherit group flags from the previous leader */
13821388
sibling->group_flags = event->group_flags;
1389+
1390+
WARN_ON_ONCE(sibling->ctx != event->ctx);
13831391
}
13841392

13851393
out:
@@ -1442,6 +1450,10 @@ event_sched_out(struct perf_event *event,
14421450
{
14431451
u64 tstamp = perf_event_time(event);
14441452
u64 delta;
1453+
1454+
WARN_ON_ONCE(event->ctx != ctx);
1455+
lockdep_assert_held(&ctx->lock);
1456+
14451457
/*
14461458
* An event which could not be activated because of
14471459
* filter mismatch still needs to have its timings
@@ -7822,14 +7834,19 @@ static void perf_free_event(struct perf_event *event,
78227834

78237835
put_event(parent);
78247836

7837+
raw_spin_lock_irq(&ctx->lock);
78257838
perf_group_detach(event);
78267839
list_del_event(event, ctx);
7840+
raw_spin_unlock_irq(&ctx->lock);
78277841
free_event(event);
78287842
}
78297843

78307844
/*
7831-
* free an unexposed, unused context as created by inheritance by
7845+
* Free an unexposed, unused context as created by inheritance by
78327846
* perf_event_init_task below, used by fork() in case of fail.
7847+
*
7848+
* Not all locks are strictly required, but take them anyway to be nice and
7849+
* help out with the lockdep assertions.
78337850
*/
78347851
void perf_event_free_task(struct task_struct *task)
78357852
{

0 commit comments

Comments
 (0)