All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC] mtd: rawnand: xway: don't yield while holding spinlock
@ 2023-03-26 23:52 Thomas Nixon
  0 siblings, 0 replies; only message in thread
From: Thomas Nixon @ 2023-03-26 23:52 UTC (permalink / raw)
  To: linux-mtd

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@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)
-- 
2.33.1


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

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-03-26 23:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-26 23:52 [PATCH RFC] mtd: rawnand: xway: don't yield while holding spinlock Thomas Nixon

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.