]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm/userfaultfd: Remove hugetlb from userfaultfd by adding
authorLiam R. Howlett <Liam.Howlett@oracle.com>
Wed, 29 Oct 2025 16:57:55 +0000 (12:57 -0400)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Thu, 30 Oct 2025 16:56:36 +0000 (12:56 -0400)
complete_register() to uffd_ops

The registration of uffd has a code block specifically for hugetlb.
Move this block to a uffd_ops and remove the dependency.

The final user of hugetlb code has been removed from userfaultfd.c, so
the hugetlb header can now be removed.

Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
include/linux/userfaultfd_k.h
mm/hugetlb.c
mm/shmem.c
mm/userfaultfd.c

index dbf5f70728995568d600cd9680b296f81eb8292e..4bf89bde3641d6713b32e913805a53079c6177f4 100644 (file)
@@ -115,6 +115,7 @@ struct uffd_info {
        .foliop = NULL,                                                 \
 }
 
+void uffd_complete_register(struct vm_area_struct *vma);
 /* VMA userfaultfd operations */
 unsigned int uffd_page_shift(struct vm_area_struct *vma);
 int uffd_writeprotect(struct uffd_info *info);
@@ -136,6 +137,7 @@ struct vm_uffd_ops {
                        struct vm_area_struct *dst, struct folio *folio,
                        unsigned long src_addr);
        unsigned int (*page_shift)(struct vm_area_struct *src_vma);
+       void (*complete_register)(struct vm_area_struct *vma);
 };
 
 #define MFILL_ATOMIC_MODE_BITS (const_ilog2(NR_MFILL_ATOMIC_MODES - 1) + 1)
index a725d6ba554e13aa08340798bf41da9a21cc4c04..d457cb268237d1728c1ece13a91d50b8f1833f4e 100644 (file)
@@ -5534,6 +5534,12 @@ static inline unsigned int hugetlb_page_shift(struct vm_area_struct *vma)
        return huge_page_shift(hstate_vma(vma));
 }
 
+static inline void hugetlb_complete_register(struct vm_area_struct *vma)
+{
+       if (is_vm_hugetlb_page(vma) && uffd_disable_huge_pmd_share(vma))
+               hugetlb_unshare_all_pmds(vma);
+}
+
 static int hugetlb_mfill_pte_poison(struct uffd_info *info);
 static int hugetlb_mfill_pte_continue(struct uffd_info *info);
 static int hugetlb_mfill_atomic_pte_copy(struct uffd_info *info);
@@ -5549,6 +5555,7 @@ static const struct vm_uffd_ops hugetlb_uffd_ops = {
        .increment              =       hugetlb_mfill_size,
        .failed_do_unlock       =       hugetlb_failed_do_unlock,
        .page_shift             =       hugetlb_page_shift,
+       .complete_register      =       hugetlb_complete_register,
 };
 #endif
 
index 55d2bb73f8c6a3bd3b2c74767988ef4aa19f57de..9bebeb1dd76daa5f6b7d56658acbbaaa4c8ca44f 100644 (file)
@@ -5278,6 +5278,7 @@ static const struct vm_uffd_ops shmem_uffd_ops = {
        .increment              =       mfill_size,
        .failed_do_unlock       =       uffd_failed_do_unlock,
        .page_shift             =       uffd_page_shift,
+       .complete_register      =       uffd_complete_register,
 };
 #endif
 
index 7614fe0398877cc5073aa411f1ad812061d5f6ce..4dc6fac270297010ef2f8d47730ab89578b1a3e6 100644 (file)
@@ -13,7 +13,6 @@
 #include <linux/swapops.h>
 #include <linux/userfaultfd_k.h>
 #include <linux/mmu_notifier.h>
-#include <linux/hugetlb.h>
 #include <asm/tlbflush.h>
 #include <asm/tlb.h>
 #include "internal.h"
@@ -468,6 +467,9 @@ static ssize_t uffd_def_is_dst_valid(struct vm_area_struct *dst_vma,
 
        return 0;
 }
+void uffd_complete_register(struct vm_area_struct *vma)
+{
+}
 
 /* Anon vma ops */
 static const struct vm_uffd_ops default_uffd_ops = {
@@ -480,6 +482,7 @@ static const struct vm_uffd_ops default_uffd_ops = {
        .increment              = mfill_size,
        .failed_do_unlock       = uffd_failed_do_unlock,
        .page_shift             = uffd_page_shift,
+       .complete_register      = uffd_complete_register,
 };
 
 unsigned int uffd_page_shift(struct vm_area_struct *vma)
@@ -1887,6 +1890,7 @@ int userfaultfd_register_range(struct userfaultfd_ctx *ctx,
        struct vm_area_struct *prev = vma_prev(&vmi);
        unsigned long vma_end;
        vm_flags_t new_flags;
+       const struct vm_uffd_ops *uffd_ops;
 
        if (vma->vm_start < start)
                prev = vma;
@@ -1926,8 +1930,9 @@ int userfaultfd_register_range(struct userfaultfd_ctx *ctx,
                 */
                userfaultfd_set_ctx(vma, ctx, vm_flags);
 
-               if (is_vm_hugetlb_page(vma) && uffd_disable_huge_pmd_share(vma))
-                       hugetlb_unshare_all_pmds(vma);
+
+               uffd_ops = vma_get_uffd_ops(vma);
+               uffd_ops->complete_register(vma);
 
 skip:
                prev = vma;