The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] userfaultfd: wait on source PMD during UFFDIO_MOVE
@ 2026-07-05 13:12 Usama Arif
  2026-07-05 19:08 ` Rik van Riel
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Usama Arif @ 2026-07-05 13:12 UTC (permalink / raw)
  To: Andrew Morton, baohua, baolin.wang, david, dev.jain, lance.yang,
	liam, linux-kernel, linux-mm, ljs, npache, ryan.roberts,
	usama.arif, ziy, aarcange, shakeel.butt, hannes, riel,
	kernel-team
  Cc: sashiko-bot

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().

Reported-by: sashiko-bot <sashiko-bot@kernel.org>
Link: https://sashiko.dev/#/patchset/20260703173903.3789516-1-usama.arif%40linux.dev?part=8
Fixes: adef440691ba ("userfaultfd: UFFDIO_MOVE uABI")
Signed-off-by: Usama Arif <usama.arif@linux.dev>
---
 mm/huge_memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index bdd8635922f9..c0892cc533a9 100644
--- 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;
-- 
2.53.0-Meta


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] userfaultfd: wait on source PMD during UFFDIO_MOVE
  2026-07-05 13:12 [PATCH] userfaultfd: wait on source PMD during UFFDIO_MOVE Usama Arif
@ 2026-07-05 19:08 ` Rik van Riel
  2026-07-05 19:24 ` Andrew Morton
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Rik van Riel @ 2026-07-05 19:08 UTC (permalink / raw)
  To: Usama Arif, Andrew Morton, baohua, baolin.wang, david, dev.jain,
	lance.yang, liam, linux-kernel, linux-mm, ljs, npache,
	ryan.roberts, ziy, aarcange, shakeel.butt, hannes, kernel-team
  Cc: sashiko-bot

On Sun, 2026-07-05 at 06:12 -0700, Usama Arif 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().
> 
> Reported-by: sashiko-bot <sashiko-bot@kernel.org>
> Link:
> https://sashiko.dev/#/patchset/20260703173903.3789516-1-usama.arif%40linux.dev?part=8
> Fixes: adef440691ba ("userfaultfd: UFFDIO_MOVE uABI")
> Signed-off-by: Usama Arif <usama.arif@linux.dev>

Reviewed-by: Rik van Riel <riel@surriel.com>

-- 
All Rights Reversed.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] userfaultfd: wait on source PMD during UFFDIO_MOVE
  2026-07-05 13:12 [PATCH] userfaultfd: wait on source PMD during UFFDIO_MOVE Usama Arif
  2026-07-05 19:08 ` Rik van Riel
@ 2026-07-05 19:24 ` Andrew Morton
  2026-07-06  1:05 ` Baolin Wang
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Andrew Morton @ 2026-07-05 19:24 UTC (permalink / raw)
  To: Usama Arif
  Cc: baohua, baolin.wang, david, dev.jain, lance.yang, liam,
	linux-kernel, linux-mm, ljs, npache, ryan.roberts, ziy, aarcange,
	shakeel.butt, hannes, riel, kernel-team, sashiko-bot

On Sun,  5 Jul 2026 06:12:31 -0700 Usama Arif <usama.arif@linux.dev> 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@kernel.org>
> 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;


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] userfaultfd: wait on source PMD during UFFDIO_MOVE
  2026-07-05 13:12 [PATCH] userfaultfd: wait on source PMD during UFFDIO_MOVE Usama Arif
  2026-07-05 19:08 ` Rik van Riel
  2026-07-05 19:24 ` Andrew Morton
