Re: in_irq_or_nmi()

From: Matthew Wilcox
Date: Wed Mar 29 2017 - 14:12:47 EST


On Wed, Mar 29, 2017 at 11:19:49AM +0200, Peter Zijlstra wrote:
> On Wed, Mar 29, 2017 at 10:59:28AM +0200, Jesper Dangaard Brouer wrote:
> > On Wed, 29 Mar 2017 10:12:19 +0200
> > Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
> > > No, that's horrible. Also, wth is this about? A memory allocator that
> > > needs in_nmi()? That sounds beyond broken.
> >
> > It is the other way around. We want to exclude NMI and HARDIRQ from
> > using the per-cpu-pages (pcp) lists "order-0 cache" (they will
> > fall-through using the normal buddy allocator path).
>
> Any in_nmi() code arriving at the allocator is broken. No need to fix
> the allocator.

That's demonstrably true. You can't grab a spinlock in NMI code and
the first thing that happens if this in_irq_or_nmi() check fails is ...
spin_lock_irqsave(&zone->lock, flags);
so this patch should just use in_irq().

(the concept of NMI code needing to allocate memory was blowing my mind
a little bit)