* [PATCH v3] mm/ksm: keep soft-dirty when merging a page
@ 2026-10-21 18:21 Samarth Narang
2026-10-22 0:51 ` Lance Yang
0 siblings, 1 reply; 2+ messages in thread
From: Samarth Narang @ 2026-10-21 18:21 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand
Cc: Xu Xin, Chengming Zhou, Peter Xu, Kiryl Shutsemau, Mike Rapoport,
Lance Yang, linux-mm, linux-kernel, Samarth Narang, stable
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")
Cc: stable@vger.kernel.org
Assisted-by: LLM
Signed-off-by: Samarth Narang <samarth.colleges@gmail.com>
---
Notes:
v2: https://lore.kernel.org/all/20261019010934.697895-1-samarth.colleges@gmail.com/
Changes since v2:
- Keep only the soft-dirty fix, as David suggested; Lance will be handling
the uffd-wp/RWP part.
- Fixes tag reduced to the soft-dirty commit.
- Dropped the Tested-by tag, since the patch changed.
mm/ksm.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/mm/ksm.c b/mm/ksm.c
index dbfb8f98b189..910a1307ac9f 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -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
base-commit: fcec4f4bcc1101dbd7e3aff267856b3bbfe128c6
--
2.53.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v3] mm/ksm: keep soft-dirty when merging a page
2026-10-21 18:21 [PATCH v3] mm/ksm: keep soft-dirty when merging a page Samarth Narang
@ 2026-10-22 0:51 ` Lance Yang
0 siblings, 0 replies; 2+ messages in thread
From: Lance Yang @ 2026-10-22 0:51 UTC (permalink / raw)
To: samarth.colleges
Cc: akpm, david, xu.xin, chengming.zhou, peterx, kas, rppt,
lance.yang, linux-mm, linux-kernel, stable
On Wed, Oct 21, 2026 at 11:21:57AM -0700, Samarth Narang wrote:
>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")
>Cc: stable@vger.kernel.org
>Assisted-by: LLM
>Signed-off-by: Samarth Narang <samarth.colleges@gmail.com>
>---
LGTM!
Reviewed-by: Lance Yang <lance.yang@linux.dev>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-22 0:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-21 18:21 [PATCH v3] mm/ksm: keep soft-dirty when merging a page Samarth Narang
2026-10-22 0:51 ` Lance Yang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®