Re: [PATCH] mm/migrate_device: Cleanup up PMD Checks and warnings

SeongJae Park
2026-04-16T23:53:00Z

On Thu, 16 Apr 2026 21:44:15 +0200 "David Hildenbrand (Arm)" <david@kernel.org> wrote:

> On 4/14/26 16:13, Sunny Patel wrote:
[...]
> > @@ -865,12 +864,13 @@ static int migrate_vma_insert_huge_pmd_page(struct migrate_vma *migrate,
> > if (userfaultfd_missing(vma))
> > goto unlock_abort;
> >
> > - if (!pmd_none(*pmdp)) {
> > + if (pmd_present(*pmdp)) {
> > if (!is_huge_zero_pmd(*pmdp))
> > goto unlock_abort;
> > 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);
> > folio_add_new_anon_rmap(folio, vma, addr, RMAP_EXCLUSIVE);
>
> is_huge_zero_pmd() checks pmd_present(), so we didn't have a bug before.
>
> We could also do:
>
> if (is_huge_zero_pmd(*pmdp)) {
> flush = true;
> } else if (!pmd_none(*pmdp)) {
> goto unlock_abort;
> }

Then we could even further remove the braces and reduce one more line, nice!

Thanks,
SJ …