Re: [PATCH 11/12] mm/madvise: send UFFD_EVENT_REMOVE when installing guard regions
From: Kiryl Shutsemau
Date: Thu Nov 12 2026 - 07:04:22 EST
On Thu, Nov 12, 2026 at 10:40:38AM +0100, Jose A. Perez de Azpillaga wrote:
> On 11/12/26 12:21 AM, Tal Zussman wrote:
> > + Jose
> >
> > On 11/11/26 2:25 PM, Kiryl Shutsemau wrote:
> >> On Wed, Nov 11, 2026 at 12:55:19PM -0500, Tal Zussman wrote:
> >>> On an anonymous VMA, the zap drops uffd-wp and RWP protection along with
> >>> the pages. Writes and accesses to the range after the guard is removed
> >>> are then not reported, and the manager cannot know that it has to
> >>> protect the range again.
> >>
> >> For RWP this only holds if the range is registered without MISSING.
> >>
> >> The zap frees the pages, so with MISSING the first access after the
> >> guard is removed is reported as a missing fault. And there is nothing to
> >> protect again: RWP only covers present PTEs, and a page faulted back in
> >> shows up as accessed in PAGEMAP_SCAN.
> >>
> > So this makes sense, but I think this gets at the documentation point
> > raised in the other thread. It seems that to use sync RWP "properly" it
> > needs to be combined with MINOR for shmem and hugetlb (and MISSING for
> > holes) and with MISSING for anonymous memory. Is that accurate?
Yes. Async mode needs neither: a page faulted back in is mapped without
the uffd bit and PAGEMAP_SCAN reports it as accessed.
> > If so, this should be stated much more explicitly in the
> > documentation + man page. I see that co-registering with MISSING is
> > mentioned, but not the rest of the points (reclaim, collapse, etc.)
> > The example in userfaultfd.rst also registers a MAP_SHARED mapping
> > only with RWP and MISSING, no MINOR, so that should be clarified
> > too.
Without MINOR the example can lose data. Eviction runs in sync mode,
but an offset that is not mapped in guest_mem, either pre-populated or
zapped by shmem reclaim or collapse, is mapped back on access without a
fault. A vCPU write between the pwrite() and the hole punch is lost.
With MINOR the access faults and waits for the handler, like an RWP
fault.
> > Hopefully this will make it into Jose's documentation patch.
>
> okay, if Kiryl is okay with that I will add it to my upcoming patch.
Yes, please.
--
Kiryl Shutsemau / Kirill A. Shutemov