Re: [PATCH V2 2/3] mm/hugetlb: disable PMD sharing for UFFD missing mode
From: Li Zhe
Date: Tue Oct 20 2026 - 23:15:50 EST
On 10/20/26 6:33 PM, David Hildenbrand (Arm) wrote:
> On 10/20/26 12:11, Mike Rapoport wrote:
>> On Mon, Oct 19, 2026 at 07:30:33PM +0800, Li Zhe wrote:
>>> From: "David Hildenbrand (Arm)" <david@xxxxxxxxxx>
>>>
>>> For UFFDIO_POISON to install a poison marker in a hugetlb mapping, it is
>>> sufficient to have the VMA registered for missing mode.
>>>
>>> However, UFFD missing mode does currently not block PMD table sharing, so
>>> installing the marker will be visible to everyone using the shared PMD
>>> table, which is wrong as UFFDIO_POISON must stay local to the process.
>>>
>>> To fix it, include VM_UFFD_MISSING in uffd_disable_huge_pmd_share(). Add
>>> a debug check on the marker installation path.
>>>
>>> The existing registration path will then unshare PMD tables, and
>>> subsequent faults will not share them while the mapping remains
>>> registered.
>>>
>>> The alternative would be to unshare PMD tables selectively when
>>> installing poison markers, which results in way more complexity. Or
>>> alternatively, simply failing the marker installation, which might break
>>> some use cases.
>>>
>>> This effectively disables PMD sharing for missing-mode registrations
>>> that never use UFFDIO_POISON.
>>>
>>> Suggested-by: Li Zhe <lizhe.67@xxxxxxxxxxxxx>
>>> Fixes: 8a13897fb0da ("mm: userfaultfd: support UFFDIO_POISON for hugetlbfs")
>>> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
>>> Signed-off-by: Li Zhe <lizhe.67@xxxxxxxxxxxxx>
>>> ---
>>> include/linux/userfaultfd_k.h | 13 +++++++++----
>>> mm/hugetlb.c | 1 +
>>> 2 files changed, 10 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/include/linux/userfaultfd_k.h b/include/linux/userfaultfd_k.h
>>> index a4351cffc60c..fe78ba14dc68 100644
>>> --- a/include/linux/userfaultfd_k.h
>>> +++ b/include/linux/userfaultfd_k.h
>>> @@ -169,7 +169,10 @@ static inline bool is_mergeable_vm_userfaultfd_ctx(struct vm_area_struct *vma,
>>> }
>>>
>>> /*
>>> - * Never enable huge pmd sharing on some uffd registered vmas:
>>> + * Never enable huge pmd sharing on the following VMAs:
>>> + *
>>> + * - VM_UFFD_MISSING VMAs, because UFFDIO_POISON may install markers and we
>>> + * want PMD tables to be unshared when installing these markers already.
>>> *
>>> * - VM_UFFD_WP and VM_UFFD_RWP VMAs, because the write protect / access
>>> * tracking information is per pgtable entry.
>>> @@ -182,9 +185,11 @@ static inline bool is_mergeable_vm_userfaultfd_ctx(struct vm_area_struct *vma,
>>> */
>>> static inline bool uffd_disable_huge_pmd_share(struct vm_area_struct *vma)
>>> {
>>> - return vma_test_any_mask(vma,
>>> - mk_vma_flags_from_masks(VMA_UFFD_WP, VMA_UFFD_RWP,
>>> - VMA_UFFD_MINOR));
>>> + const vma_flags_t uffd_flags =
>>> + mk_vma_flags_from_masks(VMA_UFFD_MISSING, VMA_UFFD_WP,
>>> + VMA_UFFD_RWP, VMA_UFFD_MINOR);
>> Since this essentially disable pmd sharing for any uffd mode, maybe replace
>> the flags check with the check for non-NULL userfaultfd_ctx?
> That would likely even better and we can just simplify the comments as well.
Agreed, thanks Mike and David.
I will update uffd_disable_huge_pmd_share() in v3 to check whether the
VMA has a userfaultfd context instead of checking the individual UFFD
mode flags, and simplify the comment accordingly.
Thanks,
Zhe