Re: Q: perf_install_in_context/perf_event_enable are racy?

From: Peter Zijlstra
Date: Thu Jan 27 2011 - 11:27:15 EST

On Thu, 2011-01-27 at 17:10 +0100, Oleg Nesterov wrote:
> > local_irq_enable();
> > + rq->in_ctxsw = 0;
> If we think that context_switch finishes here, probably it would be
> more clean to clear ->in_ctxsw before local_irq_enable().

It must in fact be done before, otherwise there's a race where we set
ctx after perf_event_task_sched_in() runs, and we send the IPI, the IPI
lands after local_irq_enable() but before rq->in_ctxsq = 0, the IPI is
ignored, nothing happens.

> > finish_lock_switch(rq, prev);
> But, otoh, maybe finish_lock_switch() can clear in_ctxsw, it already
> checks __ARCH_WANT_INTERRUPTS_ON_CTXSW. Likewise, perhaps it can be
> set in prepare_lock_switch() which enables irqs.
> But this is cosmetic and up to you.

Can't do because of the above thing..
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at