[PATCH RFC] mtd: rawnand: xway: don't yield while holding spinlock

Thomas Nixon tom at tomn.co.uk
Sun Mar 26 16:52:39 PDT 2023

xway_nand holds the ebu_lock spinlock during transactions by locking and
unlocking in select_chip. Yielding while this is held is bad, so block
in dev_ready so that nand_wait and nand_wait_ready never yield.

This fixes crashes mostly seen in ath9k_pci_owl_loader.

Tested on a bt homehub v5a, with openwrt-patched 5.10 and 5.15 kernels.

Link: https://github.com/openwrt/openwrt/issues/9829
Signed-off-by: Thomas Nixon <tom at tomn.co.uk>

Obviously this is a hack, but other options don't seem great either --
maybe someone has a better idea?

Perhaps this should implement a timeout warning too? Adding an actual
timeout seems tricky, as xway_dev_ready would have to return 1 even when
it's not ready in to break out of the loop in nand_wait/nand_wait_ready
without yielding (and triggering this bug).

 drivers/mtd/nand/raw/xway_nand.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/raw/xway_nand.c b/drivers/mtd/nand/raw/xway_nand.c
index 035b82aa2f4a..ea10a35db6db 100644
--- a/drivers/mtd/nand/raw/xway_nand.c
+++ b/drivers/mtd/nand/raw/xway_nand.c
@@ -122,7 +122,13 @@ static void xway_cmd_ctrl(struct nand_chip *chip, int cmd, unsigned int ctrl)
 static int xway_dev_ready(struct nand_chip *chip)
-	return ltq_ebu_r32(EBU_NAND_WAIT) & NAND_WAIT_RD;
+	/*
+	 * wait until ready, as otherwise the driver will yield in nand_wait or
+	 * nand_wait_ready, which is a bad idea when we're holding ebu_lock
+	 */
+	while ((ltq_ebu_r32(EBU_NAND_WAIT) & NAND_WAIT_RD) == 0)
+		;
+	return 1;
 static unsigned char xway_read_byte(struct nand_chip *chip)

More information about the linux-mtd mailing list