Re: [PATCH 02/12] mm: Convert pXd_devmap checks to vma_is_dax

Alistair Popple
2025-06-12T06:55:31Z

On Fri, May 30, 2025 at 11:37:21AM +0200, David Hildenbrand wrote:
> On 29.05.25 08:32, Alistair Popple wrote:
> > Currently dax is the only user of pmd and pud mapped ZONE_DEVICE
> > pages. Therefore page walkers that want to exclude DAX pages can check
> > pmd_devmap or pud_devmap. However soon dax will no longer set PFN_DEV,
> > meaning dax pages are mapped as normal pages.
> >
> > Ensure page walkers that currently use pXd_devmap to skip DAX pages
> > continue to do so by adding explicit checks of the VMA instead.
> >
> > Signed-off-by: Alistair Popple <apopple@nvidia.com>
> > ---
> > fs/userfaultfd.c | 2 +-
> > mm/hmm.c | 2 +-
> > mm/userfaultfd.c | 2 +-
> > 3 files changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
> > index 22f4bf9..de671d3 100644
> > --- a/fs/userfaultfd.c
> > +++ b/fs/userfaultfd.c
> > @@ -304,7 +304,7 @@ static inline bool userfaultfd_must_wait(struct userfaultfd_ctx *ctx,
> > goto out;
> > ret = false;
> > - if (!pmd_present(_pmd) || pmd_devmap(_pmd))
> > + if (!pmd_present(_pmd) || vma_is_dax(vmf->vma))
> > goto out;
> > if (pmd_trans_huge(_pmd)) {
> > diff --git a/mm/hmm.c b/mm/hmm.c
> > index 082f7b7..db12c0a 100644
> > --- a/mm/hmm.c
> > +++ b/mm/hmm.c
> > @@ -429,7 +429,7 @@ static int hmm_vma_walk_pud(pud_t *pudp, unsigned long start, unsigned long end,
> > return hmm_vma_walk_hole(start, end, -1, walk);
> > }
> > - if (pud_leaf(pud) && pud_devmap(pud)) {
> > + if (pud_leaf(pud) && vma_is_dax(walk->vma)) {
> > unsigned long i, npages, pfn;
> > unsigned int required_fault;
> > unsigned long *hmm_pfns;
> > diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
> > index e0db855..133f750 100644
> > --- a/mm/userfaultfd.c
> > +++ b/mm/userfaultfd.c
> > @@ -1791,7 +1791,7 @@ ssize_t move_pages(struct userfaultfd_ctx *ctx, unsigned long dst_start,
> > ptl = pmd_trans_huge_lock(src_pmd, src_vma);
> > if (ptl) {
> > - if (pmd_devmap(*src_pmd)) {
> > + if (vma_is_dax(src_vma)) {
> > spin_unlock(ptl);
> > err = -ENOENT;
> > break;
>
> I assume we could also just refuse dax folios, right?

Yep.

> If we decide to check VMAs, we should probably check earlier.

Ok, that makes sense.

> But I wonder, what about anonymous non-dax pages in COW mappings? Is it
> possible? Not supported?

You mean other non-dax ZONE_DEVICE pages? Currently not possible, because
non-dax ZONE_DEVICE pages can't be pmd mapped (although it is a future
enhancement I'd like to make).

> If supported, checking the actual folio would be the right thing to do.
>
> --
> Cheers,
>
> David / dhildenb
>