Re: [PATCH 3/6] userfaultfd: use userfaultfd_*() helpers instead of open coded flag tests

"Lorenzo Stoakes (ARM)" <[email protected]>
Newsgroups org.kernel.vger.linux-doc,org.kernel.vger.linux-fsdevel,org.kernel.vger.linux-kernel,org.kernel.vger.linux-trace-kernel,org.kvack.linux-mm
Message-ID <ao17rY2r-01wJxy6@gremlin>
On Tue, Aug 25, 2026 at 02:19:52PM +0300, Mike Rapoport wrote:
> > > +/*
> > > + * Don't do fault around for WP, RWP or MINOR registered uffd range.  For
> > > + * MINOR registered range, fault around will be a total disaster and ptes can
> > > + * be installed without notifications; for WP it should mostly be fine as long
> > > + * as the fault around checks for pte_none() before the installation, however
> > > + * to be super safe we just forbid it; for RWP, pre-faulted neighbours would
> > > + * be indistinguishable from accessed pages in PAGEMAP_SCAN (PAGE_IS_ACCESSED)
> > > + * and pollute the tracked working set, so each page must be populated by its
> > > + * own fault.
> > > + */
> > > +static inline bool uffd_disable_fault_around(struct vm_area_struct *vma)
> > > +{
> > > +	return userfaultfd_minor(vma) || userfaultfd_wp(vma) ||
> > > +	       userfaultfd_rwp(vma);
> >
> > This is changing the logic.
> >
> > Before we were testing only the flags, now we have:
> >
> > static inline bool userfaultfd_rwp(const struct vm_area_struct *vma)
> > {
> > 	/*
> > 	 * Callers gate PAGE_NONE usage on this; PAGE_NONE is a BUILD_BUG()
> > 	 * without CONFIG_ARCH_HAS_PTE_PROTNONE, so fold to false.
> > 	 */
> > 	if (!IS_ENABLED(CONFIG_ARCH_HAS_PTE_PROTNONE))
> > 		return false;
> > 	return vma_test_single_mask(vma, VMA_UFFD_RWP);
> > }
> >
> > I.e. adding in a CONFIG_ARCH_HAS_PTE_PROTNONE check.
>
> Without CONFIG_ARCH_HAS_PTE_PROTNONE VMA_UFFD_RWP is hardwired to VM_NONE
> so it's functionally the same ;-)

Well then you're explicitly removing logic and not mentioning it anywhere
with a NFC commit.

So please say so in the commit message.

>
> > BTW side-note these:
> >
> > static inline bool userfaultfd_missing(const struct vm_area_struct *vma)
> > {
> > 	return vma_test_any_mask(vma, VMA_UFFD_MISSING);
> > }
> >
> > static inline bool userfaultfd_wp(const struct vm_area_struct *vma)
> > {
> > 	return vma_test_any_mask(vma, VMA_UFFD_WP);
> > }
> >
> > static inline bool userfaultfd_minor(const struct vm_area_struct *vma)
> > {
> > 	return vma_test_any_mask(vma, VMA_UFFD_MINOR);
> > }
> >
> > Should all use vma_test_single_mask() really :)
>
> These are changed anyway in a later patch.

Yup, but you (potentially) break one of them. Will comment there.

>
> > --
> > Cheers, Lorenzo
>
> --
> Sincerely yours,
> Mike.

--
Cheers, Lorenzo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.