Re: [PATCH 1/2] mm/userfaultfd: prevent poison marker loss

From: David Hildenbrand (Arm)

Date: Mon Nov 16 2026 - 09:26:49 EST


On 11/14/26 19:40, Lorenzo Stoakes (ARM) wrote:
> On Sat, Nov 07, 2026 at 12:51:05AM +0100, David Hildenbrand (Arm) wrote:
>> Unregistering userfaultfd leaves poison markers in the page tables.
>> However, once unregistered, hugetlb PMD tables can be shared again.
>>
>> Further, shmem page-table retraction can discard poison markers even
>> while registered in missing mode, and fork() can skip copying page
>> tables containing poison markers.
>>
>> To fix it, add VM_MAYBE_UFFD_POISON and set it before installing poison
>> markers. Preserve it across unregistration, splits, merges and fork(),
>> just like we do with guard markers.
>>
>> Use the new atomic VMA flag to disable PMD sharing and page-table
>> retraction, and to force page-table copying during fork().
>>
>> Move VM_UFFD_WP to bit 44 and make HAVE_ARCH_USERFAULTFD_WP depend on
>> 64BIT, freeing bit 12 for the new flag on both 32-bit and 64-bit systems.
>> Expose the flag as "up" in smaps.
>>
>> Losing poison markers, while unpleasant, is not really fatal, and the
>> use case is rather a niche thing. In addition, we rely on the atomic
>> VMA flags infrastructure ... so let's not CC stable.
>>
>> Fixes: fc71884a5f59 ("mm: userfaultfd: add new UFFDIO_POISON ioctl")
>> Fixes: 8a13897fb0da ("mm: userfaultfd: support UFFDIO_POISON for hugetlbfs")
>
> Are we looking to cc: stable or this something for newer kernels only?

Per above:

"Losing poison markers, while unpleasant, is not really fatal, and the
use case is rather a niche thing. In addition, we rely on the atomic
VMA flags infrastructure ... so let's not CC stable."

We cannot really backport to the pre MADV_GUARD fixes that handle the atomic flag correctly.

We could easily backport to stable kernels that have it.

Thoughts?


[...]

>> #define VM_LOCKED INIT_VM_FLAG(LOCKED)
>> #define VM_IO INIT_VM_FLAG(IO)
>> #define VM_SEQ_READ INIT_VM_FLAG(SEQ_READ)
>> @@ -502,13 +508,17 @@ enum {
>> #endif
>>
>> /*
>> - * vma_flags_t masks for the userfaultfd VMA flags. The two high-bit modes are
>> - * gated on the same configs as their VM_* flags above -- both of which imply
>> + * vma_flags_t masks for the userfaultfd VMA flags. The three high-bit modes are
>> + * gated on the same configs as their VM_* flags above -- all of which imply
>> * 64BIT -- so an out-of-range bit is never fed to mk_vma_flags() on a build
>> * whose bitmap cannot hold it.
>> */
>> #define VMA_UFFD_MISSING mk_vma_flags(VMA_UFFD_MISSING_BIT)
>> +#ifdef CONFIG_HAVE_ARCH_USERFAULTFD_WP
>> #define VMA_UFFD_WP mk_vma_flags(VMA_UFFD_WP_BIT)
>> +#else
>> +#define VMA_UFFD_WP EMPTY_VMA_FLAGS
>> +#endif
>
> Could you just move these up to the block above to match the convention here?
>

Did you have the following change on top of my changes in mind?

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 6cd9d86f7adac..fa56d9e9f3ebd 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -410,8 +410,10 @@ enum {
#define VM_MAYBE_UFFD_POISON INIT_VM_FLAG(MAYBE_UFFD_POISON)
#ifdef CONFIG_HAVE_ARCH_USERFAULTFD_WP
#define VM_UFFD_WP INIT_VM_FLAG(UFFD_WP)
+#define VMA_UFFD_WP mk_vma_flags(VMA_UFFD_WP_BIT)
#else
#define VM_UFFD_WP VM_NONE
+#define VMA_UFFD_WP EMPTY_VMA_FLAGS
#endif
#define VM_LOCKED INIT_VM_FLAG(LOCKED)
#define VM_IO INIT_VM_FLAG(IO)
@@ -508,17 +510,12 @@ enum {
#endif

/*
- * vma_flags_t masks for the userfaultfd VMA flags. The three high-bit modes are
- * gated on the same configs as their VM_* flags above -- all of which imply
+ * vma_flags_t masks for the userfaultfd VMA flags. The two high-bit modes are
+ * gated on the same configs as their VM_* flags above -- both of which imply
* 64BIT -- so an out-of-range bit is never fed to mk_vma_flags() on a build
* whose bitmap cannot hold it.
*/
#define VMA_UFFD_MISSING mk_vma_flags(VMA_UFFD_MISSING_BIT)
-#ifdef CONFIG_HAVE_ARCH_USERFAULTFD_WP
-#define VMA_UFFD_WP mk_vma_flags(VMA_UFFD_WP_BIT)
-#else
-#define VMA_UFFD_WP EMPTY_VMA_FLAGS
-#endif
#ifdef CONFIG_HAVE_ARCH_USERFAULTFD_MINOR
#define VMA_UFFD_MINOR mk_vma_flags(VMA_UFFD_MINOR_BIT)
#else
diff --git a/include/linux/userfaultfd_k.h b/include/linux/userfaultfd_k.h
index b8b7cc2f00388..75c3e9270b62a 100644
--- a/include/linux/userfaultfd_k.h
+++ b/include/linux/userfaultfd_k.h
@@ -201,7 +201,7 @@ static inline bool userfaultfd_missing(struct vm_area_struct *vma)

static inline bool userfaultfd_wp(struct vm_area_struct *vma)
{
- return vma_test_any_mask(vma, VMA_UFFD_WP);
+ return vma_test_single_mask(vma, VMA_UFFD_WP);
}

static inline bool userfaultfd_minor(struct vm_area_struct *vma)

--
Cheers,

David