]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm/userfaultfd: Move zeropage to global validation for hugetlb
authorLiam R. Howlett <Liam.Howlett@oracle.com>
Mon, 27 Oct 2025 20:47:36 +0000 (16:47 -0400)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Thu, 30 Oct 2025 16:33:16 +0000 (12:33 -0400)
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 <Liam.Howlett@oracle.com>
mm/userfaultfd.c

index 47b169d25eb8cab1c59160a4293392343c9029d0..94e57865c0436a5c6da77dfb1c16f650f1b6359a 100644 (file)
@@ -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;