BUG: unable to handle kernel paging request in phram_read
Subsystems (2)
syzbot
syzbotHello,
syzbot found the following issue on:
HEAD commit: ad3fc05c7e65 arm64: suspend: Only track cpuidle context fo.. git tree: git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci console output: https://syzkaller.appspot.com/x/log.txt?x=165de94e580000 kernel config: https://syzkaller.appspot.com/x/.config?x=4e8e6c1701ad8af2 dashboard link: https://syzkaller.appspot.com/bug?extid=ee09ee2112d03c35f1f7 compiler: Debian clang version 22.1.8 (1~deb13u4), Debian LLD 22.1.8 userspace arch: arm64 syz repro: https://syzkaller.appspot.com/x/repro.syz?x=1796373d580000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=13fbe5c3580000
Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/a30beb3b2b82/disk-ad3fc05c.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/2eaac3d8da90/vmlinux-ad3fc05c.xz
kernel image: https://storage.googleapis.com/syzbot-assets/212a161a069b/Image-ad3fc05c.gz.xz
The issue was bisected by AI to candidate commits (most relevant first):
1da177e4c3f4 Linux-2.6.12-rc2f3d45ac21e46 mtd: phram: Module parameters add writable permissions 285133040e6c arm64: Import latest memcpy()/memmove() implementation
AI reasoning: https://syzkaller.appspot.com/ai_job?id=c053ce4a-8b95-428d-87ad-63a0065b8ed9
AI-generated root cause summary:
In drivers/mtd/devices/phram.c, registering a phram device via module parameter or sysfs (/sys/module/phram/parameters/phram) invokes register_device() with pdev = NULL, which causes new->cached to be false. As a result, phram_map() maps the physical memory region using ioremap() (mapped as PROT_DEVICE_nGnRE on arm64) and forces the pointer into mtd->priv, yet phram_read(), phram_write(), and phram_erase() access it using standard memcpy() and memset() instead of I/O memory accessors (like memcpy_fromio()). When scanning partition headers (e.g., ftl_add_mtd() reading a 68-byte header via mtd_read()), arm64's memcpy implementation issues pair-load (ldp) instructions at unaligned offsets, which unconditionally triggers an alignment fault (FSC = 0x21) on Device memory and crashes the kernel.
full analysis: https://syzkaller.appspot.com/x/ai_root_cause?x=ee09ee2112d03c35f1f7
IMPORTANT: if you fix the issue, please add the following tag to the commit:
Unable to handle kernel paging request at virtual address ffff800090ffe024 KASAN: probably user-memory-access in range [0x0000000487ff0120-0x0000000487ff0127]
Mem abort info:
ESR = 0x0000000096000021
EC = 0x25: DABT (current EL), IL = 32 bits
SET = 0, FnV = 0
EA = 0, S1PTW = 0
FSC = 0x21: alignment fault
Data abort info:
ISV = 0, ISS = 0x00000021, ISS2 = 0x00000000
CM = 0, WnR = 0, TnD = 0, TagAccess = 0
GCS = 0, Overlay = 0, DirtyBit = 0
swapper pgtable: 4k pages, 48-bit VAs, pgdp=00000002193b5000
[ffff800090ffe024] pgd=0000000000000000, p4d=100000021f6f0003, pud=100000021f6f1003, pmd=10000001013e1403, pte=0068000000000713
Internal error: Oops: 0000000096000021 [#1] SMP Modules linked in: CPU: 0 UID: 0 PID: 4957 Comm: syz.0.17 Not tainted syzkaller #0 PREEMPT Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026 pstate: 23400005 (nzCv daif +PAN -UAO +TCO +DIT -SSBS BTYPE=--) pc : __pi_memcpy_generic+0x98/0x22c arch/arm64/lib/memcpy.S:114 lr : __asan_memcpy+0x68/0x84 mm/kasan/shadow.c:109
sp : ffff800095836fc0
x29: ffff800095836fc0 x28: 1fffe00019f6102f x27: ffff0000cfb08000
x26: dfff800000000000 x25: ffff800095837150 x24: dfff800000000000
x23: ffff0000cfb08190 x22: ffff800082ab0064 x21: ffff800095837370
x20: ffff800090ffe000 x19: 0000000000000044 x18: 1fffe000359cf228
x17: 4a414d0064746d3d x16: 4d45545359534255 x15: ffff800080d0603c
x14: 0000000000000001 x13: 0000000000000009 x12: 0000000000000004
x11: ffff700012b06e76 x10: ffff700012b06e76 x9 : ffffffffffffffff x8 : ffffffffffffffff x7 : ffffffffffffffff x6 : ffffffff14000400 x5 : ffff8000958373b4 x4 : ffff800090ffe044 x3 : ffff800082ab0064 x2 : 0000000000000044 x1 : ffff800090ffe000 x0 : ffff800095837370
Call trace: __pi_memcpy_generic+0x98/0x22c arch/arm64/lib/memcpy.S:113 (P) phram_read+0x64/0x98 drivers/mtd/devices/phram.c:70 mtd_read_oob_std+0x180/0x19c drivers/mtd/mtdcore.c:1702 mtd_read_oob+0x1fc/0x4ec drivers/mtd/mtdcore.c:1811 mtd_read+0xd0/0x1a8 drivers/mtd/mtdcore.c:1603 scan_header drivers/mtd/ftl.c:164 [inline] ftl_add_mtd+0x1e8/0x16d8 drivers/mtd/ftl.c:1017 blktrans_notify_add+0xa8/0xf8 drivers/mtd/mtd_blkdevs.c:469 add_mtd_device+0xedc/0x1504 drivers/mtd/mtdcore.c:828 mtd_device_parse_register+0x660/0x7a0 drivers/mtd/mtdcore.c:1156 register_device+0x340/0x51c drivers/mtd/devices/phram.c:162 phram_setup+0x354/0x4fc drivers/mtd/devices/phram.c:324 phram_param_call+0x34/0x90 drivers/mtd/devices/phram.c:349 param_attr_store+0x144/0x1bc kernel/params.c:591 module_attr_store+0x6c/0x94 kernel/params.c:906 sysfs_kf_write+0xe0/0x108 fs/sysfs/file.c:145 kernfs_fop_write_iter+0x260/0x3b8 fs/kernfs/file.c:345 new_sync_write fs/read_write.c:595 [inline] vfs_write+0x51c/0xa0c fs/read_write.c:687 ksys_write+0x12c/0x228 fs/read_write.c:739 __do_sys_write fs/read_write.c:750 [inline] __se_sys_write fs/read_write.c:747 [inline] __arm64_sys_write+0x84/0x98 fs/read_write.c:747 __invoke_syscall arch/arm64/kernel/syscall.c:35 [inline] invoke_syscall+0x98/0x244 arch/arm64/kernel/syscall.c:49 el0_svc_common+0xec/0x23c arch/arm64/kernel/syscall.c:121 do_el0_svc+0x4c/0x5c arch/arm64/kernel/syscall.c:140 el0_svc+0x60/0x1d8 arch/arm64/kernel/entry-common.c:797 el0t_64_sync_handler+0x44/0x104 arch/arm64/kernel/entry-common.c:816 el0t_64_sync+0x198/0x19c arch/arm64/kernel/entry.S:606 Code: d65f03c0 d503201f a9401c26 a9412428 (a97e2c8a) ---[ end trace 0000000000000000 ]--- ---------------- Code disassembly (best guess): 0: d65f03c0 ret 4: d503201f nop 8: a9401c26 ldp x6, x7, [x1] c: a9412428 ldp x8, x9, [x1, #16] * 10: a97e2c8a ldp x10, x11, [x4, #-32] <-- trapping instruction
---
This report is generated by a bot. It may contain errors. See https://goo.gl/tpsmEJ for more information about syzbot. syzbot engineers can be reached at [email protected].
syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot. For information about AI bisection see: https://goo.gl/tpsmEJ#ai-bisection
If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title
If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)
If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report
If you want to undo deduplication, reply with:
#syz undup
PATCH 1/1 mtd: Use I/O memory accessors when in an uncached
When registering a phram device via module parameter or sysfs invokes register_device() with pdev = NULL, which causes new->cached to be false. As a result, phram_map() maps the physical memory region using ioremap() (mapped as PROT_DEVICE_nGnRE on arm64) and forces the pointer into mtd-> priv, yet phram_read(), phram_write(), and phram_erase() access it using standard memcpy() and memset() instead of I/O memory accessors (like memcpy_fromio()). When scanning partition headers (e.g., ftl_add_mtd() reading a 68-byte header via mtd_read()), arm64's memcpy implementation issues pair-load (ldp) instructions at unaligned offsets, which triggers an alignment fault (FSC = 0x21) on Device memory and crashes the kernel.
In phram_read/write/erase(), standard memory accessors are used when in a cached; otherwise, I/O memory accessors are used.
--- drivers/mtd/devices/phram.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
drivers/mtd/devices/phram.c +18 -3
@@ -43,8 +43,13 @@ static LIST_HEAD(phram_list);static int phram_erase (struct mtd_info *mtd,struct erase_info *instr) {u_char *start = mtd->priv; +struct device_node *np =mtd_get_of_node (mtd); +bool cached = np ? !of_property_read_bool (np,"no-map" ) : false; -memset (start + instr->addr,0xff , instr->len); +if (cached) +memset (start + instr->addr,0xff , instr->len); +else +memset_io (start + instr->addr,0xff , instr->len);return 0 ; }
@@ -66,8 +71,13 @@ static int phram_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf) { u_char *start = mtd->priv; +struct device_node *np =mtd_get_of_node (mtd); +bool cached = np ? !of_property_read_bool (np,"no-map" ) : false; -memcpy (buf, start + from, len); +if (cached) +memcpy (buf, start + from, len); +else +memcpy_fromio (buf, start + from, len); *retlen = len;return 0 ; }
@@ -76,8 +86,13 @@ static int phram_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf) { u_char *start = mtd->priv; +struct device_node *np =mtd_get_of_node (mtd); +bool cached = np ? !of_property_read_bool (np,"no-map" ) : false; -memcpy (start + to, buf, len); +if (cached) +memcpy (start + to, buf, len); +else +memcpy_fromio (start + to, buf, len); *retlen = len;return 0 ; }
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH] mtd: Use I/O memory accessors when in an uncached
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [High] mtd: phram: wrong I/O accessor memcpy_fromio() used in phram_write() - [Low] mtd: phram: missing…
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [High] mtd: phram: wrong I/O accessor memcpy_fromio() used in phram_write()
- [Low] mtd: phram: missing __iomem casts in phram_erase(), phram_read(), phram_write()
- [Low] mtd: phram: redundant DT lookup on every I/O instead of using phram->cached
--
commit 652c886e91fa425e4122f1ebcb9ef0f2b874fd28
Author: Edward Adam Davis <[email protected]>
mtd: Use I/O memory accessors when in an uncached
This commit uses I/O memory accessors instead of standard memset() and memcpy() in phram_erase(), phram_read(), and phram_write() when the phram mapping is uncached.
drivers/mtd/devices/phram.c static LIST_HEAD(phram_list); · line 47
Quoted 10 lines
drivers/mtd/devices/phram.c +2
-0@@ -43,8 +43,13 @@ static LIST_HEAD(phram_list);static int phram_erase (struct mtd_info *mtd,struct erase_info *instr) {u_char *start = mtd->priv; +struct device_node *np =mtd_get_of_node (mtd); +bool cached = np ? !of_property_read_bool (np,"no-map" ) : false;
[Severity: Low]
Can phram_erase(), phram_read(), and phram_write() read container_of(mtd, struct phram_mtd_list, mtd)->cached instead of calling of_property_read_bool() on every I/O? register_device() already computes this flag once and stores it in new->cached.
drivers/mtd/devices/phram.c static LIST_HEAD(phram_list); · line 52
Quoted 5 lines
drivers/mtd/devices/phram.c +4
-1-memset (start + instr->addr,0xff , instr->len); +if (cached) +memset (start + instr->addr,0xff , instr->len); +else +memset_io (start + instr->addr,0xff , instr->len);
[Severity: Low]
Since start is u_char *, passing start + offset to memset_io(), memcpy_fromio(), and memcpy_toio() without a (void __iomem *) cast triggers sparse address-space warnings across phram_erase(), phram_read(), and phram_write().
Quoted 20 lines
drivers/mtd/devices/phram.c +6
-1return 0 ; }@@ -66,8 +71,13 @@ static int phram_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf) { u_char *start = mtd->priv; +struct device_node *np =mtd_get_of_node (mtd); +bool cached = np ? !of_property_read_bool (np,"no-map" ) : false; -memcpy (buf, start + from, len); +if (cached) +memcpy (buf, start + from, len); +else +memcpy_fromio (buf, start + from, len); *retlen = len;return 0 ; }@@ -76,8 +86,13 @@ static int phram_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
drivers/mtd/devices/phram.c static int phram_write(struct mtd_info *mtd, loff_t to, size_t len, · line 95
Quoted 10 lines
drivers/mtd/devices/phram.c +6
-1{u_char *start = mtd->priv; +struct device_node *np =mtd_get_of_node (mtd); +bool cached = np ? !of_property_read_bool (np,"no-map" ) : false; -memcpy (start + to, buf, len); +if (cached) +memcpy (start + to, buf, len); +else +memcpy_fromio (start + to, buf, len);
[Severity: High]
Should phram_write() call memcpy_toio() instead of memcpy_fromio()?
memcpy_fromio(dst, src, count) treats src (buf) as __iomem and dst (start + to) as normal RAM: it aligns src rather than dst and writes to dst via put_unaligned(). When start + to is not aligned to sizeof(long), writing to an uncached phram device issues unaligned word stores to Device memory and triggers an alignment fault on arm64.
Signature · 5 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v2 1/1 mtd: Use I/O memory accessors when in an uncached
When registering a phram device via module parameter or sysfs invokes register_device() with pdev = NULL, which causes new->cached to be false. As a result, phram_map() maps the physical memory region using ioremap() (mapped as PROT_DEVICE_nGnRE on arm64) and forces the pointer into mtd-> priv, yet phram_read(), phram_write(), and phram_erase() access it using standard memcpy() and memset() instead of I/O memory accessors (like memcpy_fromio()). When scanning partition headers (e.g., ftl_add_mtd() reading a 68-byte header via mtd_read()), arm64's memcpy implementation issues pair-load (ldp) instructions at unaligned offsets, which triggers an alignment fault (FSC = 0x21) on Device memory and crashes the kernel.
In phram_read/write/erase(), standard memory accessors are used when in a cached; otherwise, I/O memory accessors are used.
---
v1 -> v2: use phram_mtd_list cached, add void __iomem* and write use toio
drivers/mtd/devices/phram.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)
drivers/mtd/devices/phram.c +19 -3
@@ -43,8 +43,14 @@ static LIST_HEAD(phram_list);static int phram_erase (struct mtd_info *mtd,struct erase_info *instr) {u_char *start = mtd->priv; +struct phram_mtd_list *phram = + container_of(mtd, struct phram_mtd_list, mtd); -memset (start + instr->addr,0xff , instr->len); +if (phram->cached) +memset (start + instr->addr,0xff , instr->len); +else +memset_io ((void __iomem *)start + instr->addr,0xff , + instr->len);return 0 ; }
@@ -66,8 +72,13 @@ static int phram_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf) { u_char *start = mtd->priv; +struct phram_mtd_list *phram = + container_of(mtd, struct phram_mtd_list, mtd); -memcpy (buf, start + from, len); +if (phram->cached) +memcpy (buf, start + from, len); +else +memcpy_fromio (buf, (void __iomem *)start + from, len); *retlen = len;return 0 ; }
@@ -76,8 +87,13 @@ static int phram_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf) { u_char *start = mtd->priv; +struct phram_mtd_list *phram = + container_of(mtd, struct phram_mtd_list, mtd); -memcpy (start + to, buf, len); +if (phram->cached) +memcpy (start + to, buf, len); +else +memcpy_toio ((void __iomem *)start + to, buf, len); *retlen = len;return 0 ; }
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v2] mtd: Use I/O memory accessors when in an uncached
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] mtd: phram: uncached ioremap() pointer exposed via phram_point() - [Low] mtd: phram: inaccurate…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] mtd: phram: uncached ioremap() pointer exposed via phram_point()
- [Low] mtd: phram: inaccurate Fixes trailer and truncated commit message
--
commit 54b14d07ef014deae72f6fbc65c025f6ac913af6
Author: Edward Adam Davis <[email protected]>
Quoted 13 lines
mtd: Use I/O memory accessors when in an uncached
When registering a phram device via module parameter or sysfs invokes
register_device()with pdev = NULL, which causesnew->cachedto be false. As a result,phram_map()maps the physical memory region usingioremap()(mapped asPROT_DEVICE_nGnREon arm64) and forces the pointer into mtd-> priv, yetphram_read(),phram_write(), andphram_erase()access it using standardmemcpy()andmemset()instead of I/O memory accessors (likememcpy_fromio()). When scanning partition headers (e.g.,ftl_add_mtd()reading a 68-byte header viamtd_read()), arm64's memcpy implementation issues pair-load (ldp) instructions at unaligned offsets, which triggers an alignment fault (FSC =0x21) on Device memory and crashes the kernel.
Quoted 8 lines
In phram_read/write/erase(), standard memory accessors are used when in a cached; otherwise, I/O memory accessors are used.
Fixes f3d45ac21e46 ("mtd: phram: Module parameters add writable permissions")Fixes 285133040e6c ("arm64: Import latest memcpy()/memmove() implementation")Reported-by [email protected]Signed-off-by Edward Adam Davis <[email protected]>
[Severity: Low]
Are the Fixes tags accurate here? Calling memcpy() on an __iomem pointer from ioremap() is a phram bug rather than a bug in 285133040e6c ("arm64:
Import latest memcpy()/memmove() implementation"), and this patch branches on phram->cached, which was added in 9401911f2d9f ("mtd: phram: Allow cached mappings").
Also, the subject ("mtd: Use I/O memory accessors when in an uncached") and body ("when in a cached") are missing the "mtd: phram:" prefix and the trailing noun (such as "mapping").
Quoted 25 lines
drivers/mtd/devices/phram.c +8
-1@@ -43,8 +43,14 @@ static LIST_HEAD(phram_list);static int phram_erase (struct mtd_info *mtd,struct erase_info *instr) {u_char *start = mtd->priv; +struct phram_mtd_list *phram = + container_of(mtd, struct phram_mtd_list, mtd); -memset (start + instr->addr,0xff , instr->len); +if (phram->cached) +memset (start + instr->addr,0xff , instr->len); +else +memset_io ((void __iomem *)start + instr->addr,0xff , + instr->len);return 0 ; }@@ -66,8 +72,13 @@ static int phram_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf) { u_char *start = mtd->priv; + struct phram_mtd_list *phram =
drivers/mtd/devices/phram.c static int phram_read(struct mtd_info *mtd, loff_t from, size_t len, · line 84
Quoted 10 lines
drivers/mtd/devices/phram.c +5
-1+ container_of(mtd, struct phram_mtd_list, mtd); -memcpy (buf, start + from, len); +if (phram->cached) +memcpy (buf, start + from, len); +else +memcpy_fromio (buf, (void __iomem *)start + from, len); *retlen = len;return 0 ; }
[Severity: High]
Does phram_point() still expose the uncached ioremap() pointer in mtd->priv to callers that use normal memcpy() on it?
Between phram_erase() and phram_read(), phram_point() remains unchanged and is unconditionally wired up in register_device():
drivers/mtd/devices/phram.c:phram_point() {
*virt = mtd->priv + from;
*retlen = len;
return 0;
}Callers of mtd_point() expect normal direct-accessible memory and bypass mtd_read(). For example, mounting cramfs or jffs2 on an uncached phram device succeeds in mtd_point() and runs memcpy() directly on the returned pointer (such as the 76-byte superblock read in cramfs_read_super()), triggering the same alignment fault on arm64 Device memory. Should _point and _unpoint only be registered (or phram_point() return -EOPNOTSUPP) when phram->cached is false?
Signature · 5 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Miquel Raynal
maintainerRe: [PATCH v2] mtd: Use I/O memory accessors when in an uncached
Hi Edward,
Quoted 6 lines · On 20/11/2026 at 05:35:32 GMT, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] mtd: phram: uncachedioremap()pointer exposed viaphram_point()
- [Low] mtd: phram: inaccurate Fixes trailer and truncated commit message
These issues look plausible, I'll let you answer them.
Thanks,
Miquèl
PATCH v2 1/1 mtd: Use I/O memory accessors when in an uncached
Quoted 4 lines · Miquel Raynal
Quoted 4 lines
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] mtd: phram: uncachedioremap()pointer exposed viaphram_point()
One point needs correction:_point and _unpoint should only be registered when phram->cached is true, because the I/O map is used exclusively when the mapping is uncached.
Quoted 2 lines
Quoted 2 lines
- [Low] mtd: phram: inaccurate Fixes trailer and truncated commit message
I'll update the subject in the v3;
285133040e6c ("arm64: Import latest memcpy()/memmove() implementation") In ARM64's __pi_memcpy_generic (arch/arm64/lib/memcpy.S), copies between 33 and 128 bytes branch to L(copy32_128):
L(copy32_128):
ldp A_l, A_h, [src]
ldp B_l, B_h, [src, 16]
ldp C_l, C_h, [srcend, -32]Here:
src = 0xffff80009594b000
count = 0x44
srcend = src + count = 0xffff80009594b044
srcend - 32 = 0xffff80009594b024The instruction ldp x10, x11, [x4, #-32] attempts a 16-byte pair load from address 0xffff80009594b024, which is only 4-byte aligned (offset 0x24). Because the address points into Device-nGnRE memory, the MMU generates a Data Abort alignment fault (ESR = 0x96000021, FSC = 0x21), leading to the reported kernel Oops.
It was introduced by commit 285133040e6c, so I add the Fixes tag for 285133040e6c.
Quoted 2 lines
These issues look plausible, I'll let you answer them.
BR,
Edward
PATCH v3 1/1 mtd: phram: Use I/O memory accessors when in uncached mappings
When registering a phram device via module parameter or sysfs invokes register_device() with pdev = NULL, which causes new->cached to be false. As a result, phram_map() maps the physical memory region using ioremap() (mapped as PROT_DEVICE_nGnRE on arm64) and forces the pointer into mtd-> priv, yet phram_read(), phram_write(), and phram_erase() access it using standard memcpy() and memset() instead of I/O memory accessors (like memcpy_fromio()). When scanning partition headers (e.g., ftl_add_mtd() reading a 68-byte header via mtd_read()), arm64's memcpy implementation issues pair-load (ldp) instructions at unaligned offsets, which triggers an alignment fault (FSC = 0x21) on Device memory and crashes the kernel.
phram_point() exposes a uncached pointer that obtained via ioremap() in mtd->priv, which leads callers to perform standard memcpy() on it.
In phram_read/write/erase(), standard memory accessors are used when in a cached; otherwise, I/O memory accessors are used. Only register _point and __unpoint when cached mapping.
---
v1 -> v2: use phram_mtd_list cached, add void __iomem* and write use toio v2 -> v3: update subject, conditionally register _point and _unpoint
drivers/mtd/devices/phram.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-)
drivers/mtd/devices/phram.c +23 -5
@@ -43,8 +43,14 @@ static LIST_HEAD(phram_list);static int phram_erase (struct mtd_info *mtd,struct erase_info *instr) {u_char *start = mtd->priv; +struct phram_mtd_list *phram = + container_of(mtd, struct phram_mtd_list, mtd); -memset (start + instr->addr,0xff , instr->len); +if (phram->cached) +memset (start + instr->addr,0xff , instr->len); +else +memset_io ((void __iomem *)start + instr->addr,0xff , + instr->len);return 0 ; }
@@ -66,8 +72,13 @@ static int phram_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf) { u_char *start = mtd->priv; +struct phram_mtd_list *phram = + container_of(mtd, struct phram_mtd_list, mtd); -memcpy (buf, start + from, len); +if (phram->cached) +memcpy (buf, start + from, len); +else +memcpy_fromio (buf, (void __iomem *)start + from, len); *retlen = len;return 0 ; }
@@ -76,8 +87,13 @@ static int phram_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf) { u_char *start = mtd->priv; +struct phram_mtd_list *phram = + container_of(mtd, struct phram_mtd_list, mtd); -memcpy (start + to, buf, len); +if (phram->cached) +memcpy (start + to, buf, len); +else +memcpy_toio ((void __iomem *)start + to, buf, len); *retlen = len;return 0 ; }
@@ -147,8 +163,10 @@ static int register_device(struct platform_device *pdev, const char *name, new->mtd.size = len; new->mtd.flags =MTD_CAP_RAM ; new->mtd._erase = phram_erase; - new->mtd._point = phram_point; - new->mtd._unpoint = phram_unpoint; +if (new->cached) { + new->mtd._point = phram_point; + new->mtd._unpoint = phram_unpoint; + } new->mtd._read = phram_read; new->mtd._write = phram_write; new->mtd.owner =THIS_MODULE ;
Signature · 1 line
2.43.0