Re: [PATCH] mm/vma: fix expansion of VMA_MIXEDMAP_BIT VMAs

From: Vlastimil Babka (SUSE)

Date: Mon Oct 26 2026 - 09:21:20 EST


On 10/23/26 17:17, Lorenzo Stoakes (ARM) wrote:
> 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.
>
> Reported-by: Luiz Capitulino <luizcap@xxxxxxxxxx>
> Closes: https://lore.kernel.org/all/20261023023106.515365-1-luizcap@xxxxxxxxxx/
> Fixes: ca3d76b0aa80 ("mm: add merging after mremap resize")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx>

Acked-by: Vlastimil Babka (SUSE) <vbabka@xxxxxxxxxx>