* [PATCH v4 1/4] mtd: maps: only point() maps read through the simple accessors
2026-11-17 21:41 [PATCH v4 0/4] mtd: point() for cfi_cmdset_0002, on simple maps only Orgad Shaneh
@ 2026-11-17 21:41 ` Orgad Shaneh
2026-11-17 21:41 ` [PATCH v4 2/4] mtd: cfi_cmdset_0002: implement point() for simple linear maps Orgad Shaneh
` (2 subsequent siblings)
3 siblings, 0 replies; 10+ messages in thread
From: Orgad Shaneh @ 2026-11-17 21:41 UTC (permalink / raw)
To: miquel.raynal, richard, vigneshr, tsbogend
Cc: linux-mtd, linux-mips, linux-kernel, linusw, kaloz, ulli.kroll,
john, nico, dwmw2, corbet, linux-doc
map_is_linear() only checks that a map has a physical address. Map
drivers that install their own accessors keep one, and a pointer
bypasses whatever those accessors do:
- physmap's IXP4xx support: the expansion bus only takes 16-bit
accesses (the reason it cannot use memcpy_fromio()), and on
little-endian kernels every access also flips address bit 1 and
swaps bytes;
- physmap's Gemini support enables the flash pins only inside its
accessors;
- lantiq-flash serializes the external bus against PCI and copies byte
by byte because the EBU cannot take a prefetching memcpy;
- the cobalt PCI driver's flash map (drivers/media/pci/cobalt/
cobalt-flash.c) reads at an offset inside a PCI BAR while leaving
phys 0;
- the Octeon bootbus flash map takes octeon_bootbus_sem in its
accessors, which a pointed read on an Intel NOR skips.
cfi_cmdset_0001 hands such pointers to jffs2 today, and the IXP4xx
boards carry Intel StrataFlash. lpddr, map_ram and map_rom enable
point() on the same terms (map_rom unconditionally). Add
map_is_simple(), true when the map reads through the simple accessors
(always true without CONFIG_MTD_COMPLEX_MAPPINGS, where the accessors
are inline), and require it in all four before enabling point(). Maps
with custom accessors fall back to copying through them; on big-endian
IXP4xx, where pointed reads happened to work, jffs2 mounts get slower.
Fixes: 9d3b5086f6d4 ("mtd: physmap_of_gemini: Handle pin control")
Fixes: 2aba2f2a704d ("mtd: physmap_of: add a hook for Intel IXP4xx flash probing")
Signed-off-by: Orgad Shaneh <orgads@gmail.com>
Cc: Linus Walleij <linusw@kernel.org>
Cc: Imre Kaloz <kaloz@kernel.org>
Cc: Hans Ulli Kroll <ulli.kroll@googlemail.com>
Cc: John Crispin <john@phrozen.org>
---
v4: also gate lpddr, map_ram and map_rom, which point() on the same
terms; those three are compile-tested only. Rebased onto
v7.4-rc1; the Assisted-by tag is dropped (an LLM helped write
this series).
v3: Assisted-by in the documented form.
v2: no change.
drivers/mtd/chips/cfi_cmdset_0001.c | 2 +-
drivers/mtd/chips/map_ram.c | 4 ++--
drivers/mtd/chips/map_rom.c | 6 ++++--
drivers/mtd/lpddr/lpddr_cmds.c | 2 +-
drivers/mtd/maps/map_funcs.c | 12 ++++++++++++
include/linux/mtd/map.h | 2 ++
6 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
index e5805ee..42fb042 100644
--- a/drivers/mtd/chips/cfi_cmdset_0001.c
+++ b/drivers/mtd/chips/cfi_cmdset_0001.c
@@ -299,7 +299,7 @@ static void fixup_LH28F640BF(struct mtd_info *mtd)
static void fixup_use_point(struct mtd_info *mtd)
{
struct map_info *map = mtd->priv;
- if (!mtd->_point && map_is_linear(map)) {
+ if (!mtd->_point && map_is_linear(map) && map_is_simple(map)) {
mtd->_point = cfi_intelext_point;
mtd->_unpoint = cfi_intelext_unpoint;
}
diff --git a/drivers/mtd/chips/map_ram.c b/drivers/mtd/chips/map_ram.c
index 2dde70e..77c912f 100644
--- a/drivers/mtd/chips/map_ram.c
+++ b/drivers/mtd/chips/map_ram.c
@@ -74,8 +74,8 @@ static struct mtd_info *map_ram_probe(struct map_info *map)
mtd->flags = MTD_CAP_RAM;
mtd->writesize = 1;
- /* Disable direct access when NO_XIP is set */
- if (map->phys != NO_XIP) {
+ /* Disable direct access when NO_XIP is set or the map has its own accessors */
+ if (map->phys != NO_XIP && map_is_simple(map)) {
mtd->_point = mapram_point;
mtd->_unpoint = mapram_unpoint;
}
diff --git a/drivers/mtd/chips/map_rom.c b/drivers/mtd/chips/map_rom.c
index dbc34e8..65daa14 100644
--- a/drivers/mtd/chips/map_rom.c
+++ b/drivers/mtd/chips/map_rom.c
@@ -54,8 +54,10 @@ static struct mtd_info *map_rom_probe(struct map_info *map)
mtd->name = map->name;
mtd->type = MTD_ROM;
mtd->size = map->size;
- mtd->_point = maprom_point;
- mtd->_unpoint = maprom_unpoint;
+ if (map_is_simple(map)) {
+ mtd->_point = maprom_point;
+ mtd->_unpoint = maprom_unpoint;
+ }
mtd->_read = maprom_read;
mtd->_write = maprom_write;
mtd->_sync = maprom_nop;
diff --git a/drivers/mtd/lpddr/lpddr_cmds.c b/drivers/mtd/lpddr/lpddr_cmds.c
index a4167ee..23f0550 100644
--- a/drivers/mtd/lpddr/lpddr_cmds.c
+++ b/drivers/mtd/lpddr/lpddr_cmds.c
@@ -57,7 +57,7 @@ struct mtd_info *lpddr_cmdset(struct map_info *map)
mtd->_writev = lpddr_writev;
mtd->_lock = lpddr_lock;
mtd->_unlock = lpddr_unlock;
- if (map_is_linear(map)) {
+ if (map_is_linear(map) && map_is_simple(map)) {
mtd->_point = lpddr_point;
mtd->_unpoint = lpddr_unpoint;
}
diff --git a/drivers/mtd/maps/map_funcs.c b/drivers/mtd/maps/map_funcs.c
index b005493..5991794 100644
--- a/drivers/mtd/maps/map_funcs.c
+++ b/drivers/mtd/maps/map_funcs.c
@@ -41,5 +41,17 @@ void simple_map_init(struct map_info *map)
}
EXPORT_SYMBOL(simple_map_init);
+
+/*
+ * True when every access goes through the simple accessors, so a reader
+ * may use map->virt directly; a map with its own accessors (byte swaps,
+ * bus locking, address fixups) must not be pointed at.
+ */
+bool map_is_simple(struct map_info *map)
+{
+ return map->read == simple_map_read &&
+ map->copy_from == simple_map_copy_from;
+}
+EXPORT_SYMBOL(map_is_simple);
MODULE_DESCRIPTION("Out-of-line map I/O");
MODULE_LICENSE("GPL");
diff --git a/include/linux/mtd/map.h b/include/linux/mtd/map.h
index 75b0b2a..ebee3fe 100644
--- a/include/linux/mtd/map.h
+++ b/include/linux/mtd/map.h
@@ -449,6 +449,7 @@ static inline void inline_map_copy_to(struct map_info *map, unsigned long to, co
#define map_copy_to(map, to, from, len) (map)->copy_to(map, to, from, len)
extern void simple_map_init(struct map_info *);
+bool map_is_simple(struct map_info *map);
#define map_is_linear(map) (map->phys != NO_XIP)
#else
@@ -460,6 +461,7 @@ extern void simple_map_init(struct map_info *);
#define simple_map_init(map) BUG_ON(!map_bankwidth_supported((map)->bankwidth))
#define map_is_linear(map) ({ (void)(map); 1; })
+#define map_is_simple(map) ({ (void)(map); 1; })
#endif /* !CONFIG_MTD_COMPLEX_MAPPINGS */
--
2.53.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v4 2/4] mtd: cfi_cmdset_0002: implement point() for simple linear maps
2026-11-17 21:41 [PATCH v4 0/4] mtd: point() for cfi_cmdset_0002, on simple maps only Orgad Shaneh
2026-11-17 21:41 ` [PATCH v4 1/4] mtd: maps: only point() maps read through the simple accessors Orgad Shaneh
@ 2026-11-17 21:41 ` Orgad Shaneh
2026-11-17 21:57 ` sashiko-bot
2026-11-17 21:41 ` [PATCH v4 3/4] MIPS: Octeon: flash: allocate the map per device Orgad Shaneh
2026-11-17 21:41 ` [PATCH v4 4/4] MIPS: Octeon: flash: use the simple map accessors without a shared eMMC Orgad Shaneh
3 siblings, 1 reply; 10+ messages in thread
From: Orgad Shaneh @ 2026-11-17 21:41 UTC (permalink / raw)
To: miquel.raynal, richard, vigneshr, tsbogend
Cc: linux-mtd, linux-mips, linux-kernel, linusw, kaloz, ulli.kroll,
john, nico, dwmw2, corbet, linux-doc
cfi_cmdset_0001 lets a linearly mapped chip be pointed at, so jffs2 can
scan it in place. cfi_cmdset_0002 never got point(), and the jffs2 mount
on an AMD-style NOR copies every used eraseblock through
map_copy_from() instead.
Add a point()/unpoint() pair modeled on cfi_intelext_point(), entering
array mode with the AMD reset command; get_chip() has an FL_POINT case
already, adjusted below. Like cfi_cmdset_0001 it is only enabled for
maps that are linear and read through the simple accessors. Where it
differs:
- Points share the chip when no operation is suspended, and the reboot
reset may proceed from an idle FL_POINT (the chip is already in array
mode); an unpoint after that reset is not an error. On cfi_cmdset_0001
a point held across reboot leaves cfi_intelext_reset() waiting
forever.
- unpoint() releases the chip only when the last reference goes, and
point() returns the error when nothing could be pointed.
- A point never suspends an erase; it waits for the erase to finish.
The erase would otherwise stay suspended for as long as the point
is held, and the reboot reset with it. The cost: jffs2 also points
at a data node the first time it checks its CRC
(check_node_data()), so such a read that meets a garbage-collection
erase now waits for that sector erase to finish, where mtd_read()
would have suspended it.
As with cfi_cmdset_0001, a held point makes writes, erases and
mtd_sync() on that chip wait uninterruptibly for the last unpoint, and
system suspend fails with -EAGAIN. That matters for cramfs on MTD
(CONFIG_CRAMFS_MTD), which keeps its whole image pointed while
mounted: before this patch mtd_point() failed on AMD chips and cramfs
fell back to the block device; now, with cramfs and jffs2 on the same
chip, jffs2 writes and garbage collection, flash_erase, and the
mtd_sync() in jffs2's umount - so a shutdown that unmounts jffs2 while
cramfs is still the root - block until cramfs is unmounted.
Name cfi_cmdset_0002 next to cfi_cmdset_0001 in the cramfs
documentation's list of drivers that support point().
On an Octeon CN6635 board with a 100 MB jffs2 partition on an M29EW
(8-bit bus, ~3.4 MB/s reads) the mount drops from 15-30 s to under 1 s.
Signed-off-by: Orgad Shaneh <orgads@gmail.com>
Cc: Nicolas Pitre <nico@fluxnic.net>
Cc: David Woodhouse <dwmw2@infradead.org>
---
v4: rebased onto v7.4-rc1; the Assisted-by tag is dropped (an LLM
helped write this series).
v3: the same for an XIP erase: FL_XIP_WHILE_ERASING no longer lets a
point through (sashiko). The changelog states what waiting for
the erase costs a jffs2 read, and names jffs2's umount mtd_sync()
rather than sync(2) as what blocks behind a cramfs point.
v2: a point no longer suspends an erase in progress; it waits for
the erase instead (sashiko).
Documentation/filesystems/cramfs.rst | 11 +-
drivers/mtd/chips/cfi_cmdset_0002.c | 167 ++++++++++++++++++++++++++-
2 files changed, 168 insertions(+), 10 deletions(-)
diff --git a/Documentation/filesystems/cramfs.rst b/Documentation/filesystems/cramfs.rst
index 221c0bf..7b706c5 100644
--- a/Documentation/filesystems/cramfs.rst
+++ b/Documentation/filesystems/cramfs.rst
@@ -75,11 +75,12 @@ The location of the cramfs image in memory is system dependent. You must
know the proper physical address where the cramfs image is located and
configure an MTD device for it. Also, that MTD device must be supported
by a map driver that implements the "point" method. Examples of such
-MTD drivers are cfi_cmdset_0001 (Intel/Sharp CFI flash) or physmap
-(Flash device in physical memory map). MTD partitions based on such devices
-are fine too. Then that device should be specified with the "mtd:" prefix
-as the mount device argument. For example, to mount the MTD device named
-"fs_partition" on the /mnt directory::
+MTD drivers are cfi_cmdset_0001 (Intel/Sharp CFI flash), cfi_cmdset_0002
+(AMD/Fujitsu CFI flash) or physmap (Flash device in physical memory map).
+MTD partitions based on such devices are fine too. Then that device should
+be specified with the "mtd:" prefix as the mount device argument. For
+example, to mount the MTD device named "fs_partition" on the /mnt
+directory::
$ mount -t cramfs mtd:fs_partition /mnt
diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
index 100cab9..1fc2709 100644
--- a/drivers/mtd/chips/cfi_cmdset_0002.c
+++ b/drivers/mtd/chips/cfi_cmdset_0002.c
@@ -63,6 +63,9 @@ enum cfi_quirks {
};
static int cfi_amdstd_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
+static int cfi_amdstd_point(struct mtd_info *mtd, loff_t from, size_t len,
+ size_t *retlen, void **virt, resource_size_t *phys);
+static int cfi_amdstd_unpoint(struct mtd_info *mtd, loff_t from, size_t len);
static int cfi_amdstd_write_words(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
#if !FORCE_WORD_WRITE
static int cfi_amdstd_write_buffers(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
@@ -511,6 +514,22 @@ static struct cfi_fixup jedec_fixup_table[] = {
{ 0, 0, NULL }
};
+/*
+ * Let jffs2 scan a linearly mapped flash in place, as cfi_cmdset_0001
+ * does: without point() its mount copies every used eraseblock. Only
+ * for maps read through the simple accessors - a pointer bypasses any
+ * byte swapping or bus locking a map driver does in its own.
+ */
+static void fixup_use_point(struct mtd_info *mtd)
+{
+ struct map_info *map = mtd->priv;
+
+ if (!mtd->_point && map_is_linear(map) && map_is_simple(map)) {
+ mtd->_point = cfi_amdstd_point;
+ mtd->_unpoint = cfi_amdstd_unpoint;
+ }
+}
+
static struct cfi_fixup fixup_table[] = {
/* The CFI vendor ids and the JEDEC vendor IDs appear
* to be common. It is like the devices id's are as
@@ -518,6 +537,7 @@ static struct cfi_fixup fixup_table[] = {
* we know that is the case.
*/
{ CFI_MFR_ANY, CFI_ID_ANY, fixup_use_erase_chip },
+ { CFI_MFR_ANY, CFI_ID_ANY, fixup_use_point },
{ CFI_MFR_ATMEL, AT49BV6416, fixup_use_atmel_lock },
{ 0, 0, NULL }
};
@@ -921,8 +941,12 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
return 0;
case FL_ERASING:
+ /*
+ * Not for a point: the erase would stay suspended for as
+ * long as it is held, which for cramfs is the whole mount.
+ */
if (!cfip || !(cfip->EraseSuspend & (0x1|0x2)) ||
- !(mode == FL_READY || mode == FL_POINT ||
+ !(mode == FL_READY ||
(mode == FL_WRITING && (cfip->EraseSuspend & 0x2))))
goto sleep;
@@ -963,8 +987,9 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
return 0;
case FL_XIP_WHILE_ERASING:
- if (mode != FL_READY && mode != FL_POINT &&
- (!cfip || !(cfip->EraseSuspend&2)))
+ /* Not for a point either, see FL_ERASING */
+ if (mode == FL_POINT ||
+ (mode != FL_READY && (!cfip || !(cfip->EraseSuspend & 2))))
goto sleep;
chip->oldstate = chip->state;
chip->state = FL_READY;
@@ -975,8 +1000,13 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
return -EIO;
case FL_POINT:
- /* Only if there's no operation suspended... */
- if (mode == FL_READY && chip->oldstate == FL_READY)
+ /*
+ * Only if there's no operation suspended: the chip is in
+ * array mode, so reads, further points and the reboot
+ * reset (which only re-enters array mode) can go ahead.
+ */
+ if ((mode == FL_READY || mode == FL_POINT ||
+ mode == FL_SHUTDOWN) && chip->oldstate == FL_READY)
return 0;
fallthrough;
default:
@@ -1215,6 +1245,133 @@ do { \
#endif
+static int do_point_onechip(struct map_info *map, struct flchip *chip,
+ loff_t adr, size_t len)
+{
+ unsigned long cmd_addr;
+ struct cfi_private *cfi = map->fldrv_priv;
+ int ret;
+
+ adr += chip->start;
+
+ /* Ensure cmd read/writes are aligned. */
+ cmd_addr = adr & ~(map_bankwidth(map) - 1);
+
+ mutex_lock(&chip->mutex);
+ ret = get_chip(map, chip, cmd_addr, FL_POINT);
+ if (!ret) {
+ if (chip->state != FL_POINT && chip->state != FL_READY)
+ map_write(map, CMD(0xf0), cmd_addr);
+
+ chip->state = FL_POINT;
+ chip->ref_point_counter++;
+ }
+ mutex_unlock(&chip->mutex);
+
+ return ret;
+}
+
+static int cfi_amdstd_point(struct mtd_info *mtd, loff_t from, size_t len,
+ size_t *retlen, void **virt, resource_size_t *phys)
+{
+ struct map_info *map = mtd->priv;
+ struct cfi_private *cfi = map->fldrv_priv;
+ unsigned long ofs, last_end = 0;
+ int chipnum;
+ int ret = -EINVAL;
+
+ if (!map->virt)
+ return -EINVAL;
+
+ /* ofs: offset within the first chip that the first read should start */
+ chipnum = (from >> cfi->chipshift);
+ ofs = from - (chipnum << cfi->chipshift);
+
+ *virt = map->virt + cfi->chips[chipnum].start + ofs;
+ if (phys)
+ *phys = map->phys + cfi->chips[chipnum].start + ofs;
+
+ while (len) {
+ unsigned long thislen;
+
+ if (chipnum >= cfi->numchips)
+ break;
+
+ /* We cannot point across chips that are virtually disjoint */
+ if (!last_end)
+ last_end = cfi->chips[chipnum].start;
+ else if (cfi->chips[chipnum].start != last_end)
+ break;
+
+ if ((len + ofs - 1) >> cfi->chipshift)
+ thislen = (1 << cfi->chipshift) - ofs;
+ else
+ thislen = len;
+
+ ret = do_point_onechip(map, &cfi->chips[chipnum], ofs, thislen);
+ if (ret)
+ break;
+
+ *retlen += thislen;
+ len -= thislen;
+
+ ofs = 0;
+ last_end += 1 << cfi->chipshift;
+ chipnum++;
+ }
+ return *retlen ? 0 : ret;
+}
+
+static int cfi_amdstd_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
+{
+ struct map_info *map = mtd->priv;
+ struct cfi_private *cfi = map->fldrv_priv;
+ unsigned long ofs;
+ int chipnum, err = 0;
+
+ /* ofs: offset within the first chip that the first read should start */
+ chipnum = (from >> cfi->chipshift);
+ ofs = from - (chipnum << cfi->chipshift);
+
+ while (len && !err) {
+ unsigned long thislen;
+ struct flchip *chip;
+
+ if (chipnum >= cfi->numchips)
+ break;
+ chip = &cfi->chips[chipnum];
+
+ if ((len + ofs - 1) >> cfi->chipshift)
+ thislen = (1 << cfi->chipshift) - ofs;
+ else
+ thislen = len;
+
+ mutex_lock(&chip->mutex);
+ if (chip->state == FL_POINT) {
+ /* The last reader resumes whatever the first suspended */
+ if (--chip->ref_point_counter == 0) {
+ chip->state = FL_READY;
+ put_chip(map, chip, chip->start);
+ }
+ } else if (chip->state != FL_SHUTDOWN) {
+ /*
+ * After the reboot reset nothing is pointed any more;
+ * ref_point_counter no longer matters there.
+ */
+ pr_err("%s: Error: unpoint called on non pointed region\n",
+ map->name);
+ err = -EINVAL;
+ }
+ mutex_unlock(&chip->mutex);
+
+ len -= thislen;
+ ofs = 0;
+ chipnum++;
+ }
+
+ return err;
+}
+
static inline int do_read_onechip(struct map_info *map, struct flchip *chip, loff_t adr, size_t len, u_char *buf)
{
unsigned long cmd_addr;
--
2.53.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH v4 2/4] mtd: cfi_cmdset_0002: implement point() for simple linear maps
2026-11-17 21:41 ` [PATCH v4 2/4] mtd: cfi_cmdset_0002: implement point() for simple linear maps Orgad Shaneh
@ 2026-11-17 21:57 ` sashiko-bot
2026-11-17 22:06 ` Orgad Shaneh
0 siblings, 1 reply; 10+ messages in thread
From: sashiko-bot @ 2026-11-17 21:57 UTC (permalink / raw)
To: Orgad Shaneh, miquel.raynal, richard, vigneshr, tsbogend
Cc: linux-mtd, linusw, kaloz, ulli.kroll, john, nico, dwmw2, corbet
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mtd: cfi_cmdset_0002: non-NULL *virt left set on error in
cfi_amdstd_point()
--
commit 835d3eca515ca7b5849007a0b580221ecff2887b
Author: Orgad Shaneh <orgads@gmail.com>
mtd: cfi_cmdset_0002: implement point() for simple linear maps
This commit implements the point() and unpoint() methods for linearly
mapped AMD/Fujitsu CFI flash chips using simple map accessors, and updates
the cramfs documentation accordingly.
> diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
> index 100cab95a17b1..1fc2709539ed0 100644
> --- a/drivers/mtd/chips/cfi_cmdset_0002.c
> +++ b/drivers/mtd/chips/cfi_cmdset_0002.c
[ ... ]
> @@ -1215,6 +1245,133 @@ do { \
>
> #endif
>
> +static int do_point_onechip(struct map_info *map, struct flchip *chip,
> + loff_t adr, size_t len)
> +{
> + unsigned long cmd_addr;
> + struct cfi_private *cfi = map->fldrv_priv;
> + int ret;
> +
> + adr += chip->start;
> +
> + /* Ensure cmd read/writes are aligned. */
> + cmd_addr = adr & ~(map_bankwidth(map) - 1);
> +
> + mutex_lock(&chip->mutex);
> + ret = get_chip(map, chip, cmd_addr, FL_POINT);
> + if (!ret) {
> + if (chip->state != FL_POINT && chip->state != FL_READY)
> + map_write(map, CMD(0xf0), cmd_addr);
> +
> + chip->state = FL_POINT;
> + chip->ref_point_counter++;
> + }
> + mutex_unlock(&chip->mutex);
> +
> + return ret;
> +}
> +
> +static int cfi_amdstd_point(struct mtd_info *mtd, loff_t from, size_t len,
> + size_t *retlen, void **virt, resource_size_t *phys)
> +{
> + struct map_info *map = mtd->priv;
> + struct cfi_private *cfi = map->fldrv_priv;
> + unsigned long ofs, last_end = 0;
> + int chipnum;
> + int ret = -EINVAL;
> +
> + if (!map->virt)
> + return -EINVAL;
> +
> + /* ofs: offset within the first chip that the first read should start */
> + chipnum = (from >> cfi->chipshift);
> + ofs = from - (chipnum << cfi->chipshift);
> +
> + *virt = map->virt + cfi->chips[chipnum].start + ofs;
> + if (phys)
> + *phys = map->phys + cfi->chips[chipnum].start + ofs;
> +
> + while (len) {
> + unsigned long thislen;
> +
> + if (chipnum >= cfi->numchips)
> + break;
> +
> + /* We cannot point across chips that are virtually disjoint */
> + if (!last_end)
> + last_end = cfi->chips[chipnum].start;
> + else if (cfi->chips[chipnum].start != last_end)
> + break;
> +
> + if ((len + ofs - 1) >> cfi->chipshift)
> + thislen = (1 << cfi->chipshift) - ofs;
> + else
> + thislen = len;
> +
> + ret = do_point_onechip(map, &cfi->chips[chipnum], ofs, thislen);
> + if (ret)
> + break;
> +
> + *retlen += thislen;
> + len -= thislen;
> +
> + ofs = 0;
> + last_end += 1 << cfi->chipshift;
> + chipnum++;
> + }
> + return *retlen ? 0 : ret;
> +}
[Severity: Medium]
Does cfi_amdstd_point() leave *virt set to a non-NULL address when
do_point_onechip() fails on the first chip?
Unlike cfi_intelext_point(), which always returns 0, cfi_amdstd_point()
returns ret when *retlen is 0, after already assigning *virt. In
jffs2_scan_medium(), flashbuf is only reset to NULL when mtd_point()
returns 0 with a short pointlen:
fs/jffs2/scan.c:jffs2_scan_medium() {
...
ret = mtd_point(c->mtd, 0, c->mtd->size, &pointlen,
(void **)&flashbuf, NULL);
if (!ret && pointlen < c->mtd->size) {
/* Don't muck about if it won't let us point to the whole flash */
jffs2_dbg(1, "MTD point returned len too short: 0x%zx\n",
pointlen);
mtd_unpoint(c->mtd, 0, pointlen);
flashbuf = NULL;
}
if (ret && ret != -EOPNOTSUPP)
jffs2_dbg(1, "MTD point failed %d\n", ret);
#endif
if (!flashbuf) {
...
}
If do_point_onechip() returns an error on the first chip, flashbuf remains
non-NULL with buf_size == 0, so jffs2_scan_medium() scans the mapping
directly without holding the chip in FL_POINT or array mode and then calls
mtd_unpoint(c->mtd, 0, c->mtd->size) on cleanup. Setting *virt and *phys
only after at least one chip is pointed, or clearing *virt on error, would
avoid this.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117214141.3826637-1-orgads@gmail.com?part=2
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH v4 2/4] mtd: cfi_cmdset_0002: implement point() for simple linear maps
2026-11-17 21:57 ` sashiko-bot
@ 2026-11-17 22:06 ` Orgad Shaneh
0 siblings, 0 replies; 10+ messages in thread
From: Orgad Shaneh @ 2026-11-17 22:06 UTC (permalink / raw)
To: sashiko-reviews
Cc: miquel.raynal, richard, vigneshr, tsbogend, linux-mtd, linusw,
kaloz, ulli.kroll, john, nico, dwmw2, corbet
> Does cfi_amdstd_point() leave *virt set to a non-NULL address when
> do_point_onechip() fails on the first chip?
It does, and jffs2 would then scan through it. v5 clears *virt and
*phys when nothing was pointed. I'll wait for review of the rest
before posting it.
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v4 3/4] MIPS: Octeon: flash: allocate the map per device
2026-11-17 21:41 [PATCH v4 0/4] mtd: point() for cfi_cmdset_0002, on simple maps only Orgad Shaneh
2026-11-17 21:41 ` [PATCH v4 1/4] mtd: maps: only point() maps read through the simple accessors Orgad Shaneh
2026-11-17 21:41 ` [PATCH v4 2/4] mtd: cfi_cmdset_0002: implement point() for simple linear maps Orgad Shaneh
@ 2026-11-17 21:41 ` Orgad Shaneh
2026-11-17 21:50 ` sashiko-bot
2026-11-17 21:41 ` [PATCH v4 4/4] MIPS: Octeon: flash: use the simple map accessors without a shared eMMC Orgad Shaneh
3 siblings, 1 reply; 10+ messages in thread
From: Orgad Shaneh @ 2026-11-17 21:41 UTC (permalink / raw)
To: miquel.raynal, richard, vigneshr, tsbogend
Cc: linux-mtd, linux-mips, linux-kernel, linusw, kaloz, ulli.kroll,
john, nico, dwmw2, corbet, linux-doc
octeon_flash_probe() fills in one static map_info for every "cfi-flash"
node it binds to, so a second chip select overwrites the phys, virt,
size and bank width of the first while that MTD device still uses the
map. A probe whose do_map_probe() finds no chip also keeps its
ioremap() mapping and still returns success.
Allocate the map with devm_kzalloc(), map it with devm_ioremap() and
fail the probe when no chip is found or the partitions cannot be
registered, so the mapping goes away with the device. mymtd was never
read; drop it.
The driver has no remove(), and the mapping is now device-managed: a
sysfs unbind would unmap the flash while its MTD device stays
registered. Set suppress_bind_attrs to rule that out.
Signed-off-by: Orgad Shaneh <orgads@gmail.com>
---
v4: new. sashiko flagged the shared static flash_map against v2 and
v3 of the next patch; v3 left it as it is in mainline, this fixes
it first.
arch/mips/cavium-octeon/flash_setup.c | 49 ++++++++++++++++-----------
1 file changed, 30 insertions(+), 19 deletions(-)
diff --git a/arch/mips/cavium-octeon/flash_setup.c b/arch/mips/cavium-octeon/flash_setup.c
index 66d173b..0e5652f 100644
--- a/arch/mips/cavium-octeon/flash_setup.c
+++ b/arch/mips/cavium-octeon/flash_setup.c
@@ -18,8 +18,6 @@
#include <asm/octeon/octeon.h>
-static struct map_info flash_map;
-static struct mtd_info *mymtd;
static const char *part_probe_types[] = {
"cmdlinepart",
#if IS_ENABLED(CONFIG_MTD_REDBOOT_PARTS)
@@ -71,6 +69,8 @@ static void octeon_flash_map_copy_to(struct map_info *map, unsigned long to,
static int octeon_flash_probe(struct platform_device *pdev)
{
union cvmx_mio_boot_reg_cfgx region_cfg;
+ struct map_info *map;
+ struct mtd_info *mtd;
u32 cs;
int r;
struct device_node *np = pdev->dev.of_node;
@@ -85,6 +85,9 @@ static int octeon_flash_probe(struct platform_device *pdev)
*/
region_cfg.u64 = cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(cs));
if (region_cfg.s.en) {
+ map = devm_kzalloc(&pdev->dev, sizeof(*map), GFP_KERNEL);
+ if (!map)
+ return -ENOMEM;
/*
* The bootloader always takes the flash and sets its
* address so the entire flash fits below
@@ -94,26 +97,32 @@ static int octeon_flash_probe(struct platform_device *pdev)
* access 4MB.
*/
/* Use this name so old part lines work */
- flash_map.name = "phys_mapped_flash";
- flash_map.phys = region_cfg.s.base << 16;
- flash_map.size = 0x1fc00000 - flash_map.phys;
+ map->name = "phys_mapped_flash";
+ map->phys = region_cfg.s.base << 16;
+ map->size = 0x1fc00000 - map->phys;
/* 8-bit bus (0 + 1) or 16-bit bus (1 + 1) */
- flash_map.bankwidth = region_cfg.s.width + 1;
- flash_map.virt = ioremap(flash_map.phys, flash_map.size);
+ map->bankwidth = region_cfg.s.width + 1;
+ map->virt = devm_ioremap(&pdev->dev, map->phys, map->size);
+ if (!map->virt)
+ return -ENOMEM;
pr_notice("Bootbus flash: Setting flash for %luMB flash at "
- "0x%08llx\n", flash_map.size >> 20, flash_map.phys);
- WARN_ON(!map_bankwidth_supported(flash_map.bankwidth));
- flash_map.read = octeon_flash_map_read;
- flash_map.write = octeon_flash_map_write;
- flash_map.copy_from = octeon_flash_map_copy_from;
- flash_map.copy_to = octeon_flash_map_copy_to;
- mymtd = do_map_probe("cfi_probe", &flash_map);
- if (mymtd) {
- mymtd->owner = THIS_MODULE;
- mtd_device_parse_register(mymtd, part_probe_types,
- NULL, NULL, 0);
- } else {
+ "0x%08llx\n", map->size >> 20, map->phys);
+ WARN_ON(!map_bankwidth_supported(map->bankwidth));
+ map->read = octeon_flash_map_read;
+ map->write = octeon_flash_map_write;
+ map->copy_from = octeon_flash_map_copy_from;
+ map->copy_to = octeon_flash_map_copy_to;
+ mtd = do_map_probe("cfi_probe", map);
+ if (!mtd) {
pr_err("Failed to register MTD device for flash\n");
+ return -ENXIO;
+ }
+ mtd->owner = THIS_MODULE;
+ r = mtd_device_parse_register(mtd, part_probe_types,
+ NULL, NULL, 0);
+ if (r) {
+ map_destroy(mtd);
+ return r;
}
}
return 0;
@@ -131,6 +140,8 @@ static struct platform_driver of_flash_driver = {
.driver = {
.name = "octeon-of-flash",
.of_match_table = of_flash_match,
+ /* No remove(): the map and the MTD device stay registered */
+ .suppress_bind_attrs = true,
},
.probe = octeon_flash_probe,
};
--
2.53.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH v4 3/4] MIPS: Octeon: flash: allocate the map per device
2026-11-17 21:41 ` [PATCH v4 3/4] MIPS: Octeon: flash: allocate the map per device Orgad Shaneh
@ 2026-11-17 21:50 ` sashiko-bot
2026-11-17 22:06 ` Orgad Shaneh
0 siblings, 1 reply; 10+ messages in thread
From: sashiko-bot @ 2026-11-17 21:50 UTC (permalink / raw)
To: Orgad Shaneh, miquel.raynal, richard, vigneshr, tsbogend
Cc: linux-mtd, linusw, kaloz, ulli.kroll, john, nico, dwmw2, corbet
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] MIPS: Octeon: missing Fixes trailer for octeon_flash_probe()
static map bug
--
commit be5173a34aecc571a39f6355a5088e09f2d61146
Author: Orgad Shaneh <orgads@gmail.com>
> MIPS: Octeon: flash: allocate the map per device
>
> octeon_flash_probe() fills in one static map_info for every "cfi-flash"
> node it binds to, so a second chip select overwrites the phys, virt,
> size and bank width of the first while that MTD device still uses the
> map. A probe whose do_map_probe() finds no chip also keeps its
> ioremap() mapping and still returns success.
>
> Allocate the map with devm_kzalloc(), map it with devm_ioremap() and
> fail the probe when no chip is found or the partitions cannot be
> registered, so the mapping goes away with the device. mymtd was never
> read; drop it.
>
> The driver has no remove(), and the mapping is now device-managed: a
> sysfs unbind would unmap the flash while its MTD device stays
> registered. Set suppress_bind_attrs to rule that out.
>
> Signed-off-by: Orgad Shaneh <orgads@gmail.com>
[Severity: Low]
This fixes the static flash_map overwrite and probe error handling in
octeon_flash_probe(). Should it include:
Fixes: 7f481716bc90 ("MIPS: OCTEON: Use device tree to probe for flash chips.")
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117214141.3826637-1-orgads@gmail.com?part=3
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH v4 3/4] MIPS: Octeon: flash: allocate the map per device
2026-11-17 21:50 ` sashiko-bot
@ 2026-11-17 22:06 ` Orgad Shaneh
0 siblings, 0 replies; 10+ messages in thread
From: Orgad Shaneh @ 2026-11-17 22:06 UTC (permalink / raw)
To: sashiko-reviews
Cc: miquel.raynal, richard, vigneshr, tsbogend, linux-mtd, linusw,
kaloz, ulli.kroll, john, nico, dwmw2, corbet
> Fixes: 7f481716bc90 ("MIPS: OCTEON: Use device tree to probe for flash chips.")
Right, that commit made the init a per-device probe around the one
static map. v5 adds the tag.
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v4 4/4] MIPS: Octeon: flash: use the simple map accessors without a shared eMMC
2026-11-17 21:41 [PATCH v4 0/4] mtd: point() for cfi_cmdset_0002, on simple maps only Orgad Shaneh
` (2 preceding siblings ...)
2026-11-17 21:41 ` [PATCH v4 3/4] MIPS: Octeon: flash: allocate the map per device Orgad Shaneh
@ 2026-11-17 21:41 ` Orgad Shaneh
2026-11-17 22:06 ` sashiko-bot
3 siblings, 1 reply; 10+ messages in thread
From: Orgad Shaneh @ 2026-11-17 21:41 UTC (permalink / raw)
To: miquel.raynal, richard, vigneshr, tsbogend
Cc: linux-mtd, linux-mips, linux-kernel, linusw, kaloz, ulli.kroll,
john, nico, dwmw2, corbet, linux-doc
CAVIUM_OCTEON_SOC selects MTD_COMPLEX_MAPPINGS, and since
commit 8c1e6b14e27d ("MIPS: OCTEON: Protect accesses to bootbus flash
with octeon_bootbus_sem.") the flash map accessors take the semaphore
around every access. Its only other user is the eMMC host of the older
parts ("cavium,octeon-6130-mmc" in drivers/mmc/host/cavium-octeon.c),
which shares the boot bus; the CIU3 parts serialize their eMMC with a
lock of their own.
On boards without that host the semaphore guards nothing, but the
custom accessors make the map non-simple, so MTD will not let jffs2
point at it and its mount copies every used eraseblock. Use
simple_map_init() there. The test is for the node, not the driver, so
a disabled mmc node keeps the semaphore.
simple_map_init() BUG()s on an unsupported bank width; the old code
warned and then hit the BUG() in the inline map accessors on the first
probe command. Check the width before mapping anything and fail the
probe instead.
On an Octeon CN6635 board (no eMMC) with a 100 MB jffs2 partition on
an 8-bit NOR the mount drops from 15-30 s to under 1 s together with
point() support in cfi_cmdset_0002.
Signed-off-by: Orgad Shaneh <orgads@gmail.com>
---
v4: rebased onto v7.4-rc1; the Assisted-by tag is dropped (an LLM
helped write this series).
On top of the new 3/4: simple_map_init() gets the per-device
map, and the bank width check runs before the allocation.
v3: Assisted-by in the documented form.
v2: check the bank width before ioremap() and drop the added
iounmap() calls: flash_map was one static instance, so they could
unmap a mapping that an earlier probe registered (sashiko).
arch/mips/cavium-octeon/flash_setup.c | 36 +++++++++++++++++++++++----
1 file changed, 31 insertions(+), 5 deletions(-)
diff --git a/arch/mips/cavium-octeon/flash_setup.c b/arch/mips/cavium-octeon/flash_setup.c
index 0e5652f..62612cd 100644
--- a/arch/mips/cavium-octeon/flash_setup.c
+++ b/arch/mips/cavium-octeon/flash_setup.c
@@ -61,6 +61,17 @@ static void octeon_flash_map_copy_to(struct map_info *map, unsigned long to,
up(&octeon_bootbus_sem);
}
+static bool octeon_flash_bus_shared(void)
+{
+ struct device_node *np;
+ bool shared;
+
+ np = of_find_compatible_node(NULL, NULL, "cavium,octeon-6130-mmc");
+ shared = !!np;
+ of_node_put(np);
+ return shared;
+}
+
/*
* Module/ driver initialization.
*
@@ -85,6 +96,12 @@ static int octeon_flash_probe(struct platform_device *pdev)
*/
region_cfg.u64 = cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(cs));
if (region_cfg.s.en) {
+ /* 8-bit bus (0 + 1) or 16-bit bus (1 + 1) */
+ if (!map_bankwidth_supported(region_cfg.s.width + 1)) {
+ pr_err("Unsupported flash bank width %d\n",
+ region_cfg.s.width + 1);
+ return -EINVAL;
+ }
map = devm_kzalloc(&pdev->dev, sizeof(*map), GFP_KERNEL);
if (!map)
return -ENOMEM;
@@ -107,11 +124,20 @@ static int octeon_flash_probe(struct platform_device *pdev)
return -ENOMEM;
pr_notice("Bootbus flash: Setting flash for %luMB flash at "
"0x%08llx\n", map->size >> 20, map->phys);
- WARN_ON(!map_bankwidth_supported(map->bankwidth));
- map->read = octeon_flash_map_read;
- map->write = octeon_flash_map_write;
- map->copy_from = octeon_flash_map_copy_from;
- map->copy_to = octeon_flash_map_copy_to;
+ /*
+ * The boot bus semaphore only serializes the flash against
+ * an eMMC host that shares the bus (the CIU3 parts have
+ * their own). Without one, use the simple accessors: they
+ * let MTD point at the flash, so jffs2 scans it in place.
+ */
+ if (octeon_flash_bus_shared()) {
+ map->read = octeon_flash_map_read;
+ map->write = octeon_flash_map_write;
+ map->copy_from = octeon_flash_map_copy_from;
+ map->copy_to = octeon_flash_map_copy_to;
+ } else {
+ simple_map_init(map);
+ }
mtd = do_map_probe("cfi_probe", map);
if (!mtd) {
pr_err("Failed to register MTD device for flash\n");
--
2.53.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH v4 4/4] MIPS: Octeon: flash: use the simple map accessors without a shared eMMC
2026-11-17 21:41 ` [PATCH v4 4/4] MIPS: Octeon: flash: use the simple map accessors without a shared eMMC Orgad Shaneh
@ 2026-11-17 22:06 ` sashiko-bot
0 siblings, 0 replies; 10+ messages in thread
From: sashiko-bot @ 2026-11-17 22:06 UTC (permalink / raw)
To: Orgad Shaneh, miquel.raynal, richard, vigneshr, tsbogend
Cc: linux-mtd, linusw, kaloz, ulli.kroll, john, nico, dwmw2, corbet
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] MIPS: Octeon: flash: simple_map_init() breaks little-endian
mtd_point()
--
commit 56e2d356f36cb97dd336d231b8f3f9d7b285369c
Author: Orgad Shaneh <orgads@gmail.com>
MIPS: Octeon: flash: use the simple map accessors without a shared eMMC
This commit checks whether the boot bus is shared with a
"cavium,octeon-6130-mmc" device node and calls simple_map_init() when it
is not, while checking map_bankwidth_supported() before mapping the
flash.
> diff --git a/arch/mips/cavium-octeon/flash_setup.c b/arch/mips/cavium-octeon/flash_setup.c
> index 0e5652fc0c2ef..62612cd75d1b0 100644
> --- a/arch/mips/cavium-octeon/flash_setup.c
> +++ b/arch/mips/cavium-octeon/flash_setup.c
[ ... ]
> @@ -107,11 +124,20 @@ static int octeon_flash_probe(struct platform_device *pdev)
> return -ENOMEM;
> pr_notice("Bootbus flash: Setting flash for %luMB flash at "
> "0x%08llx\n", map->size >> 20, map->phys);
> - WARN_ON(!map_bankwidth_supported(map->bankwidth));
> - map->read = octeon_flash_map_read;
> - map->write = octeon_flash_map_write;
> - map->copy_from = octeon_flash_map_copy_from;
> - map->copy_to = octeon_flash_map_copy_to;
> + /*
> + * The boot bus semaphore only serializes the flash against
> + * an eMMC host that shares the bus (the CIU3 parts have
> + * their own). Without one, use the simple accessors: they
> + * let MTD point at the flash, so jffs2 scans it in place.
> + */
> + if (octeon_flash_bus_shared()) {
> + map->read = octeon_flash_map_read;
> + map->write = octeon_flash_map_write;
> + map->copy_from = octeon_flash_map_copy_from;
> + map->copy_to = octeon_flash_map_copy_to;
> + } else {
> + simple_map_init(map);
> + }
[Severity: Medium]
Does calling simple_map_init(map) break mtd_point() on little-endian
Octeon kernels (CONFIG_CPU_LITTLE_ENDIAN=y)?
On Octeon, the boot bus is wired big-endian into the 64-bit IOB, so
sub-64-bit MMIO accesses under __LITTLE_ENDIAN require address swizzling:
arch/mips/include/asm/mach-cavium-octeon/mangle-port.h:
# define __swizzle_addr_b(port) \
(__should_swizzle_addr(port) ? (port) ^ 7 : (port))
# define __swizzle_addr_w(port) \
(__should_swizzle_addr(port) ? (port) ^ 6 : (port))
# define __swizzle_addr_l(port) \
(__should_swizzle_addr(port) ? (port) ^ 4 : (port))
inline_map_read() and inline_map_write() go through __raw_readb()/w() and
__raw_writeb()/w(), which apply those swizzles. Marking the map as simple
causes cfi_cmdset_0001 and cfi_cmdset_0002 to wire up mtd->_point, so
callers such as JFFS2 directly dereference map->virt + ofs with normal CPU
loads and read scrambled flash offsets.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117214141.3826637-1-orgads@gmail.com?part=4
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 10+ messages in thread