public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Thomas Nixon <tom@tomn.co.uk>
To: linux-mtd@lists.infradead.org
Subject: [PATCH RFC] mtd: rawnand: xway: don't yield while holding spinlock
Date: Mon, 27 Mar 2023 00:52:39 +0100	[thread overview]
Message-ID: <ZCDax6AWvz9mKGPr@tom-tp> (raw)

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/

                 reply	other threads:[~2023-03-26 23:53 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZCDax6AWvz9mKGPr@tom-tp \
    --to=tom@tomn.co.uk \
    --cc=linux-mtd@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox