Re: [PATCH v3 14/16] mm: remove is_hugetlb_entry_[migration, hwpoisoned]()

From: Lorenzo Stoakes

Date: Thu Nov 27 2025 - 12:42:32 EST


On Thu, Nov 27, 2025 at 06:29:39PM +0100, Vlastimil Babka wrote:
> On 11/10/25 23:21, Lorenzo Stoakes wrote:
> > We do not need to have explicit helper functions for these, it adds a level
> > of confusion and indirection when we can simply use software leaf entry
> > logic here instead and spell out the special huge_pte_none() case we must
> > consider.
> >
> > No functional change intended.
> >
> > Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@xxxxxxxxxx>
>
> Reviewed-by: Vlastimil Babka <vbabka@xxxxxxx>
>
> But seems to me a fixup is needed:
>
> > ---
> > fs/proc/task_mmu.c | 19 +++++----
> > include/linux/hugetlb.h | 2 -
> > mm/hugetlb.c | 91 +++++++++++++++++------------------------
> > mm/mempolicy.c | 17 +++++---
> > mm/migrate.c | 15 +++++--
> > 5 files changed, 69 insertions(+), 75 deletions(-)
> >
> > diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
> > index 6cb9e1691e18..3cdefa7546db 100644
> > --- a/fs/proc/task_mmu.c
> > +++ b/fs/proc/task_mmu.c
> > @@ -2499,22 +2499,23 @@ static void make_uffd_wp_huge_pte(struct vm_area_struct *vma,
> > unsigned long addr, pte_t *ptep,
> > pte_t ptent)
> > {
> > - unsigned long psize;
> > + const unsigned long psize = huge_page_size(hstate_vma(vma));
> > + softleaf_t entry;
> >
> > - if (is_hugetlb_entry_hwpoisoned(ptent) || pte_is_marker(ptent))
> > - return;
> > + if (huge_pte_none(ptent))
> > + set_huge_pte_at(vma->vm_mm, addr, ptep,
> > + make_pte_marker(PTE_MARKER_UFFD_WP), psize);
>
> Shouldn't we return here? Otherwise AFAICS we'll also reach the
> huge_ptep_modify_prot_commit() below and that wasn't happening before.

Yup, will reply with fix-patch, thanks.

>
> >
> > - psize = huge_page_size(hstate_vma(vma));
> > + entry = softleaf_from_pte(ptent);
> > + if (softleaf_is_hwpoison(entry) || softleaf_is_marker(entry))
> > + return;
> >
> > - if (is_hugetlb_entry_migration(ptent))
> > + if (softleaf_is_migration(entry))
> > set_huge_pte_at(vma->vm_mm, addr, ptep,
> > pte_swp_mkuffd_wp(ptent), psize);
> > - else if (!huge_pte_none(ptent))
> > + else
> > huge_ptep_modify_prot_commit(vma, addr, ptep, ptent,
> > huge_pte_mkuffd_wp(ptent));
> > - else
> > - set_huge_pte_at(vma->vm_mm, addr, ptep,
> > - make_pte_marker(PTE_MARKER_UFFD_WP), psize);
> > }
> > #endif /* CONFIG_HUGETLB_PAGE */
> >