Re: [PATCH] mtd: spi-nor: Reschedule in spi_nor_wait_till_ready()
From: Miquel Raynal
Date: Tue Nov 17 2026 - 03:48:28 EST
On 06/11/2026 at 13:11:08 -08, Bart Van Assche <bvanassche@xxxxxxx> wrote:
> On 11/6/26 1:04 PM, Bart Van Assche wrote:
>> In spi_nor_wait_till_ready_with_timeout(), cond_resched() is only
>> called after spi_nor_ready() returns 0. If the flash is already ready on
>> the first status check, the function returns before reaching
>> cond_resched(). This happens e.g. under QEMU, where SPI NOR page
>> programs and sector erases complete synchronously during the MMIO write,
>> combined with a controller driver that polls without sleeping.
>> Consequently, multi-sector erases in spi_nor_erase() and multi-page
>> writes in spi_nor_write() may iterate over thousands of sectors or pages
>> without ever yielding the CPU on kernels built without
>> CONFIG_PREEMPTION, e.g. ARM32 kernels with CONFIG_PREEMPT_VOLUNTARY=y.
>> This triggers soft lockup and RCU stall reports.
>> Move cond_resched() to the start of the polling loop such that every
>> call reschedules if needed, even if the flash is ready on the first
>> check. Doing this in the shared wait helper instead of in the
>> spi_nor_erase() and spi_nor_write() loops covers all callers that wait
>> for a program or erase operation to complete.
>> Signed-off-by: Bart Van Assche <bvanassche@xxxxxxx>
>> ---
Reviewed-by: Miquel Raynal <miquel.raynal@xxxxxxxxxxx>