@ 2026-07-06  1:05 ` Baolin Wang
  2026-07-06  2:18 ` Lance Yang
  2026-07-06  9:00 ` David Hildenbrand (Arm)
  4 siblings, 0 replies; 6+ messages in thread
From: Baolin Wang @ 2026-07-06  1:05 UTC (permalink / raw)
  To: Usama Arif, Andrew Morton, baohua, david, dev.jain, lance.yang,
	liam, linux-kernel, linux-mm, ljs, npache, ryan.roberts, ziy,
	aarcange, shakeel.butt, hannes, riel, kernel-team
  Cc: sashiko-bot



On 7/5/26 9:12 PM, Usama Arif 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().
> 
> Reported-by: sashiko-bot <sashiko-bot@kernel.org>
> Link: https://sashiko.dev/#/patchset/20260703173903.3789516-1-usama.arif%40linux.dev?part=8
> Fixes: adef440691ba ("userfaultfd: UFFDIO_MOVE uABI")
> Signed-off-by: Usama Arif <usama.arif@linux.dev>
> ---

Good catch. Agree with Andrew that we should cc stable.
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] userfaultfd: wait on source PMD during UFFDIO_MOVE
  2026-07-05 13:12 [PATCH] userfaultfd: wait on source PMD during UFFDIO_MOVE Usama Arif
                   ` (2 preceding siblings ...)
  2026-07-06  1:05 ` Baolin Wang
@ 2026-07-06  2:18 ` Lance Yang
  2026-07-06  9:00 ` David Hildenbrand (Arm)
  4 siblings, 0 replies; 6+ messages in thread
From: Lance Yang @ 2026-07-06  2:18 UTC (permalink / raw)
  To: Usama Arif
  Cc: aarcange, ziy, david, baolin.wang, baohua, ryan.roberts, npache,
	ljs, dev.jain, linux-mm, sashiko-bot, Andrew Morton, linux-kernel,
	kernel-team, hannes, shakeel.butt, riel, liam



On 2026/7/5 21:12, Usama Arif 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()

Well spotted!

> 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().
> 
> Reported-by: sashiko-bot <sashiko-bot@kernel.org>
> Link: https://sashiko.dev/#/patchset/20260703173903.3789516-1-usama.arif%40linux.dev?part=8
> Fixes: adef440691ba ("userfaultfd: UFFDIO_MOVE uABI")
> Signed-off-by: Usama Arif <usama.arif@linux.dev>
> ---

As Andrew and Baolin pointed out, this should go to stable ;)

With that,

Reviewed-by: Lance Yang <lance.yang@linux.dev>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] userfaultfd: wait on source PMD during UFFDIO_MOVE
  2026-07-05 13:12 [PATCH] userfaultfd: wait on source PMD during UFFDIO_MOVE Usama Arif
                   ` (3 preceding siblings ...)
  2026-07-06  2:18 ` Lance Yang
@ 2026-07-06  9:00 ` David Hildenbrand (Arm)
  4 siblings, 0 replies; 6+ messages in thread
From: David Hildenbrand (Arm) @ 2026-07-06  9:00 UTC (permalink / raw)
  To: Usama Arif, Andrew Morton, baohua, baolin.wang, dev.jain,
	lance.yang, liam, linux-kernel, linux-mm, ljs, npache,
	ryan.roberts, ziy, aarcange, shakeel.butt, hannes, riel,
	kernel-team
  Cc: sashiko-bot

On 7/5/26 15:12, Usama Arif 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().
> 
> Reported-by: sashiko-bot <sashiko-bot@kernel.org>
> Link: https://sashiko.dev/#/patchset/20260703173903.3789516-1-usama.arif%40linux.dev?part=8
> Fixes: adef440691ba ("userfaultfd: UFFDIO_MOVE uABI")
> Signed-off-by: Usama Arif <usama.arif@linux.dev>
> ---
>  mm/huge_memory.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index bdd8635922f9..c0892cc533a9 100644
> --- 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;

Looks good and follows roughly what we do in __handle_mm_fault().

Acked-by: David Hildenbrand (Arm) <david@kernel.org>

-- 
Cheers,

David

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-07-06  9:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-05 13:12 [PATCH] userfaultfd: wait on source PMD during UFFDIO_MOVE Usama Arif
2026-07-05 19:08 ` Rik van Riel
2026-07-05 19:24 ` Andrew Morton
2026-07-06  1:05 ` Baolin Wang
2026-07-06  2:18 ` Lance Yang
2026-07-06  9:00 ` David Hildenbrand (Arm)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox