Skip to contentSkip to conversation

mm/migrate_device: fix spinlock leak in migrate_vma_insert_huge_pmd_page

PATCH Applied Sunny Patel 5 participants 5 messages Apr 25 – Apr 27

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/migrate_device: fix spinlock leak in migrate_vma_insert_huge_pmd_page

When check_stable_address_space() fails after the PMD spinlock has been acquired via pmd_lock(), the code jumps directly to the abort label, bypassing the spin_unlock() call in unlock_abort. This causes the PMD spinlock to be permanently held, leading to a deadlock.

Change the goto target from abort to unlock_abort to ensure the spinlock is always released on this error path.

---
 mm/migrate_device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/migrate_device.c +1 -1
index fbfe5715f635..ab49d4dcdb60 100644
@@ -850,7 +850,7 @@ static int migrate_vma_insert_huge_pmd_page(struct migrate_vma *migrate,
 	ptl = pmd_lock(vma->vm_mm, pmdp);
 	csa_ret = check_stable_address_space(vma->vm_mm);
 	if (csa_ret)
-		goto abort;
+		goto unlock_abort;
 
 	/*
 	 * Check for userfaultfd but do not deliver the fault. Instead,
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 13 lines · On Sat, 25 Apr 2026 19:05:27 +0530 Sunny Patel <[email protected]>…

When check_stable_address_space() fails after the PMD spinlock has been acquired via pmd_lock(), the code jumps directly to the abort label, bypassing the spin_unlock() call in unlock_abort. This causes the PMD spinlock to be permanently held, leading to a deadlock.

Change the goto target from abort to unlock_abort to ensure the spinlock is always released on this error path.

...

mm/migrate_device.c static int migrate_vma_insert_huge_pmd_page(struct migrate_vma *migrate, · line 856

Quoted 8 lines
mm/migrate_device.c +1 -1
@@ -850,7 +850,7 @@ static int migrate_vma_insert_huge_pmd_page(struct migrate_vma *migrate,
 	ptl = pmd_lock(vma->vm_mm, pmdp);
 	csa_ret = check_stable_address_space(vma->vm_mm);
 	if (csa_ret)
-		goto abort;
+		goto unlock_abort;
 
 	/*
 	 * Check for userfaultfd but do not deliver the fault. Instead,

whoops.

Fixes a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone device pages")
Acked-by
#2 lore raw
Quoted 21 lines · Andrew Morton
Quoted 19 lines · On Sat, 25 Apr 2026 19:05:27 +0530 Sunny Patel <[email protected]>…

When check_stable_address_space() fails after the PMD spinlock has been acquired via pmd_lock(), the code jumps directly to the abort label, bypassing the spin_unlock() call in unlock_abort. This causes the PMD spinlock to be permanently held, leading to a deadlock.

Change the goto target from abort to unlock_abort to ensure the spinlock is always released on this error path.

...

mm/migrate_device.c +1 -1
@@ -850,7 +850,7 @@ static int migrate_vma_insert_huge_pmd_page(struct migrate_vma *migrate,
 	ptl = pmd_lock(vma->vm_mm, pmdp);
 	csa_ret = check_stable_address_space(vma->vm_mm);
 	if (csa_ret)
-		goto abort;
+		goto unlock_abort;
 
Quoted 7 lines

mm/migrate_device.c static int migrate_vma_insert_huge_pmd_page(struct migrate_vma *migrate, · line 856

Quoted 2 lines
mm/migrate_device.c +0 -0
 	/*
 	 * Check for userfaultfd but do not deliver the fault. Instead,

whoops.

Fixes a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone device pages")

Thanks

reviewer Acked-by on v1 1/1
#3 lore raw
In reply to Sunny Patel
Quoted 5 lines · Sunny Patel

When check_stable_address_space() fails after the PMD spinlock has been acquired via pmd_lock(), the code jumps directly to the abort label, bypassing the spin_unlock() call in unlock_abort. This causes the PMD spinlock to be permanently held, leading to a deadlock.

Quoted 8 lines

Change the goto target from abort to unlock_abort to ensure the spinlock is always released on this error path.

---
 mm/migrate_device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

LGTM.

--
Best Regards,
Yan, Zi

maintainer Acked-by on v1 1/1
#4 lore raw
In reply to Sunny Patel
Quoted 10 lines · Sunny Patel

When check_stable_address_space() fails after the PMD spinlock has been acquired via pmd_lock(), the code jumps directly to the abort label, bypassing the spin_unlock() call in unlock_abort. This causes the PMD spinlock to be permanently held, leading to a deadlock.

Change the goto target from abort to unlock_abort to ensure the spinlock is always released on this error path.

---

Thanks!

Signature · 3 lines
Cheers,

David