Re: [PATCH] mm/hmm: account for subpage offsets in device-private PMDs
From: Aveline Noir
Date: Sun Nov 22 2026 - 09:53:46 EST
Hi Andrew,
On Sun, 22 Nov 2026 01:52:46 -0800 Andrew Morton wrote:
> Store the corresponding RAM backing page instead.
This avoids the oops on the first read through the second descriptor,
but leaves a stale backing page pointer after CPU faultback.
Since the mirror XArray entries don't take a page reference, they rely
on invalidation. When the CPU later faults the page back to RAM,
dmirror_interval_invalidate() skips MMU_NOTIFY_MIGRATE for the same
mdevice, and dmirror_devmem_fault_alloc_and_copy() only clears the
migrating descriptor's entry before the backing folio is freed. The
second descriptor still points to that freed backing page.
Reading the same page again through the second descriptor in QEMU
triggers a KASAN use-after-free in dmirror_do_read(), and the read
returns the stale data instead of what the CPU wrote.
The second descriptor's entry probably needs to be invalidated before
the backing page is freed, and it'd be nice to cover a second read
after faultback in the selftest too.
Thanks,
Aveline Noir