mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2025-04-02 16:50:26 +07:00
perf: Fix branch stack refcount leak on callchain init failure
On callchain buffers allocation failure, free_event() is called and all the accounting performed in perf_event_alloc() for that event is cancelled. But if the event has branch stack sampling, it is unaccounted as well from the branch stack sampling events refcounts. This is a bug because this accounting is performed after the callchain buffer allocation. As a result, the branch stack sampling events refcount can become negative. To fix this, move the branch stack event accounting before the callchain buffer allocation. Reported-by: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Stephane Eranian <eranian@google.com> Signed-off-by: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/1374539466-4799-2-git-send-email-fweisbec@gmail.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:
parent
7d9ffa8961
commit
6050cb0b0b
@ -6567,6 +6567,12 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
|
|||||||
atomic_inc(&nr_comm_events);
|
atomic_inc(&nr_comm_events);
|
||||||
if (event->attr.task)
|
if (event->attr.task)
|
||||||
atomic_inc(&nr_task_events);
|
atomic_inc(&nr_task_events);
|
||||||
|
if (has_branch_stack(event)) {
|
||||||
|
static_key_slow_inc(&perf_sched_events.key);
|
||||||
|
if (!(event->attach_state & PERF_ATTACH_TASK))
|
||||||
|
atomic_inc(&per_cpu(perf_branch_stack_events,
|
||||||
|
event->cpu));
|
||||||
|
}
|
||||||
if (event->attr.sample_type & PERF_SAMPLE_CALLCHAIN) {
|
if (event->attr.sample_type & PERF_SAMPLE_CALLCHAIN) {
|
||||||
err = get_callchain_buffers();
|
err = get_callchain_buffers();
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -6574,12 +6580,6 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
|
|||||||
return ERR_PTR(err);
|
return ERR_PTR(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (has_branch_stack(event)) {
|
|
||||||
static_key_slow_inc(&perf_sched_events.key);
|
|
||||||
if (!(event->attach_state & PERF_ATTACH_TASK))
|
|
||||||
atomic_inc(&per_cpu(perf_branch_stack_events,
|
|
||||||
event->cpu));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return event;
|
return event;
|
||||||
|
Loading…
Reference in New Issue
Block a user