public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	patches@lists.linux.dev, Sean Nyekjaer <sean@geanix.com>,
	Boris Brezillon <boris.brezillon@collabora.com>,
	Miquel Raynal <miquel.raynal@bootlin.com>,
	Florian Fainelli <florian.fainelli@broadcom.com>
Subject: [PATCH 5.4 34/66] mtd: rawnand: protect access to rawnand devices while in suspend
Date: Fri, 15 Nov 2024 07:37:43 +0100	[thread overview]
Message-ID: <20241115063724.075230501@linuxfoundation.org> (raw)
In-Reply-To: <20241115063722.834793938@linuxfoundation.org>

5.4-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Sean Nyekjaer <sean@geanix.com>

commit 8cba323437a49a45756d661f500b324fc2d486fe upstream.

Prevent rawnand access while in a suspended state.

Commit 013e6292aaf5 ("mtd: rawnand: Simplify the locking") allows the
rawnand layer to return errors rather than waiting in a blocking wait.

Tested on a iMX6ULL.

Fixes: 013e6292aaf5 ("mtd: rawnand: Simplify the locking")
Signed-off-by: Sean Nyekjaer <sean@geanix.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Cc: stable@vger.kernel.org
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20220208085213.1838273-1-sean@geanix.com
[florian: Adjust rawnand.h members documentation and position]
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/mtd/nand/raw/nand_base.c |   44 +++++++++++++++++----------------------
 include/linux/mtd/rawnand.h      |    2 +
 2 files changed, 22 insertions(+), 24 deletions(-)

