Re: [PATCH] perf/core: fix RCU issues with cgroup monitoring mode
From: Stephane Eranian
Date: Mon Oct 19 2015 - 03:58:53 EST
Peter,
On Sat, Oct 17, 2015 at 2:56 AM, Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
>
> On Sat, Oct 17, 2015 at 03:28:11AM +0200, Stephane Eranian wrote:
> >
> > This patch eliminates all known RCU violations detected
> > by the RCU checker (PROVE_RCU). The impact code paths
> > were all related to cgroup mode monitoring and involved
> > access a task's cgrp.
>
> But were they right? This patch provides no clues.
>
I am assuming that is the checker detects something suspicious there is likely
a problem.
Take for instance:
perf_cgroup_sched_out()->perf_cgroup_from_task() ->task_subsys_state()
That one fires the checker. I think because we are accessing the css
state without
protection.
The other places are similar.
I am also trying to avoid double taking the rcu-read-lock(), so I have moved
the rcu_read_lock() out of some functions to place them in the caller. The
perf_cgroup_switch() is a performance sensitive path.
If this is not the way to fix this, let me know and I'll rewrite the patch.
Thanks.
> > Signed-off-by: Stephane Eranian <eranian@xxxxxxxxxx>
> > ---
>
> > @@ -2094,6 +2104,7 @@ static int __perf_install_in_context(void *info)
> > cpuctx->task_ctx = task_ctx;
> > task = task_ctx->task;
> > }
> > + rcu_read_lock();
> >
> > cpu_ctx_sched_out(cpuctx, EVENT_ALL);
> >
> > @@ -2112,6 +2123,8 @@ static int __perf_install_in_context(void *info)
> > */
> > perf_event_sched_in(cpuctx, task_ctx, task);
> >
> > + rcu_read_unlock();
> > +
> > perf_pmu_enable(cpuctx->ctx.pmu);
> > perf_ctx_unlock(cpuctx, task_ctx);
> >
> > @@ -2398,7 +2411,9 @@ static void ctx_sched_out(struct perf_event_context *ctx,
> > return;
> >
> > update_context_time(ctx);
> > + rcu_read_lock();
> > update_cgrp_time_from_cpuctx(cpuctx);
> > + rcu_read_unlock();
> > if (!ctx->nr_active)
> > return;
> >
>
> And these impact !cgroup code, and the last looks like it should be
> inside update_cgrp_time_from_cpuctx() if at all.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/