[PATCH 08/13] mm/migrate_device: fix ksmd oops on a migrated KSM page
From: Lorenzo Stoakes (ARM)
Date: Wed Nov 11 2026 - 13:25:30 EST
From: Chris Mason <mason@xxxxxxxxxx>
After a KSM page is migrated to device private memory, ksmd can oops,
and KSM then stops until reboot. A process that maps the page can also
loop in page faults when it next accesses the page.
The problem arises because KSM doesn't know not to try to look at device
private memory that does not exist in the direct map.
Disallow this from happening by explicitly testing for this scenario in
__migrate_device_pages().
Fixes: a5430dda8a3a ("mm/migrate: support un-addressable ZONE_DEVICE page in migration")
Cc: <stable@xxxxxxxxxxxxxxx>
Signed-off-by: Chris Mason <mason@xxxxxxxxxx>
[ ljs: tweak commit message, comment ]
Signed-off-by: Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx>
---
mm/migrate_device.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/mm/migrate_device.c b/mm/migrate_device.c
index 45e571dbfb4c..7ebd02ec303b 100644
--- a/mm/migrate_device.c
+++ b/mm/migrate_device.c
@@ -1205,6 +1205,15 @@ static void __migrate_device_pages(unsigned long *src_pfns,
}
+ /*
+ * KSM doesn't know not to try to read device private pages, so
+ * disallow the combination.
+ */
+ if (folio_is_device_private(newfolio) && folio_test_ksm(folio)) {
+ src_pfns[i] &= ~MIGRATE_PFN_MIGRATE;
+ goto next;
+ }
+
if (folio_is_device_private(newfolio) ||
folio_is_device_coherent(newfolio)) {
if (mapping) {
--
2.56.0