Re: [PATCH 08/13] mm/migrate_device: fix ksmd oops on a migrated KSM page

From: Alistair Popple

Date: Wed Nov 11 2026 - 18:08:55 EST


On 2026-11-12 at 08:54 +1100, "David Hildenbrand (Arm)" <david@xxxxxxxxxx> wrote...
> On 11/11/26 19:13, Lorenzo Stoakes (ARM) wrote:
> > 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;
>
> In general, LGTM. I was just wondering if we could reject that earlier. because
> apparently we already allocated a destination folio :)

You could do it in migrate_vma_collect_pmd(), but that would prevent migration
of KSM pages to DEVICE_COHERENT pages. DEVICE_COHERENT pages are always in the
direct map and are by definition fine to look at, so I think it's better just to
do the check here.

Reviewed-by: Alistair Popple <apopple@xxxxxxxxxx>

> --
> Cheers,
>
> David