FAILED: patch "[PATCH] mm/vma: fix expansion of VMA_MIXEDMAP_BIT VMAs" failed to apply to 6.18-stable tree
Subsystems (3)
Sasha Levin
maintainerThe patch below does not apply to the 6.18-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.18.y
git checkout FETCH_HEAD
git cherry-pick -x 8146c6478224d8f6395c6b08a19c344a56d79867
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.18.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 8146c6478224d8f6395c6b08a19c344a56d79867 Mon Sep 17 00:00:00 2001
From: "Lorenzo Stoakes (ARM)" <[email protected]>
Date: Fri, 23 Oct 2026 16:17:31 +0100
Subject: [PATCH] mm/vma: fix expansion of VMA_MIXEDMAP_BIT VMAs
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Commit ca3d76b0aa80 ("mm: add merging after mremap resize") combined merging with expansion of mremap()'d VMAs, however it also unintentionally disallowed the expansion of unmergeable VMAs.
Previously it was possible to expand a mixed mapping which mremap() had already ensured was a legal expansion.
This is clearly seen in the mremap() logic, as it checks vma_is_fixed_mapping() to determine legality of an expansion rather than vma_can_merge().
Additionally, copy_vma() allows for a failed merge to result in a new VMA being instantiated if MREMAP_MAYMOVE is specified.
However, this is not attempted, as a failure in vma_merge_extend() is assumed to be an -ENOMEM failure.
Since vma_merge_extend() is used exclusively by mremap() to perform a merge and/or expansion, resolve the issue by invoking vma_expand() for unmergeable VMAs there.
Explicitly assert that the VMA is both non-fixed and a mixed mapping. This provides double insurance against broken changes in future.
Note that khugepaged_enter_vma() (which vma_merge_new_range() runs) is redundant in this case, as a mixed mapping is not subject to khugepaged.
Also update the VMA userland tests to add a required predicate.
--- mm/vma.c | 19 ++++++++++++++++--- tools/testing/vma/include/dup.h | 5 +++++ 2 files changed, 21 insertions(+), 3 deletions(-)
mm/vma.c +16 -3
@@ -1851,12 +1851,25 @@ struct vm_area_struct *vma_merge_extend(struct vma_iterator *vmi, struct vm_area_struct *vma, unsigned long delta) { - VMG_VMA_STATE(vmg, vmi, vma, vma, vma->vm_end, vma->vm_end + delta); +const unsigned long start = +vma_can_merge (vma) ? vma->vm_end : vma->vm_start; +VMG_VMA_STATE (vmg, vmi, vma, vma, start, vma->vm_end + delta); - vmg.next =vma_iter_next_rewind (vmi,NULL ); vmg.middle =NULL ;/* We use the VMA to populate VMG fields only. */ -return vma_merge_new_range (&vmg); +if (vma_can_merge (vma)) { + vmg.next =vma_iter_next_rewind (vmi,NULL ); +return vma_merge_new_range (&vmg); + } + +/* Mixed mappings are permitted to be expanded, not merged. */ +VM_WARN_ON_ONCE (vma_is_fixed_mapping (vma)); +VM_WARN_ON_ONCE (!vma_test (vma,VMA_MIXEDMAP_BIT )); +vma_prev (vmi);/* Reposition to start of VMA. */ + vmg.target = vma; +if (vma_expand (&vmg)) +return NULL ; +return vma; }void unlink_file_vma_batch_init (struct unlink_vma_file_batch *vb)
tools/testing/vma/include/dup.h +5 -0
@@ -1727,3 +1727,8 @@ static inline bool vma_flags_can_merge(const vma_flags_t *flags)*/ return !vma_flags_is_hugetlb (flags); } + +static inline bool vma_can_merge (const struct vm_area_struct *vma) +{ +return vma_flags_can_merge (&vma->flags); +}
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/1 mm/vma: fix expansion of VMA_MIXEDMAP_BIT VMAs
From: "Lorenzo Stoakes (ARM)" <[email protected]>
[ Upstream commit 8146c6478224d8f6395c6b08a19c344a56d79867 ]
Commit ca3d76b0aa80 ("mm: add merging after mremap resize") combined merging with expansion of mremap()'d VMAs, however it also unintentionally disallowed the expansion of unmergeable VMAs.
Previously it was possible to expand a mixed mapping which mremap() had already ensured was a legal expansion.
This is clearly seen in the mremap() logic, as it checks vma_is_fixed_mapping() to determine legality of an expansion rather than vma_can_merge().
Additionally, copy_vma() allows for a failed merge to result in a new VMA being instantiated if MREMAP_MAYMOVE is specified.
However, this is not attempted, as a failure in vma_merge_extend() is assumed to be an -ENOMEM failure.
Since vma_merge_extend() is used exclusively by mremap() to perform a merge and/or expansion, resolve the issue by invoking vma_expand() for unmergeable VMAs there.
Explicitly assert that the VMA is both non-fixed and a mixed mapping. This provides double insurance against broken changes in future.
Note that khugepaged_enter_vma() (which vma_merge_new_range() runs) is redundant in this case, as a mixed mapping is not subject to khugepaged.
Also update the VMA userland tests to add a required predicate.
--- mm/vma.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)
mm/vma.c +19 -3
@@ -1770,12 +1770,28 @@ struct vm_area_struct *vma_merge_extend(struct vma_iterator *vmi, struct vm_area_struct *vma, unsigned long delta) { - VMG_VMA_STATE(vmg, vmi, vma, vma, vma->vm_end, vma->vm_end + delta); +const bool can_merge = !(vma->vm_flags & (VM_PFNMAP |VM_DONTEXPAND | +VM_MIXEDMAP )) && + !is_vm_hugetlb_page (vma); +const unsigned long start = + can_merge ? vma->vm_end : vma->vm_start; +VMG_VMA_STATE (vmg, vmi, vma, vma, start, vma->vm_end + delta); - vmg.next =vma_iter_next_rewind (vmi,NULL ); vmg.middle =NULL ;/* We use the VMA to populate VMG fields only. */ -return vma_merge_new_range (&vmg); +if (can_merge) { + vmg.next =vma_iter_next_rewind (vmi,NULL ); +return vma_merge_new_range (&vmg); + } + +/* Mixed mappings are permitted to be expanded, not merged. */ +VM_WARN_ON_ONCE (vma->vm_flags & (VM_PFNMAP |VM_DONTEXPAND )); +VM_WARN_ON_ONCE (!(vma->vm_flags &VM_MIXEDMAP )); +vma_prev (vmi);/* Reposition to start of VMA. */ + vmg.target = vma; +if (vma_expand (&vmg)) +return NULL ; +return vma; }void unlink_file_vma_batch_init (struct unlink_vma_file_batch *vb)
Signature · 1 line
2.53.0
Re: [PATCH 6.18.y] mm/vma: fix expansion of VMA_MIXEDMAP_BIT VMAs
Quoted 33 lines · Sasha Levin
From: "Lorenzo Stoakes (ARM)" <[email protected]>
[ Upstream commit
8146c6478224d8f6395c6b08a19c344a56d79867]Commit
ca3d76b0aa80("mm: add merging after mremap resize") combined merging with expansion of mremap()'d VMAs, however it also unintentionally disallowed the expansion of unmergeable VMAs.Previously it was possible to expand a mixed mapping which
mremap()had already ensured was a legal expansion.This is clearly seen in the
mremap()logic, as it checksvma_is_fixed_mapping()to determine legality of an expansion rather thanvma_can_merge().Additionally,
copy_vma()allows for a failed merge to result in a new VMA being instantiated ifMREMAP_MAYMOVEis specified.However, this is not attempted, as a failure in
vma_merge_extend()is assumed to be an-ENOMEMfailure.Since
vma_merge_extend()is used exclusively bymremap()to perform a merge and/or expansion, resolve the issue by invokingvma_expand()for unmergeable VMAs there.Explicitly assert that the VMA is both non-fixed and a mixed mapping. This provides double insurance against broken changes in future.
Note that
khugepaged_enter_vma()(whichvma_merge_new_range()runs) is redundant in this case, as a mixed mapping is not subject to khugepaged.Also update the VMA userland tests to add a required predicate.
Quoted 14 lines
Fixes ca3d76b0aa80 ("mm: add merging after mremap resize")Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>Signed-off-by Andrew Morton <[email protected]>Reported-by Luiz Capitulino <[email protected]>Reviewed-by Pedro Falcato <[email protected]>Cc Liam R. Howlett <[email protected]>Cc Jann Horn <[email protected]>Cc Jakub Matěna <[email protected]>Cc <[email protected]>[ sashal: replaced newer VMA helpers with equivalent vm_flags checks using the existing is_vm_hugetlb_page() helper ]Signed-off-by Sasha Levin <[email protected]>
I tested this against the in-tree reproducer, ran the MM kselftests and the vma selftest, all is good:
Quoted 40 lines
--- mm/vma.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)mm/vma.c +19
-3@@ -1770,12 +1770,28 @@ struct vm_area_struct *vma_merge_extend(struct vma_iterator *vmi, struct vm_area_struct *vma, unsigned long delta) { - VMG_VMA_STATE(vmg, vmi, vma, vma, vma->vm_end, vma->vm_end + delta); +const bool can_merge = !(vma->vm_flags & (VM_PFNMAP |VM_DONTEXPAND | +VM_MIXEDMAP )) && + !is_vm_hugetlb_page (vma); +const unsigned long start = + can_merge ? vma->vm_end : vma->vm_start; +VMG_VMA_STATE (vmg, vmi, vma, vma, start, vma->vm_end + delta); - vmg.next =vma_iter_next_rewind (vmi,NULL ); vmg.middle =NULL ;/* We use the VMA to populate VMG fields only. */ -return vma_merge_new_range (&vmg); +if (can_merge) { + vmg.next =vma_iter_next_rewind (vmi,NULL ); +return vma_merge_new_range (&vmg); + } + +/* Mixed mappings are permitted to be expanded, not merged. */ +VM_WARN_ON_ONCE (vma->vm_flags & (VM_PFNMAP |VM_DONTEXPAND )); +VM_WARN_ON_ONCE (!(vma->vm_flags &VM_MIXEDMAP )); +vma_prev (vmi);/* Reposition to start of VMA. */ + vmg.target = vma; +if (vma_expand (&vmg)) +return NULL ; +return vma; }void unlink_file_vma_batch_init (struct unlink_vma_file_batch *vb)