From: Lance Yang <lance.yang@linux.dev>
To: akpm@linux-foundation.org, david@redhat.com
Cc: xu.xin16@zte.com.cn, chengming.zhou@linux.dev,
ran.xiaokai@zte.com.cn, yang.yang29@zte.com.cn,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
ioworker0@gmail.com, Lance Yang <lance.yang@linux.dev>
Subject: [PATCH 1/1] mm/ksm: fix spurious soft-dirty bit on zero-filled page merging
Date: Sun, 28 Sep 2025 12:52:07 +0800 [thread overview]
Message-ID: <20250928045207.78546-1-lance.yang@linux.dev> (raw)
From: Lance Yang <lance.yang@linux.dev>
When KSM merges a zero-filled page with the shared zeropage, it uses
pte_mkdirty() to mark the new PTE for internal accounting. However,
pte_mkdirty() unconditionally sets both the hardware dirty bit and the
soft-dirty bit.
This behavior causes false positives in userspace tools like CRIU that
rely on the soft-dirty mechanism for tracking memory changes.
So, preserve the correct state by reading the old PTE under the page
table lock and explicitly clearing the soft-dirty bit from the new PTE
if the original was not soft-dirty.
Fixes: 79271476b336 ("ksm: support unsharing KSM-placed zero pages")
Signed-off-by: Lance Yang <lance.yang@linux.dev>
---
mm/ksm.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/mm/ksm.c b/mm/ksm.c
index 04019a15b25d..e34516b8fbe4 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -1403,6 +1403,9 @@ static int replace_page(struct vm_area_struct *vma, struct page *page,
* the dirty bit in zero page's PTE is set.
*/
newpte = pte_mkdirty(pte_mkspecial(pfn_pte(page_to_pfn(kpage), vma->vm_page_prot)));
+ if (!pte_soft_dirty(ptep_get(ptep)))
+ newpte = pte_clear_soft_dirty(newpte);
+
ksm_map_zero_page(mm);
/*
* We're replacing an anonymous page with a zero page, which is
--
2.49.0
next reply other threads:[~2025-09-28 4:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-28 4:52 Lance Yang [this message]
2025-09-29 8:25 ` David Hildenbrand
2025-09-29 10:08 ` Lance Yang
2025-09-30 7:32 ` David Hildenbrand
2025-09-30 7:36 ` Lance Yang
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=20250928045207.78546-1-lance.yang@linux.dev \
--to=lance.yang@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=chengming.zhou@linux.dev \
--cc=david@redhat.com \
--cc=ioworker0@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ran.xiaokai@zte.com.cn \
--cc=xu.xin16@zte.com.cn \
--cc=yang.yang29@zte.com.cn \
/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