mm/migrate_device: Cleanup up PMD Checks and warnings
Subsystems (2)
PATCH v2 1/1 mm/migrate_device: Cleanup up PMD Checks and warnings
Remove the odd VM_WARN_ON_FOLIO(!folio, folio) usage and replace it with a simpler VM_WARN_ON_ONCE(!folio) check.
Drop the redundant VM_WARN_ON_ONCE(!pmd_none(*pmdp) && !is_huge_zero_pmd(*pmdp)).
Refactor the PMD checks, making the control flow
clearer and avoiding duplicate condition checks.
---
Changes in v2:
- Removed additional check for pmd_present() as is_huge_zero_pmd() already checks for pmd_present().
Missed it in first version of this patch.
mm/migrate_device.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
mm/migrate_device.c +3 -6
@@ -807,8 +807,7 @@ static int migrate_vma_insert_huge_pmd_page(struct migrate_vma *migrate,bool flush = false;unsigned long i; -VM_WARN_ON_FOLIO (!folio, folio); -VM_WARN_ON_ONCE (!pmd_none (*pmdp) && !is_huge_zero_pmd (*pmdp)); +VM_WARN_ON_ONCE (!folio);if (!thp_vma_suitable_order (vma, addr,HPAGE_PMD_ORDER ))return -EINVAL ;
@@ -865,11 +864,9 @@ static int migrate_vma_insert_huge_pmd_page(struct migrate_vma *migrate,if (userfaultfd_missing (vma)) goto unlock_abort; -if (!pmd_none (*pmdp)) { -if (!is_huge_zero_pmd (*pmdp)) - goto unlock_abort; +if (is_huge_zero_pmd (*pmdp)) flush = true; - }else if (!pmd_none (*pmdp)) +else if (!pmd_none (*pmdp)) goto unlock_abort;add_mm_counter (vma->vm_mm,MM_ANONPAGES ,HPAGE_PMD_NR );
Signature · 1 line
2.43.0
Quoted 12 lines · Sunny Patel
Remove the odd
VM_WARN_ON_FOLIO(!folio, folio)usage and replace it with a simplerVM_WARN_ON_ONCE(!folio)check.Drop the redundant
VM_WARN_ON_ONCE(!pmd_none(*pmdp) && !is_huge_zero_pmd(*pmdp)).Refactor the PMD checks, making the control flow
clearer and avoiding duplicate condition checks.Signed-off-by Sunny Patel <[email protected]>---
Quoted 9 lines
Changes in v2:
- Removed additional check forpmd_present()asis_huge_zero_pmd()already checks forpmd_present().Missed it in first version of this patch.
mm/migrate_device.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
LGTM.
--
Best Regards,
Yan, Zi
Quoted 39 lines · Sunny Patel
Remove the odd
VM_WARN_ON_FOLIO(!folio, folio)usage and replace it with a simplerVM_WARN_ON_ONCE(!folio)check.Drop the redundant
VM_WARN_ON_ONCE(!pmd_none(*pmdp) && !is_huge_zero_pmd(*pmdp)).Refactor the PMD checks, making the control flow
clearer and avoiding duplicate condition checks.Signed-off-by Sunny Patel <[email protected]>---
Changes in v2:
- Removed additional check forpmd_present()asis_huge_zero_pmd()already checks forpmd_present().Missed it in first version of this patch.
mm/migrate_device.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)mm/migrate_device.c +1
-2@@ -807,8 +807,7 @@ static int migrate_vma_insert_huge_pmd_page(struct migrate_vma *migrate,bool flush = false;unsigned long i; -VM_WARN_ON_FOLIO (!folio, folio); -VM_WARN_ON_ONCE (!pmd_none (*pmdp) && !is_huge_zero_pmd (*pmdp)); +VM_WARN_ON_ONCE (!folio);if (!thp_vma_suitable_order (vma, addr,HPAGE_PMD_ORDER ))return -EINVAL ;@@ -865,11 +864,9 @@ static int migrate_vma_insert_huge_pmd_page(struct migrate_vma *migrate,if (userfaultfd_missing (vma)) goto unlock_abort;
mm/migrate_device.c static int migrate_vma_insert_huge_pmd_page(struct migrate_vma *migrate, · line 872
Quoted 10 lines
mm/migrate_device.c +2
-4-if (!pmd_none (*pmdp)) { -if (!is_huge_zero_pmd (*pmdp)) - goto unlock_abort; +if (is_huge_zero_pmd (*pmdp)) flush = true; - }else if (!pmd_none (*pmdp)) +else if (!pmd_none (*pmdp)) goto unlock_abort;add_mm_counter (vma->vm_mm,MM_ANONPAGES ,HPAGE_PMD_NR );
LGTM, feel free to add my
in the future versions.
---
Best Regards,
Huang, Ying
Quoted 11 lines · Sunny Patel
Remove the odd
VM_WARN_ON_FOLIO(!folio, folio)usage and replace it with a simplerVM_WARN_ON_ONCE(!folio)check.Drop the redundant
VM_WARN_ON_ONCE(!pmd_none(*pmdp) && !is_huge_zero_pmd(*pmdp)).Refactor the PMD checks, making the control flow
clearer and avoiding duplicate condition checks.Signed-off-by Sunny Patel <[email protected]>---
Signature · 3 lines
Cheers, David
Andrew Morton
maintainerQuoted 8 lines · On Sun, 19 Apr 2026 23:17:43 +0530 Sunny Patel <[email protected]>…
Remove the odd
VM_WARN_ON_FOLIO(!folio, folio)usage and replace it with a simplerVM_WARN_ON_ONCE(!folio)check.Drop the redundant
VM_WARN_ON_ONCE(!pmd_none(*pmdp) && !is_huge_zero_pmd(*pmdp)).Refactor the PMD checks, making the control flow
clearer and avoiding duplicate condition checks.
AI review might have found a bug in the surrounding code:
https://sashiko.dev/#/patchset/[email protected]
Quoted 8 lines · On Sun, 19 Apr 2026 23:17:43 +0530 Sunny Patel <[email protected]>…
Remove the odd
VM_WARN_ON_FOLIO(!folio, folio)usage and replace it with a simplerVM_WARN_ON_ONCE(!folio)check.Drop the redundant
VM_WARN_ON_ONCE(!pmd_none(*pmdp) && !is_huge_zero_pmd(*pmdp)).Refactor the PMD checks, making the control flow
clearer and avoiding duplicate condition checks.
AI review might have found a bug in the surrounding code:
https://sashiko.dev/#/patchset/[email protected]
After looking into the AI comment found two potential leak.
1. The goto should be unlock_abort instead of abort to ensure the spinlock is released.
2. The pgtable allocation at the top of the function is indeed not freed on the unlock_abort path. Will add a pte_free(vma->vm_mm, pgtable).
Since this patch is more of Cleanup on PMD checks and Warnings Is it ok if I send different patch to address this potential leak issues or need it in this revision itself?
Thanks,
Sunny Patel
Andrew Morton
maintainerQuoted 19 lines · On Fri, 24 Apr 2026 22:52:08 +0530 Sunny Patel <[email protected]>…
Quoted 8 lines · On Sun, 19 Apr 2026 23:17:43 +0530 Sunny Patel <[email protected]>…
Remove the odd
VM_WARN_ON_FOLIO(!folio, folio)usage and replace it with a simplerVM_WARN_ON_ONCE(!folio)check.Drop the redundant
VM_WARN_ON_ONCE(!pmd_none(*pmdp) && !is_huge_zero_pmd(*pmdp)).Refactor the PMD checks, making the control flow
clearer and avoiding duplicate condition checks.AI review might have found a bug in the surrounding code:
https://sashiko.dev/#/patchset/[email protected]After looking into the AI comment found two potential leak.
1. The goto should be
unlock_abortinstead of abort to ensure the spinlock is released.
Quoted 8 lines
2. The pgtable allocation at the top of the function is indeed not freed on the
unlock_abortpath. Will add apte_free(vma->vm_mm, pgtable).Since this patch is more of Cleanup on PMD checks and Warnings Is it ok if I send different patch to address this potential leak issues or need it in this revision itself?
A separate patch, please.
It's best to prepare the bugfix patch against current Linus mainline, then any cleanups come on top of the bugfix.
Thanks.
Quoted 8 lines · On Sun, 19 Apr 2026 23:17:43 +0530 Sunny Patel <[email protected]>…
Remove the odd
VM_WARN_ON_FOLIO(!folio, folio)usage and replace it with a simplerVM_WARN_ON_ONCE(!folio)check.Drop the redundant
VM_WARN_ON_ONCE(!pmd_none(*pmdp) && !is_huge_zero_pmd(*pmdp)).Refactor the PMD checks, making the control flow
clearer and avoiding duplicate condition checks.
AI review might have found a bug in the surrounding code:
https://sashiko.dev/#/patchset/[email protected]
NOTE: Ignore the previous message was sent on different Subject Header by mistake.
After looking into the AI comment found two potential leak.
1. The goto should be unlock_abort instead of abort to ensure the spinlock is released.
2. The pgtable allocation at the top of the function is indeed not freed on the unlock_abort path. Will add a pte_free(vma->vm_mm, pgtable).
Since this patch is more of Cleanup on PMD checks and Warnings Is it ok if I send different patch to address this potential leak issues or need it in this revision itself?
Thanks,
Sunny Patel
David Hildenbrand (Arm)
maintainerQuoted 22 lines · Sunny Patel
Quoted 8 lines · On Sun, 19 Apr 2026 23:17:43 +0530 Sunny Patel <[email protected]>…
Remove the odd
VM_WARN_ON_FOLIO(!folio, folio)usage and replace it with a simplerVM_WARN_ON_ONCE(!folio)check.Drop the redundant
VM_WARN_ON_ONCE(!pmd_none(*pmdp) && !is_huge_zero_pmd(*pmdp)).Refactor the PMD checks, making the control flow
clearer and avoiding duplicate condition checks.AI review might have found a bug in the surrounding code:
https://sashiko.dev/#/patchset/[email protected]NOTE: Ignore the previous message was sent on different Subject Header by mistake.
After looking into the AI comment found two potential leak.
1. The goto should be
unlock_abortinstead of abort to ensure the spinlock is released.
Quoted 8 lines
2. The pgtable allocation at the top of the function is indeed not freed on the
unlock_abortpath. Will add apte_free(vma->vm_mm, pgtable).Since this patch is more of Cleanup on PMD checks and Warnings Is it ok if I send different patch to address this potential leak issues or need it in this revision itself?
No, independent issues -> independent patches :)
Signature · 3 lines
Cheers, David
Quoted 1 line · David Hildenbrand
No, independent issues -> independent patches :)
Sent two individual patches for review as discussed.
1. https://lore.kernel.org/linux-mm/[email protected]/T/#u
2. https://lore.kernel.org/linux-mm/[email protected]/T/#u
Thanks,
Sunny Patel