Re: [PATCH 11/12] mm/madvise: send UFFD_EVENT_REMOVE when installing guard regions
From: Tal Zussman
Date: Wed Nov 11 2026 - 18:39:57 EST
+ 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? 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. Hopefully this will
make it into Jose's documentation patch.
In any case, this change is also needed for MISSING faults. If a guard
discards the contents of a page registered with MISSING, the manager
isn't told. Once the guard is removed and the page is faulted in again,
the manager may fill it with the old contents, when instead it should
have discarded them and filled it with zeroes. This is similar to
MADV_DONTNEED's handling. I'll update the commit message to emphasize
this point rather than the WP/RWP aspect.
Thanks,
Tal