public inbox for linux-mm@kvack.org
 help / color / mirror / Atom feed
From: Ahmed Elaidy <elaidya225@gmail.com>
To: Andrei Vagin <avagin@gmail.com>
Cc: stable@vger.kernel.org, lorenzo.stoakes@oracle.com,
	akpm@linux-foundation.org, linux-mm@kvack.org,
	Ahmed Elaidy <elaidya225@gmail.com>
Subject: [PATCH 6.18.y v3] mm: fix VM_SOFTDIRTY propagation on VMA merge
Date: Mon,  4 May 2026 22:54:47 +0300	[thread overview]
Message-ID: <20260504195447.31794-1-elaidya225@gmail.com> (raw)
In-Reply-To: <CANaxB-xFcF7U=wJv8EqKy=j=-P3SN+sLQ9ytH8Ej69h03tqL8Q@mail.gmail.com>

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 and mmap. This patch ensures the resulting merged VMA retains
the VM_SOFTDIRTY flag if either of the original VMAs had it.

Fixes: 34228d473efe ("mm: ignore VM_SOFTDIRTY on VMA merging")
Suggested-by: Andrei Vagin <avagin@gmail.com>
Cc: stable@vger.kernel.org # 6.18.x
Cc: lorenzo.stoakes@oracle.com
Signed-off-by: Ahmed Elaidy <elaidya225@gmail.com>
---
 mm/vma.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/mm/vma.c b/mm/vma.c
index 5815ae9e5770..2988f6b3feff 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);
+
 	khugepaged_enter_vma(vmg->target, vmg->vm_flags);
 	vmg->state = VMA_MERGE_SUCCESS;
 	return vmg->target;
@@ -1098,6 +1106,14 @@ struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg)
 	 * following VMA if we have VMAs on both sides.
 	 */
 	if (vmg->target && !vma_expand(vmg)) {
+		/*
+		 * VM_SOFTDIRTY is excluded from normal flag comparison to allow
+		 * merging, 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);
+
 		khugepaged_enter_vma(vmg->target, vmg->vm_flags);
 		vmg->state = VMA_MERGE_SUCCESS;
 		return vmg->target;
-- 
2.54.0



  parent reply	other threads:[~2026-05-04 19:55 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-24 21:12 [PATCH 6.18.y v1 0/9] mm: backport sticky VMA flags and soft-dirty fix Ahmed Elaidy
2026-04-24 21:12 ` [PATCH v1 1/9] mm: introduce VM_MAYBE_GUARD and make visible in /proc/$pid/smaps Ahmed Elaidy
2026-04-24 21:12 ` [PATCH v1 2/9] mm: add atomic VMA flags and set VM_MAYBE_GUARD as such Ahmed Elaidy
2026-04-24 21:12 ` [PATCH v1 3/9] mm: update vma_modify_flags() to handle residual flags, document Ahmed Elaidy
2026-04-24 21:12 ` [PATCH v1 4/9] mm: implement sticky VMA flags Ahmed Elaidy
2026-04-24 21:12 ` [PATCH v1 5/9] mm: introduce copy-on-fork VMAs and make VM_MAYBE_GUARD one Ahmed Elaidy
2026-04-24 21:12 ` [PATCH v1 6/9] mm: set the VM_MAYBE_GUARD flag on guard region install Ahmed Elaidy
2026-04-24 21:12 ` [PATCH v1 7/9] tools/testing/vma: add VMA sticky userland tests Ahmed Elaidy
2026-04-24 21:12 ` [PATCH v1 8/9] mm: propagate VM_SOFTDIRTY on merge Ahmed Elaidy
2026-04-24 21:12 ` [PATCH v1 9/9] testing/selftests/mm: add soft-dirty merge self-test Ahmed Elaidy
2026-04-24 21:55 ` [PATCH 6.18.y v1 0/9] mm: backport sticky VMA flags and soft-dirty fix Andrei Vagin
2026-04-24 22:11   ` [PATCH v2] mm: fix VM_SOFTDIRTY propagation on VMA merge Ahmed Elaidy
2026-05-04 16:42     ` Andrei Vagin
2026-05-04 19:54       ` Ahmed Elaidy
2026-05-04 19:54       ` Ahmed Elaidy [this message]
2026-05-04 19:58       ` Ahmed Elaidy

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=20260504195447.31794-1-elaidya225@gmail.com \
    --to=elaidya225@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=avagin@gmail.com \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=stable@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox