Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1232881 > unrolled thread

[PATCH 0/5] mtd: nand/UBI: add power-cut emulation

Started byBoris Brezillon <boris.brezillon@free-electrons.com>
First post2015-09-25 17:20 +0200
Last post2015-09-25 17:20 +0200
Articles 5 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 0/5] mtd: nand/UBI: add power-cut emulation Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-09-25 17:20 +0200
    [PATCH 3/5] UBI: switch the UBI device in read-only mode when mtd returns -EROFS Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-09-25 17:20 +0200
      Re: [PATCH 3/5] UBI: switch the UBI device in read-only mode when mtd  returns -EROFS Richard Weinberger <richard@nod.at> - 2015-09-25 19:40 +0200
        Re: [PATCH 3/5] UBI: switch the UBI device in read-only mode when  mtd returns -EROFS Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-09-26 10:50 +0200
    [PATCH 2/5] mtd: nand: return -EROFS in case of power-cut emulation Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-09-25 17:20 +0200

#1232881 — [PATCH 0/5] mtd: nand/UBI: add power-cut emulation

FromBoris Brezillon <boris.brezillon@free-electrons.com>
Date2015-09-25 17:20 +0200
Subject[PATCH 0/5] mtd: nand/UBI: add power-cut emulation
Message-ID<qcCWZ-58P-3@gated-at.bofh.it>
Hello,

This series aims at adding a power-cut emulation layer at the nandsim
level.
The final goal is to support MLC NAND emulation in nandsim in order to
validate the work done in the NAND, UBI and UBIFS layers to reliably
support those chips.

Even though the UBI layer already provides a power-cut emulation
infrastructure, I decided to add one at the nandsim layer for the
following reasons:
- IMO it is cleaner to isolate MLC NAND emulation in the NAND layer
- emulating unstable bits in UBI is not so easy: the unstable bits
  issue happens when a program or erase operation is interrupted (by a
  power-cut) while it is almost finished. In this case the next read
  operation will succeed (return the expected data), but not the following
  ones.
  Emulating this problem requires knowing which block/page was being
  accessed when the power-cut occurred, and if we want to validate that
  UBI (not UBIFS) is robust to such errors, we have to reattach the mtd
  partition to the UBI layer, and by doing that we loose the information
  of which page/block was being programmed/erased when the power-cut
  occurred.
  By implementing the power-cut emulation at the nandsim level, we can
  easily detach/attach the emulated device, and check still keep those
  information.
- emulating paired pages in UBI is a bit easier but still requires some
  knowledge about the pairing scheme (which differs from one chip to
  another), and I'm not sure yet how this will be exposed by the MTD/NAND
  layers.

This being said, I might be wrong in my assumptions, so feel free to
comment on that decision.

Regarding the code itself, this series adds a simple power-cut emulation
layer, and modifies the intermediate layers (NAND and UBI) to forward
emulated power-cut errors and let the UBIFS layer switch into read-only
mode.

Paired pages and unstable bits emulation is not part of the series, but
can be added on top of those changes by tweaking the actions taken in
nandsim when a power-cut is emulated.

Also, I'm not sure about the method used to inform NAND core when a
power-cut was emulated: I'm currently adding a virtual NAND status flag,
but adding a new field in the nand_chip struct might be a better approach.
This would also allow us to compile out code sections that are only useful
when doing NAND emulation.

Best Regards,

Boris

Boris Brezillon (5):
  mtd: nand: add basic stuff to support power-cut emulation
  mtd: nand: return -EROFS in case of power-cut emulation
  UBI: switch the UBI device in read-only mode when mtd returns -EROFS
  mtd: nand: nandsim: implement ->get_status()
  mtd: nand: nandsim: add support for power-cut emulation

 drivers/mtd/nand/nand_base.c |  34 ++++++--
 drivers/mtd/nand/nandsim.c   | 182 ++++++++++++++++++++++++++++++++++++++++---
 drivers/mtd/ubi/io.c         |   4 +-
 include/linux/mtd/nand.h     |   4 +
 4 files changed, 207 insertions(+), 17 deletions(-)

