FAILED: patch "[PATCH] mm/hugetlb: fix mremap move length truncation" failed to apply to 6.1-stable tree
Subsystems (3)
Sasha Levin
maintainerThe patch below does not apply to the 6.1-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y
git checkout FETCH_HEAD
git cherry-pick -x dfb190302d2b4af86c6ae48af0d3b09f28b35460
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.1.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From dfb190302d2b4af86c6ae48af0d3b09f28b35460 Mon Sep 17 00:00:00 2001
From: Li Zhe <[email protected]>
Date: Thu, 22 Oct 2026 11:45:41 +0800
Subject: [PATCH] mm/hugetlb: fix mremap move length truncation
Patch series "mm/hugetlb: fix mremap bugs", v3.
This series fixes a few hugetlb mremap bugs.
Patch 1 fixes the return type of move_hugetlb_page_tables(), so large hugetlb moves cannot be truncated when reported back to the generic mremap code.
Patch 2 disables hugetlb PMD sharing for UFFD missing mode, so UFFDIO_POISON markers cannot become visible through shared PMD page tables.
Patch 3 fixes the recursive i_mmap_rwsem deadlock in the hugetlb mremap path by avoiding the destination PMD sharing allocation path while the mapping lock is already held for write.
This patch (of 3):
move_hugetlb_page_tables() returns the number of bytes moved, but its return type is int while the generic move_page_tables() path uses unsigned long lengths.
A hugetlb mremap() move length above INT_MAX can therefore be misreported to copy_vma_and_data(). The out-of-range conversion to int is implementation-defined; on common 64-bit builds, for example, a 4 GiB move can be reported as zero, making the caller treat the move as a failure and use the wrong length for rollback.
Return unsigned long from move_hugetlb_page_tables(), matching move_page_tables() and preserving the full byte count.
--- include/linux/hugetlb.h | 15 ++++++--------- mm/hugetlb.c | 7 +++---- 2 files changed, 9 insertions(+), 13 deletions(-)
include/linux/hugetlb.h +6 -9
@@ -121,10 +121,9 @@ void hugepage_put_subpool(struct hugepage_subpool *spool);void hugetlb_dup_vma_private (struct vm_area_struct *vma);void clear_vma_resv_huge_pages (struct vm_area_struct *vma); -int move_hugetlb_page_tables (struct vm_area_struct *vma, -struct vm_area_struct *new_vma, -unsigned long old_addr,unsigned long new_addr, -unsigned long len); +unsigned long move_hugetlb_page_tables (struct vm_area_struct *vma, +struct vm_area_struct *new_vma,unsigned long old_addr, +unsigned long new_addr,unsigned long len);int copy_hugetlb_page_range (struct mm_struct *,struct mm_struct *,struct vm_area_struct *,struct vm_area_struct *); void unmap_hugepage_range(struct vm_area_struct *,
@@ -338,11 +337,9 @@ static inline int copy_hugetlb_page_range(struct mm_struct *dst,return 0 ; } -static inline int move_hugetlb_page_tables (struct vm_area_struct *vma, -struct vm_area_struct *new_vma, -unsigned long old_addr, -unsigned long new_addr, -unsigned long len) +static inline unsigned long move_hugetlb_page_tables (struct vm_area_struct *vma, +struct vm_area_struct *new_vma,unsigned long old_addr, +unsigned long new_addr,unsigned long len) {BUG ();return 0 ;
mm/hugetlb.c +3 -4
@@ -5195,10 +5195,9 @@ static void move_huge_pte(struct vm_area_struct *vma, unsigned long old_addr,spin_unlock (dst_ptl); } -int move_hugetlb_page_tables (struct vm_area_struct *vma, -struct vm_area_struct *new_vma, -unsigned long old_addr,unsigned long new_addr, -unsigned long len) +unsigned long move_hugetlb_page_tables (struct vm_area_struct *vma, +struct vm_area_struct *new_vma,unsigned long old_addr, +unsigned long new_addr,unsigned long len) {struct hstate *h =hstate_vma (vma);struct address_space *mapping = vma->vm_file->f_mapping;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/2 mm: hugetlb: move hugeltb sysctls to its own file
From: Kefeng Wang <[email protected]>
[ Upstream commit 962de54828c5bb100eb8de881b79ed9c8b7468c0 ]
This moves all hugetlb sysctls to its own file, also kill an useless hugetlb_treat_movable_handler() defination.
Stable-dep-of: dfb190302d2b ("mm/hugetlb: fix mremap move length truncation")
--- include/linux/hugetlb.h | 8 ------- kernel/sysctl.c | 32 -------------------------- mm/hugetlb.c | 51 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 48 insertions(+), 43 deletions(-)
include/linux/hugetlb.h +0 -8
@@ -137,14 +137,6 @@ void hugepage_put_subpool(struct hugepage_subpool *spool);void hugetlb_dup_vma_private (struct vm_area_struct *vma);void clear_vma_resv_huge_pages (struct vm_area_struct *vma); -int hugetlb_sysctl_handler (struct ctl_table *,int ,void *,size_t *,loff_t *); -int hugetlb_overcommit_handler (struct ctl_table *,int ,void *,size_t *, -loff_t *); -int hugetlb_treat_movable_handler (struct ctl_table *,int ,void *,size_t *, -loff_t *); -int hugetlb_mempolicy_sysctl_handler (struct ctl_table *,int ,void *,size_t *, -loff_t *); - int move_hugetlb_page_tables(struct vm_area_struct *vma, struct vm_area_struct *new_vma, unsigned long old_addr, unsigned long new_addr,
kernel/sysctl.c +0 -32
@@ -2162,38 +2162,6 @@ static struct ctl_table vm_table[] = { .extra1 = SYSCTL_ZERO, .extra2 = SYSCTL_ONE, }, -#endif -#ifdef CONFIG_HUGETLB_PAGE - { - .procname = "nr_hugepages", - .data = NULL, - .maxlen = sizeof(unsigned long), - .mode = 0644, - .proc_handler = hugetlb_sysctl_handler, - }, -#ifdef CONFIG_NUMA - { - .procname = "nr_hugepages_mempolicy", - .data = NULL, - .maxlen = sizeof(unsigned long), - .mode = 0644, - .proc_handler = &hugetlb_mempolicy_sysctl_handler, - }, -#endif - { - .procname = "hugetlb_shm_group", - .data = &sysctl_hugetlb_shm_group, - .maxlen = sizeof(gid_t), - .mode = 0644, - .proc_handler = proc_dointvec, - }, - { - .procname = "nr_overcommit_hugepages", - .data = NULL, - .maxlen = sizeof(unsigned long), - .mode = 0644, - .proc_handler = hugetlb_overcommit_handler, - },#endif { .procname = "lowmem_reserve_ratio",
mm/hugetlb.c +48 -3
87 lines not on this page · raw message
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 mm/hugetlb: fix mremap move length truncation
From: Li Zhe <[email protected]>
[ Upstream commit dfb190302d2b4af86c6ae48af0d3b09f28b35460 ]
Patch series "mm/hugetlb: fix mremap bugs", v3.
This series fixes a few hugetlb mremap bugs.
Patch 1 fixes the return type of move_hugetlb_page_tables(), so large hugetlb moves cannot be truncated when reported back to the generic mremap code.
Patch 2 disables hugetlb PMD sharing for UFFD missing mode, so UFFDIO_POISON markers cannot become visible through shared PMD page tables.
Patch 3 fixes the recursive i_mmap_rwsem deadlock in the hugetlb mremap path by avoiding the destination PMD sharing allocation path while the mapping lock is already held for write.
This patch (of 3):
move_hugetlb_page_tables() returns the number of bytes moved, but its return type is int while the generic move_page_tables() path uses unsigned long lengths.
A hugetlb mremap() move length above INT_MAX can therefore be misreported to copy_vma_and_data(). The out-of-range conversion to int is implementation-defined; on common 64-bit builds, for example, a 4 GiB move can be reported as zero, making the caller treat the move as a failure and use the wrong length for rollback.
Return unsigned long from move_hugetlb_page_tables(), matching move_page_tables() and preserving the full byte count.
--- include/linux/hugetlb.h | 15 ++++++--------- mm/hugetlb.c | 7 +++---- 2 files changed, 9 insertions(+), 13 deletions(-)
include/linux/hugetlb.h +6 -9
@@ -137,10 +137,9 @@ void hugepage_put_subpool(struct hugepage_subpool *spool);void hugetlb_dup_vma_private (struct vm_area_struct *vma);void clear_vma_resv_huge_pages (struct vm_area_struct *vma); -int move_hugetlb_page_tables (struct vm_area_struct *vma, -struct vm_area_struct *new_vma, -unsigned long old_addr,unsigned long new_addr, -unsigned long len); +unsigned long move_hugetlb_page_tables (struct vm_area_struct *vma, +struct vm_area_struct *new_vma,unsigned long old_addr, +unsigned long new_addr,unsigned long len);int copy_hugetlb_page_range (struct mm_struct *,struct mm_struct *,struct vm_area_struct *,struct vm_area_struct *); long follow_hugetlb_page(struct mm_struct *, struct vm_area_struct *,
@@ -296,11 +295,9 @@ static inline int copy_hugetlb_page_range(struct mm_struct *dst,return 0 ; } -static inline int move_hugetlb_page_tables (struct vm_area_struct *vma, -struct vm_area_struct *new_vma, -unsigned long old_addr, -unsigned long new_addr, -unsigned long len) +static inline unsigned long move_hugetlb_page_tables (struct vm_area_struct *vma, +struct vm_area_struct *new_vma,unsigned long old_addr, +unsigned long new_addr,unsigned long len) {BUG ();return 0 ;
mm/hugetlb.c +3 -4
@@ -5304,10 +5304,9 @@ static void move_huge_pte(struct vm_area_struct *vma, unsigned long old_addr,spin_unlock (dst_ptl); } -int move_hugetlb_page_tables (struct vm_area_struct *vma, -struct vm_area_struct *new_vma, -unsigned long old_addr,unsigned long new_addr, -unsigned long len) +unsigned long move_hugetlb_page_tables (struct vm_area_struct *vma, +struct vm_area_struct *new_vma,unsigned long old_addr, +unsigned long new_addr,unsigned long len) {struct hstate *h =hstate_vma (vma);struct address_space *mapping = vma->vm_file->f_mapping;
Signature · 1 line
2.53.0