[PATCH 1/2] jffs2: check the data CRC of a node in RAM, not through point()
From: Orgad Shaneh
Date: Wed Nov 18 2026 - 16:40:56 EST
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@xxxxxxxxx/
Signed-off-by: Orgad Shaneh <orgads@xxxxxxxxx>
---
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