Re: [PATCH 1/2] firmware: arm_sdei: Do not signal event 0 to a masked PE
From: Kiryl Shutsemau (Meta)
Date: Wed Nov 25 2026 - 09:00:52 EST
On Wed, Nov 25, 2026 at 05:50:10PM +0800, YinFengwei wrote:
> Hi Kirill,
>
> On Tue, Nov 24, 2026 at 07:47:04PM +0000, Kiryl Shutsemau (Meta) wrote:
> > The SDEI NMI backtrace signals event 0 to every other CPU, idle ones
> <snip>
> > +static void sdei_block_signal(void)
> > +{
> > + struct sdei_pe *pe = this_cpu_ptr(&sdei_pe);
> > + unsigned long flags;
> > +
> > + /*
> > + * A panic from an SDEI event or a pseudo-NMI may have left the lock
> > + * held by this CPU. The CPUs that could signal it are stopped by now.
> > + */
> > + if (panic_on_this_cpu()) {
> > + WRITE_ONCE(pe->unmasked, false);
> If the panic didn't take the lock, should lock be taken
> just like "else" path?
If another CPU holds it at this point, that CPU was stopped in the
middle of signalling this one, and it will never drop the lock. The
panic would hang on it.
If nobody holds it, there is nothing for it to keep out. This runs at
the end of smp_send_stop(), after the other CPUs have been stopped. A
sender stopped after it took the lock has either counted its signal,
which sdei_wait_in_flight() waits for, or never sent one.
Telling the two apart takes a trylock, and on failure we would go ahead
without the lock anyway.
> > + } else {
> > + raw_spin_lock_irqsave(&pe->lock, flags);
> > + WRITE_ONCE(pe->unmasked, false);
> > + raw_spin_unlock_irqrestore(&pe->lock, flags);
> > + }
> > +
> > + sdei_wait_in_flight(pe);
> > +}
> > +
> > static int sdei_pm_notifier(struct notifier_block *nb, unsigned long action,
> > void *data)
> > {
> > + struct sdei_pe *pe = this_cpu_ptr(&sdei_pe);
> > int rv;
> >
> > WARN_ON_ONCE(preemptible());
> >
> > switch (action) {
> > case CPU_PM_ENTER:
> > + /*
> > + * Leave alone a PE that is masked already: before
> > + * sdei_cpuhp_up(), or after sdei_cpuhp_down(), as cpuidle runs
> > + * until CPU_OFF. CPU_PM_EXIT must not unmask it.
> > + */
> > + if (!pe->unmasked)
> I am wondering whether READ_ONCE() should be used here?
No.
We read the flag of this CPU, and only this CPU writes pe->unmasked.
The notifier runs with IRQs off, so no store can race with this load.
What can still interrupt it, a stop or a panic from an SDEI event or a
pseudo-NMI, does not return here.
READ_ONCE()/WRITE_ONCE() are for sdei_event_signal(), which reads the
flag from another CPU.
Left plain, KCSAN will report it if that ever changes. See item 5 under
"Use of Plain C-Language Accesses" in
tools/memory-model/Documentation/access-marking.txt.
--
Kiryl Shutsemau / Kirill A. Shutemov