Linux kernel -stable discussions
 help / color / mirror / Atom feed
* FAILED: patch "[PATCH] mm/vma: fix expansion of VMA_MIXEDMAP_BIT VMAs" failed to apply to 6.6-stable tree
@ 2026-11-10  1:12 Sasha Levin
  2026-11-12  3:47 ` [PATCH 6.6.y] mm/vma: fix expansion of VMA_MIXEDMAP_BIT VMAs Sasha Levin
  0 siblings, 1 reply; 4+ messages in thread
From: Sasha Levin @ 2026-11-10  1:12 UTC (permalink / raw)
  To: ljs, akpm, luizcap, vbabka, pfalcato, liam, jannh, matenajakub; +Cc: stable

The 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 <stable@vger.kernel.org>.

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 8146c6478224d8f6395c6b08a19c344a56d79867
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<stable@vger.kernel.org>' --in-reply-to '20261109201217-failed-6.6-8146c6478224@kernel.org' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'

Thanks,
Sasha

------------------ original commit in Linus's tree ------------------

From 8146c6478224d8f6395c6b08a19c344a56d79867 Mon Sep 17 00:00:00 2001
From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
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.

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>
---
 mm/vma.c                        | 19 ++++++++++++++++---
 tools/testing/vma/include/dup.h |  5 +++++
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/mm/vma.c b/mm/vma.c
index 1be613044b4a5..88ef92ab24ecf 100644
--- a/mm/vma.c
+++ b/mm/vma.c
@@ -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)
diff --git a/tools/testing/vma/include/dup.h b/tools/testing/vma/include/dup.h
index f449129ea97a9..e0eab4eca998e 100644
--- a/tools/testing/vma/include/dup.h
+++ b/tools/testing/vma/include/dup.h
@@ -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);
+}
-- 
2.53.0





^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 6.6.y] mm/vma: fix expansion of VMA_MIXEDMAP_BIT VMAs
  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
  2026-11-12 20:34   ` Luiz Capitulino
  0 siblings, 1 reply; 4+ messages in thread
From: Sasha Levin @ 2026-11-12  3:47 UTC (permalink / raw)
  To: stable
  Cc: Lorenzo Stoakes (ARM), Andrew Morton, Luiz Capitulino,
	Vlastimil Babka (SUSE), Pedro Falcato, Liam R. Howlett, Jann Horn,
	Jakub Matěna, Sasha Levin

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 6.6.y] mm/vma: fix expansion of VMA_MIXEDMAP_BIT VMAs
  2026-11-12  3:47 ` [PATCH 6.6.y] mm/vma: fix expansion of VMA_MIXEDMAP_BIT VMAs Sasha Levin
@ 2026-11-12 20:34   ` Luiz Capitulino
  2026-11-12 20:37     ` Luiz Capitulino
  0 siblings, 1 reply; 4+ messages in thread
From: Luiz Capitulino @ 2026-11-12 20:34 UTC (permalink / raw)
  To: Sasha Levin, stable
  Cc: Lorenzo Stoakes (ARM), Andrew Morton, Vlastimil Babka (SUSE),
	Pedro Falcato, Liam R. Howlett, Jann Horn, Jakub Matěna



On 11/11/26 10:47 PM, Sasha Levin wrote:
> 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>

I tested this against the in-tree reproducer and ran the MM kselftests
(which I had to hack to build). All is good:

Tested-by: Luiz Capitulino <luizcap@redhat.com>

> ---
>   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;


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 6.6.y] mm/vma: fix expansion of VMA_MIXEDMAP_BIT VMAs
  2026-11-12 20:34   ` Luiz Capitulino
@ 2026-11-12 20:37     ` Luiz Capitulino
  0 siblings, 0 replies; 4+ messages in thread
From: Luiz Capitulino @ 2026-11-12 20:37 UTC (permalink / raw)
  To: Sasha Levin, stable
  Cc: Lorenzo Stoakes (ARM), Andrew Morton, Vlastimil Babka (SUSE),
	Pedro Falcato, Liam R. Howlett, Jann Horn, Jakub Matěna



On 11/12/26 3:34 PM, Luiz Capitulino wrote:
> 
> 
> On 11/11/26 10:47 PM, Sasha Levin wrote:
>> 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>
> 
> I tested this against the in-tree reproducer and ran the MM kselftests
> (which I had to hack to build). All is good:
> 
> Tested-by: Luiz Capitulino <luizcap@redhat.com>

I forgot to mention one thing below:

>> ---
>>   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))) {

I think we could check only for VM_MIXEDMAP? Although, AI is telling me
the fix is correct and it makes no difference...

>> +                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;


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-12 20:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 6.6.y] mm/vma: fix expansion of VMA_MIXEDMAP_BIT VMAs Sasha Levin
2026-11-12 20:34   ` Luiz Capitulino
2026-11-12 20:37     ` Luiz Capitulino

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox