edf0626860922641fd33d1a324ff44a4e57b7da1
[openwrt/openwrt.git] / target / linux / lantiq / patches-5.10 / 0400-mtd-rawnand-xway-don-t-yield-while-holding-spinlock.patch
1 From 416f25a948d11ef15733f2e31658d31b5cc7bef6 Mon Sep 17 00:00:00 2001
2 From: Thomas Nixon <tom@tomn.co.uk>
3 Date: Sun, 26 Mar 2023 11:08:49 +0100
4 Subject: [PATCH] mtd: rawnand: xway: don't yield while holding spinlock
5
6 The nand driver normally while waiting for the device to become ready;
7 this is normally fine, but xway_nand holds the ebu_lock spinlock, and
8 this can cause lockups if other threads which use ebu_lock are
9 interleaved. Fix this by waiting instead of polling.
10
11 This mainly showed up as crashes in ath9k_pci_owl_loader (see
12 https://github.com/openwrt/openwrt/issues/9829 ), but turning on
13 spinlock debugging shows this happening in other places too.
14
15 This doesn't seem to measurably impact boot time.
16
17 Signed-off-by: Thomas Nixon <tom@tomn.co.uk>
18 ---
19 drivers/mtd/nand/raw/xway_nand.c | 8 +++++++-
20 1 file changed, 7 insertions(+), 1 deletion(-)
21
22 --- a/drivers/mtd/nand/raw/xway_nand.c
23 +++ b/drivers/mtd/nand/raw/xway_nand.c
24 @@ -175,7 +175,13 @@ static void xway_cmd_ctrl(struct nand_ch
25
26 static int xway_dev_ready(struct nand_chip *chip)
27 {
28 - return ltq_ebu_r32(EBU_NAND_WAIT) & NAND_WAIT_RD;
29 + /*
30 + * wait until ready, as otherwise the driver will yield in nand_wait or
31 + * nand_wait_ready, which is a bad idea when we're holding ebu_lock
32 + */
33 + while ((ltq_ebu_r32(EBU_NAND_WAIT) & NAND_WAIT_RD) == 0)
34 + cpu_relax();
35 + return 1;
36 }
37
38 static unsigned char xway_read_byte(struct nand_chip *chip)