mtd: point() for cfi_cmdset_0002, on simple maps only
Subsystems (4)
v4 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 otherwise. cfi_cmdset_0002 has no point(), so an Octeon CN6635 board with a 100 MB jffs2 partition on an 8-bit M29EW spends 15-30 s mounting it at every boot.
1/4 lets point() through only for maps read through the simple accessors; cfi_cmdset_0001, lpddr, map_ram and map_rom point today at maps whose own accessors swap bytes, switch pins or lock the bus. 2/4 adds point() to cfi_cmdset_0002 behind that gate.
3/4 gives each Octeon flash device its own map.
4/4 lets that map use the simple accessors when no eMMC shares the boot bus. 3/4 and 4/4 build alone, but 4/4 only pays off with 1/4 and 2/4, so taking all four through mtd with an ack from Thomas seems simplest.
Tested on that board with 7.3.4: the mount drops to 0.55-0.6 s, and an 8 MB file written to the jffs2 partition keeps its md5 across a reboot. v3 held its md5s across ten 8 MB write/delete rounds on 7.2.9. The series applies to v7.4-rc1.
One question: a cramfs on AMD flash falls back to the block device today. After 2/4 it keeps its image pointed while mounted, as it does on Intel flash, so jffs2 writes to the same chip wait until cramfs is unmounted. Is that acceptable, or should point() in cfi_cmdset_0002 be opt-in?
Changes in v4:
- 1/4 also gates lpddr, map_ram and map_rom (compile-tested only).
- New 3/4: the per-device map sashiko asked for on v2 and v3.
- Rebased onto v7.4-rc1; Assisted-by dropped (an LLM helped write this series).
Earlier changes, in v4 numbering:
- v3: in 2/4, an XIP erase no longer lets a point through either.
- v2: in 2/4, a point no longer suspends an erase in progress; 4/4 checks the bank width before ioremap().
v3: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
Orgad Shaneh (4):
mtd: maps: only point() maps read through the simple accessors
mtd: cfi_cmdset_0002: implement point() for simple linear maps
MIPS: Octeon: flash: allocate the map per device
MIPS: Octeon: flash: use the simple map accessors without a shared eMMC
Documentation/filesystems/cramfs.rst | 11 ++- arch/mips/cavium-octeon/flash_setup.c | 73 +++++++++++---- drivers/mtd/chips/cfi_cmdset_0001.c | 2 +- drivers/mtd/chips/cfi_cmdset_0002.c | 167 +++++++++++++++++++++++++++++++++- 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 + 9 files changed, 245 insertions(+), 34 deletions(-)
Signature · 1 line
2.53.0
PATCH v4 1/4 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;
- 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.
---
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(-)
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/chips/map_ram.c +2 -2
@@ -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; }
drivers/mtd/chips/map_rom.c +4 -2
@@ -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;
drivers/mtd/lpddr/lpddr_cmds.c +1 -1
@@ -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; }
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 v4 2/4 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() 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.
---
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(-)
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 v4 3/4 MIPS: Octeon: flash: allocate the map per device
In reply to Orgad Shanehocteon_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.
---
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(-)
arch/mips/cavium-octeon/flash_setup.c +30 -19
@@ -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, };
Signature · 1 line
2.53.0
PATCH v4 4/4 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.
---
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(-)
arch/mips/cavium-octeon/flash_setup.c +31 -5
@@ -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" );
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v4 3/4] MIPS: Octeon: flash: allocate the map per device
In reply to Orgad ShanehThank 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 --
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 <[email protected]>
Quoted 13 lines
MIPS: Octeon: flash: allocate the map per device
octeon_flash_probe()fills in one staticmap_infofor 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 whosedo_map_probe()finds no chip also keeps itsioremap()mapping and still returns success.Allocate the map with
devm_kzalloc(), map it withdevm_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.
Quoted 5 lines
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. Setsuppress_bind_attrsto rule that out.Signed-off-by Orgad Shaneh <[email protected]>
[Severity: Low]
This fixes the static flash_map overwrite and probe error handling in octeon_flash_probe(). Should it include:
Signature · 5 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
[email protected]
AI reviewRe: [PATCH v4 2/4] mtd: cfi_cmdset_0002: implement point() for simple linear maps
In reply to Orgad ShanehThank 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() --
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 <[email protected]>
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.
Quoted 4 lines
drivers/mtd/chips/cfi_cmdset_0002.c +0
-0
[ ... ]
Quoted 70 lines
drivers/mtd/chips/cfi_cmdset_0002.c +66
-0@@ -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 ;
drivers/mtd/chips/cfi_cmdset_0002.c do { \ · line 1323
Quoted 10 lines
drivers/mtd/chips/cfi_cmdset_0002.c +10
-0+ + *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.
Signature · 5 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v4 2/4] mtd: cfi_cmdset_0002: implement point() for simple linear maps
Quoted 2 lines
Does
cfi_amdstd_point()leave *virt set to a non-NULL address whendo_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.
Re: [PATCH v4 3/4] MIPS: Octeon: flash: allocate the map per device
In reply to [email protected]Quoted 1 line
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.
[email protected]
AI reviewRe: [PATCH v4 4/4] MIPS: Octeon: flash: use the simple map accessors without a shared eMMC
In reply to Orgad ShanehThank 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() --
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 <[email protected]>
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.
Quoted 4 lines
arch/mips/cavium-octeon/flash_setup.c +0
-0
[ ... ]
Quoted 13 lines
arch/mips/cavium-octeon/flash_setup.c +4
-5@@ -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
arch/mips/cavium-octeon/flash_setup.c static int octeon_flash_probe(struct platform_device *pdev) · line 140
Quoted 10 lines
arch/mips/cavium-octeon/flash_setup.c +10
-0+* 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.
Signature · 5 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v4 4/4] MIPS: Octeon: flash: use the simple map accessors without a shared eMMC
Quoted 2 lines
Does calling
simple_map_init(map)breakmtd_point()on little-endian Octeon kernels (CONFIG_CPU_LITTLE_ENDIAN=y)?
It does. memcpy_fromio() stays correct there (unswizzled 64-bit reads, swizzled byte reads), but loads through a pointed address get no swizzle. v5 keeps the semaphore accessors on little-endian kernels.
Miquel, Richard, Vignesh: please don't apply v4; v5 with these three fixes follows in a few days.