-
Uncached Device-nGnRE Mapping for Parameter-Registered Devices:
When a phram device is configured dynamically via the sysfs attribute /sys/module/phram/parameters/phram (or through kernel module command-line arguments), execution flows through phram_param_call() $\rightarrow$ phram_setup() $\rightarrow$ register_device(NULL, name, start, len, erasesize). Because pdev is NULL:
struct device_node *np = pdev ? pdev->dev.of_node : NULL;
bool cached = np ? !of_property_read_bool(np, "no-map") : false;
new->cached is set to false.
In phram_map():
if (phram->cached)
addr = memremap(start, len, MEMREMAP_WB);
else
addr = (void __force *)ioremap(start, len);
The driver maps the physical RAM region using ioremap(), stripping the __iomem qualifier via (void __force *) and assigning it to mtd->priv. On ARM64, ioremap() sets the page translation attributes to PROT_DEVICE_nGnRE (memory attribute index MT_DEVICE_nGnRE = 4, as evidenced by the page table entry pte=0068000000000713 in the fault report).
-
Improper Access of I/O / Device Memory with Standard memcpy():
Memory mapped with PROT_DEVICE_nGnRE represents MMIO/Device memory. In the ARM architecture:
- Any unaligned access to Device memory is strictly prohibited and unconditionally causes an alignment fault (
FSC = 0x21).
- Load/store pair instructions (
ldp and stp) require natural alignment and generate faults on Device memory.
Despite the pointer referencing __iomem Device-nGnRE space, phram_read(), phram_write(), and phram_erase() use standard memory routines rather than their I/O counterparts:
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;
memcpy(buf, start + from, len);
*retlen = len;
return 0;
}
(Similarly, phram_write() uses memcpy() instead of memcpy_toio(), and phram_erase() uses memset() instead of memset_io().)
-
Triggering the Alignment Fault During MTD Registration:
During register_device() $\rightarrow$ mtd_device_register() $\rightarrow$ blktrans_notify_add() $\rightarrow$ ftl_add_mtd(), scan_header() attempts to detect an FTL partition by reading 68 bytes (sizeof(header) = 0x44) at offset 0:
err = mtd_read(part->mbd.mtd, offset, sizeof(header), &ret, (unsigned char *)&header);
This invokes phram_read() with from = 0 and len = 68 (0x44).
-
ARM64 memcpy Execution:
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 = 0xffff80009594b024
The 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.