Re: Bug in on_each_cpu?

Andrew Morton
2007-03-01T15:22:34Z

On Thu, 01 Mar 2007 03:47:39 -0800 Zachary Amsden <zach@vmware.com> wrote:

> Rusty Russell wrote:
> > On Thu, 2007-03-01 at 03:34 -0800, Zachary Amsden wrote:
> >
> >> What would be really, really nice would be to statically check all
> >> callsites that issue irq disables actually keep irqs disabled.
> >> Presumably, there was a reason they disabled irqs, and re-enabling them
> >> underneath their noses, even if it is to avoid a race, breaks the logic
> >> behind that reason.
> >>
> >
> > For the moment, how about a BUG_ON() in on_each_cpu()?
> >
>
> Sounds quite decent. But why does on_each_cpu need to disable
> interrupts at all? It just calls func(), then re-enables interrupts.
> So whatever was going to happen during func() that might not be
> interrupt safe could just be done in the callee, avoiding the rather
> expensive mess of disabling and re-enabling interrupts for those cases
> where it doesn't matter.

The handler for smp_call_function() is called with local interrupts
disabled (from the IPI handler).

So to provide a consistent call environment for that handler, on_each_cpu()
will also disable local interrupts when making the direct call on this CPU.

Similarly the !CONFIG_SMP version of on_each_cpu() disables local
interrupts when running the caller's function.