mirror of https://gitee.com/openkylin/linux.git
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 <eranian@google.com> Cc: peterz@infradead.org Cc: perfmon2-devel@lists.sf.net Cc: paulus@samba.org Cc: davem@davemloft.net LKML-Reference: <20110323150306.GA1580@quad> Signed-off-by: Ingo Molnar <mingo@elte.hu>
This commit is contained in:
parent
ce2d17ca7f
commit
68cacd2916
|
@ -938,9 +938,7 @@ struct perf_cpu_context {
|
||||||
struct list_head rotation_list;
|
struct list_head rotation_list;
|
||||||
int jiffies_interval;
|
int jiffies_interval;
|
||||||
struct pmu *active_pmu;
|
struct pmu *active_pmu;
|
||||||
#ifdef CONFIG_CGROUP_PERF
|
|
||||||
struct perf_cgroup *cgrp;
|
struct perf_cgroup *cgrp;
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct perf_output_handle {
|
struct perf_output_handle {
|
||||||
|
|
|
@ -941,6 +941,7 @@ static void perf_group_attach(struct perf_event *event)
|
||||||
static void
|
static void
|
||||||
list_del_event(struct perf_event *event, struct perf_event_context *ctx)
|
list_del_event(struct perf_event *event, struct perf_event_context *ctx)
|
||||||
{
|
{
|
||||||
|
struct perf_cpu_context *cpuctx;
|
||||||
/*
|
/*
|
||||||
* We can have double detach due to exit/hot-unplug + close.
|
* We can have double detach due to exit/hot-unplug + close.
|
||||||
*/
|
*/
|
||||||
|
@ -949,8 +950,17 @@ list_del_event(struct perf_event *event, struct perf_event_context *ctx)
|
||||||
|
|
||||||
event->attach_state &= ~PERF_ATTACH_CONTEXT;
|
event->attach_state &= ~PERF_ATTACH_CONTEXT;
|
||||||
|
|
||||||
if (is_cgroup_event(event))
|
if (is_cgroup_event(event)) {
|
||||||
ctx->nr_cgroups--;
|
ctx->nr_cgroups--;
|
||||||
|
cpuctx = __get_cpu_context(ctx);
|
||||||
|
/*
|
||||||
|
* if there are no more cgroup events
|
||||||
|
* then cler cgrp to avoid stale pointer
|
||||||
|
* in update_cgrp_time_from_cpuctx()
|
||||||
|
*/
|
||||||
|
if (!ctx->nr_cgroups)
|
||||||
|
cpuctx->cgrp = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
ctx->nr_events--;
|
ctx->nr_events--;
|
||||||
if (event->attr.inherit_stat)
|
if (event->attr.inherit_stat)
|
||||||
|
|
Loading…
Reference in New Issue