From: Orgad Shaneh <orgads@gmail.com>
To: dwmw2@infradead.org, richard@nod.at
Cc: miquel.raynal@bootlin.com, linux-mtd@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] jffs2: check the data CRC of a node in RAM, not through point()
Date: Wed, 18 Nov 2026 21:40:44 +0000 [thread overview]
Message-ID: <20261118214045.107562-1-orgads@gmail.com> (raw)
check_node_data() points at the node data when the MTD supports it
and runs crc32() over the flash, which saves a kmalloc() and a copy.
That paid off while the generic crc32() read words (slice-by-8). Since
commit 5e3c1c48fac3 ("lib/crc32: remove other generic implementations")
it reads a byte at a time, and on a CPU without an arch CRC32 and an
uncached map, such as a NOR flash on a boot bus, every byte is a bus
access of its own, while jffs2_flash_read() copies a word per load.
The MTDs that can be pointed at today are cfi_cmdset_0001 (Intel NOR),
lpddr, map_ram and map_rom.
On an Octeon board with an 8-bit AMD NOR, with point() added to
cfi_cmdset_0002 (under review [1]), the first lookup of a 46.6 MB
file checks the data at 2.77 MB/s through point() and at 3.37 MB/s
from a buffer (16.8 s against 13.8 s), the rate of a plain read of
the partition.
Always read the data into a buffer. MTDs that can be pointed at now
pay a kmalloc() and a copy per node, as all others already do.
[1] https://lore.kernel.org/all/20261117214141.3826637-1-orgads@gmail.com/
Signed-off-by: Orgad Shaneh <orgads@gmail.com>
---
fs/jffs2/readinode.c | 65 +++++++++++++++-----------------------------
1 file changed, 22 insertions(+), 43 deletions(-)
diff --git a/fs/jffs2/readinode.c b/fs/jffs2/readinode.c
index 1caabff9d..18a47b432 100644
--- a/fs/jffs2/readinode.c
+++ b/fs/jffs2/readinode.c
@@ -31,7 +31,7 @@
static int check_node_data(struct jffs2_sb_info *c, struct jffs2_tmp_dnode_info *tn)
{
struct jffs2_raw_node_ref *ref = tn->fn->raw;
- int err = 0, pointed = 0;
+ int err = 0;
struct jffs2_eraseblock *jeb;
unsigned char *buffer;
uint32_t crc, ofs, len;
@@ -61,48 +61,32 @@ static int check_node_data(struct jffs2_sb_info *c, struct jffs2_tmp_dnode_info
dbg_readinode("check node at %#08x, data length %u, partial CRC %#08x, correct CRC %#08x, data starts at %#08x, start checking from %#08x - %u bytes.\n",
ref_offset(ref), tn->csize, tn->partial_crc, tn->data_crc, ofs - len, ofs, len);
-#ifndef __ECOS
- /* TODO: instead, incapsulate point() stuff to jffs2_flash_read(),
- * adding and jffs2_flash_read_end() interface. */
- err = mtd_point(c->mtd, ofs, len, &retlen, (void **)&buffer, NULL);
- if (!err && retlen < len) {
- JFFS2_WARNING("MTD point returned len too short: %zu instead of %u.\n", retlen, tn->csize);
- mtd_unpoint(c->mtd, ofs, retlen);
- } else if (err) {
- if (err != -EOPNOTSUPP)
- JFFS2_WARNING("MTD point failed: error code %d.\n", err);
- } else
- pointed = 1; /* successfully pointed to device */
-#endif
-
- if (!pointed) {
- buffer = kmalloc(len, GFP_KERNEL);
- if (unlikely(!buffer))
- return -ENOMEM;
+ /*
+ * Read the data into RAM even when the flash can be pointed at:
+ * the generic crc32() goes through it a byte at a time, and on an
+ * uncached map each byte is a bus access of its own, while the
+ * read copies a word per load.
+ */
+ buffer = kmalloc(len, GFP_KERNEL);
+ if (unlikely(!buffer))
+ return -ENOMEM;
- /* TODO: this is very frequent pattern, make it a separate
- * routine */
- err = jffs2_flash_read(c, ofs, len, &retlen, buffer);
- if (err) {
- JFFS2_ERROR("can not read %d bytes from 0x%08x, error code: %d.\n", len, ofs, err);
- goto free_out;
- }
+ /* TODO: this is very frequent pattern, make it a separate routine */
+ err = jffs2_flash_read(c, ofs, len, &retlen, buffer);
+ if (err) {
+ JFFS2_ERROR("can not read %d bytes from 0x%08x, error code: %d.\n", len, ofs, err);
+ goto free_out;
+ }
- if (retlen != len) {
- JFFS2_ERROR("short read at %#08x: %zd instead of %d.\n", ofs, retlen, len);
- err = -EIO;
- goto free_out;
- }
+ if (retlen != len) {
+ JFFS2_ERROR("short read at %#08x: %zd instead of %d.\n", ofs, retlen, len);
+ err = -EIO;
+ goto free_out;
}
/* Continue calculating CRC */
crc = crc32(tn->partial_crc, buffer, len);
- if(!pointed)
- kfree(buffer);
-#ifndef __ECOS
- else
- mtd_unpoint(c->mtd, ofs, len);
-#endif
+ kfree(buffer);
if (crc != tn->data_crc) {
JFFS2_NOTICE("wrong data CRC in data node at 0x%08x: read %#08x, calculated %#08x.\n",
@@ -133,12 +117,7 @@ static int check_node_data(struct jffs2_sb_info *c, struct jffs2_tmp_dnode_info
return 0;
free_out:
- if(!pointed)
- kfree(buffer);
-#ifndef __ECOS
- else
- mtd_unpoint(c->mtd, ofs, len);
-#endif
+ kfree(buffer);
return err;
}
--
2.53.0
WARNING: multiple messages have this Message-ID (diff)
From: Orgad Shaneh <orgads@gmail.com>
To: dwmw2@infradead.org, richard@nod.at
Cc: miquel.raynal@bootlin.com, linux-mtd@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] jffs2: check the data CRC of a node in RAM, not through point()
Date: Wed, 18 Nov 2026 21:40:44 +0000 [thread overview]
Message-ID: <20261118214045.107562-1-orgads@gmail.com> (raw)
check_node_data() points at the node data when the MTD supports it
and runs crc32() over the flash, which saves a kmalloc() and a copy.
That paid off while the generic crc32() read words (slice-by-8). Since
commit 5e3c1c48fac3 ("lib/crc32: remove other generic implementations")
it reads a byte at a time, and on a CPU without an arch CRC32 and an
uncached map, such as a NOR flash on a boot bus, every byte is a bus
access of its own, while jffs2_flash_read() copies a word per load.
The MTDs that can be pointed at today are cfi_cmdset_0001 (Intel NOR),
lpddr, map_ram and map_rom.
On an Octeon board with an 8-bit AMD NOR, with point() added to
cfi_cmdset_0002 (under review [1]), the first lookup of a 46.6 MB
file checks the data at 2.77 MB/s through point() and at 3.37 MB/s
from a buffer (16.8 s against 13.8 s), the rate of a plain read of
the partition.
Always read the data into a buffer. MTDs that can be pointed at now
pay a kmalloc() and a copy per node, as all others already do.
[1] https://lore.kernel.org/all/20261117214141.3826637-1-orgads@gmail.com/
Signed-off-by: Orgad Shaneh <orgads@gmail.com>
---
fs/jffs2/readinode.c | 65 +++++++++++++++-----------------------------
1 file changed, 22 insertions(+), 43 deletions(-)
diff --git a/fs/jffs2/readinode.c b/fs/jffs2/readinode.c
index 1caabff9d..18a47b432 100644
--- a/fs/jffs2/readinode.c
+++ b/fs/jffs2/readinode.c
@@ -31,7 +31,7 @@
static int check_node_data(struct jffs2_sb_info *c, struct jffs2_tmp_dnode_info *tn)
{
struct jffs2_raw_node_ref *ref = tn->fn->raw;
- int err = 0, pointed = 0;
+ int err = 0;
struct jffs2_eraseblock *jeb;
unsigned char *buffer;
uint32_t crc, ofs, len;
@@ -61,48 +61,32 @@ static int check_node_data(struct jffs2_sb_info *c, struct jffs2_tmp_dnode_info
dbg_readinode("check node at %#08x, data length %u, partial CRC %#08x, correct CRC %#08x, data starts at %#08x, start checking from %#08x - %u bytes.\n",
ref_offset(ref), tn->csize, tn->partial_crc, tn->data_crc, ofs - len, ofs, len);
-#ifndef __ECOS
- /* TODO: instead, incapsulate point() stuff to jffs2_flash_read(),
- * adding and jffs2_flash_read_end() interface. */
- err = mtd_point(c->mtd, ofs, len, &retlen, (void **)&buffer, NULL);
- if (!err && retlen < len) {
- JFFS2_WARNING("MTD point returned len too short: %zu instead of %u.\n", retlen, tn->csize);
- mtd_unpoint(c->mtd, ofs, retlen);
- } else if (err) {
- if (err != -EOPNOTSUPP)
- JFFS2_WARNING("MTD point failed: error code %d.\n", err);
- } else
- pointed = 1; /* successfully pointed to device */
-#endif
-
- if (!pointed) {
- buffer = kmalloc(len, GFP_KERNEL);
- if (unlikely(!buffer))
- return -ENOMEM;
+ /*
+ * Read the data into RAM even when the flash can be pointed at:
+ * the generic crc32() goes through it a byte at a time, and on an
+ * uncached map each byte is a bus access of its own, while the
+ * read copies a word per load.
+ */
+ buffer = kmalloc(len, GFP_KERNEL);
+ if (unlikely(!buffer))
+ return -ENOMEM;
- /* TODO: this is very frequent pattern, make it a separate
- * routine */
- err = jffs2_flash_read(c, ofs, len, &retlen, buffer);
- if (err) {
- JFFS2_ERROR("can not read %d bytes from 0x%08x, error code: %d.\n", len, ofs, err);
- goto free_out;
- }
+ /* TODO: this is very frequent pattern, make it a separate routine */
+ err = jffs2_flash_read(c, ofs, len, &retlen, buffer);
+ if (err) {
+ JFFS2_ERROR("can not read %d bytes from 0x%08x, error code: %d.\n", len, ofs, err);
+ goto free_out;
+ }
- if (retlen != len) {
- JFFS2_ERROR("short read at %#08x: %zd instead of %d.\n", ofs, retlen, len);
- err = -EIO;
- goto free_out;
- }
+ if (retlen != len) {
+ JFFS2_ERROR("short read at %#08x: %zd instead of %d.\n", ofs, retlen, len);
+ err = -EIO;
+ goto free_out;
}
/* Continue calculating CRC */
crc = crc32(tn->partial_crc, buffer, len);
- if(!pointed)
- kfree(buffer);
-#ifndef __ECOS
- else
- mtd_unpoint(c->mtd, ofs, len);
-#endif
+ kfree(buffer);
if (crc != tn->data_crc) {
JFFS2_NOTICE("wrong data CRC in data node at 0x%08x: read %#08x, calculated %#08x.\n",
@@ -133,12 +117,7 @@ static int check_node_data(struct jffs2_sb_info *c, struct jffs2_tmp_dnode_info
return 0;
free_out:
- if(!pointed)
- kfree(buffer);
-#ifndef __ECOS
- else
- mtd_unpoint(c->mtd, ofs, len);
-#endif
+ kfree(buffer);
return err;
}
--
2.53.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next reply other threads:[~2026-11-18 21:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 21:40 Orgad Shaneh [this message]
2026-11-18 21:40 ` [PATCH 1/2] jffs2: check the data CRC of a node in RAM, not through point() Orgad Shaneh
2026-11-18 21:40 ` [PATCH 2/2] jffs2: reschedule between the data CRC checks of an inode Orgad Shaneh
2026-11-18 21:40 ` Orgad Shaneh
2026-11-18 21:44 ` sashiko-bot
2026-11-19 8:01 ` Orgad Shaneh
2026-11-19 8:01 ` Orgad Shaneh
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=20261118214045.107562-1-orgads@gmail.com \
--to=orgads@gmail.com \
--cc=dwmw2@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=miquel.raynal@bootlin.com \
--cc=richard@nod.at \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.