[PATCH v2 08/13] mm/migrate_device: fix ksmd oops on a migrated KSM page
From: Lorenzo Stoakes (ARM)
Date: Fri Nov 13 2026 - 16:47:10 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.
In addition, ksmd skips all device pages when it scans, so it drops its
rmap of a KSM page which was migrated to device private or device
coherent memory.
Disallow migrating a KSM page to either by explicitly testing for this
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, also refuse device coherent ]
Tested-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
Acked-by: Balbir Singh <balbirs@xxxxxxxxxx>
Reviewed-by: Alistair Popple <apopple@xxxxxxxxxx>
Signed-off-by: Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx>
---
mm/migrate_device.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/mm/migrate_device.c b/mm/migrate_device.c
index 45e571dbfb4c..141d60d27e90 100644
--- a/mm/migrate_device.c
+++ b/mm/migrate_device.c
@@ -1207,6 +1207,11 @@ static void __migrate_device_pages(unsigned long *src_pfns,
if (folio_is_device_private(newfolio) ||
folio_is_device_coherent(newfolio)) {
+ /* KSM does not scan or track device pages. */
+ if (folio_test_ksm(folio)) {
+ src_pfns[i] &= ~MIGRATE_PFN_MIGRATE;
+ goto next;
+ }
if (mapping) {
/*
* For now only support anonymous memory migrating to
--
2.56.0