Skip to content

Commit 68cacd2

Browse files
Stephane EranianIngo Molnar
authored andcommitted
perf_events: Fix stale ->cgrp pointer in update_cgrp_time_from_cpuctx()
This patch solves a stale pointer problem in update_cgrp_time_from_cpuctx(). The cpuctx->cgrp was not cleared on all possible event exit paths, including: close() perf_release() perf_release_kernel() list_del_event() This patch fixes list_del_event() to clear cpuctx->cgrp when there are no cgroup events left in the context. [ This second version makes the code compile when CONFIG_CGROUP_PERF is not enabled. We unconditionally define perf_cpu_context->cgrp. ] Signed-off-by: Stephane Eranian <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] LKML-Reference: <20110323150306.GA1580@quad> Signed-off-by: Ingo Molnar <[email protected]>
1 parent ce2d17c commit 68cacd2

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

include/linux/perf_event.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -938,9 +938,7 @@ struct perf_cpu_context {
938938
struct list_head rotation_list;
939939
int jiffies_interval;
940940
struct pmu *active_pmu;
941-
#ifdef CONFIG_CGROUP_PERF
942941
struct perf_cgroup *cgrp;
943-
#endif
944942
};
945943

946944
struct perf_output_handle {

kernel/perf_event.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,7 @@ static void perf_group_attach(struct perf_event *event)
941941
static void
942942
list_del_event(struct perf_event *event, struct perf_event_context *ctx)
943943
{
944+
struct perf_cpu_context *cpuctx;
944945
/*
945946
* We can have double detach due to exit/hot-unplug + close.
946947
*/
@@ -949,8 +950,17 @@ list_del_event(struct perf_event *event, struct perf_event_context *ctx)
949950

950951
event->attach_state &= ~PERF_ATTACH_CONTEXT;
951952

952-
if (is_cgroup_event(event))
953+
if (is_cgroup_event(event)) {
953954
ctx->nr_cgroups--;
955+
cpuctx = __get_cpu_context(ctx);
956+
/*
957+
* if there are no more cgroup events
958+
* then cler cgrp to avoid stale pointer
959+
* in update_cgrp_time_from_cpuctx()
960+
*/
961+
if (!ctx->nr_cgroups)
962+
cpuctx->cgrp = NULL;
963+
}
954964

955965
ctx->nr_events--;
956966
if (event->attr.inherit_stat)

0 commit comments

Comments
 (0)