Re: [PATCH] userfaultfd: wait on source PMD during UFFDIO_MOVE
From: Andrew Morton
Date: Sun Jul 05 2026 - 15:24:56 EST
On Sun, 5 Jul 2026 06:12:31 -0700 Usama Arif <usama.arif@xxxxxxxxx> wrote:
> move_pages_huge_pmd() snapshots src_pmdval under src_ptl, drops the lock,
> and, for migration entries, waits with pmd_migration_entry_wait().
>
> Passing &src_pmdval is wrong. pmd_migration_entry_wait() must lock and
> re-read the real page-table PMD; on split-PMD-lock kernels, a stack
> address also resolves to the wrong lock. softleaf_entry_wait_on_locked()
> then waits without a folio reference, which is safe only while serialized
> against migration-entry removal by the real PT lock.
>
> Pass src_pmd, matching __handle_mm_fault() and hmm_vma_walk_pmd().
Thanks.
> Reported-by: sashiko-bot <sashiko-bot@xxxxxxxxxx>
> Link: https://sashiko.dev/#/patchset/20260703173903.3789516-1-usama.arif%40linux.dev?part=8
Sashiko says "wild spinlock acquisition and memory corruption", so I'll
add a cc:stable to this.
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -2775,7 +2775,7 @@ int move_pages_huge_pmd(struct mm_struct *mm, pmd_t *dst_pmd, pmd_t *src_pmd, pm
> if (!pmd_trans_huge(src_pmdval)) {
> spin_unlock(src_ptl);
> if (pmd_is_migration_entry(src_pmdval)) {
> - pmd_migration_entry_wait(mm, &src_pmdval);
> + pmd_migration_entry_wait(mm, src_pmd);
> return -EAGAIN;
> }
> return -ENOENT;