Re: [PATCH v3] irqchip/ls-extirq: fix invalid wait context by avoiding to use regmap

From: Vladimir Oltean
Date: Thu Jul 28 2022 - 09:31:09 EST


Hello Marc,

On Thu, Jul 28, 2022 at 08:44:58AM +0100, Marc Zyngier wrote:
> On Wed, 27 Jul 2022 17:09:15 +0100,
> Vladimir Oltean <vladimir.oltean@xxxxxxx> wrote:
> >
> > The irqchip->irq_set_type method is called by __irq_set_trigger() under
> > the desc->lock raw spinlock.
> >
> > The ls-extirq implementation, ls_extirq_irq_set_type(), uses an MMIO
> > regmap created by of_syscon_register(), which uses plain spinlocks
> > (the kind that are sleepable on RT).
> >
> > Therefore, this is an invalid locking scheme for which we get a kernel
> > splat stating just that ("[ BUG: Invalid wait context ]"), because the
> > context in which the plain spinlock may sleep is atomic due to the raw
> > spinlock. We need to go raw spinlocks all the way.
>
> Interesting you say that...
> > - regmap_update_bits(priv->syscon, priv->intpcr, mask, value);
> > +
> > + intpcr = priv->read(priv->intpcr);
> > + intpcr &= ~mask;
> > + intpcr |= value;
> > + priv->write(priv->intpcr, intpcr);
>
> Which really begs a few questions:
>
> - Where is the locking gone? Sure, the warning is gone. But the driver
> is now broken for *all* configurations, and not only RT. Result!

Correct, I had assumed that calls to irq_chip :: irq_set_type() are
implicitly serialized with respect to each other by means of the irq
descriptor's desc->lock, but clearly that is only true for a single
interrupt line. So I'll add back a lock that keeps the rmw atomic.

> - Is it *really* worth it to have 4 dumb helpers that bring nothing in
> terms of abstraction, and two indirections for something that could
> equally be expressed with a conditional?

Probably not, but it was a choice no worse than going through regmap's
own indirection. I'll try to come up with something that avoids function
pointers.