Re: [PATCH 06/13] mm/migrate_device: don't let go of the fault page
From: Gregory Price (Meta)
Date: Thu Nov 12 2026 - 13:06:12 EST
On 2026-11-11 18:13 +0000, Lorenzo Stoakes (ARM) wrote:
> From: Josef Bacik <josef@xxxxxxxxxxxxxx>
>
> When migrate_vma_split_folio() has split the folio of the fault page,
> the lock and the reference which the fault handler has taken are at the
> former head page.
>
> It then moves them to the folio which now holds the fault page, by
> taking a reference on and locking that folio, then unlocking and putting
> the former head.
>
> split_folio() has unlocked the new folio and has dropped its own
> reference on it, so until folio_get() nothing but the page table entry
> holds it.
>
> Only the mmap lock is held for read, which does not prevent another thread
> from zapping the entry with MADV_DONTNEED.
>
> If this happens the folio is freed which results in folio_get() taking a
> reference on a free device page, which the driver can hand out again at any
> time.
>
> In addition, folio_lock() can sleep here with the lock of the head page
> held.
>
> Utilise split_huge_page() which will leave the lock and reference at the
> fault page correctly.
>
> Fixes: 022a12deda53 ("mm/migrate_device: handle partially mapped folios during collection")
> Cc: <stable@xxxxxxxxxxxxxxx>
> Signed-off-by: Josef Bacik <josef@xxxxxxxxxxxxxx>
> [ ljs: tweaked commit message ]
> Signed-off-by: Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx>
I was able to reproduce/observe the ownership gap trivially.
With some effort i was able to generate folio_get()'s zero-ref BUG()
Can't say I understand the change well enough to give an R-by, but
the patch does resolve the issue.
Tested-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
--
~Gregory