FAILED: patch "[PATCH] mm/mremap: correctly uncharge accountable VMAs in error path" 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 65e722a74df992719676ead85a9e93fb2b5a0983
# <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 65e722a74df992719676ead85a9e93fb2b5a0983 Mon Sep 17 00:00:00 2001
From: "Lorenzo Stoakes (ARM)" <[email protected]>
Date: Mon, 19 Oct 2026 16:57:48 +0100
Subject: [PATCH] mm/mremap: correctly uncharge accountable VMAs in error path
The mremap error path is a fragile and unwieldy beast - it reverses the page table move then updates vma_remap_struct state to swap VMA, length and address between old and new VMAs in copy_vma_and_data().
If the mremap() operation didn't specify MREMAP_DONTUNMAP then its caller, move_vma(), invokes unmap_source_vma(), which unmaps the new VMA rather than the old one.
For accountable VMAs when MREMAP_DONTUNMAP is not specified, unmap_source_vma() unsets VMA_ACCOUNT_BIT during this unmap in order that only the delta of a VMA expansion is charged (performed by vrm_calc_charge() earlier).
Therefore nothing uncharges the expanded VMA size, and there is a permanent leak in global Committed_AS.
Resolve the issue by uncharging when MREMAP_DONTUNMAP is not specified.
--- mm/mremap.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
mm/mremap.c +14 -0
@@ -1339,6 +1339,20 @@ static int copy_vma_and_data(struct vma_remap_struct *vrm, pmc_revert.need_rmap_locks = true;move_page_tables (&pmc_revert); +/* +* When copy_vma_and_data() returns, the new VMA will be +* unmapped rather than the old one. +* +* When an accountable move is being performed, this unmapping +* will not uncharge any expansion, so do that now. +* +* A move is accountable if the VMA is accountable and +* MREMAP_DONTUNMAP is not specified, so only do so if the +* latter is true. +*/ +if (!(vrm->flags &MREMAP_DONTUNMAP )) +vrm_uncharge (vrm); + vrm->vma = new_vma; vrm->old_len = vrm->new_len; vrm->addr = vrm->new_addr;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/1 mm/mremap: correctly uncharge accountable VMAs in error path
From: "Lorenzo Stoakes (ARM)" <[email protected]>
[ Upstream commit 65e722a74df992719676ead85a9e93fb2b5a0983 ]
The mremap error path is a fragile and unwieldy beast - it reverses the page table move then updates vma_remap_struct state to swap VMA, length and address between old and new VMAs in copy_vma_and_data().
If the mremap() operation didn't specify MREMAP_DONTUNMAP then its caller, move_vma(), invokes unmap_source_vma(), which unmaps the new VMA rather than the old one.
For accountable VMAs when MREMAP_DONTUNMAP is not specified, unmap_source_vma() unsets VMA_ACCOUNT_BIT during this unmap in order that only the delta of a VMA expansion is charged (performed by vrm_calc_charge() earlier).
Therefore nothing uncharges the expanded VMA size, and there is a permanent leak in global Committed_AS.
Resolve the issue by uncharging when MREMAP_DONTUNMAP is not specified.
--- mm/mremap.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
mm/mremap.c +13 -0
@@ -715,6 +715,19 @@ static unsigned long move_vma(struct vm_area_struct *vma,*/ move_page_tables (new_vma, new_addr, vma, old_addr, moved_len, true); + +/* +* The new VMA will be unmapped rather than the old one. +* +* When an accountable move is being performed, this unmapping +* will not uncharge any expansion, so do that now. +* +* A move is accountable if the VMA is accountable and +* MREMAP_DONTUNMAP is not specified. +*/ +if (vm_flags &VM_ACCOUNT && !(flags &MREMAP_DONTUNMAP )) +vm_unacct_memory (to_account >>PAGE_SHIFT ); + vma = new_vma; old_len = new_len; old_addr = new_addr;
Signature · 1 line
2.53.0