From: Liam R. Howlett Date: Mon, 27 Oct 2025 20:47:36 +0000 (-0400) Subject: mm/userfaultfd: Move zeropage to global validation for hugetlb X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=2205f1b5e8e23255ddab05ca23a17ec55b70d275;p=users%2Fjedix%2Flinux-maple.git mm/userfaultfd: Move zeropage to global validation for hugetlb This is for review reasons, with the goal of showing hugetlb is the same as everything else in mfill_atomic(). Signed-off-by: Liam R. Howlett --- diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 47b169d25eb8..94e57865c043 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -575,6 +575,16 @@ uffd_ctx_lock_and_validate_dst(struct userfaultfd_ctx *ctx, if ((flags & MFILL_ATOMIC_WP) && !(dst_vma->vm_flags & VM_UFFD_WP)) return -EINVAL; + /* + * There is no default zero huge page for all huge page sizes as + * supported by hugetlb. A PMD_SIZE huge pages may exist as used + * by THP. Since we can not reliably insert a zero page, this + * feature is not supported. + */ + if (is_vm_hugetlb_page(dst_vma) && + uffd_flags_mode_is(flags, MFILL_ATOMIC_ZEROPAGE)) + return -EINVAL; + uffd_ops = vma_get_uffd_ops(dst_vma); WARN_ON_ONCE(!uffd_ops || !uffd_ops->is_dst_valid); return uffd_ops->is_dst_valid(dst_vma, dst_start, len); @@ -601,18 +611,6 @@ static __always_inline ssize_t mfill_atomic_hugetlb(struct userfaultfd_ctx *ctx, const struct vm_uffd_ops *uffd_ops; unsigned long increment; - /* - * There is no default zero huge page for all huge page sizes as - * supported by hugetlb. A PMD_SIZE huge pages may exist as used - * by THP. Since we can not reliably insert a zero page, this - * feature is not supported. - */ - if (uffd_flags_mode_is(flags, MFILL_ATOMIC_ZEROPAGE)) { - up_read(&ctx->map_changing_lock); - uffd_mfill_unlock(dst_vma); - return -EINVAL; - } - src_addr = src_start; dst_addr = dst_start; copied = 0;