Skip to contentSkip to conversation

FAILED: patch "[PATCH] mm/ksm: keep soft-dirty when merging a page" failed to apply to 5.15-stable tree

PATCH New Sasha Levin 1 participant 2 messages Nov 10 – Nov 11

Subsystems (3)
lore
Share & tools
lore

Sasha Levin

author maintainer
#0 lore raw

The patch below does not apply to the 5.15-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 <[email protected]>.

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-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x 2efc6332f18bfd848f74f3d5ba45b31450601faa
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 5.15.y' 'HEAD^..'

Thanks,
Sasha

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

From 2efc6332f18bfd848f74f3d5ba45b31450601faa Mon Sep 17 00:00:00 2001
From: Samarth Narang <[email protected]>
Date: Wed, 21 Oct 2026 11:21:57 -0700
Subject: [PATCH] mm/ksm: keep soft-dirty when merging a page

replace_page() maps the KSM page with a PTE built from scratch, so the soft-dirty bit of the PTE it replaces is lost. A page written since "clear_refs 4" then no longer shows as soft-dirty once it is merged, and a soft-dirty based dumper treats it as unchanged.

Copy the soft-dirty bit from the original PTE to the new PTE.

Fixes 0f8975ec4db2 ("mm: soft-dirty bits for user memory changes tracking")
Assisted-by LLM
Cc Xu Xin <[email protected]>
Cc Chengming Zhou <[email protected]>
Cc Peter Xu <[email protected]>
Cc Kiryl Shutsemau <[email protected]>
Cc Mike Rapoport <[email protected]>
---
 mm/ksm.c | 4 ++++
 1 file changed, 4 insertions(+)
mm/ksm.c +4 -0
index dbfb8f98b1892..910a1307ac9f3 100644
@@ -1463,6 +1463,10 @@ static int replace_page(struct vm_area_struct *vma, struct page *page,
 		dec_mm_counter(mm, MM_ANONPAGES);
 	}
 
+	/* Preserve soft-dirty when replacing the page. */
+	if (pte_soft_dirty(orig_pte))
+		newpte = pte_mksoft_dirty(newpte);
+
 	flush_cache_page(vma, addr, pte_pfn(ptep_get(ptep)));
 	/*
 	 * No need to notify as we are replacing a read only page with another
Signature · 1 line
2.53.0
author maintainer
#1 lore raw

PATCH 1/1 mm/ksm: keep soft-dirty when merging a page

From: Samarth Narang <[email protected]>

[ Upstream commit 2efc6332f18bfd848f74f3d5ba45b31450601faa ]

replace_page() maps the KSM page with a PTE built from scratch, so the soft-dirty bit of the PTE it replaces is lost. A page written since "clear_refs 4" then no longer shows as soft-dirty once it is merged, and a soft-dirty based dumper treats it as unchanged.

Copy the soft-dirty bit from the original PTE to the new PTE.

Fixes 0f8975ec4db2 ("mm: soft-dirty bits for user memory changes tracking")
Assisted-by LLM
Cc Xu Xin <[email protected]>
Cc Chengming Zhou <[email protected]>
Cc Peter Xu <[email protected]>
Cc Kiryl Shutsemau <[email protected]>
Cc Mike Rapoport <[email protected]>
[ sashal: adjusted context because flush_cache_page() uses *ptep instead of ptep_get(ptep) ]
---
 mm/ksm.c | 4 ++++
 1 file changed, 4 insertions(+)
mm/ksm.c +4 -0
index 3ed1bd6085f91..26d9beca82095 100644
@@ -1163,6 +1163,10 @@ static int replace_page(struct vm_area_struct *vma, struct page *page,
 		dec_mm_counter(mm, MM_ANONPAGES);
 	}
 
+	/* Preserve soft-dirty when replacing the page. */
+	if (pte_soft_dirty(orig_pte))
+		newpte = pte_mksoft_dirty(newpte);
+
 	flush_cache_page(vma, addr, pte_pfn(*ptep));
 	/*
 	 * No need to notify as we are replacing a read only page with another
Signature · 1 line
2.53.0