[PATCH v2 1/7] spi: spi-mem: Add support for panic mem writes
Miquel Raynal
miquel.raynal at bootlin.com
Tue Oct 13 08:57:26 PDT 2026
Hi Paul,
On 13/10/2026 at 17:33:32 +02, Paul Cercueil <paul.cercueil at bootlin.com> wrote:
> Hi Sashiko,
:-)
>> > - ret = spi_mem_access_start(mem);
>> > + if (!op->panic_write)
>> > + ret = spi_mem_access_start(mem);
>> > + else if (ctlr->auto_runtime_pm)
>> > + ret = pm_runtime_get_if_active(ctlr->dev.parent);
>> > if (ret)
>> > return ret;
>>
>> [Severity: High]
>> Is it safe to call pm_runtime_get_if_active() here during a kernel panic?
>>
>> pm_runtime_get_if_active() relies on pm_runtime_get_conditional(), which
>> unconditionally acquires dev->power.lock via spin_lock_irqsave(). In a panic
>> context with NMIs or IRQs disabled, trying to acquire a spinlock that may be
>> held by a halted CPU causes an infinite spin. On PREEMPT_RT,
>> spin_lock_irqsave()
>> maps to a sleeping rt_mutex, which is strictly forbidden in atomic context.
>
> ACK, I'll just drop pm_runtime_get_if_active() here, and restore the return -
> EOPNOTSUPP that was in v1 when ctlr->auto_runtime_pm is set.
This is tricky but automatically rules out about 1/6th of the
controllers (45 controllers set this boolean out of +300). I don't like
it much. I guess it deserves a comment in case someone ever wants to
enable this feature on their auto-RPM-enabled controller, to understand
why this is not possible. My gut feeling is that the runtime PM layer
lacks its own understanding of what a panic is. We should, I believe, be
able to query the usage_count of a controller without taking the lock
during a panic write.
Nevertheless, let's move forward and return an error for now.
Thanks,
Miquèl
More information about the linux-mtd
mailing list