Fix double counting of S/W ECC engines' ECC stat
Subsystems (2)
cover Fix double counting of S/W ECC engines' ECC stat
Hello,
This series fix the double counting of S/W ECC engines' ECC stat
If you use SPI-NAND with SW-ECC engine, the ECC related statistics (ecc_stats.failed & ecc_stats.corrected) will be doubled, because those numbers will be double-counted in ecc-sw-[bch/hamming].c and drivers/mtd/nand/spi/core.c.
This can be found by using nandtest/nandbiterrs validation.
Thanks for your time.
YouChing Lin (2):
mtd: nand: ecc-bch: Fix the double counting of ECC stat
mtd: nand: ecc-hamming: Fix the double counting of ECC stat
drivers/mtd/nand/ecc-sw-bch.c | 9 +++++---- drivers/mtd/nand/ecc-sw-hamming.c | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-)
Signature · 1 line
1.9.1
PATCH 1/2 mtd: nand: ecc-bch: Fix the double counting of ECC stat
If you use SPI-NAND with SW-ECC engine, the ECC related statistics (ecc_stats.failed & ecc_stats.corrected) will be doubled, because those numbers will be double-counted in ecc-sw-bch.c and drivers/mtd/nand/spi/core.c.
This can be found by using nandtest/nandbiterrs validation.
--- drivers/mtd/nand/ecc-sw-bch.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/mtd/nand/ecc-sw-bch.c +5 -4
@@ -372,11 +372,12 @@ static int nand_ecc_sw_bch_finish_io_req(struct nand_device *nand, &ecccode[i], &ecccalc[i]);if (stat <0 ) { - mtd->ecc_stats.failed++; - }else { - mtd->ecc_stats.corrected += stat; - max_bitflips = max_t(unsigned int, max_bitflips, stat); +nand_ecc_restore_req (&engine_conf->req_ctx, req); + +return -EBADMSG ; } + + max_bitflips = max_t(unsigned int, max_bitflips, stat); }nand_ecc_restore_req (&engine_conf->req_ctx, req);
Signature · 1 line
1.9.1
PATCH 2/2 mtd: nand: ecc-hamming: Fix the double counting of ECC stat
In reply to YouChing LinIf you use SPI-NAND with SW-ECC engine, the ECC related statistics (ecc_stats.failed & ecc_stats.corrected) will be doubled, because those numbers will be double-counted in ecc-sw-hamming.c and drivers/mtd/nand/spi/core.c.
This can be found by using nandtest/nandbiterrs validation.
--- drivers/mtd/nand/ecc-sw-hamming.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/mtd/nand/ecc-sw-hamming.c +5 -4
@@ -625,11 +625,12 @@ static int nand_ecc_sw_hamming_finish_io_req(struct nand_device *nand, &ecccode[i], &ecccalc[i]);if (stat <0 ) { - mtd->ecc_stats.failed++; - }else { - mtd->ecc_stats.corrected += stat; - max_bitflips = max_t(unsigned int, max_bitflips, stat); +nand_ecc_restore_req (&engine_conf->req_ctx, req); + +return -EBADMSG ; } + + max_bitflips = max_t(unsigned int, max_bitflips, stat); }nand_ecc_restore_req (&engine_conf->req_ctx, req);
Signature · 1 line
1.9.1
Miquel Raynal
maintainerHi YouChing,
YouChing Lin <[email protected]> wrote on Tue, 11 May 2021 09:40:33 +0800:
Quoted 10 lines
Hello,
This series fix the double counting of S/W ECC engines' ECC stat
If you use SPI-NAND with SW-ECC engine, the ECC related statistics (ecc_stats.failed & ecc_stats.corrected) will be doubled, because those numbers will be double-counted in ecc-sw-[bch/hamming].c and
drivers/mtd/nand/spi/core.c.This can be found by using nandtest/nandbiterrs validation.
Good catch!
However I don't think the current fix is valid because these engines are meant to be used by the raw NAND core as well, I propose something like the below, can you please tell me if it works as expected? (not even build tested)
Thanks,
Miquèl
----8<----
Author: Miquel Raynal <[email protected]> Date: Tue May 11 10:41:56 2021 +0200
mtd: spinand: Fix double counting of ECC stats
In the raw NAND world, ECC engines increment ecc_stats and the final caller is responsible for returning -EBADMSG if the verification failed.
In the SPI-NAND world it was a bit different until now because there was only one possible ECC engine: the on-die one. Indeed, the spinand_mtd_read() call was incrementing the ecc_stats counters depending on the outcome of spinand_check_ecc_status() directly.
So now let's split the logic like this:
- spinand_check_ecc_status() is specific to the SPI-NAND on-die engine and is kept very simple: it just returns the ECC status (bonus point:
the content of this helper can be overloaded).
- spinand_ondie_ecc_finish_io_req() is the caller of spinand_check_ecc_status() and will increment the counters and eventually return -EBADMSG.
- spinand_mtd_read() is not tied to the on-die ECC implementation and should be able to handle results coming from other ECC engines: it has the responsibility of returning the maximum number of bitflips which happened during the entire operation as this is the only helper that is aware that several pages may be read in a row.
drivers/mtd/nand/spi/core.c +11 -6
@@ -290,6 +290,8 @@ static int spinand_ondie_ecc_finish_io_req(struct nand_device *nand, {struct spinand_ondie_ecc_conf *engine_conf = nand->ecc.ctx.priv;struct spinand_device *spinand =nand_to_spinand (nand); +struct mtd_info *mtd =spinand_to_mtd (spinand); +int ret;if (req->mode ==MTD_OPS_RAW )return 0 ;
@@ -299,7 +301,13 @@ static int spinand_ondie_ecc_finish_io_req(struct nand_device *nand,return 0 ;/* Finish a page write: check the status, report errors/bitflips */ -return spinand_check_ecc_status (spinand, engine_conf->status); + ret =spinand_check_ecc_status (spinand, engine_conf->status); +if (ret == -EBADMSG ) + mtd->ecc_stats.failed++; +else if (ret >0 ) + mtd->ecc_stats.corrected += ret; + +return ret; }static struct nand_ecc_engine_ops spinand_ondie_ecc_engine_ops = {
@@ -620,13 +628,10 @@ static int spinand_mtd_read(struct mtd_info *mtd, loff_t from,if (ret <0 && ret != -EBADMSG )break ; -if (ret == -EBADMSG ) { +if (ret == -EBADMSG ) ecc_failed = true; - mtd->ecc_stats.failed++; - }else { - mtd->ecc_stats.corrected += ret; +else max_bitflips = max_t(unsigned int, max_bitflips, ret); - } ret =0 ; ops->retlen += iter.req.datalen;
Quoted 2 lines
"Miquel Raynal" <[email protected]>
<deleted>
Quoted 12 lines
Good catch!
However I don't think the current fix is valid because these engines are meant to be used by the raw NAND core as well, I propose something like the below, can you please tell me if it works as expected? (not even build tested)
Thanks,
Miquèl
<deleted>
Thanks for your work.
I tested the two patches(yours and mine) separately in our environment:
1) MXIC NFC(&raw NAND),2) MXIC SPI host(&SPI-NAND) with S/W BCH engine. Both patches are valid(using nandtest/nandbiterrs, values of ecc_stats are normal).
This seems to be because the function(nand_ecc_sw_bch_finish_io_req() in ecc-sw-bch.c) that would increase the ecc_stats counter is not used in the raw NAND world. Am I misunderstanding or is it platform dependency?
BTW, I think your modification should be more in line with the design spirit
of generic ECC engine framework.
Thanks,
YouChing
CONFIDENTIALITY NOTE:
This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.
Macronix International Co., Ltd.
=====================================================================
============================================================================
CONFIDENTIALITY NOTE:
This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.
Macronix International Co., Ltd.
=====================================================================
Miquel Raynal
maintainerHi YouChing,
[email protected] wrote on Thu, 13 May 2021 10:11:02 +0800:
Quoted 18 lines
Quoted 1 line
"Miquel Raynal" <[email protected]>
<deleted>
Quoted 12 lines
Good catch!
However I don't think the current fix is valid because these engines are meant to be used by the raw NAND core as well, I propose something like the below, can you please tell me if it works as expected? (not even build tested)
Thanks,
Miquèl<deleted>
Thanks for your work.
Quoted 8 lines
I tested the two patches(yours and mine) separately in our environment:
1) MXICNFC(&raw NAND),2) MXIC SPIhost(&SPI-NAND)with S/W BCH engine. Both patches arevalid(using nandtest/nandbiterrs, values of ecc_stats are normal).This seems to be because the
function(nand_ecc_sw_bch_finish_io_req() in ecc-sw-bch.c)that would increase theecc_statscounter is not used in the raw NAND world. Am I misunderstanding or is it platform dependency?
I don't think it can be called a platform dependency, it's more like legacy from the raw NAND world which makes the use of the generic ECC framework hard and thus is limited to a given set of functions.
Quoted 3 lines
BTW, I think your modification should be more in line with the design spirit
of generic ECC engine framework.
Yes, ideally raw NAND should fully comply to this framework but this would require a hundred days of work and dozens of available boards to test. During the past 20 years people assumed NAND controller and ECC engine were a single entity which makes the use of the generic ECC framework hard to implemented in the raw NAND. So I decided not to put all my energy there in order to first get this framework available to SPI-NAND devices.
Thanks,
Miquèl
[email protected]
Tested-byHi Miquèl,
Quoted 14 lines
"Miquel Raynal" <[email protected]>
Re: [PATCH 0/2] Fix double counting of S/W ECC engines' ECC statHi YouChing,
[email protected] wrote on Thu, 13 May 2021 10:11:02 +0800:
Quoted 7 lines
Quoted 1 line
"Miquel Raynal" <[email protected]>
<deleted>
Quoted 5 lines
Good catch!
However I don't think the current fix is valid because these engines are meant to be used by the raw NAND core as well, I propose
something
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
like the below, can you please tell me if it works as expected? (not even build tested)
Thanks,
Miquèl
Quoted 5 lines
Quoted 5 lines
<deleted>
Thanks for your work.
I tested the two patches(yours and mine) separately in our
environment:
Quoted 1 line
Quoted 1 line
1) MXIC
NFC(&raw NAND),2) MXIC SPIhost(&SPI-NAND)with S/W BCH
engine.
Quoted 1 line
Quoted 1 line
Both patches are valid(using nandtest/nandbiterrs, values of
ecc_stats
are
Quoted 6 lines
Quoted 6 lines
normal).
This seems to be because the
function(nand_ecc_sw_bch_finish_io_req() in ecc-sw-bch.c)that would increase theecc_statscounter is not usedin the raw NAND world. Am I misunderstanding or is it platform
dependency?
Quoted 9 lines
I don't think it can be called a platform dependency, it's more like legacy from the raw NAND world which makes the use of the generic ECC framework hard and thus is limited to a given set of functions.
Quoted 3 lines
BTW, I think your modification should be more in line with the design spirit
of generic ECC engine framework.
Quoted 7 lines
Yes, ideally raw NAND should fully comply to this framework but this would require a hundred days of work and dozens of available boards to test. During the past 20 years people assumed NAND controller and ECC engine were a single entity which makes the use of the generic ECC framework hard to implemented in the raw NAND. So I decided not to put all my energy there in order to first get this framework available to SPI-NAND devices.
Thanks for your detailed explanation.
I agree with your change and it works fine in SPI-NAND world (with on-die or S/W ECC engines) and raw NAND world(with S/W ECC engines).
CONFIDENTIALITY NOTE:
This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.
Macronix International Co., Ltd.
=====================================================================
============================================================================
CONFIDENTIALITY NOTE:
This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.
Macronix International Co., Ltd.
=====================================================================
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/