Skip to contentSkip to conversation

mtd: rawnand: xway: don't yield while holding spinlock

RFC PATCH New Thomas Nixon 1 participant 1 message Mar 26, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 mtd: rawnand: xway: don't yield while holding spinlock

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.

---

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(-)
drivers/mtd/nand/raw/xway_nand.c +7 -1
index 035b82aa2f4a..ea10a35db6db 100644
@@ -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)
Signature · 6 lines
2.33.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/