--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -359,16 +359,19 @@ static int nand_isbad_bbm(struct nand_ch
  *
  * Return: -EBUSY if the chip has been suspended, 0 otherwise
  */
-static int nand_get_device(struct nand_chip *chip)
+static void nand_get_device(struct nand_chip *chip)
 {
-	mutex_lock(&chip->lock);
-	if (chip->suspended) {
+	/* Wait until the device is resumed. */
+	while (1) {
+		mutex_lock(&chip->lock);
+		if (!chip->suspended) {
+			mutex_lock(&chip->controller->lock);
+			return;
+		}
 		mutex_unlock(&chip->lock);
-		return -EBUSY;
-	}
-	mutex_lock(&chip->controller->lock);
 
-	return 0;
+		wait_event(chip->resume_wq, !chip->suspended);
+	}
 }
 
 /**
@@ -593,9 +596,7 @@ static int nand_block_markbad_lowlevel(s
 		nand_erase_nand(chip, &einfo, 0);
 
 		/* Write bad block marker to OOB */
-		ret = nand_get_device(chip);
-		if (ret)
-			return ret;
+		nand_get_device(chip);
 
 		ret = nand_markbad_bbm(chip, ofs);
 		nand_release_device(chip);
@@ -3576,9 +3577,7 @@ static int nand_read_oob(struct mtd_info
 	    ops->mode != MTD_OPS_RAW)
 		return -ENOTSUPP;
 
-	ret = nand_get_device(chip);
-	if (ret)
-		return ret;
+	nand_get_device(chip);
 
 	if (!ops->datbuf)
 		ret = nand_do_read_oob(chip, from, ops);
@@ -4122,13 +4121,11 @@ static int nand_write_oob(struct mtd_inf
 			  struct mtd_oob_ops *ops)
 {
 	struct nand_chip *chip = mtd_to_nand(mtd);
-	int ret;
+	int ret = 0;
 
 	ops->retlen = 0;
 
-	ret = nand_get_device(chip);
-	if (ret)
-		return ret;
+	nand_get_device(chip);
 
 	switch (ops->mode) {
 	case MTD_OPS_PLACE_OOB:
@@ -4184,9 +4181,7 @@ int nand_erase_nand(struct nand_chip *ch
 		return -EINVAL;
 
 	/* Grab the lock and see if the device is available */
-	ret = nand_get_device(chip);
-	if (ret)
-		return ret;
+	nand_get_device(chip);
 
 	/* Shift to get first page */
 	page = (int)(instr->addr >> chip->page_shift);
@@ -4273,7 +4268,7 @@ static void nand_sync(struct mtd_info *m
 	pr_debug("%s: called\n", __func__);
 
 	/* Grab the lock and see if the device is available */
-	WARN_ON(nand_get_device(chip));
+	nand_get_device(chip);
 	/* Release it and go back */
 	nand_release_device(chip);
 }
@@ -4290,9 +4285,7 @@ static int nand_block_isbad(struct mtd_i
 	int ret;
 
 	/* Select the NAND device */
-	ret = nand_get_device(chip);
-	if (ret)
-		return ret;
+	nand_get_device(chip);
 
 	nand_select_target(chip, chipnr);
 
@@ -4354,6 +4347,8 @@ static void nand_resume(struct mtd_info
 		pr_err("%s called for a chip which is not in suspended state\n",
 			__func__);
 	mutex_unlock(&chip->lock);
+
+	wake_up_all(&chip->resume_wq);
 }
 
 /**
@@ -5014,6 +5009,7 @@ static int nand_scan_ident(struct nand_c
 	chip->cur_cs = -1;
 
 	mutex_init(&chip->lock);
+	init_waitqueue_head(&chip->resume_wq);
 
 	/* Enforce the right timings for reset/detection */
 	onfi_fill_data_interface(chip, NAND_SDR_IFACE, 0);
--- a/include/linux/mtd/rawnand.h
+++ b/include/linux/mtd/rawnand.h
@@ -1064,6 +1064,7 @@ struct nand_legacy {
  * @lock:		lock protecting the suspended field. Also used to
  *			serialize accesses to the NAND device.
  * @suspended:		set to 1 when the device is suspended, 0 when it's not.
+ * @resume_wq:		wait queue to sleep if rawnand is in suspended state.
  * @bbt:		[INTERN] bad block table pointer
  * @bbt_td:		[REPLACEABLE] bad block table descriptor for flash
  *			lookup.
@@ -1117,6 +1118,7 @@ struct nand_chip {
 
 	struct mutex lock;
 	unsigned int suspended : 1;
+	wait_queue_head_t resume_wq;
 
 	uint8_t *oob_poi;
 	struct nand_controller *controller;



  parent reply	other threads:[~2024-11-15  6:43 UTC|newest]

Thread overview: 77+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-15  6:37 [PATCH 5.4 00/66] 5.4.286-rc1 review Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 01/66] arm64: dts: rockchip: Fix rt5651 compatible value on rk3399-sapphire-excavator Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 02/66] arm64: dts: rockchip: Remove hdmis 2nd interrupt on rk3328 Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 03/66] arm64: dts: rockchip: Fix bluetooth properties on Rock960 boards Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 04/66] arm64: dts: rockchip: Remove #cooling-cells from fan on Theobroma lion Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 05/66] ARM: dts: rockchip: fix rk3036 acodec node Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 06/66] ARM: dts: rockchip: drop grf reference from rk3036 hdmi Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 07/66] ARM: dts: rockchip: Fix the spi controller on rk3036 Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 08/66] ARM: dts: rockchip: Fix the realtek audio codec on rk3036-kylin Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 09/66] HID: core: zero-initialize the report buffer Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 10/66] security/keys: fix slab-out-of-bounds in key_task_permission Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 11/66] enetc: simplify the return expression of enetc_vf_set_mac_addr() Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 12/66] net: enetc: set MAC address to the VF net_device Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 13/66] sctp: properly validate chunk size in sctp_sf_ootb() Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 14/66] can: c_can: fix {rx,tx}_errors statistics Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 15/66] net: hns3: fix kernel crash when uninstalling driver Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 16/66] media: stb0899_algo: initialize cfr before using it Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 17/66] media: dvbdev: prevent the risk of out of memory access Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 18/66] media: dvb_frontend: dont play tricks with underflow values Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 19/66] media: adv7604: prevent underflow condition when reporting colorspace Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 20/66] ALSA: firewire-lib: fix return value on fail in amdtp_tscm_init() Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 21/66] media: s5p-jpeg: prevent buffer overflows Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 22/66] media: cx24116: prevent overflows on SNR calculus Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 23/66] media: v4l2-tpg: prevent the risk of a division by zero Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 24/66] pwm: imx-tpm: Use correct MODULO value for EPWM mode Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 25/66] drm/amdgpu: add missing size check in amdgpu_debugfs_gprwave_read() Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 26/66] drm/amdgpu: prevent NULL pointer dereference if ATIF is not supported Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 27/66] dm cache: correct the number of origin blocks to match the target length Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 28/66] dm cache: fix out-of-bounds access to the dirty bitset when resizing Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 29/66] dm cache: optimize dirty bit checking with find_next_bit " Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 30/66] dm cache: fix potential out-of-bounds access on the first resume Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 31/66] dm-unstriped: cast an operand to sector_t to prevent potential uint32_t overflow Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 32/66] nfs: Fix KMSAN warning in decode_getfattr_attrs() Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 33/66] btrfs: reinitialize delayed ref list after deleting it from the list Greg Kroah-Hartman
2024-11-15  6:37 ` Greg Kroah-Hartman [this message]
2024-11-15  6:37 ` [PATCH 5.4 35/66] spi: Fix deadlock when adding SPI controllers on SPI buses Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 36/66] spi: fix use-after-free of the add_lock mutex Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 37/66] net: bridge: xmit: make sure we have at least eth header len bytes Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 38/66] media: uvcvideo: Skip parsing frames of type UVC_VS_UNDEFINED in uvc_parse_format Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 39/66] fs/proc: fix compile warning about variable vmcore_mmap_ops Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 40/66] usb: musb: sunxi: Fix accessing an released usb phy Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 41/66] USB: serial: io_edgeport: fix use after free in debug printk Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 42/66] USB: serial: qcserial: add support for Sierra Wireless EM86xx Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 43/66] USB: serial: option: add Fibocom FG132 0x0112 composition Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 44/66] USB: serial: option: add Quectel RG650V Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 45/66] irqchip/gic-v3: Force propagation of the active state with a read-back Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 46/66] ocfs2: remove entry once instead of null-ptr-dereference in ocfs2_xa_remove() Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 47/66] ALSA: usb-audio: Support jack detection on Dell dock Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 48/66] ALSA: usb-audio: Add quirks for Dell WD19 dock Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 49/66] NFSD: Fix NFSv4s PUTPUBFH operation Greg Kroah-Hartman
2024-11-15  6:37 ` [PATCH 5.4 50/66] ftrace: Fix possible use-after-free issue in ftrace_location() Greg Kroah-Hartman
2024-11-15 15:24   ` Steven Rostedt
2025-01-07  8:51   ` Koichiro Den
2025-01-07 16:14     ` Steven Rostedt
2025-01-08  2:35       ` Koichiro Den
2024-11-15  6:38 ` [PATCH 5.4 51/66] hv_sock: Initializing vsk->trans to NULL to prevent a dangling pointer Greg Kroah-Hartman
2024-11-15  6:38 ` [PATCH 5.4 52/66] vsock/virtio: Initialization of the dangling pointer occurring in vsk->trans Greg Kroah-Hartman
2024-11-15  6:38 ` [PATCH 5.4 53/66] ALSA: usb-audio: Add endianness annotations Greg Kroah-Hartman
2024-11-15  6:38 ` [PATCH 5.4 54/66] 9p: Avoid creating multiple slab caches with the same name Greg Kroah-Hartman
2024-11-15  6:38 ` [PATCH 5.4 55/66] HID: multitouch: Add quirk for HONOR MagicBook Art 14 touchpad Greg Kroah-Hartman
2024-11-15  6:38 ` [PATCH 5.4 56/66] bpf: use kvzmalloc to allocate BPF verifier environment Greg Kroah-Hartman
2024-11-15  6:38 ` [PATCH 5.4 57/66] sound: Make CONFIG_SND depend on INDIRECT_IOMEM instead of UML Greg Kroah-Hartman
2024-11-15  6:38 ` [PATCH 5.4 58/66] powerpc/powernv: Free name on error in opal_event_init() Greg Kroah-Hartman
2024-11-15  6:38 ` [PATCH 5.4 59/66] fs: Fix uninitialized value issue in from_kuid and from_kgid Greg Kroah-Hartman
2024-11-15  6:38 ` [PATCH 5.4 60/66] net: usb: qmi_wwan: add Fibocom FG132 0x0112 composition Greg Kroah-Hartman
2024-11-15  6:38 ` [PATCH 5.4 61/66] md/raid10: improve code of mrdev in raid10_sync_request Greg Kroah-Hartman
2024-11-15  6:38 ` [PATCH 5.4 62/66] mm: clarify a confusing comment for remap_pfn_range() Greg Kroah-Hartman
2024-11-15  7:00   ` Harshvardhan Jha
2024-11-15  8:28     ` Greg Kroah-Hartman
2024-11-15  8:33       ` Harshvardhan Jha
2024-11-15  9:21         ` Greg Kroah-Hartman
2024-11-15  9:36           ` Harshvardhan Jha
2024-11-15  6:38 ` [PATCH 5.4 63/66] mm: fix ambiguous comments for better code readability Greg Kroah-Hartman
2024-11-15  6:38 ` [PATCH 5.4 64/66] mm/memory.c: make remap_pfn_range() reject unaligned addr Greg Kroah-Hartman
2024-11-15  6:38 ` [PATCH 5.4 65/66] mm: add remap_pfn_range_notrack Greg Kroah-Hartman
2024-11-15  6:38 ` [PATCH 5.4 66/66] 9p: fix slab cache name creation for real Greg Kroah-Hartman
2024-11-15 15:59 ` [PATCH 5.4 00/66] 5.4.286-rc1 review Harshit Mogalapalli

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=20241115063724.075230501@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=boris.brezillon@collabora.com \
    --cc=florian.fainelli@broadcom.com \
    --cc=miquel.raynal@bootlin.com \
    --cc=patches@lists.linux.dev \
    --cc=sean@geanix.com \
    --cc=stable@vger.kernel.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