Skip to content

Commit

Permalink
perf/core: Fix perf_sched_count derailment
Browse files Browse the repository at this point in the history
[ Upstream commit 927a557 ]

The error path in perf_event_open() is such that asking for a sampling
event on a PMU that doesn't generate interrupts will end up in dropping
the perf_sched_count even though it hasn't been incremented for this
event yet.

Given a sufficient amount of these calls, we'll end up disabling
scheduler's jump label even though we'd still have active events in the
system, thereby facilitating the arrival of the infernal regions upon us.

I'm fixing this by moving account_event() inside perf_event_alloc().

Signed-off-by: Alexander Shishkin <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Cc: <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Vince Weaver <[email protected]>
Cc: [email protected]
Link: http://lkml.kernel.org/r/1456917854-29427-1-git-send-email-alexander.shishkin@linux.intel.com
Signed-off-by: Ingo Molnar <[email protected]>
Signed-off-by: He Kuang <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
virtuoso authored and sashalevin committed Mar 24, 2016
1 parent 882f862 commit 919e67a
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions kernel/events/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -7641,6 +7641,9 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
}
}

/* symmetric to unaccount_event() in _free_event() */
account_event(event);

return event;

err_per_task:
Expand Down Expand Up @@ -8004,8 +8007,6 @@ SYSCALL_DEFINE5(perf_event_open,
}
}

account_event(event);

/*
* Special case software events and allow them to be part of
* any hardware group.
Expand Down Expand Up @@ -8270,8 +8271,6 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu,
/* Mark owner so we could distinguish it from user events. */
event->owner = EVENT_OWNER_KERNEL;

account_event(event);

ctx = find_get_context(event->pmu, task, event);
if (IS_ERR(ctx)) {
err = PTR_ERR(ctx);
Expand Down

0 comments on commit 919e67a

Please sign in to comment.