diff mbox series

mtd: ubi: io: add retries mtd_write

Message ID 20210901085637.210572-1-sean@geanix.com
State Under Review
Delegated to: Richard Weinberger
Headers show
Series mtd: ubi: io: add retries mtd_write | expand

Commit Message

Sean Nyekjaer Sept. 1, 2021, 8:56 a.m. UTC
Fix "Device or resource busy" when resuming from suspend. Sometimes ubi
tries to call mtd_write before the rawnand is resumed.

So add 3 retries to the mtd_write call:
PM: suspend devices took 0.030 seconds
ubi0 warning: ubi_io_write: error -16 while writing 4096 bytes to PEB 1762:94208, written 0 bytes
Disabling non-boot CPUs ...
ubi0 warning: ubi_io_write: error -16 while writing 4096 bytes to PEB 1762:94208, written 0 bytes
ubi0 warning: ubi_io_write: error -16 while writing 4096 bytes to PEB 1762:94208, written 0 bytes
PM: resume devices took 0.110 seconds
OOM killer enabled.
Restarting tasks ... done.
PM: suspend exit

Signed-off-by: Sean Nyekjaer <sean@geanix.com>
---

Some explanation/discussion here:
http://lists.infradead.org/pipermail/linux-mtd/2021-July/087390.html

 drivers/mtd/ubi/io.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

Comments

Sean Nyekjaer Sept. 20, 2021, 7:48 a.m. UTC | #1
On Wed, Sep 01, 2021 at 10:56:37AM +0200, Sean Nyekjaer wrote:
> Fix "Device or resource busy" when resuming from suspend. Sometimes ubi
> tries to call mtd_write before the rawnand is resumed.
> 
> So add 3 retries to the mtd_write call:
> PM: suspend devices took 0.030 seconds
> ubi0 warning: ubi_io_write: error -16 while writing 4096 bytes to PEB 1762:94208, written 0 bytes
> Disabling non-boot CPUs ...
> ubi0 warning: ubi_io_write: error -16 while writing 4096 bytes to PEB 1762:94208, written 0 bytes
> ubi0 warning: ubi_io_write: error -16 while writing 4096 bytes to PEB 1762:94208, written 0 bytes
> PM: resume devices took 0.110 seconds
> OOM killer enabled.
> Restarting tasks ... done.
> PM: suspend exit
> 
> Signed-off-by: Sean Nyekjaer <sean@geanix.com>
> ---
> 
> Some explanation/discussion here:
> http://lists.infradead.org/pipermail/linux-mtd/2021-July/087390.html
> 

This is still an issue... Anyway to block ubi from accessing a suspended
rawnand?

Richard do you have an idea to solve this?

/Sean
diff mbox series

Patch

diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index 0e3a76a9e2f8..fc01ee429358 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -89,6 +89,7 @@ 
 #include <linux/crc32.h>
 #include <linux/err.h>
 #include <linux/slab.h>
+#include <linux/delay.h>
 #include "ubi.h"
 
 static int self_check_not_bad(const struct ubi_device *ubi, int pnum);
@@ -235,7 +236,7 @@  int ubi_io_read(const struct ubi_device *ubi, void *buf, int pnum, int offset,
 int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset,
 		 int len)
 {
-	int err;
+	int err, retries = 0;
 	size_t written;
 	loff_t addr;
 
@@ -281,8 +282,16 @@  int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset,
 	}
 
 	addr = (loff_t)pnum * ubi->peb_size + offset;
+retry:
 	err = mtd_write(ubi->mtd, addr, len, &written, buf);
 	if (err) {
+		if (retries++ < UBI_IO_RETRIES) {
+			ubi_warn(ubi, "error %d while writing %d bytes to PEB %d:%d, written %zd bytes",
+				 err, len, pnum, offset, written);
+			mdelay(10); yield();
+			goto retry;
+		}
+
 		ubi_err(ubi, "error %d while writing %d bytes to PEB %d:%d, written %zd bytes",
 			err, len, pnum, offset, written);
 		dump_stack();