From: Liam R. Howlett Date: Wed, 29 Oct 2025 16:57:55 +0000 (-0400) Subject: mm/userfaultfd: Remove hugetlb from userfaultfd by adding X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=bbf1ed20522d71ebc1f7330870107c950bade547;p=users%2Fjedix%2Flinux-maple.git mm/userfaultfd: Remove hugetlb from userfaultfd by adding 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 --- diff --git a/include/linux/userfaultfd_k.h b/include/linux/userfaultfd_k.h index dbf5f7072899..4bf89bde3641 100644 --- a/include/linux/userfaultfd_k.h +++ b/include/linux/userfaultfd_k.h @@ -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) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index a725d6ba554e..d457cb268237 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -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 diff --git a/mm/shmem.c b/mm/shmem.c index 55d2bb73f8c6..9bebeb1dd76d 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -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 diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 7614fe039887..4dc6fac27029 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #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;