FAILED: patch "[PATCH] mm/hugetlb: unshare page tables during VMA split, not before" failed to apply to 6.12-stable tree
Subsystems (4)
[email protected]
maintainerThe patch below does not apply to the 6.12-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.12.y
git checkout FETCH_HEAD
git cherry-pick -x 081056dc00a27bccb55ccc3c6f230a3d5fd3f7e0
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2025062039-jet-eskimo-201a@gregkh' --subject-prefix 'PATCH 6.12.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 081056dc00a27bccb55ccc3c6f230a3d5fd3f7e0 Mon Sep 17 00:00:00 2001
From: Jann Horn <[email protected]>
Date: Tue, 27 May 2025 23:23:53 +0200
Subject: [PATCH] mm/hugetlb: unshare page tables during VMA split, not before
Currently, __split_vma() triggers hugetlb page table unsharing through vm_ops->may_split(). This happens before the VMA lock and rmap locks are taken - which is too early, it allows racing VMA-locked page faults in our process and racing rmap walks from other processes to cause page tables to be shared again before we actually perform the split.
Fix it by explicitly calling into the hugetlb unshare logic from __split_vma() in the same place where THP splitting also happens. At that point, both the VMA and the rmap(s) are write-locked.
An annoying detail is that we can now call into the helper hugetlb_unshare_pmds() from two different locking contexts:
1. from hugetlb_split(), holding:
- mmap lock (exclusively)
- VMA lock
- file rmap lock (exclusively)
2. hugetlb_unshare_all_pmds(), which I think is designed to be able to call us with only the mmap lock held (in shared mode), but currently only runs while holding mmap lock (exclusively) and VMA lock
Backporting note:
This commit fixes a racy protection that was introduced in commit b30c14cd6102 ("hugetlb: unshare some PMDs when splitting VMAs"); that commit claimed to fix an issue introduced in 5.13, but it should actually also go all the way back.
include/linux/hugetlb.h +3 -0
@@ -279,6 +279,7 @@ bool is_hugetlb_entry_migration(pte_t pte);bool is_hugetlb_entry_hwpoisoned (pte_t pte);void hugetlb_unshare_all_pmds (struct vm_area_struct *vma);void fixup_hugetlb_reservations (struct vm_area_struct *vma); +void hugetlb_split (struct vm_area_struct *vma,unsigned long addr);#else /* !CONFIG_HUGETLB_PAGE */
@@ -476,6 +477,8 @@ static inline void fixup_hugetlb_reservations(struct vm_area_struct *vma) { } +static inline void hugetlb_split (struct vm_area_struct *vma,unsigned long addr) {} +#endif /* !CONFIG_HUGETLB_PAGE */ #ifndef pgd_write
mm/hugetlb.c +44 -16
109 lines not on this page · raw message
mm/vma.c +7 -0
@@ -539,7 +539,14 @@ __split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma,init_vma_prep (&vp, vma); vp.insert = new;vma_prepare (&vp); + +/* +* Get rid of huge pages and shared page tables straddling the split +* boundary. +*/ vma_adjust_trans_huge (vma, vma->vm_start, addr,NULL ); +if (is_vm_hugetlb_page (vma)) +hugetlb_split (vma, addr);if (new_below) { vma->vm_start = addr;
tools/testing/vma/vma_internal.h +2 -0
@@ -932,6 +932,8 @@ static inline void vma_adjust_trans_huge(struct vm_area_struct *vma, (void )next; } +static inline void hugetlb_split (struct vm_area_struct *,unsigned long ) {} +static inline void vma_iter_free (struct vma_iterator *vmi) {mas_destroy (&vmi->mas);
Jann Horn
reviewerPATCH 1/1 mm/hugetlb: unshare page tables during VMA split, not before
Currently, __split_vma() triggers hugetlb page table unsharing through vm_ops->may_split(). This happens before the VMA lock and rmap locks are taken - which is too early, it allows racing VMA-locked page faults in our process and racing rmap walks from other processes to cause page tables to be shared again before we actually perform the split.
Fix it by explicitly calling into the hugetlb unshare logic from __split_vma() in the same place where THP splitting also happens. At that point, both the VMA and the rmap(s) are write-locked.
An annoying detail is that we can now call into the helper hugetlb_unshare_pmds() from two different locking contexts:
1. from hugetlb_split(), holding:
- mmap lock (exclusively)
- VMA lock
- file rmap lock (exclusively)
2. hugetlb_unshare_all_pmds(), which I think is designed to be able to call us with only the mmap lock held (in shared mode), but currently only runs while holding mmap lock (exclusively) and VMA lock
Backporting note:
This commit fixes a racy protection that was introduced in commit b30c14cd6102 ("hugetlb: unshare some PMDs when splitting VMAs"); that commit claimed to fix an issue introduced in 5.13, but it should actually also go all the way back.
--- include/linux/hugetlb.h | 3 ++ mm/hugetlb.c | 60 +++++++++++++++++++++++--------- mm/vma.c | 7 ++++ mm/vma_internal.h | 1 + tools/testing/vma/vma_internal.h | 2 ++ 5 files changed, 57 insertions(+), 16 deletions(-)
include/linux/hugetlb.h +3 -0
@@ -272,6 +272,7 @@ long hugetlb_change_protection(struct vm_area_struct *vma,bool is_hugetlb_entry_migration (pte_t pte);bool is_hugetlb_entry_hwpoisoned (pte_t pte);void hugetlb_unshare_all_pmds (struct vm_area_struct *vma); +void hugetlb_split (struct vm_area_struct *vma,unsigned long addr);#else /* !CONFIG_HUGETLB_PAGE */
@@ -465,6 +466,8 @@ static inline vm_fault_t hugetlb_fault(struct mm_struct *mm,static inline void hugetlb_unshare_all_pmds (struct vm_area_struct *vma) { } +static inline void hugetlb_split (struct vm_area_struct *vma,unsigned long addr) {} +#endif /* !CONFIG_HUGETLB_PAGE */ #ifndef pgd_write
mm/hugetlb.c +44 -16
109 lines not on this page · raw message
mm/vma.c +7 -0
@@ -416,7 +416,14 @@ static int __split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma,init_vma_prep (&vp, vma); vp.insert = new;vma_prepare (&vp); + +/* +* Get rid of huge pages and shared page tables straddling the split +* boundary. +*/ vma_adjust_trans_huge (vma, vma->vm_start, addr,0 ); +if (is_vm_hugetlb_page (vma)) +hugetlb_split (vma, addr);if (new_below) { vma->vm_start = addr;
mm/vma_internal.h +1 -0
@@ -17,6 +17,7 @@#include <linux/file.h> #include <linux/fs.h> #include <linux/huge_mm.h> +#include <linux/hugetlb.h> #include <linux/hugetlb_inline.h> #include <linux/kernel.h> #include <linux/khugepaged.h>
tools/testing/vma/vma_internal.h +2 -0
@@ -735,6 +735,8 @@ static inline void vma_adjust_trans_huge(struct vm_area_struct *vma, (void )adjust_next; } +static inline void hugetlb_split (struct vm_area_struct *,unsigned long ) {} +static inline void vma_iter_free (struct vma_iterator *vmi) {mas_destroy (&vmi->mas);
Signature · 1 line
2.50.0.rc2.701.gf1e915cc24-goog