Re: [PATCH] mm/migrate_device: use locked folio in migrate_device_{range,pfns}()

From: David Hildenbrand (Arm)

Date: Wed Nov 25 2026 - 17:42:07 EST


On 11/25/26 23:27, Elkin Cruz wrote:
> migrate_device_range() and migrate_device_pfns() read a speculative
> folio pointer via page_folio() prior to taking a reference or lock in
> migrate_device_pfn_lock(). If the page splits or changes compound state
> before lock acquisition, folio_nr_pages(folio) inspects stale state and
> the nr > npages - i error path calls unpin_anon_rmap(), folio_unlock(),
> and folio_put() on the unowned speculative pointer while leaking the
> reference and lock on the folio actually locked by
> migrate_device_pfn_lock().
>
> Return the referenced, locked folio directly from
> migrate_device_pfn_lock() and skip unlocked entries cleanly.
>
> Fixes: dc41e961a269 ("mm/migrate_device: avoid out-of-bounds writes for compound folios")
> Fixes: a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone device pages")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Elkin Cruz <elkin@xxxxxxxxxx>
> ---
>
> I am trying out new Clang static analysis checks for kernel bug
> classes, and they flagged this code as possibly buggy. The findings
> were triaged/fixed and commit descriptions were drafted with help of AI,
> then checked against linux-next (not runtime-tested on hardware).

Before you send any more: if you cannot reproduce it in the tree, don't report it.

So can this here be reproduced?

We're very interested in real bugs, but not in theoretical ones.

--
Cheers,

David