* [PATCH v2 0/2] mtd: rawnand: NAND early identification fixes
@ 2024-05-16 13:13 Miquel Raynal
2024-05-16 13:13 ` [PATCH v2 1/2] mtd: rawnand: Fix the nand_read_data_op() early check Miquel Raynal
2024-05-16 13:13 ` [PATCH v2 2/2] mtd: rawnand: Bypass a couple of sanity checks during NAND identification Miquel Raynal
0 siblings, 2 replies; 7+ messages in thread
From: Miquel Raynal @ 2024-05-16 13:13 UTC (permalink / raw)
To: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Pratyush Yadav, Michael Walle, linux-mtd
Cc: Alexander Dahl, Steven Seeger, Sascha Hauer, Thomas Petazzoni,
Miquel Raynal
Steven, Alexander,
Thanks a lot for your reports and your patience, I am sorry it took me
so long to dig into this, but I think I've now addressed your two
issues, with PATCH 1/2 already shared and PATCH 2/2 for a more complete
coverage of the issue.
This is only compile-tested. Can you please give these two patches a try
and let me know if it solves all your issues or if there is something
else we should take care of?
Cheers,
Miquèl
Changes in v2:
* PATCH 1/2: No change.
* PATCH 2/2: I also covered nand_fill_column_cycles() and addressed a
style issue.
Miquel Raynal (2):
mtd: rawnand: Fix the nand_read_data_op() early check
mtd: rawnand: Bypass a couple of sanity checks during NAND
identification
drivers/mtd/nand/raw/nand_base.c | 59 ++++++++++++++++++--------------
1 file changed, 33 insertions(+), 26 deletions(-)
--
2.40.1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH v2 1/2] mtd: rawnand: Fix the nand_read_data_op() early check 2024-05-16 13:13 [PATCH v2 0/2] mtd: rawnand: NAND early identification fixes Miquel Raynal @ 2024-05-16 13:13 ` Miquel Raynal 2024-05-27 12:15 ` Miquel Raynal 2024-05-16 13:13 ` [PATCH v2 2/2] mtd: rawnand: Bypass a couple of sanity checks during NAND identification Miquel Raynal 1 sibling, 1 reply; 7+ messages in thread From: Miquel Raynal @ 2024-05-16 13:13 UTC (permalink / raw) To: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus, Pratyush Yadav, Michael Walle, linux-mtd Cc: Alexander Dahl, Steven Seeger, Sascha Hauer, Thomas Petazzoni, Miquel Raynal, stable The nand_read_data_op() operation, which only consists in DATA_IN cycles, is sadly not supported by all controllers despite being very basic. The core, for some time, supposed all drivers would support it. An improvement to this situation for supporting more constrained controller added a check to verify if the operation was supported before attempting it by running the function with the check_only boolean set first, and then possibly falling back to another (possibly slightly less optimized) alternative. An even newer addition moved that check very early and probe time, in order to perform the check only once. The content of the operation was not so important, as long as the controller driver would tell whether such operation on the NAND bus would be possible or not. In practice, no buffer was provided (no fake buffer or whatever) as it is anyway not relevant for the "check_only" condition. Unfortunately, early in the function, there is an if statement verifying that the input parameters are right for normal use, making the early check always unsuccessful. Fixes: 9f820fc0651c ("mtd: rawnand: Check the data only read pattern only once") Cc: stable@vger.kernel.org Reported-by: Alexander Dahl <ada@thorsis.com> Closes: https://lore.kernel.org/linux-mtd/20240306-shaky-bunion-d28b65ea97d7@thorsis.com/ Reported-by: Steven Seeger <steven.seeger@flightsystems.net> Closes: https://lore.kernel.org/linux-mtd/DM6PR05MB4506554457CF95191A670BDEF7062@DM6PR05MB4506.namprd05.prod.outlook.com/ Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Reviewed-by: Alexander Dahl <ada@thorsis.com> --- drivers/mtd/nand/raw/nand_base.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index acd137dd0957..248e654ecefd 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -2173,7 +2173,7 @@ EXPORT_SYMBOL_GPL(nand_reset_op); int nand_read_data_op(struct nand_chip *chip, void *buf, unsigned int len, bool force_8bit, bool check_only) { - if (!len || !buf) + if (!len || (!check_only && !buf)) return -EINVAL; if (nand_has_exec_op(chip)) { -- 2.40.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/2] mtd: rawnand: Fix the nand_read_data_op() early check 2024-05-16 13:13 ` [PATCH v2 1/2] mtd: rawnand: Fix the nand_read_data_op() early check Miquel Raynal @ 2024-05-27 12:15 ` Miquel Raynal 0 siblings, 0 replies; 7+ messages in thread From: Miquel Raynal @ 2024-05-27 12:15 UTC (permalink / raw) To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus, Pratyush Yadav, Michael Walle, linux-mtd Cc: Alexander Dahl, Steven Seeger, Sascha Hauer, Thomas Petazzoni, stable On Thu, 2024-05-16 at 13:13:19 UTC, Miquel Raynal wrote: > The nand_read_data_op() operation, which only consists in DATA_IN > cycles, is sadly not supported by all controllers despite being very > basic. The core, for some time, supposed all drivers would support > it. An improvement to this situation for supporting more constrained > controller added a check to verify if the operation was supported before > attempting it by running the function with the check_only boolean set > first, and then possibly falling back to another (possibly slightly less > optimized) alternative. > > An even newer addition moved that check very early and probe time, in > order to perform the check only once. The content of the operation was > not so important, as long as the controller driver would tell whether > such operation on the NAND bus would be possible or not. In practice, no > buffer was provided (no fake buffer or whatever) as it is anyway not > relevant for the "check_only" condition. Unfortunately, early in the > function, there is an if statement verifying that the input parameters > are right for normal use, making the early check always unsuccessful. > > Fixes: 9f820fc0651c ("mtd: rawnand: Check the data only read pattern only once") > Cc: stable@vger.kernel.org > Reported-by: Alexander Dahl <ada@thorsis.com> > Closes: https://lore.kernel.org/linux-mtd/20240306-shaky-bunion-d28b65ea97d7@thorsis.com/ > Reported-by: Steven Seeger <steven.seeger@flightsystems.net> > Closes: https://lore.kernel.org/linux-mtd/DM6PR05MB4506554457CF95191A670BDEF7062@DM6PR05MB4506.namprd05.prod.outlook.com/ > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> > Reviewed-by: Alexander Dahl <ada@thorsis.com> Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/fixes. Miquel ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 2/2] mtd: rawnand: Bypass a couple of sanity checks during NAND identification 2024-05-16 13:13 [PATCH v2 0/2] mtd: rawnand: NAND early identification fixes Miquel Raynal 2024-05-16 13:13 ` [PATCH v2 1/2] mtd: rawnand: Fix the nand_read_data_op() early check Miquel Raynal @ 2024-05-16 13:13 ` Miquel Raynal 2024-05-16 13:51 ` Sascha Hauer 2024-05-27 12:14 ` Miquel Raynal 1 sibling, 2 replies; 7+ messages in thread From: Miquel Raynal @ 2024-05-16 13:13 UTC (permalink / raw) To: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus, Pratyush Yadav, Michael Walle, linux-mtd Cc: Alexander Dahl, Steven Seeger, Sascha Hauer, Thomas Petazzoni, Miquel Raynal, stable Early during NAND identification, mtd_info fields have not yet been initialized (namely, writesize and oobsize) and thus cannot be used for sanity checks yet. Of course if there is a misuse of nand_change_read_column_op() so early we won't be warned, but there is anyway no actual check to perform at this stage as we do not yet know the NAND geometry. So, if the fields are empty, especially mtd->writesize which is *always* set quite rapidly after identification, let's skip the sanity checks. nand_change_read_column_op() is subject to be used early for ONFI/JEDEC identification in the very unlikely case of: - bitflips appearing in the parameter page, - the controller driver not supporting simple DATA_IN cycles. As nand_change_read_column_op() uses nand_fill_column_cycles() the logic explaind above also applies in this secondary helper. Fixes: c27842e7e11f ("mtd: rawnand: onfi: Adapt the parameter page read to constraint controllers") Fixes: daca31765e8b ("mtd: rawnand: jedec: Adapt the parameter page read to constraint controllers") Cc: stable@vger.kernel.org Reported-by: Alexander Dahl <ada@thorsis.com> Closes: https://lore.kernel.org/linux-mtd/20240306-shaky-bunion-d28b65ea97d7@thorsis.com/ Reported-by: Steven Seeger <steven.seeger@flightsystems.net> Closes: https://lore.kernel.org/linux-mtd/DM6PR05MB4506554457CF95191A670BDEF7062@DM6PR05MB4506.namprd05.prod.outlook.com/ Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> --- Changes in v2: * Dropped the double (( )) * Fixed nand_fill_column_cycles() as well. --- drivers/mtd/nand/raw/nand_base.c | 57 ++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 248e654ecefd..53e16d39af4b 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -1093,28 +1093,32 @@ static int nand_fill_column_cycles(struct nand_chip *chip, u8 *addrs, unsigned int offset_in_page) { struct mtd_info *mtd = nand_to_mtd(chip); + bool ident_stage = !mtd->writesize; - /* Make sure the offset is less than the actual page size. */ - if (offset_in_page > mtd->writesize + mtd->oobsize) - return -EINVAL; - - /* - * On small page NANDs, there's a dedicated command to access the OOB - * area, and the column address is relative to the start of the OOB - * area, not the start of the page. Asjust the address accordingly. - */ - if (mtd->writesize <= 512 && offset_in_page >= mtd->writesize) - offset_in_page -= mtd->writesize; - - /* - * The offset in page is expressed in bytes, if the NAND bus is 16-bit - * wide, then it must be divided by 2. - */ - if (chip->options & NAND_BUSWIDTH_16) { - if (WARN_ON(offset_in_page % 2)) + /* Bypass all checks during NAND identification */ + if (likely(!ident_stage)) { + /* Make sure the offset is less than the actual page size. */ + if (offset_in_page > mtd->writesize + mtd->oobsize) return -EINVAL; - offset_in_page /= 2; + /* + * On small page NANDs, there's a dedicated command to access the OOB + * area, and the column address is relative to the start of the OOB + * area, not the start of the page. Asjust the address accordingly. + */ + if (mtd->writesize <= 512 && offset_in_page >= mtd->writesize) + offset_in_page -= mtd->writesize; + + /* + * The offset in page is expressed in bytes, if the NAND bus is 16-bit + * wide, then it must be divided by 2. + */ + if (chip->options & NAND_BUSWIDTH_16) { + if (WARN_ON(offset_in_page % 2)) + return -EINVAL; + + offset_in_page /= 2; + } } addrs[0] = offset_in_page; @@ -1123,7 +1127,7 @@ static int nand_fill_column_cycles(struct nand_chip *chip, u8 *addrs, * Small page NANDs use 1 cycle for the columns, while large page NANDs * need 2 */ - if (mtd->writesize <= 512) + if (!ident_stage && mtd->writesize <= 512) return 1; addrs[1] = offset_in_page >> 8; @@ -1436,16 +1440,19 @@ int nand_change_read_column_op(struct nand_chip *chip, unsigned int len, bool force_8bit) { struct mtd_info *mtd = nand_to_mtd(chip); + bool ident_stage = !mtd->writesize; if (len && !buf) return -EINVAL; - if (offset_in_page + len > mtd->writesize + mtd->oobsize) - return -EINVAL; + if (!ident_stage) { + if (offset_in_page + len > mtd->writesize + mtd->oobsize) + return -EINVAL; - /* Small page NANDs do not support column change. */ - if (mtd->writesize <= 512) - return -ENOTSUPP; + /* Small page NANDs do not support column change. */ + if (mtd->writesize <= 512) + return -ENOTSUPP; + } if (nand_has_exec_op(chip)) { const struct nand_interface_config *conf = -- 2.40.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 2/2] mtd: rawnand: Bypass a couple of sanity checks during NAND identification 2024-05-16 13:13 ` [PATCH v2 2/2] mtd: rawnand: Bypass a couple of sanity checks during NAND identification Miquel Raynal @ 2024-05-16 13:51 ` Sascha Hauer 2024-05-16 14:45 ` Miquel Raynal 2024-05-27 12:14 ` Miquel Raynal 1 sibling, 1 reply; 7+ messages in thread From: Sascha Hauer @ 2024-05-16 13:51 UTC (permalink / raw) To: Miquel Raynal Cc: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus, Pratyush Yadav, Michael Walle, linux-mtd, Alexander Dahl, Steven Seeger, Thomas Petazzoni, stable On Thu, May 16, 2024 at 03:13:20PM +0200, Miquel Raynal wrote: > Early during NAND identification, mtd_info fields have not yet been > initialized (namely, writesize and oobsize) and thus cannot be used for > sanity checks yet. Of course if there is a misuse of > nand_change_read_column_op() so early we won't be warned, but there is > anyway no actual check to perform at this stage as we do not yet know > the NAND geometry. > > So, if the fields are empty, especially mtd->writesize which is *always* > set quite rapidly after identification, let's skip the sanity checks. > > nand_change_read_column_op() is subject to be used early for ONFI/JEDEC > identification in the very unlikely case of: > - bitflips appearing in the parameter page, > - the controller driver not supporting simple DATA_IN cycles. > > As nand_change_read_column_op() uses nand_fill_column_cycles() the logic > explaind above also applies in this secondary helper. > > Fixes: c27842e7e11f ("mtd: rawnand: onfi: Adapt the parameter page read to constraint controllers") > Fixes: daca31765e8b ("mtd: rawnand: jedec: Adapt the parameter page read to constraint controllers") > Cc: stable@vger.kernel.org > Reported-by: Alexander Dahl <ada@thorsis.com> > Closes: https://lore.kernel.org/linux-mtd/20240306-shaky-bunion-d28b65ea97d7@thorsis.com/ > Reported-by: Steven Seeger <steven.seeger@flightsystems.net> > Closes: https://lore.kernel.org/linux-mtd/DM6PR05MB4506554457CF95191A670BDEF7062@DM6PR05MB4506.namprd05.prod.outlook.com/ > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> With the attached debug patch applied I can confirm that I can now read all three ONFI parameter pages successfully using nand_change_read_column_op(), so: Tested-by: Sascha Hauer <s.hauer@pengutronix.de> Sascha -----------------------------------8<-------------------------------------- diff --git a/drivers/mtd/nand/raw/nand_onfi.c b/drivers/mtd/nand/raw/nand_onfi.c index 861975e44b552..ca6b4bf426750 100644 --- a/drivers/mtd/nand/raw/nand_onfi.c +++ b/drivers/mtd/nand/raw/nand_onfi.c @@ -180,6 +180,9 @@ int nand_onfi_detect(struct nand_chip *chip) ret = nand_change_read_column_op(chip, sizeof(*pbuf) * i, &pbuf[i], sizeof(*pbuf), true); + + print_hex_dump(KERN_INFO, "onfi: ", DUMP_PREFIX_OFFSET, 16, 1, &pbuf[i], sizeof(*pbuf), true); + if (ret) { ret = 0; goto free_onfi_param_page; @@ -188,7 +191,6 @@ int nand_onfi_detect(struct nand_chip *chip) crc = onfi_crc16(ONFI_CRC_BASE, (u8 *)&pbuf[i], 254); if (crc == le16_to_cpu(pbuf[i].crc)) { p = &pbuf[i]; - break; } } -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 2/2] mtd: rawnand: Bypass a couple of sanity checks during NAND identification 2024-05-16 13:51 ` Sascha Hauer @ 2024-05-16 14:45 ` Miquel Raynal 0 siblings, 0 replies; 7+ messages in thread From: Miquel Raynal @ 2024-05-16 14:45 UTC (permalink / raw) To: Sascha Hauer Cc: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus, Pratyush Yadav, Michael Walle, linux-mtd, Alexander Dahl, Steven Seeger, Thomas Petazzoni, stable Hi Sascha, s.hauer@pengutronix.de wrote on Thu, 16 May 2024 15:51:49 +0200: > On Thu, May 16, 2024 at 03:13:20PM +0200, Miquel Raynal wrote: > > Early during NAND identification, mtd_info fields have not yet been > > initialized (namely, writesize and oobsize) and thus cannot be used for > > sanity checks yet. Of course if there is a misuse of > > nand_change_read_column_op() so early we won't be warned, but there is > > anyway no actual check to perform at this stage as we do not yet know > > the NAND geometry. > > > > So, if the fields are empty, especially mtd->writesize which is *always* > > set quite rapidly after identification, let's skip the sanity checks. > > > > nand_change_read_column_op() is subject to be used early for ONFI/JEDEC > > identification in the very unlikely case of: > > - bitflips appearing in the parameter page, > > - the controller driver not supporting simple DATA_IN cycles. > > > > As nand_change_read_column_op() uses nand_fill_column_cycles() the logic > > explaind above also applies in this secondary helper. > > > > Fixes: c27842e7e11f ("mtd: rawnand: onfi: Adapt the parameter page read to constraint controllers") > > Fixes: daca31765e8b ("mtd: rawnand: jedec: Adapt the parameter page read to constraint controllers") > > Cc: stable@vger.kernel.org > > Reported-by: Alexander Dahl <ada@thorsis.com> > > Closes: https://lore.kernel.org/linux-mtd/20240306-shaky-bunion-d28b65ea97d7@thorsis.com/ > > Reported-by: Steven Seeger <steven.seeger@flightsystems.net> > > Closes: https://lore.kernel.org/linux-mtd/DM6PR05MB4506554457CF95191A670BDEF7062@DM6PR05MB4506.namprd05.prod.outlook.com/ > > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> > > With the attached debug patch applied I can confirm that I can now read > all three ONFI parameter pages successfully using > nand_change_read_column_op(), so: > > Tested-by: Sascha Hauer <s.hauer@pengutronix.de> Excellent! Thanks, Miquèl ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 2/2] mtd: rawnand: Bypass a couple of sanity checks during NAND identification 2024-05-16 13:13 ` [PATCH v2 2/2] mtd: rawnand: Bypass a couple of sanity checks during NAND identification Miquel Raynal 2024-05-16 13:51 ` Sascha Hauer @ 2024-05-27 12:14 ` Miquel Raynal 1 sibling, 0 replies; 7+ messages in thread From: Miquel Raynal @ 2024-05-27 12:14 UTC (permalink / raw) To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus, Pratyush Yadav, Michael Walle, linux-mtd Cc: Alexander Dahl, Steven Seeger, Sascha Hauer, Thomas Petazzoni, stable On Thu, 2024-05-16 at 13:13:20 UTC, Miquel Raynal wrote: > Early during NAND identification, mtd_info fields have not yet been > initialized (namely, writesize and oobsize) and thus cannot be used for > sanity checks yet. Of course if there is a misuse of > nand_change_read_column_op() so early we won't be warned, but there is > anyway no actual check to perform at this stage as we do not yet know > the NAND geometry. > > So, if the fields are empty, especially mtd->writesize which is *always* > set quite rapidly after identification, let's skip the sanity checks. > > nand_change_read_column_op() is subject to be used early for ONFI/JEDEC > identification in the very unlikely case of: > - bitflips appearing in the parameter page, > - the controller driver not supporting simple DATA_IN cycles. > > As nand_change_read_column_op() uses nand_fill_column_cycles() the logic > explaind above also applies in this secondary helper. > > Fixes: c27842e7e11f ("mtd: rawnand: onfi: Adapt the parameter page read to constraint controllers") > Fixes: daca31765e8b ("mtd: rawnand: jedec: Adapt the parameter page read to constraint controllers") > Cc: stable@vger.kernel.org > Reported-by: Alexander Dahl <ada@thorsis.com> > Closes: https://lore.kernel.org/linux-mtd/20240306-shaky-bunion-d28b65ea97d7@thorsis.com/ > Reported-by: Steven Seeger <steven.seeger@flightsystems.net> > Closes: https://lore.kernel.org/linux-mtd/DM6PR05MB4506554457CF95191A670BDEF7062@DM6PR05MB4506.namprd05.prod.outlook.com/ > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> > Tested-by: Sascha Hauer <s.hauer@pengutronix.de> Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/fixes. Miquel ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-05-27 12:15 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-05-16 13:13 [PATCH v2 0/2] mtd: rawnand: NAND early identification fixes Miquel Raynal 2024-05-16 13:13 ` [PATCH v2 1/2] mtd: rawnand: Fix the nand_read_data_op() early check Miquel Raynal 2024-05-27 12:15 ` Miquel Raynal 2024-05-16 13:13 ` [PATCH v2 2/2] mtd: rawnand: Bypass a couple of sanity checks during NAND identification Miquel Raynal 2024-05-16 13:51 ` Sascha Hauer 2024-05-16 14:45 ` Miquel Raynal 2024-05-27 12:14 ` Miquel Raynal
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox