Re: [PATCH v2] mm: fix VM_SOFTDIRTY propagation on VMA merge

Andrei Vagin
2026-05-04T16:42:52Z

[-- Attachment #1: Type: text/plain, Size: 1996 bytes --]

On Fri, Apr 24, 2026 at 3:11 PM Ahmed Elaidy <elaidya225@gmail.com> wrote:

> During VMA merging, such as through mprotect(), VM_SOFTDIRTY flags could be
> lost. This breaks tools relying on soft-dirty tracking, such as CRIU
> incremental dump/restore.
>
> Upstream resolved this using a broader VM_STICKY infrastructure (commit
> bf14d4a05387 "mm: propagate VM_SOFTDIRTY on merge"). To minimize churn and
> risk in the stable 6.18.y tree, this patch skips backporting the entire
> VM_STICKY series (9 patches). Instead, it introduces a minimal standalone
> fix.
>
> VM_SOFTDIRTY is intentionally excluded from normal flag comparison to allow
> merging in mprotect. This patch ensures the resulting merged VMA retains
> the VM_SOFTDIRTY flag if either of the original VMAs had it.
>
> Suggested-by: Andrei Vagin <avagin@gmail.com>
> Cc: stable@vger.kernel.org

It probably should be: Cc: stable@vger.kernel.org # 6.18.x and
the prefix in the subject can be [PATCH 6.18.y]..

Please add The Fixes tag to the commit that introduced the issue.

> Cc: lorenzo.stoakes@oracle.com
> Signed-off-by: Ahmed Khalid Elaidy <elaidya225@gmail.com>
> ---
> mm/vma.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/mm/vma.c b/mm/vma.c
> index 5815ae9e5770..03728d855684 100644
> --- a/mm/vma.c
> +++ b/mm/vma.c
> @@ -978,6 +978,14 @@ static __must_check struct vm_area_struct
> *vma_merge_existing_range(
> if (err || commit_merge(vmg))
> goto abort;
>
> + /*
> + * VM_SOFTDIRTY is excluded from normal flag comparison to allow
> + * merging in mprotect, but we have to ensure the result is
> correctly
> + * marked with it if either side had it.
> + */
> + if ((vmg->target->vm_flags ^ vmg->vm_flags) & VM_SOFTDIRTY)
> + vm_flags_set(vmg->target, VM_SOFTDIRTY);
>

Should we fix vma_merge_new_range too?

How are you testing this patch?

Thanks,
Andrei

[-- Attachment #2: Type: text/html, Size: 3022 bytes --]