mtd: point() for cfi_cmdset_0002, on simple maps only
Subsystems (4)
cover mtd: point() for cfi_cmdset_0002, on simple maps only
jffs2 scans a flash in place through mtd_point() when the chip driver offers it, and copies every used eraseblock through mtd_read() otherwise. cfi_cmdset_0002 never had point(), so every jffs2 mount on an AMD-style NOR copies the whole used area. On an Octeon CN6635 board with a 100 MB jffs2 partition on an 8-bit M29EW that takes 15-30 s at every boot.
1/3 tightens the existing gate first. map_is_linear() only checks for a physical address, so cfi_cmdset_0001 already points at maps whose own accessors swap bytes (IXP4xx), switch pins (Gemini) or lock the bus (lantiq). The new map_is_simple() also requires the simple accessors.
2/3 adds point()/unpoint() to cfi_cmdset_0002 behind the same gate, modeled on cfi_cmdset_0001, and lists it in the cramfs documentation.
3/3 lets the Octeon flash map use the simple accessors when no eMMC host shares its boot bus. Without it, 2/3 changes nothing on Octeon. It builds without 1/3 and 2/3 but only pays off once they are in, so taking all three through mtd with an ack from Thomas seems simplest.
Tested on that board with 7.2.9: the mount drops to 0.6-0.8 s. The md5s of the images on the jffs2 partition held across reboots and across ten 8 MB write/delete rounds. The series applies to v7.3-rc4 and to mtd/next.
Separately, for the MTD maintainers to judge: the write-buffer count truncation that cfc5ebc9540e ("mtd: cfi_cmdset_0002: cap the write-buffer chunk at 256 bytes on an x8 device") fixed in cfi_cmdset_0002 has two siblings. do_write_buffer() in cfi_cmdset_0001 writes CMD(words) and the one in cfi_cmdset_0020 writes CMD(len / map_bankwidth(map) - 1). On an x8 device CMD() keeps only the low 8 bits of the count in each device lane, so a write buffer larger than 256 bytes per device would be programmed with a truncated count. I have no x8 Intel or ST part to test on, so I have not touched either; I do not know whether such a part exists.
Orgad Shaneh (3):
mtd: maps: only point() maps read through the simple accessors
mtd: cfi_cmdset_0002: implement point() for simple linear maps
MIPS: Octeon: flash: use the simple map accessors without a shared
eMMC
Documentation/filesystems/cramfs.rst | 11 +- arch/mips/cavium-octeon/flash_setup.c | 37 +++++- drivers/mtd/chips/cfi_cmdset_0001.c | 2 +- drivers/mtd/chips/cfi_cmdset_0002.c | 156 +++++++++++++++++++++++++- drivers/mtd/maps/map_funcs.c | 12 ++ include/linux/mtd/map.h | 2 + 6 files changed, 207 insertions(+), 13 deletions(-)
--
2.53.0
PATCH 1/3 mtd: maps: only point() maps read through the simple accessors
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;
- cobalt-flash reads at an offset inside a PCI BAR while leaving phys 0.
cfi_cmdset_0001 hands such pointers to jffs2 today, and the IXP4xx boards carry Intel StrataFlash. 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 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.
--- drivers/mtd/chips/cfi_cmdset_0001.c | 2 +- drivers/mtd/maps/map_funcs.c | 12 ++++++++++++ include/linux/mtd/map.h | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-)
drivers/mtd/chips/cfi_cmdset_0001.c +1 -1
@@ -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; }
drivers/mtd/maps/map_funcs.c +12 -0
@@ -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" );
include/linux/mtd/map.h +2 -0
@@ -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 */
Signature · 1 line
2.53.0
PATCH 2/3 mtd: cfi_cmdset_0002: implement point() for simple linear maps
In reply to Orgad Shanehcfi_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() already handles FL_POINT. 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.
As with cfi_cmdset_0001, a held point makes writes, erases and 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, sync(2) - and so reboot(8), which syncs first - 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.
--- Documentation/filesystems/cramfs.rst | 11 +- drivers/mtd/chips/cfi_cmdset_0002.c | 156 ++++++++++++++++++++++++++- 2 files changed, 160 insertions(+), 7 deletions(-)
Documentation/filesystems/cramfs.rst +6 -5
@@ -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
drivers/mtd/chips/cfi_cmdset_0002.c +154 -2
186 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH 2/3] mtd: cfi_cmdset_0002: implement point() for simple linear maps
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] mtd: cfi_cmdset_0002: unbounded TASK_UNINTERRUPTIBLE sleep causes Hung Task Panic --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] mtd: cfi_cmdset_0002: unbounded TASK_UNINTERRUPTIBLE sleep causes Hung Task Panic --
commit 97c2e746b1f52c7744c56b40bf00fe410dca196f
Author: Orgad Shaneh <[email protected]>
mtd: cfi_cmdset_0002: implement point() for simple linear maps
This commit adds point() and unpoint() support for simple linear maps to the cfi_cmdset_0002 driver. This allows filesystems like jffs2 or cramfs to scan memory in place without copying every used eraseblock. When a chip is pointed to, writes, erases, and sync operations wait for the unpoint.
Quoted 4 lines
drivers/mtd/chips/cfi_cmdset_0002.c +0
-0
[ ... ]
Quoted 5 lines
drivers/mtd/chips/cfi_cmdset_0002.c +0
-1@@ -960,8 +980,13 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adrreturn -EIO ;case FL_POINT : -/* Only if there's no operation suspended... */
drivers/mtd/chips/cfi_cmdset_0002.c static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr · line 991
Quoted 10 lines
drivers/mtd/chips/cfi_cmdset_0002.c +7
-1-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;
[Severity: High]
Does this logic in get_chip() cause unintended blocking when the chip has a suspended operation?
If a filesystem like CramFS mounts an MTD partition and calls mtd_point(), chip->state becomes FL_POINT indefinitely until unmount. If this point happens while an erase is suspended (chip->oldstate == FL_ERASING), requests for FL_READY or FL_SHUTDOWN will fail the check for chip->oldstate == FL_READY.
They will then fall through to the default sleep path. Because the point is held indefinitely by the filesystem, could this cause the reboot notifier (FL_SHUTDOWN) to deadlock permanently?
drivers/mtd/chips/cfi_cmdset_0002.c
Quoted 9 lines
drivers/mtd/chips/cfi_cmdset_0002.c +0
-0default :drivers/mtd/chips/cfi_cmdset_0002.c +0
-0sleep:set_current_state (TASK_UNINTERRUPTIBLE );add_wait_queue (&chip->wq, &wait);mutex_unlock (&chip->mutex);schedule ();remove_wait_queue (&chip->wq, &wait);mutex_lock (&chip->mutex); goto resettime;
[Severity: High]
Is it safe to use TASK_UNINTERRUPTIBLE for unbounded synchronization here?
When chip->state is FL_POINT (held long-term by a mounted filesystem), and another task initiates a flash write, erase, or sync, get_chip() is called with FL_WRITING, FL_ERASING, or FL_SYNCING. These modes do not match the FL_POINT exceptions and fall through directly to this sleep block.
Since FL_POINT won't be released until the filesystem is unmounted, tasks sleeping here will remain in TASK_UNINTERRUPTIBLE indefinitely. Could this cause a hung task panic after the standard 120-second timeout, allowing a local user to crash the system simply by running sync(2) while CramFS is mounted?
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
PATCH 3/3 MIPS: Octeon: flash: use the simple map accessors without a shared eMMC
In reply to Orgad ShanehCAVIUM_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 first and fail the probe instead, and unmap the window when the probe fails.
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.
--- arch/mips/cavium-octeon/flash_setup.c | 37 +++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 5 deletions(-)
arch/mips/cavium-octeon/flash_setup.c +32 -5
@@ -63,6 +63,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. *
@@ -102,11 +113,26 @@ static int octeon_flash_probe(struct platform_device *pdev) flash_map.virt =ioremap (flash_map.phys, flash_map.size);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; +if (!map_bankwidth_supported (flash_map.bankwidth)) { +pr_err ("Unsupported flash bank width %d\n" , + flash_map.bankwidth); +iounmap (flash_map.virt); +return -EINVAL ; + } +/* +* 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 ()) { + 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; + }else { +simple_map_init (&flash_map); + } mymtd =do_map_probe ("cfi_probe" , &flash_map);if (mymtd) { mymtd->owner =THIS_MODULE ;
@@ -114,6 +140,7 @@ static int octeon_flash_probe(struct platform_device *pdev) NULL, NULL, 0); }else {pr_err ("Failed to register MTD device for flash\n" ); +iounmap (flash_map.virt); } }return 0 ;
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH 3/3] MIPS: Octeon: flash: use the simple map accessors without a shared eMMC
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] mips: cavium-octeon: global state corruption on multiple flash probes --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] mips: cavium-octeon: global state corruption on multiple flash probes --
commit 9e242ec4162d9c7c06bd10d98f2bbfb32869d150
Author: Orgad Shaneh <[email protected]>
MIPS: Octeon: flash: use the simple map accessors without a shared eMMC
This patch updates the Cavium Octeon flash setup to use simple map accessors when there is no shared eMMC host on the boot bus. It also changes the flash bank width check to fail and unmap the memory if unsupported, rather than just warning.
Quoted 4 lines
arch/mips/cavium-octeon/flash_setup.c +0
-0
[ ... ]
Quoted 5 lines
arch/mips/cavium-octeon/flash_setup.c +0
-1@@ -102,11 +113,26 @@ static int octeon_flash_probe(struct platform_device *pdev) flash_map.virt =ioremap (flash_map.phys, flash_map.size);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));
arch/mips/cavium-octeon/flash_setup.c static int octeon_flash_probe(struct platform_device *pdev) · line 121
Quoted 10 lines
arch/mips/cavium-octeon/flash_setup.c +6
-4- 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; +if (!map_bankwidth_supported (flash_map.bankwidth)) { +pr_err ("Unsupported flash bank width %d\n" , + flash_map.bankwidth); +iounmap (flash_map.virt); +return -EINVAL ; + }
[Severity: High]
Since flash_map is a static global structure, what happens if there are multiple flash devices probed sequentially?
The line just above this block unconditionally overwrites flash_map.virt with a new ioremap() on each probe, which appears to leak the previous mapping and corrupt the state of any already-registered MTD device.
If octeon_flash_probe() executes a second time and fails the bank width check here, it calls iounmap(flash_map.virt) and returns an error. Does this unmap operation turn the first successfully probed MTD device's shared reference into a dangling pointer, leading to an invalid memory access when the first device is accessed?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
v2 cover mtd: point() for cfi_cmdset_0002, on simple maps only
In reply to Orgad Shanehjffs2 scans a flash in place through mtd_point() when the chip driver offers it, and copies every used eraseblock through mtd_read() otherwise. cfi_cmdset_0002 never had point(), so every jffs2 mount on an AMD-style NOR copies the whole used area. On an Octeon CN6635 board with a 100 MB jffs2 partition on an 8-bit M29EW that takes 15-30 s at every boot.
1/3 tightens the existing gate first. map_is_linear() only checks for a physical address, so cfi_cmdset_0001 already points at maps whose own accessors swap bytes (IXP4xx), switch pins (Gemini) or lock the bus (lantiq). The new map_is_simple() also requires the simple accessors.
2/3 adds point()/unpoint() to cfi_cmdset_0002 behind the same gate, modeled on cfi_cmdset_0001, and lists it in the cramfs documentation.
3/3 lets the Octeon flash map use the simple accessors when no eMMC host shares its boot bus. Without it, 2/3 changes nothing on Octeon. It builds without 1/3 and 2/3 but only pays off once they are in, so taking all three through mtd with an ack from Thomas seems simplest.
Tested on that board with 7.2.9: the mount drops to 0.6-0.8 s. The md5s of the images on the jffs2 partition held across reboots and across ten 8 MB write/delete rounds. The series applies to v7.3-rc4 and to mtd/next.
Separately, for the MTD maintainers to judge: the write-buffer count truncation that cfc5ebc9540e ("mtd: cfi_cmdset_0002: cap the write-buffer chunk at 256 bytes on an x8 device") fixed in cfi_cmdset_0002 has two siblings. do_write_buffer() in cfi_cmdset_0001 writes CMD(words) and the one in cfi_cmdset_0020 writes CMD(len / map_bankwidth(map) - 1). On an x8 device CMD() keeps only the low 8 bits of the count in each device lane, so a write buffer larger than 256 bytes per device would be programmed with a truncated count. I have no x8 Intel or ST part to test on, so I have not touched either; I do not know whether such a part exists.
Changes in v2, all from sashiko's review of v1:
- 2/3: a point no longer suspends an erase in progress. cramfs holds its point for the whole mount, so the erase - and the task waiting on it, and the reboot reset - would stay suspended until umount.
- 3/3: the bank width is checked before ioremap(), and the iounmap() calls v1 added are gone; flash_map is a single static instance, so on a second probe they could unmap what the first one registered.
- Not changed: sashiko also asked about writers sleeping uninterruptibly behind a long-held point. That is how cfi_cmdset_0001 has always behaved, and 2/3 describes the cramfs
consequence: a cramfs mounted from /dev/mtdblockN on AMD flash today falls back to the block device, and after this series it takes the direct path, so writes to other partitions of the same chip wait until it is unmounted. If you would rather not change that, I can make point() in cfi_cmdset_0002 opt-in.
v1: https://lore.kernel.org/all/[email protected]/
Orgad Shaneh (3):
mtd: maps: only point() maps read through the simple accessors
mtd: cfi_cmdset_0002: implement point() for simple linear maps
MIPS: Octeon: flash: use the simple map accessors without a shared
eMMC
Documentation/filesystems/cramfs.rst | 11 +- arch/mips/cavium-octeon/flash_setup.c | 36 +++++- drivers/mtd/chips/cfi_cmdset_0001.c | 2 +- drivers/mtd/chips/cfi_cmdset_0002.c | 162 +++++++++++++++++++++++++- drivers/mtd/maps/map_funcs.c | 12 ++ include/linux/mtd/map.h | 2 + 6 files changed, 211 insertions(+), 14 deletions(-)
Signature · 1 line
2.53.0
PATCH v2 1/3 mtd: maps: only point() maps read through the simple accessors
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;
- cobalt-flash reads at an offset inside a PCI BAR while leaving phys 0.
cfi_cmdset_0001 hands such pointers to jffs2 today, and the IXP4xx boards carry Intel StrataFlash. 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 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.
---
v2: no change.
drivers/mtd/chips/cfi_cmdset_0001.c | 2 +- drivers/mtd/maps/map_funcs.c | 12 ++++++++++++ include/linux/mtd/map.h | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-)
drivers/mtd/chips/cfi_cmdset_0001.c +1 -1
@@ -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; }
drivers/mtd/maps/map_funcs.c +12 -0
@@ -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" );
include/linux/mtd/map.h +2 -0
@@ -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 */
Signature · 1 line
2.53.0
PATCH v2 2/3 mtd: cfi_cmdset_0002: implement point() for simple linear maps
In reply to Orgad Shanehcfi_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() already handles FL_POINT. 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.
As with cfi_cmdset_0001, a held point makes writes, erases and 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, sync(2) - and so reboot(8), which syncs first - 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.
---
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 | 162 ++++++++++++++++++++++++++- 2 files changed, 165 insertions(+), 8 deletions(-)
Documentation/filesystems/cramfs.rst +6 -5
@@ -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
drivers/mtd/chips/cfi_cmdset_0002.c +159 -3
199 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v2 2/3] mtd: cfi_cmdset_0002: implement point() for simple linear maps
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] mtd: cfi_cmdset_0002: FL_POINT deadlocks and hangs XIP erases via FL_XIP_WHILE_ERASING --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] mtd: cfi_cmdset_0002: FL_POINT deadlocks and hangs XIP erases via FL_XIP_WHILE_ERASING --
commit 5f3b3543d5ee6dad5e8171d86ea7a290abab737e
Author: Orgad Shaneh <[email protected]>
mtd: cfi_cmdset_0002: implement point() for simple linear maps
This commit adds a point() and unpoint() pair for cfi_cmdset_0002, modeled on cfi_intelext_point(), allowing linearly mapped chips to be scanned in place. It handles FL_POINT operations and ensures that a point does not suspend an erase, but waits for it to finish instead.
Quoted 4 lines
drivers/mtd/chips/cfi_cmdset_0002.c +0
-0
[ ... ]
drivers/mtd/chips/cfi_cmdset_0002.c static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr · line 936
Quoted 13 lines
drivers/mtd/chips/cfi_cmdset_0002.c +5
-1@@ -906,8 +926,12 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adrreturn 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;
[Severity: High]
This patch correctly prevents FL_POINT from suspending an erase here, but does this also need to be applied to FL_XIP_WHILE_ERASING?
If mtd_point() is called during FL_XIP_WHILE_ERASING, get_chip() still allows mode == FL_POINT:
drivers/mtd/chips/cfi_cmdset_0002.c:get_chip() {
...
case FL_XIP_WHILE_ERASING:
if (mode != FL_READY && mode != FL_POINT &&
(!cfip || !(cfip->EraseSuspend&2)))
goto sleep;
chip->oldstate = chip->state;
chip->state = FL_READY;
return 0;
...
}This allows do_point_onechip() to successfully change chip->state to FL_POINT while leaving chip->oldstate as FL_XIP_WHILE_ERASING.
[ ... ]
Quoted 6 lines
drivers/mtd/chips/cfi_cmdset_0002.c +0
-2@@ -960,8 +984,13 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adrreturn -EIO ;case FL_POINT : -/* Only if there's no operation suspended... */ -if (mode ==FL_READY && chip->oldstate ==FL_READY )
drivers/mtd/chips/cfi_cmdset_0002.c static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr · line 996
Quoted 10 lines
drivers/mtd/chips/cfi_cmdset_0002.c +7
-0+/* +* 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 :
[Severity: High]
If chip->oldstate is FL_XIP_WHILE_ERASING because it wasn't filtered out above, will subsequent operations deadlock here?
Because oldstate is not FL_READY, normal read operations (FL_READY) would fall through to the sleep block indefinitely until the point is released (which for cramfs is the mount lifetime).
Could this also cause the XIP background erase loop to spin indefinitely waiting for chip->state to return to FL_XIP_WHILE_ERASING?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
PATCH v2 3/3 MIPS: Octeon: flash: use the simple map accessors without a shared eMMC
In reply to Orgad ShanehCAVIUM_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.
---
v2: check the bank width before ioremap() and drop the added
iounmap() calls: flash_map is 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(-)
arch/mips/cavium-octeon/flash_setup.c +31 -5
@@ -63,6 +63,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 ; + }/* * The bootloader always takes the flash and sets its * address so the entire flash fits below
@@ -102,11 +119,20 @@ static int octeon_flash_probe(struct platform_device *pdev) flash_map.virt =ioremap (flash_map.phys, flash_map.size);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; +/* +* 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 ()) { + 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; + }else { +simple_map_init (&flash_map); + } mymtd =do_map_probe ("cfi_probe" , &flash_map);if (mymtd) { mymtd->owner =THIS_MODULE ;
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v2 3/3] MIPS: Octeon: flash: use the simple map accessors without a shared eMMC
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] mips: cavium-octeon: static map_info overwrite and memory leak in octeon_flash_probe --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] mips: cavium-octeon: static map_info overwrite and memory leak in octeon_flash_probe --
commit 2d9aae5bb3f634f71b28d3ae93087e12e701fbe6
Author: Orgad Shaneh <[email protected]>
MIPS: Octeon: flash: use the simple map accessors without a shared eMMC
This commit updates the Octeon flash driver to use simple_map_init() when the boot bus isn't shared with an eMMC host, reducing mount times significantly. It also checks for supported bank widths earlier in the probe function to avoid hitting BUG calls on unsupported widths.
Quoted 4 lines
arch/mips/cavium-octeon/flash_setup.c +0
-0
[ ... ]
Quoted 1 line
arch/mips/cavium-octeon/flash_setup.c +0
-0@@ -85,6 +96,12 @@ static int octeon_flash_probe(struct platform_device *pdev)
[ ... ]
arch/mips/cavium-octeon/flash_setup.c
Quoted 4 lines
arch/mips/cavium-octeon/flash_setup.c +0
-0flash_map.size =0x1fc00000 - flash_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);
[Severity: Medium]
If multiple flash devices are probed, does this unconditionally overwrite the static flash_map.virt with a new ioremap() mapping?
If an earlier probe successfully registered an MTD device, overwriting the singleton flash_map could corrupt the previous device's mapping.
Quoted 2 lines
arch/mips/cavium-octeon/flash_setup.c +0
-0pr_notice ("Bootbus flash: Setting flash for %luMB flash at " "0x%08llx\n" , flash_map.size >>20 , flash_map.phys);
[ ... ]
arch/mips/cavium-octeon/flash_setup.c
Quoted 8 lines
arch/mips/cavium-octeon/flash_setup.c +0
-0mymtd =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 {pr_err ("Failed to register MTD device for flash\n" ); }
[Severity: Medium]
Is an iounmap(flash_map.virt) needed here when do_map_probe() fails?
Without it, this error path appears to leak the virtual mapping.
The v2 changelog mentions omitting iounmap() because it could unmap a mapping that an earlier probe registered. However, since the static flash_map.virt is unconditionally overwritten by ioremap() earlier in this function, wouldn't the singleton already be corrupted if a prior probe existed?
Skipping iounmap() in this path appears to just leak memory rather than safely preserving any previous mapping.
Quoted 3 lines
arch/mips/cavium-octeon/flash_setup.c +0
-0}return 0 ; }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
v3 cover mtd: point() for cfi_cmdset_0002, on simple maps only
In reply to Orgad Shanehjffs2 scans a flash in place through mtd_point() when the chip driver offers it, and copies every used eraseblock through mtd_read() otherwise. cfi_cmdset_0002 never had point(), so every jffs2 mount on an AMD-style NOR copies the whole used area. On an Octeon CN6635 board with a 100 MB jffs2 partition on an 8-bit M29EW that takes 15-30 s at every boot.
1/3 tightens the existing gate first. map_is_linear() only checks for a physical address, so cfi_cmdset_0001 already points at maps whose own accessors swap bytes (IXP4xx), switch pins (Gemini) or lock the bus (lantiq). The new map_is_simple() also requires the simple accessors.
2/3 adds point()/unpoint() to cfi_cmdset_0002 behind the same gate, modeled on cfi_cmdset_0001, and lists it in the cramfs documentation.
3/3 lets the Octeon flash map use the simple accessors when no eMMC host shares its boot bus. Without it, 2/3 changes nothing on Octeon. It builds without 1/3 and 2/3 but only pays off once they are in, so taking all three through mtd with an ack from Thomas seems simplest.
Tested on that board with 7.2.9: the mount drops to 0.6-0.8 s. The md5s of the images on the jffs2 partition held across reboots and across ten 8 MB write/delete rounds. The series applies to v7.3-rc4 and to mtd/next.
Separately, for the MTD maintainers to judge: the write-buffer count truncation that cfc5ebc9540e ("mtd: cfi_cmdset_0002: cap the write-buffer chunk at 256 bytes on an x8 device") fixed in cfi_cmdset_0002 has two siblings. do_write_buffer() in cfi_cmdset_0001 writes CMD(words) and the one in cfi_cmdset_0020 writes CMD(len / map_bankwidth(map) - 1). On an x8 device CMD() keeps only the low 8 bits of the count in each device lane, so a write buffer larger than 256 bytes per device would be programmed with a truncated count. I have no x8 Intel or ST part to test on, so I have not touched either; I do not know whether such a part exists.
Changes in v3, from sashiko's review of v2:
- 2/3: an XIP erase (FL_XIP_WHILE_ERASING) no longer lets a point through either; v2 only covered FL_ERASING.
- 2/3: the changelog now states the cost of that rule: jffs2 points at a data node the first time it checks its CRC, so a read that meets a garbage-collection erase waits for that sector erase instead of suspending it. It also names what really blocks behind a cramfs
point: jffs2's umount calls mtd_sync(); sync(2) does not reach the chip driver.
- Assisted-by in the form Documentation/process/coding-assistants.rst now asks for.
- Not changed: sashiko notes that 3/3 keeps the static flash_map, which a second probe overwrites, and leaks the mapping when do_map_probe() fails. Both are as in mainline today; v2 removed the iounmap() v1 added because, with the shared instance, it could unmap a registered device's window. Making the map per device would fix both, and I can send that separately if wanted.
Changes in v2, all from sashiko's review of v1:
- 2/3: a point no longer suspends an erase in progress. cramfs holds its point for the whole mount, so the erase - and the task waiting on it, and the reboot reset - would stay suspended until umount.
- 3/3: the bank width is checked before ioremap(), and the iounmap() calls v1 added are gone; flash_map is a single static instance, so on a second probe they could unmap what the first one registered.
- Not changed: sashiko also asked about writers sleeping uninterruptibly behind a long-held point. That is how cfi_cmdset_0001 has always behaved, and 2/3 describes the cramfs
consequence: a cramfs mounted from /dev/mtdblockN on AMD flash today falls back to the block device, and after this series it takes the direct path, so writes to other partitions of the same chip wait until it is unmounted. If you would rather not change that, I can make point() in cfi_cmdset_0002 opt-in.
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
Orgad Shaneh (3):
mtd: maps: only point() maps read through the simple accessors
mtd: cfi_cmdset_0002: implement point() for simple linear maps
MIPS: Octeon: flash: use the simple map accessors without a shared
eMMC
Documentation/filesystems/cramfs.rst | 11 +- arch/mips/cavium-octeon/flash_setup.c | 36 +++++- drivers/mtd/chips/cfi_cmdset_0001.c | 2 +- drivers/mtd/chips/cfi_cmdset_0002.c | 167 +++++++++++++++++++++++++- drivers/mtd/maps/map_funcs.c | 12 ++ include/linux/mtd/map.h | 2 + 6 files changed, 214 insertions(+), 16 deletions(-)
Signature · 1 line
2.53.0
PATCH v3 1/3 mtd: maps: only point() maps read through the simple accessors
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;
- cobalt-flash reads at an offset inside a PCI BAR while leaving phys 0.
cfi_cmdset_0001 hands such pointers to jffs2 today, and the IXP4xx boards carry Intel StrataFlash. 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 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.
---
v3: Assisted-by in the documented form.
v2: no change.
drivers/mtd/chips/cfi_cmdset_0001.c | 2 +- drivers/mtd/maps/map_funcs.c | 12 ++++++++++++ include/linux/mtd/map.h | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-)
drivers/mtd/chips/cfi_cmdset_0001.c +1 -1
@@ -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; }
drivers/mtd/maps/map_funcs.c +12 -0
@@ -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" );
include/linux/mtd/map.h +2 -0
@@ -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 */
Signature · 1 line
2.53.0
PATCH v3 2/3 mtd: cfi_cmdset_0002: implement point() for simple linear maps
In reply to Orgad Shanehcfi_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() already handles FL_POINT. 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.
---
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(-)
Documentation/filesystems/cramfs.rst +6 -5
@@ -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
drivers/mtd/chips/cfi_cmdset_0002.c +162 -5
210 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v3 3/3 MIPS: Octeon: flash: use the simple map accessors without a shared eMMC
In reply to Orgad ShanehCAVIUM_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.
---
v3: Assisted-by in the documented form.
v2: check the bank width before ioremap() and drop the added
iounmap() calls: flash_map is 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(-)
arch/mips/cavium-octeon/flash_setup.c +31 -5
@@ -63,6 +63,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 ; + }/* * The bootloader always takes the flash and sets its * address so the entire flash fits below
@@ -102,11 +119,20 @@ static int octeon_flash_probe(struct platform_device *pdev) flash_map.virt =ioremap (flash_map.phys, flash_map.size);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; +/* +* 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 ()) { + 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; + }else { +simple_map_init (&flash_map); + } mymtd =do_map_probe ("cfi_probe" , &flash_map);if (mymtd) { mymtd->owner =THIS_MODULE ;
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v3 3/3] MIPS: Octeon: flash: use the simple map accessors without a shared eMMC
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] mtd: cavium: global state corruption of flash_map on multiple probes --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] mtd: cavium: global state corruption of flash_map on multiple probes --
commit c32cf6c857e3356732452178a52a4e739fcaf273
Author: Orgad Shaneh <[email protected]>
MIPS: Octeon: flash: use the simple map accessors without a shared eMMC
This commit modifies the Octeon flash driver to conditionally use simple map accessors when the bootbus is not shared with an eMMC host. Doing so avoids unnecessary semaphore usage and enables MTD to use the point() method for faster jffs2 mounts. It also adds early bank width validation before mapping memory.
Quoted 4 lines
arch/mips/cavium-octeon/flash_setup.c +0
-0
[ ... ]
Quoted 14 lines
arch/mips/cavium-octeon/flash_setup.c +5
-5@@ -102,11 +119,20 @@ static int octeon_flash_probe(struct platform_device *pdev) flash_map.virt =ioremap (flash_map.phys, flash_map.size);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; +/* +* 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.
arch/mips/cavium-octeon/flash_setup.c static int octeon_flash_probe(struct platform_device *pdev) · line 136
Quoted 10 lines
arch/mips/cavium-octeon/flash_setup.c +9
-0+*/ +if (octeon_flash_bus_shared ()) { + 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; + }else { +simple_map_init (&flash_map); + } mymtd =do_map_probe ("cfi_probe" , &flash_map);
[Severity: High]
Can this cause global state corruption if multiple flash devices are probed?
Looking at arch/mips/cavium-octeon/flash_setup.c, flash_map is defined as a single static struct map_info instance:
static struct map_info flash_map;
If multiple cfi-flash devices are present on the platform bus, octeon_flash_probe() will be called for each of them. A second probe will overwrite the phys, virt, size, and bankwidth fields of the shared flash_map instance.
Since do_map_probe() passes a pointer to flash_map to the CFI layer, both mtd_info instances will retain a reference to this single map via mtd->priv. Any I/O on the first flash device would then use the mapped memory, size, and CFI state of the second device, which could lead to data corruption.
Does it make sense to allocate struct map_info dynamically per device instead?
Quoted 2 lines
arch/mips/cavium-octeon/flash_setup.c +0
-0if (mymtd) { mymtd->owner =THIS_MODULE ;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3