FAILED: patch "[PATCH] mm/mremap: recheck PUDs under the page table lock" failed to apply to 6.6-stable tree
Subsystems (3)
Sasha Levin
maintainerThe patch below does not apply to the 6.6-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.6.y
git checkout FETCH_HEAD
git cherry-pick -x 402882943dfa8bab5c2bcc66189f9fb2828f248e
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 402882943dfa8bab5c2bcc66189f9fb2828f248e Mon Sep 17 00:00:00 2001
From: "David Hildenbrand (Arm)" <[email protected]>
Date: Sat, 31 Oct 2026 10:40:00 +0100
Subject: [PATCH] mm/mremap: recheck PUDs under the page table lock
Once get_old_pud() is fixed to accept PUD leaves, unmap_mapping_range() can clear a leaf between the lookup and the move. Holding mmap_lock in write mode does not prevent this.
If the zap happens before move_page_tables() tests the entry, an empty PUD can reach move_normal_pud(), where pud_populate() turns it into a present page table entry. If it happens after the test, move_huge_pud() can instead try to move an empty entry, triggering CONFIG_DEBUG_VM warnings on powerpc.
Recheck the source under the page table lock in both helpers. Treat an empty source in move_normal_pud() as a completed move, and use __pud_trans_huge_lock() in move_huge_pud().
In the future we should likely have the code lookup a PUD/PMD lockless once, instead of multiple times, because one of the problematic bits here is the:
pud_trans_huge(*old_pud)
--- mm/mremap.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
mm/mremap.c +8 -2
@@ -461,14 +461,18 @@ static bool move_normal_pud(struct pagetable_move_control *pmc,if (new_ptl != old_ptl)spin_lock_nested (new_ptl,SINGLE_DEPTH_NESTING ); -/* Clear the pud */ pud = *old_pud; +if (unlikely (pud_none (pud))) + goto out_unlock; + +/* Clear the pud */ pud_clear (old_pud);VM_BUG_ON (!pud_none (*new_pud));pud_populate (mm, new_pud,pud_pgtable (pud));flush_tlb_range (vma, pmc->old_addr, pmc->old_addr +PUD_SIZE ); +out_unlock:if (new_ptl != old_ptl)spin_unlock (new_ptl);spin_unlock (old_ptl);
@@ -503,7 +507,9 @@ static bool move_huge_pud(struct pagetable_move_control *pmc,* We don't have to worry about the ordering of src and dst * ptlocks because exclusive mmap_lock prevents deadlock. */ - old_ptl =pud_lock (mm, old_pud); + old_ptl =__pud_trans_huge_lock (old_pud, vma); +if (unlikely (!old_ptl)) +return false; new_ptl =pud_lockptr (mm, new_pud);if (new_ptl != old_ptl)spin_lock_nested (new_ptl,SINGLE_DEPTH_NESTING );
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/1 mm/mremap: recheck PUDs under the page table lock
From: "David Hildenbrand (Arm)" <[email protected]>
[ Upstream commit 402882943dfa8bab5c2bcc66189f9fb2828f248e ]
Once get_old_pud() is fixed to accept PUD leaves, unmap_mapping_range() can clear a leaf between the lookup and the move. Holding mmap_lock in write mode does not prevent this.
If the zap happens before move_page_tables() tests the entry, an empty PUD can reach move_normal_pud(), where pud_populate() turns it into a present page table entry. If it happens after the test, move_huge_pud() can instead try to move an empty entry, triggering CONFIG_DEBUG_VM warnings on powerpc.
Recheck the source under the page table lock in both helpers. Treat an empty source in move_normal_pud() as a completed move, and use __pud_trans_huge_lock() in move_huge_pud().
In the future we should likely have the code lookup a PUD/PMD lockless once, instead of multiple times, because one of the problematic bits here is the:
pud_trans_huge(*old_pud)
--- mm/mremap.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
mm/mremap.c +8 -2
@@ -363,14 +363,18 @@ static bool move_normal_pud(struct vm_area_struct *vma, unsigned long old_addr,if (new_ptl != old_ptl)spin_lock_nested (new_ptl,SINGLE_DEPTH_NESTING ); -/* Clear the pud */ pud = *old_pud; +if (unlikely (pud_none (pud))) + goto out_unlock; + +/* Clear the pud */ pud_clear (old_pud);VM_BUG_ON (!pud_none (*new_pud));pud_populate (mm, new_pud,pud_pgtable (pud));flush_tlb_range (vma, old_addr, old_addr +PUD_SIZE ); +out_unlock:if (new_ptl != old_ptl)spin_unlock (new_ptl);spin_unlock (old_ptl);
@@ -405,7 +409,9 @@ static bool move_huge_pud(struct vm_area_struct *vma, unsigned long old_addr,* We don't have to worry about the ordering of src and dst * ptlocks because exclusive mmap_lock prevents deadlock. */ - old_ptl =pud_lock (vma->vm_mm, old_pud); + old_ptl =__pud_trans_huge_lock (old_pud, vma); +if (unlikely (!old_ptl)) +return false; new_ptl =pud_lockptr (mm, new_pud);if (new_ptl != old_ptl)spin_lock_nested (new_ptl,SINGLE_DEPTH_NESTING );
Signature · 1 line
2.53.0