From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Luiz Capitulino" <luizcap@redhat.com>,
"Vlastimil Babka (SUSE)" <vbabka@kernel.org>,
"Pedro Falcato" <pfalcato@suse.de>,
"Liam R. Howlett" <liam@infradead.org>,
"Jann Horn" <jannh@google.com>,
"Jakub Matěna" <matenajakub@gmail.com>,
"Sasha Levin" <sashal@kernel.org>
Subject: [PATCH 6.6.y] mm/vma: fix expansion of VMA_MIXEDMAP_BIT VMAs
Date: Wed, 11 Nov 2026 22:47:57 -0500 [thread overview]
Message-ID: <20261112034659.1574521-1-sashal@kernel.org> (raw)
In-Reply-To: <20261109201217-failed-6.6-8146c6478224@kernel.org>
From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
[ 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.
Link: https://lore.kernel.org/20261023-vma-expansion-fix-v1-1-6142baf1f46b@kernel.org
Fixes: ca3d76b0aa80 ("mm: add merging after mremap resize")
Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reported-by: Luiz Capitulino <luizcap@redhat.com>
Closes: https://lore.kernel.org/all/20261023023106.515365-1-luizcap@redhat.com/
Acked-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
Reviewed-by: Pedro Falcato <pfalcato@suse.de>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Jann Horn <jannh@google.com>
Cc: Jakub Matěna <matenajakub@gmail.com>
Cc: <stable@vger.kernel.org>
[ sashal: Adapted vma_merge_extend() changes to the inline mremap() implementation using the older vma_expand() interface. ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
mm/mremap.c | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/mm/mremap.c b/mm/mremap.c
index 0739a31b54eed..a37bcfda29261 100644
--- a/mm/mremap.c
+++ b/mm/mremap.c
@@ -1120,10 +1120,21 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
* the next vma if it becomes adjacent to the expanded
* vma and otherwise compatible.
*/
- vma = vma_merge(&vmi, mm, vma, extension_start,
- extension_end, vma->vm_flags, vma->anon_vma,
- vma->vm_file, extension_pgoff, vma_policy(vma),
- vma->vm_userfaultfd_ctx, anon_vma_name(vma));
+ if (!(vma->vm_flags & (VM_PFNMAP | VM_DONTEXPAND |
+ VM_MIXEDMAP))) {
+ vma = vma_merge(&vmi, mm, vma, extension_start,
+ extension_end, vma->vm_flags, vma->anon_vma,
+ vma->vm_file, extension_pgoff, vma_policy(vma),
+ vma->vm_userfaultfd_ctx, anon_vma_name(vma));
+ } else {
+ /* 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. */
+ if (vma_expand(&vmi, vma, vma->vm_start,
+ extension_end, vma->vm_pgoff, NULL))
+ vma = NULL;
+ }
if (!vma) {
vm_unacct_memory(pages);
ret = -ENOMEM;
--
2.53.0
next prev parent reply other threads:[~2026-11-12 3:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 1:12 FAILED: patch "[PATCH] mm/vma: fix expansion of VMA_MIXEDMAP_BIT VMAs" failed to apply to 6.6-stable tree Sasha Levin
2026-11-12 3:47 ` Sasha Levin [this message]
2026-11-12 20:34 ` [PATCH 6.6.y] mm/vma: fix expansion of VMA_MIXEDMAP_BIT VMAs Luiz Capitulino
2026-11-12 20:37 ` Luiz Capitulino
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261112034659.1574521-1-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=jannh@google.com \
--cc=liam@infradead.org \
--cc=ljs@kernel.org \
--cc=luizcap@redhat.com \
--cc=matenajakub@gmail.com \
--cc=pfalcato@suse.de \
--cc=stable@vger.kernel.org \
--cc=vbabka@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.