-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1232882 — [PATCH 3/5] UBI: switch the UBI device in read-only mode when mtd returns -EROFS

FromBoris Brezillon <boris.brezillon@free-electrons.com>
Date2015-09-25 17:20 +0200
Subject[PATCH 3/5] UBI: switch the UBI device in read-only mode when mtd returns -EROFS
Message-ID<qcCX0-58P-21@gated-at.bofh.it>
In reply to#1232881
The NAND layer is now able to forward power-cut emulation errors from
a NAND driver to the MTD user.
Check for this kind of errors in UBI and switch the UBI device in read-only
mode if such an error occurs.
The error will also be forwarded to the UBI user requesting the operation
if any, thus allowing UBIFS to act accordingly.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
 drivers/mtd/ubi/io.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index 5bbd1f0..c5ebef7 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -303,6 +303,8 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset,
 		len = ubi->peb_size - offset;
 		if (len)
 			err = ubi_self_check_all_ff(ubi, pnum, offset, len);
+	} else if (err == -EROFS) {
+		ubi_ro_mode(ubi);
 	}
 
 	return err;
@@ -355,7 +357,7 @@ retry:
 
 	err = mtd_erase(ubi->mtd, &ei);
 	if (err) {
-		if (retries++ < UBI_IO_RETRIES) {
+		if (err != -EROFS && retries++ < UBI_IO_RETRIES) {
 			ubi_warn(ubi, "error %d while erasing PEB %d, retry",
 				 err, pnum);
 			yield();
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1232962 — Re: [PATCH 3/5] UBI: switch the UBI device in read-only mode when mtd returns -EROFS

FromRichard Weinberger <richard@nod.at>
Date2015-09-25 19:40 +0200
SubjectRe: [PATCH 3/5] UBI: switch the UBI device in read-only mode when mtd returns -EROFS
Message-ID<qcF8t-8dM-1@gated-at.bofh.it>
In reply to#1232882
Am 25.09.2015 um 17:09 schrieb Boris Brezillon:
> The NAND layer is now able to forward power-cut emulation errors from
> a NAND driver to the MTD user.
> Check for this kind of errors in UBI and switch the UBI device in read-only
> mode if such an error occurs.
> The error will also be forwarded to the UBI user requesting the operation
> if any, thus allowing UBIFS to act accordingly.
> 
> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> ---
>  drivers/mtd/ubi/io.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
> index 5bbd1f0..c5ebef7 100644
> --- a/drivers/mtd/ubi/io.c
> +++ b/drivers/mtd/ubi/io.c
> @@ -303,6 +303,8 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset,
>  		len = ubi->peb_size - offset;
>  		if (len)
>  			err = ubi_self_check_all_ff(ubi, pnum, offset, len);
> +	} else if (err == -EROFS) {
> +		ubi_ro_mode(ubi);
>  	}
>  
>  	return err;
> @@ -355,7 +357,7 @@ retry:
>  
>  	err = mtd_erase(ubi->mtd, &ei);
>  	if (err) {
> -		if (retries++ < UBI_IO_RETRIES) {
> +		if (err != -EROFS && retries++ < UBI_IO_RETRIES) {

Looks good! :)
One small nit, can you please add a comment above both lines that the EROFS checks are
here because of emulators.

Thanks,
//richard
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1233170 — Re: [PATCH 3/5] UBI: switch the UBI device in read-only mode when mtd returns -EROFS

FromBoris Brezillon <boris.brezillon@free-electrons.com>
Date2015-09-26 10:50 +0200
SubjectRe: [PATCH 3/5] UBI: switch the UBI device in read-only mode when mtd returns -EROFS
Message-ID<qcTl8-3gR-3@gated-at.bofh.it>
In reply to#1232962
Hi Richard,

On Fri, 25 Sep 2015 19:34:42 +0200
Richard Weinberger <richard@nod.at> wrote:

> Am 25.09.2015 um 17:09 schrieb Boris Brezillon:
> > The NAND layer is now able to forward power-cut emulation errors from
> > a NAND driver to the MTD user.
> > Check for this kind of errors in UBI and switch the UBI device in read-only
> > mode if such an error occurs.
> > The error will also be forwarded to the UBI user requesting the operation
> > if any, thus allowing UBIFS to act accordingly.
> > 
> > Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> > ---
> >  drivers/mtd/ubi/io.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
> > index 5bbd1f0..c5ebef7 100644
> > --- a/drivers/mtd/ubi/io.c
> > +++ b/drivers/mtd/ubi/io.c
> > @@ -303,6 +303,8 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset,
> >  		len = ubi->peb_size - offset;
> >  		if (len)
> >  			err = ubi_self_check_all_ff(ubi, pnum, offset, len);
> > +	} else if (err == -EROFS) {
> > +		ubi_ro_mode(ubi);
> >  	}
> >  
> >  	return err;
> > @@ -355,7 +357,7 @@ retry:
> >  
> >  	err = mtd_erase(ubi->mtd, &ei);
> >  	if (err) {
> > -		if (retries++ < UBI_IO_RETRIES) {
> > +		if (err != -EROFS && retries++ < UBI_IO_RETRIES) {
> 
> Looks good! :)
> One small nit, can you please add a comment above both lines that the EROFS checks are
> here because of emulators.

Sure, I'll add a comment.

Thanks,

Boris

-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1232883 — [PATCH 2/5] mtd: nand: return -EROFS in case of power-cut emulation

FromBoris Brezillon <boris.brezillon@free-electrons.com>
Date2015-09-25 17:20 +0200
Subject[PATCH 2/5] mtd: nand: return -EROFS in case of power-cut emulation
Message-ID<qcCX0-58P-19@gated-at.bofh.it>
In reply to#1232881
Now that we are able to emulate power-cuts, we should differentiate the
power-cut emulation and input/output error cases to let the MTD user
decide what it should do.
EROFS was chosen to mimic what's done in UBI when a power-cut emulation
occurs.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
 drivers/mtd/nand/nand_base.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index a621814..223aabdb 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -1951,6 +1951,9 @@ static int nand_write_oob_std(struct mtd_info *mtd, struct nand_chip *chip,
 
 	status = chip->waitfunc(mtd, chip);
 
+	if (unlikely(status & NAND_STATUS_POWER_CUT))
+		return -EROFS;
+
 	return status & NAND_STATUS_FAIL ? -EIO : 0;
 }
 
@@ -2009,6 +2012,8 @@ static int nand_write_oob_syndrome(struct mtd_info *mtd,
 
 	chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
 	status = chip->waitfunc(mtd, chip);
+	if (unlikely(status & NAND_STATUS_POWER_CUT))
+		return -EROFS;
 
 	return status & NAND_STATUS_FAIL ? -EIO : 0;
 }
@@ -2442,6 +2447,9 @@ static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip,
 			status = chip->errstat(mtd, chip, FL_WRITING, status,
 					       page);
 
+		if (unlikely(status & NAND_STATUS_POWER_CUT))
+			return -EROFS;
+
 		if (status & NAND_STATUS_FAIL)
 			return -EIO;
 	} else {
@@ -2868,7 +2876,7 @@ static int nand_erase(struct mtd_info *mtd, struct erase_info *instr)
 int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr,
 		    int allowbbt)
 {
-	int page, status, pages_per_block, ret, chipnr;
+	int page, status = 0, pages_per_block, ret, chipnr;
 	struct nand_chip *chip = mtd->priv;
 	loff_t len;
 
@@ -2958,7 +2966,12 @@ int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr,
 
 erase_exit:
 
-	ret = instr->state == MTD_ERASE_DONE ? 0 : -EIO;
+	if (instr->state == MTD_ERASE_DONE)
+		ret = 0;
+	else if (unlikely(status & NAND_STATUS_POWER_CUT))
+		ret = -EROFS;
+	else
+		ret = -EIO;
 
 	/* Deselect and wake up anyone waiting on the device */
 	chip->select_chip(mtd, -1);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web