> > I'll see if I can confirm that this is indeed possible and send a > > repro if it is. > > I think your analysis above is correct. The key being the failure to unshare > in the non-PUD_SIZE vma after the split. I do indeed hit the WARN_ON_ONCE (repro attached), and the MADV wasn't even needed (the UFFDIO_REGISTER does the VMA split before "unsharing all PMDs"). With the fix, we avoid the WARN_ON_ONCE, but the behavior is still incorrect: I expect the address range to be write-protected, but it isn't. The reason why is that hugetlb_change_protection uses huge_pte_offset, even if it's being called for a UFFDIO_WRITEPROTECT with UFFDIO_WRITEPROTECT_MODE_WP. In that particular case, I'm pretty sure we should be using huge_pte_alloc, but even so, it's not trivial to get an allocation failure back up to userspace. The non-hugetlb implementation of UFFDIO_WRITEPROTECT seems to also have this problem. Peter, what do you think? > > To me, the fact it was somewhat difficult to come up with this scenario is an > argument what we should just unshare at split time as you propose. Who > knows what other issues may exist. > > > 60dfaad65a ("mm/hugetlb: allow uffd wr-protect none ptes") is the > > commit that introduced the WARN_ON_ONCE; perhaps it's a good choice > > for a Fixes: tag (if above is indeed true). > > If the key issue in your above scenario is indeed the failure of > hugetlb_unshare_all_pmds in the non-PUD_SIZE vma, then perhaps we tag? > > 6dfeaff93be1 ("hugetlb/userfaultfd: unshare all pmds for hugetlbfs when > register wp") SGTM. Thanks Mike.