mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/3] mm: fix soft-dirty false positives in mprotect() of large folios
@ 2026-11-25 13:32 Shivank Garg
  2026-11-25 13:32 ` [PATCH 1/3] mm: move the soft-dirty fallbacks up in pgtable.h Shivank Garg
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Shivank Garg @ 2026-11-25 13:32 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, Dev Jain, Zi Yan, Baolin Wang,
	Nico Pache, Ryan Roberts, Barry Song, Lance Yang, Usama Arif,
	Kiryl Shutsemau, Peter Xu, Shuah Khan, Michał Mirosław,
	Andrei Vagin, Paul Gofman, Bharata B Rao, Daniel Wade, Yin Tirui,
	Muhammad Usama Anjum
  Cc: linux-mm, linux-kselftest, linux-kernel, Shivank Garg

mprotect() handles the PTEs of a large folio as one batch, and marks the
whole batch dirty with pte_mkdirty() if any of its PTEs is dirty.  On
x86, powerpc, riscv and s390, pte_mkdirty() also sets the soft-dirty
bit, so after clear_refs, mprotect() marks unwritten pages soft-dirty.
With 64K mTHP on x86-64, all 240 unwritten pages of a 1MiB region are
reported soft-dirty; with my fix, none are.

I fix this issue similar to how commit 055267feaecc ("mm/migrate:
preserve exact soft-dirty state") fixed remove_migration_pte() and add
a selftest.
On Zen5, an mprotect() loop over 256MiB is 2-4% slower with 16K to 1M
mTHP and unchanged with 4K pages.  Patch 3 adds a selftest.

I first hit this while stress testing [1] and [2] with LLM-generated
test cases: both build swap or migration entries from
get_and_clear_full_ptes(), and their soft-dirty tests failed on x86.
Looking into it, I found that mprotect() batching, already in mainline,
has the same pattern and reproduces the problem.

Two other places have the same pattern, but I left them out since
over-indicating soft-dirty is sometimes considered fine:

 - get_and_clear_full_ptes(): when reclaim of a lazyfree large folio
   fails because the folio was written to, try_to_unmap_one() restores
   the PTEs from the merged PTE, and all of them become soft-dirty.
 - remove_migration_pmd(): pmd_mkdirty() marks a migrated PMD THP
   soft-dirty.

Are they worth fixing?

[1] https://lore.kernel.org/20261123053543.295467-1-dev.jain@arm.com
[2] https://lore.kernel.org/20260813-migrate-rmap-batch-v2-0-3c5424c555c7@amd.com

---
Shivank Garg (3):
      mm: move the soft-dirty fallbacks up in pgtable.h
      mm: don't let modify_prot_start_ptes() set soft-dirty on clean PTEs
      selftests/mm: soft-dirty: check that mprotect() keeps PTE-mapped THPs clean

 include/linux/pgtable.h                 | 188 ++++++++++++++++----------------
 tools/testing/selftests/mm/soft-dirty.c |  48 +++++++-
 2 files changed, 143 insertions(+), 93 deletions(-)
---
base-commit: 98f6b507621822477db7ec7cef8519de0dd243c4
base-tree: git://git.kernel.org/pub/scm/linux/kernel/git/mm/core.git for-next
change-id: 20261124-b4-mm-soft-dirty-fixes-68c578e1dfbd

Best regards,
--  
Shivank Garg <shivankg@amd.com>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/3] mm: move the soft-dirty fallbacks up in pgtable.h
  2026-11-25 13:32 [PATCH 0/3] mm: fix soft-dirty false positives in mprotect() of large folios Shivank Garg
@ 2026-11-25 13:32 ` Shivank Garg
  2026-11-25 16:44   ` kernel test robot
  2026-11-25 16:44   ` kernel test robot
  2026-11-25 13:32 ` [PATCH 2/3] mm: don't let modify_prot_start_ptes() set soft-dirty on clean PTEs Shivank Garg
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 10+ messages in thread
From: Shivank Garg @ 2026-11-25 13:32 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, Dev Jain, Zi Yan, Baolin Wang,
	Nico Pache, Ryan Roberts, Barry Song, Lance Yang, Usama Arif,
	Kiryl Shutsemau, Peter Xu, Shuah Khan, Michał Mirosław,
	Andrei Vagin, Paul Gofman, Bharata B Rao, Daniel Wade, Yin Tirui,
	Muhammad Usama Anjum
  Cc: linux-mm, linux-kselftest, linux-kernel, Shivank Garg

The fallbacks for pte_soft_dirty() and friends on architectures without
CONFIG_HAVE_ARCH_SOFT_DIRTY are defined near the end of pgtable.h, after
the batched PTE helper modify_prot_start_ptes().

Move them, together with pgtable_supports_soft_dirty(), up next to the
other generic PTE and PMD accessors, so that the next patch can use them
in that helper.

No functional change.

Signed-off-by: Shivank Garg <shivankg@amd.com>
---
 include/linux/pgtable.h | 182 ++++++++++++++++++++++++------------------------
 1 file changed, 91 insertions(+), 91 deletions(-)

diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index 66d369870a74..b1db7aec5362 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -194,6 +194,97 @@ static inline int pmd_dirty(pmd_t pmd)
 }
 #endif
 
+/*
+ * Some platforms can customize the PTE soft-dirty bit making it unavailable
+ * even if the architecture provides the resource.
+ * Adding this API allows architectures to add their own checks for the
+ * devices on which the kernel is running.
+ * Note: When overriding it, please make sure the CONFIG_MEM_SOFT_DIRTY
+ * is part of this macro.
+ */
+#ifndef pgtable_supports_soft_dirty
+#define pgtable_supports_soft_dirty()	IS_ENABLED(CONFIG_MEM_SOFT_DIRTY)
+#endif
+
+#ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY
+#ifndef CONFIG_ARCH_HAS_PMD_SOFTLEAVES
+static inline pmd_t pmd_swp_mksoft_dirty(pmd_t pmd)
+{
+	return pmd;
+}
+
+static inline int pmd_swp_soft_dirty(pmd_t pmd)
+{
+	return 0;
+}
+
+static inline pmd_t pmd_swp_clear_soft_dirty(pmd_t pmd)
+{
+	return pmd;
+}
+#endif
+#else /* !CONFIG_HAVE_ARCH_SOFT_DIRTY */
+static inline int pte_soft_dirty(pte_t pte)
+{
+	return 0;
+}
+
+static inline int pmd_soft_dirty(pmd_t pmd)
+{
+	return 0;
+}
+
+static inline pte_t pte_mksoft_dirty(pte_t pte)
+{
+	return pte;
+}
+
+static inline pmd_t pmd_mksoft_dirty(pmd_t pmd)
+{
+	return pmd;
+}
+
+static inline pte_t pte_clear_soft_dirty(pte_t pte)
+{
+	return pte;
+}
+
+static inline pmd_t pmd_clear_soft_dirty(pmd_t pmd)
+{
+	return pmd;
+}
+
+static inline pte_t pte_swp_mksoft_dirty(pte_t pte)
+{
+	return pte;
+}
+
+static inline int pte_swp_soft_dirty(pte_t pte)
+{
+	return 0;
+}
+
+static inline pte_t pte_swp_clear_soft_dirty(pte_t pte)
+{
+	return pte;
+}
+
+static inline pmd_t pmd_swp_mksoft_dirty(pmd_t pmd)
+{
+	return pmd;
+}
+
+static inline int pmd_swp_soft_dirty(pmd_t pmd)
+{
+	return 0;
+}
+
+static inline pmd_t pmd_swp_clear_soft_dirty(pmd_t pmd)
+{
+	return pmd;
+}
+#endif
+
 /*
  * A facility to provide lazy MMU batching.  This allows PTE updates and
  * page invalidations to be delayed until a call to leave lazy MMU mode
@@ -1850,97 +1941,6 @@ static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
 #define arch_start_context_switch(prev)	do {} while (0)
 #endif
 
-/*
- * Some platforms can customize the PTE soft-dirty bit making it unavailable
- * even if the architecture provides the resource.
- * Adding this API allows architectures to add their own checks for the
- * devices on which the kernel is running.
- * Note: When overriding it, please make sure the CONFIG_MEM_SOFT_DIRTY
- * is part of this macro.
- */
-#ifndef pgtable_supports_soft_dirty
-#define pgtable_supports_soft_dirty()	IS_ENABLED(CONFIG_MEM_SOFT_DIRTY)
-#endif
-
-#ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY
-#ifndef CONFIG_ARCH_HAS_PMD_SOFTLEAVES
-static inline pmd_t pmd_swp_mksoft_dirty(pmd_t pmd)
-{
-	return pmd;
-}
-
-static inline int pmd_swp_soft_dirty(pmd_t pmd)
-{
-	return 0;
-}
-
-static inline pmd_t pmd_swp_clear_soft_dirty(pmd_t pmd)
-{
-	return pmd;
-}
-#endif
-#else /* !CONFIG_HAVE_ARCH_SOFT_DIRTY */
-static inline int pte_soft_dirty(pte_t pte)
-{
-	return 0;
-}
-
-static inline int pmd_soft_dirty(pmd_t pmd)
-{
-	return 0;
-}
-
-static inline pte_t pte_mksoft_dirty(pte_t pte)
-{
-	return pte;
-}
-
-static inline pmd_t pmd_mksoft_dirty(pmd_t pmd)
-{
-	return pmd;
-}
-
-static inline pte_t pte_clear_soft_dirty(pte_t pte)
-{
-	return pte;
-}
-
-static inline pmd_t pmd_clear_soft_dirty(pmd_t pmd)
-{
-	return pmd;
-}
-
-static inline pte_t pte_swp_mksoft_dirty(pte_t pte)
-{
-	return pte;
-}
-
-static inline int pte_swp_soft_dirty(pte_t pte)
-{
-	return 0;
-}
-
-static inline pte_t pte_swp_clear_soft_dirty(pte_t pte)
-{
-	return pte;
-}
-
-static inline pmd_t pmd_swp_mksoft_dirty(pmd_t pmd)
-{
-	return pmd;
-}
-
-static inline int pmd_swp_soft_dirty(pmd_t pmd)
-{
-	return 0;
-}
-
-static inline pmd_t pmd_swp_clear_soft_dirty(pmd_t pmd)
-{
-	return pmd;
-}
-#endif
-
 #ifndef __HAVE_PFNMAP_TRACKING
 /*
  * Interfaces that can be used by architecture code to keep track of

-- 
2.53.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 2/3] mm: don't let modify_prot_start_ptes() set soft-dirty on clean PTEs
  2026-11-25 13:32 [PATCH 0/3] mm: fix soft-dirty false positives in mprotect() of large folios Shivank Garg
  2026-11-25 13:32 ` [PATCH 1/3] mm: move the soft-dirty fallbacks up in pgtable.h Shivank Garg
@ 2026-11-25 13:32 ` Shivank Garg
  2026-11-25 13:32 ` [PATCH 3/3] selftests/mm: soft-dirty: check that mprotect() keeps PTE-mapped THPs clean Shivank Garg
  2026-11-25 13:43 ` [PATCH 0/3] mm: fix soft-dirty false positives in mprotect() of large folios David Hildenbrand (Arm)
  3 siblings, 0 replies; 10+ messages in thread
From: Shivank Garg @ 2026-11-25 13:32 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, Dev Jain, Zi Yan, Baolin Wang,
	Nico Pache, Ryan Roberts, Barry Song, Lance Yang, Usama Arif,
	Kiryl Shutsemau, Peter Xu, Shuah Khan, Michał Mirosław,
	Andrei Vagin, Paul Gofman, Bharata B Rao, Daniel Wade, Yin Tirui,
	Muhammad Usama Anjum
  Cc: linux-mm, linux-kselftest, linux-kernel, Shivank Garg

Since commit cac1db8c3aad ("mm: optimize mprotect() by PTE batching"),
mprotect() of large folios marks pages soft-dirty that were not written
since the soft-dirty bits were cleared.

modify_prot_start_ptes() folds the dirty bits of a batch into the
returned PTE with pte_mkdirty(), which also sets the soft-dirty bit on
architectures that support it.  If any PTE of the batch is hardware
dirty, change_pte_range() then marks the whole batch soft-dirty.
clear_refs keeps the hardware dirty bit, so after clear_refs, mprotect()
makes nearly every page of a populated region look written, which can
mislead tools like CRIU into copying it again.

Reproducer, with 64K mTHP enabled:

 1. mmap() a 64K-aligned 1MiB anonymous region and populate it
 2. write "4" to /proc/self/clear_refs
 3. write to the first page of each 64K folio
 4. mprotect(PROT_READ) the region
 5. read bit 55 of /proc/self/pagemap for each page

Only the 16 written pages should be soft-dirty, but on x86-64 all 256
are.

Instead, mark the returned PTE soft-dirty if any PTE of the batch is
soft-dirty, and clear the bit otherwise, undoing the soft-dirty bit
that pte_mkdirty() set.

Fixes: cac1db8c3aad ("mm: optimize mprotect() by PTE batching")
Signed-off-by: Shivank Garg <shivankg@amd.com>
---
 include/linux/pgtable.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index b1db7aec5362..bbba2cc71096 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -1785,8 +1785,10 @@ static inline pte_t modify_prot_start_ptes(struct vm_area_struct *vma,
 		unsigned long addr, pte_t *ptep, unsigned int nr)
 {
 	pte_t pte, tmp_pte;
+	bool soft_dirty;
 
 	pte = ptep_modify_prot_start(vma, addr, ptep);
+	soft_dirty = pte_soft_dirty(pte);
 	while (--nr) {
 		ptep++;
 		addr += PAGE_SIZE;
@@ -1795,8 +1797,10 @@ static inline pte_t modify_prot_start_ptes(struct vm_area_struct *vma,
 			pte = pte_mkdirty(pte);
 		if (pte_young(tmp_pte))
 			pte = pte_mkyoung(pte);
+		soft_dirty |= pte_soft_dirty(tmp_pte);
 	}
-	return pte;
+	/* pte_mkdirty() also sets the soft-dirty bit. */
+	return soft_dirty ? pte_mksoft_dirty(pte) : pte_clear_soft_dirty(pte);
 }
 #endif
 

-- 
2.53.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 3/3] selftests/mm: soft-dirty: check that mprotect() keeps PTE-mapped THPs clean
  2026-11-25 13:32 [PATCH 0/3] mm: fix soft-dirty false positives in mprotect() of large folios Shivank Garg
  2026-11-25 13:32 ` [PATCH 1/3] mm: move the soft-dirty fallbacks up in pgtable.h Shivank Garg
  2026-11-25 13:32 ` [PATCH 2/3] mm: don't let modify_prot_start_ptes() set soft-dirty on clean PTEs Shivank Garg
@ 2026-11-25 13:32 ` Shivank Garg
  2026-11-25 13:43 ` [PATCH 0/3] mm: fix soft-dirty false positives in mprotect() of large folios David Hildenbrand (Arm)
  3 siblings, 0 replies; 10+ messages in thread
From: Shivank Garg @ 2026-11-25 13:32 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, Dev Jain, Zi Yan, Baolin Wang,
	Nico Pache, Ryan Roberts, Barry Song, Lance Yang, Usama Arif,
	Kiryl Shutsemau, Peter Xu, Shuah Khan, Michał Mirosław,
	Andrei Vagin, Paul Gofman, Bharata B Rao, Daniel Wade, Yin Tirui,
	Muhammad Usama Anjum
  Cc: linux-mm, linux-kselftest, linux-kernel, Shivank Garg

Add a test that clears the soft-dirty bits of a dirty, PTE-mapped THP,
mprotect()s it without writing to it, and checks that pagemap reports no
page as soft-dirty.  mprotect() batches the PTEs of the large folio, so
this covers modify_prot_start_ptes().

On x86-64, the test fails without the previous patch.  It is skipped
without THP.

Signed-off-by: Shivank Garg <shivankg@amd.com>
---
 tools/testing/selftests/mm/soft-dirty.c | 48 ++++++++++++++++++++++++++++++++-
 1 file changed, 47 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/mm/soft-dirty.c b/tools/testing/selftests/mm/soft-dirty.c
index 7f649b673355..1764e285f125 100644
--- a/tools/testing/selftests/mm/soft-dirty.c
+++ b/tools/testing/selftests/mm/soft-dirty.c
@@ -310,6 +310,51 @@ static void test_merge(int pagemap_fd, int pagesize)
 	munmap(map, 2 * pagesize);
 }
 
+/*
+ * Clear the soft-dirty bits of a dirty PTE-mapped THP, then mprotect() it
+ * without writing to it. mprotect() batches the PTEs of the large folio
+ * and must not mark them soft-dirty.
+ */
+static void test_thp_mprotect(int pagemap_fd, int pagesize)
+{
+	size_t hpage_len = read_pmd_pagesize();
+	size_t len = hpage_len - pagesize;
+	unsigned long nr = 0;
+	size_t offs;
+	char *map;
+
+	if (!thp_is_enabled() || !hpage_len) {
+		ksft_test_result_skip("Test %s no THP\n", __func__);
+		return;
+	}
+
+	map = memalign(hpage_len, hpage_len);
+	if (!map)
+		ksft_exit_fail_msg("memalign failed\n");
+	if (madvise(map, hpage_len, MADV_HUGEPAGE))
+		ksft_exit_fail_msg("madvise failed\n");
+	memset(map, 1, hpage_len);
+
+	if (!check_huge_anon(map, hpage_len, 1, hpage_len)) {
+		ksft_test_result_skip("Test %s no THP\n", __func__);
+		goto out;
+	}
+
+	/* Zapping the last page PTE-maps the rest of the THP. */
+	madvise(map + len, pagesize, MADV_DONTNEED);
+	clear_softdirty();
+	mprotect(map, len, PROT_READ);
+
+	for (offs = 0; offs < len; offs += pagesize)
+		nr += pagemap_is_softdirty(pagemap_fd, map + offs);
+	ksft_test_result(!nr, "Test %s soft-dirty clear after mprotect\n",
+			 __func__);
+
+	mprotect(map, len, PROT_READ | PROT_WRITE);
+out:
+	free(map);
+}
+
 static void test_mprotect_anon(int pagemap_fd, int pagesize)
 {
 	test_mprotect(pagemap_fd, pagesize, true);
@@ -330,7 +375,7 @@ int main(int argc, char **argv)
 	if (!softdirty_supported())
 		ksft_exit_skip("soft-dirty is not support\n");
 
-	ksft_set_plan(19);
+	ksft_set_plan(20);
 	pagemap_fd = open(PAGEMAP_FILE_PATH, O_RDONLY);
 	if (pagemap_fd < 0)
 		ksft_exit_fail_msg("Failed to open %s\n", PAGEMAP_FILE_PATH);
@@ -343,6 +388,7 @@ int main(int argc, char **argv)
 	test_mprotect_anon(pagemap_fd, pagesize);
 	test_mprotect_file(pagemap_fd, pagesize);
 	test_merge(pagemap_fd, pagesize);
+	test_thp_mprotect(pagemap_fd, pagesize);
 
 	close(pagemap_fd);
 

-- 
2.53.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] mm: fix soft-dirty false positives in mprotect() of large folios
  2026-11-25 13:32 [PATCH 0/3] mm: fix soft-dirty false positives in mprotect() of large folios Shivank Garg
                   ` (2 preceding siblings ...)
  2026-11-25 13:32 ` [PATCH 3/3] selftests/mm: soft-dirty: check that mprotect() keeps PTE-mapped THPs clean Shivank Garg
@ 2026-11-25 13:43 ` David Hildenbrand (Arm)
  2026-11-25 14:16   ` Garg, Shivank
  2026-11-25 15:42   ` Paul Gofman
  3 siblings, 2 replies; 10+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-25 13:43 UTC (permalink / raw)
  To: Shivank Garg, Andrew Morton, Lorenzo Stoakes, Liam R. Howlett,
	Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
	Dev Jain, Zi Yan, Baolin Wang, Nico Pache, Ryan Roberts,
	Barry Song, Lance Yang, Usama Arif, Kiryl Shutsemau, Peter Xu,
	Shuah Khan, Michał Mirosław, Andrei Vagin, Paul Gofman,
	Bharata B Rao, Daniel Wade, Yin Tirui, Muhammad Usama Anjum
  Cc: linux-mm, linux-kselftest, linux-kernel

On 11/25/26 14:32, Shivank Garg wrote:
> mprotect() handles the PTEs of a large folio as one batch, and marks the
> whole batch dirty with pte_mkdirty() if any of its PTEs is dirty.  On
> x86, powerpc, riscv and s390, pte_mkdirty() also sets the soft-dirty
> bit, so after clear_refs, mprotect() marks unwritten pages soft-dirty.
> With 64K mTHP on x86-64, all 240 unwritten pages of a 1MiB region are
> reported soft-dirty; with my fix, none are.

Why do we care? Just over-indicate soft-dirty. It's valid, and the whole feature
is full of holes and buggy as hell.

-- 
Cheers,

David

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] mm: fix soft-dirty false positives in mprotect() of large folios
  2026-11-25 13:43 ` [PATCH 0/3] mm: fix soft-dirty false positives in mprotect() of large folios David Hildenbrand (Arm)
@ 2026-11-25 14:16   ` Garg, Shivank
  2026-11-25 15:42   ` Paul Gofman
  1 sibling, 0 replies; 10+ messages in thread
From: Garg, Shivank @ 2026-11-25 14:16 UTC (permalink / raw)
  To: usama.anjum, nico.pache, rppt, shuah, Rao, Bharata Bhasker,
	yintirui, vbabka, emmir, danjwade95, pgofman, david, akpm,
	dev.jain, surenb, kas, peterx, usama.arif, ziy, ryan.roberts,
	baolin.wang, liam, mhocko, ljs, lance.yang, baohua, avagin
  Cc: linux-mm, linux-kselftest, linux-kernel

On Wed, 2026-11-25 at 14:43 +0100, David Hildenbrand (Arm) wrote:
> On 11/25/26 14:32, Shivank Garg wrote:
> > mprotect() handles the PTEs of a large folio as one batch, and marks the
> > whole batch dirty with pte_mkdirty() if any of its PTEs is dirty.  On
> > x86, powerpc, riscv and s390, pte_mkdirty() also sets the soft-dirty
> > bit, so after clear_refs, mprotect() marks unwritten pages soft-dirty.
> > With 64K mTHP on x86-64, all 240 unwritten pages of a 1MiB region are
> > reported soft-dirty; with my fix, none are.
> 
> Why do we care? Just over-indicate soft-dirty. It's valid, and the whole feature
> is full of holes and buggy as hell.

Sure, I'll drop this. I was concerned because I was working on related code
in my migration series [1].

[1]https://lore.kernel.org/linux-mm/20260813-migrate-rmap-batch-v2-0-3c5424c555c7@amd.com

Thanks,
Shivank

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] mm: fix soft-dirty false positives in mprotect() of large folios
  2026-11-25 13:43 ` [PATCH 0/3] mm: fix soft-dirty false positives in mprotect() of large folios David Hildenbrand (Arm)
  2026-11-25 14:16   ` Garg, Shivank
@ 2026-11-25 15:42   ` Paul Gofman
  2026-11-25 16:11     ` Garg, Shivank
  1 sibling, 1 reply; 10+ messages in thread
From: Paul Gofman @ 2026-11-25 15:42 UTC (permalink / raw)
  To: David Hildenbrand (Arm),
	Shivank Garg, Andrew Morton, Lorenzo Stoakes, Liam R. Howlett,
	Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
	Dev Jain, Zi Yan, Baolin Wang, Nico Pache, Ryan Roberts,
	Barry Song, Lance Yang, Usama Arif, Kiryl Shutsemau, Peter Xu,
	Shuah Khan, Michał Mirosław, Andrei Vagin,
	Bharata B Rao, Daniel Wade, Yin Tirui, Muhammad Usama Anjum,
	wine-devel
  Cc: linux-mm, linux-kselftest, linux-kernel

On 11/25/26 07:43, David Hildenbrand (Arm) wrote:
> On 11/25/26 14:32, Shivank Garg wrote:
>> mprotect() handles the PTEs of a large folio as one batch, and marks the
>> whole batch dirty with pte_mkdirty() if any of its PTEs is dirty.  On
>> x86, powerpc, riscv and s390, pte_mkdirty() also sets the soft-dirty
>> bit, so after clear_refs, mprotect() marks unwritten pages soft-dirty.
>> With 64K mTHP on x86-64, all 240 unwritten pages of a 1MiB region are
>> reported soft-dirty; with my fix, none are.
> Why do we care? Just over-indicate soft-dirty. It's valid, and the whole feature
> is full of holes and buggy as hell.
>
Do I understand correctly that these issues only affect the old soft 
dirty feature and not UFFD WP async (UFFD_FEATURE_WP_ASYNC)? 
Over-indicating written pages with the newer UFFD support is not 
expected and Wine usage of the feature requires that. But I guess it is 
not what is concerned here?


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] mm: fix soft-dirty false positives in mprotect() of large folios
  2026-11-25 15:42   ` Paul Gofman
@ 2026-11-25 16:11     ` Garg, Shivank
  0 siblings, 0 replies; 10+ messages in thread
From: Garg, Shivank @ 2026-11-25 16:11 UTC (permalink / raw)
  To: usama.anjum, nico.pache, rppt, shuah, Rao, Bharata Bhasker,
	yintirui, vbabka, emmir, danjwade95, david, akpm, dev.jain,
	pgofman, surenb, peterx, usama.arif, kas, ziy, ryan.roberts,
	baohua, liam, mhocko, ljs, lance.yang, baolin.wang, wine-devel,
	avagin
  Cc: linux-mm, linux-kselftest, linux-kernel

On Wed, 2026-11-25 at 09:42 -0600, Paul Gofman wrote:
> On 11/25/26 07:43, David Hildenbrand (Arm) wrote:
> > On 11/25/26 14:32, Shivank Garg wrote:
> > > mprotect() handles the PTEs of a large folio as one batch, and marks the
> > > whole batch dirty with pte_mkdirty() if any of its PTEs is dirty.  On
> > > x86, powerpc, riscv and s390, pte_mkdirty() also sets the soft-dirty
> > > bit, so after clear_refs, mprotect() marks unwritten pages soft-dirty.
> > > With 64K mTHP on x86-64, all 240 unwritten pages of a 1MiB region are
> > > reported soft-dirty; with my fix, none are.
> > Why do we care? Just over-indicate soft-dirty. It's valid, and the whole feature
> > is full of holes and buggy as hell.
> > 
> Do I understand correctly that these issues only affect the old soft 
> dirty feature and not UFFD WP async (UFFD_FEATURE_WP_ASYNC)? 
> Over-indicating written pages with the newer UFFD support is not 
> expected and Wine usage of the feature requires that. But I guess it is 
> not what is concerned here?

Yes, right. This only affect the soft-dirty bit, and not uffd-wp feature.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/3] mm: move the soft-dirty fallbacks up in pgtable.h
  2026-11-25 13:32 ` [PATCH 1/3] mm: move the soft-dirty fallbacks up in pgtable.h Shivank Garg
@ 2026-11-25 16:44   ` kernel test robot
  2026-11-25 16:44   ` kernel test robot
  1 sibling, 0 replies; 10+ messages in thread
From: kernel test robot @ 2026-11-25 16:44 UTC (permalink / raw)
  To: Shivank Garg, Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, Dev Jain, Zi Yan, Baolin Wang,
	Nico Pache, Ryan Roberts, Barry Song, Lance Yang, Usama Arif,
	Kiryl Shutsemau, Peter Xu, Shuah Khan, Michał Mirosław,
	Andrei Vagin, Paul Gofman, Bharata B Rao, Daniel Wade, Yin Tirui,
	Muhammad Usama Anjum
  Cc: oe-kbuild-all, Linux Memory Management List, linux-kselftest,
	linux-kernel, Shivank Garg

Hi Shivank,

kernel test robot noticed the following build errors:

[auto build test ERROR on 98f6b507621822477db7ec7cef8519de0dd243c4]

url:    https://github.com/intel-lab-lkp/linux/commits/Shivank-Garg/mm-move-the-soft-dirty-fallbacks-up-in-pgtable-h/20261125-133227
base:   98f6b507621822477db7ec7cef8519de0dd243c4
patch link:    https://lore.kernel.org/r/20261125-b4-mm-soft-dirty-fixes-v1-1-538e3cdb618c%40amd.com
patch subject: [PATCH 1/3] mm: move the soft-dirty fallbacks up in pgtable.h
config: m68k-allnoconfig (https://download.01.org/0day-ci/archive/20261126/20261126003419.x9qXgaij-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 16.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261126/20261126003419.x9qXgaij-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/20261126003419.x9qXgaij-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from include/linux/init.h:5,
                    from include/linux/printk.h:6,
                    from include/asm-generic/bug.h:31,
                    from arch/m68k/include/asm/bug.h:32,
                    from include/linux/bug.h:5,
                    from include/linux/thread_info.h:13,
                    from include/asm-generic/preempt.h:5,
                    from ./arch/m68k/include/generated/asm/preempt.h:1,
                    from include/linux/preempt.h:107,
                    from arch/m68k/include/asm/irqflags.h:6,
                    from include/linux/irqflags.h:18,
                    from arch/m68k/include/asm/atomic.h:6,
                    from include/linux/atomic.h:7,
                    from include/linux/jump_label.h:243,
                    from include/linux/once.h:6,
                    from include/linux/prandom.h:12,
                    from kernel/sched/sched.h:8,
                    from kernel/sched/rq-offsets.c:5:
   include/linux/mm.h: In function 'vm_flags_init':
>> include/linux/mm.h:972:26: error: implicit declaration of function 'pgtable_supports_soft_dirty' [-Wimplicit-function-declaration]
     972 |         VM_WARN_ON_ONCE(!pgtable_supports_soft_dirty() && (flags & VM_SOFTDIRTY));
         |                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/build_bug.h:30:63: note: in definition of macro 'BUILD_BUG_ON_INVALID'
      30 | #define BUILD_BUG_ON_INVALID(e) ((void)(sizeof((__force long)(e))))
         |                                                               ^
   include/linux/mm.h:972:9: note: in expansion of macro 'VM_WARN_ON_ONCE'
     972 |         VM_WARN_ON_ONCE(!pgtable_supports_soft_dirty() && (flags & VM_SOFTDIRTY));
         |         ^~~~~~~~~~~~~~~
   make[3]: *** [scripts/Makefile.build:185: kernel/sched/rq-offsets.s] Error 1
   make[3]: Target 'prepare' not remade because of errors.
   make[2]: *** [Makefile:1417: prepare0] Error 2
   make[2]: Target 'prepare' not remade because of errors.
   make[1]: *** [Makefile:248: __sub-make] Error 2
   make[1]: Target 'prepare' not remade because of errors.
   make: *** [Makefile:248: __sub-make] Error 2
   make: Target 'prepare' not remade because of errors.


vim +/pgtable_supports_soft_dirty +972 include/linux/mm.h

027232da7c7c1c7 Kiryl Shutsemau    2018-07-26  967  
bc292ab00f6c7a6 Suren Baghdasaryan 2023-01-26  968  /* Use when VMA is not part of the VMA tree and needs no locking */
bc292ab00f6c7a6 Suren Baghdasaryan 2023-01-26  969  static inline void vm_flags_init(struct vm_area_struct *vma,
bc292ab00f6c7a6 Suren Baghdasaryan 2023-01-26  970  				 vm_flags_t flags)
bc292ab00f6c7a6 Suren Baghdasaryan 2023-01-26  971  {
277a1ae3879a82a Chunyan Zhang      2025-11-13 @972  	VM_WARN_ON_ONCE(!pgtable_supports_soft_dirty() && (flags & VM_SOFTDIRTY));
9ea35a25d51b130 Lorenzo Stoakes    2025-11-25  973  	vma_flags_clear_all(&vma->flags);
9ea35a25d51b130 Lorenzo Stoakes    2025-11-25  974  	vma_flags_overwrite_word(&vma->flags, flags);
bc292ab00f6c7a6 Suren Baghdasaryan 2023-01-26  975  }
bc292ab00f6c7a6 Suren Baghdasaryan 2023-01-26  976  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/3] mm: move the soft-dirty fallbacks up in pgtable.h
  2026-11-25 13:32 ` [PATCH 1/3] mm: move the soft-dirty fallbacks up in pgtable.h Shivank Garg
  2026-11-25 16:44   ` kernel test robot
@ 2026-11-25 16:44   ` kernel test robot
  1 sibling, 0 replies; 10+ messages in thread
From: kernel test robot @ 2026-11-25 16:44 UTC (permalink / raw)
  To: Shivank Garg, Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, Dev Jain, Zi Yan, Baolin Wang,
	Nico Pache, Ryan Roberts, Barry Song, Lance Yang, Usama Arif,
	Kiryl Shutsemau, Peter Xu, Shuah Khan, Michał Mirosław,
	Andrei Vagin, Paul Gofman, Bharata B Rao, Daniel Wade, Yin Tirui,
	Muhammad Usama Anjum
  Cc: llvm, oe-kbuild-all, Linux Memory Management List,
	linux-kselftest, linux-kernel, Shivank Garg

Hi Shivank,

kernel test robot noticed the following build errors:

[auto build test ERROR on 98f6b507621822477db7ec7cef8519de0dd243c4]

url:    https://github.com/intel-lab-lkp/linux/commits/Shivank-Garg/mm-move-the-soft-dirty-fallbacks-up-in-pgtable-h/20261125-133227
base:   98f6b507621822477db7ec7cef8519de0dd243c4
patch link:    https://lore.kernel.org/r/20261125-b4-mm-soft-dirty-fixes-v1-1-538e3cdb618c%40amd.com
patch subject: [PATCH 1/3] mm: move the soft-dirty fallbacks up in pgtable.h
config: arm-allnoconfig (https://download.01.org/0day-ci/archive/20261126/20261126003542.QALFbvl0-lkp@intel.com/config)
compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261126/20261126003542.QALFbvl0-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/20261126003542.QALFbvl0-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from arch/arm/kernel/asm-offsets.c:14:
>> include/linux/mm.h:972:19: error: call to undeclared function 'pgtable_supports_soft_dirty'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     972 |         VM_WARN_ON_ONCE(!pgtable_supports_soft_dirty() && (flags & VM_SOFTDIRTY));
         |                          ^
   include/linux/mm.h:985:19: error: call to undeclared function 'pgtable_supports_soft_dirty'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     985 |         VM_WARN_ON_ONCE(!pgtable_supports_soft_dirty() && (flags & VM_SOFTDIRTY));
         |                          ^
   include/linux/mm.h:1000:19: error: call to undeclared function 'pgtable_supports_soft_dirty'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    1000 |         VM_WARN_ON_ONCE(!pgtable_supports_soft_dirty() && (flags & VM_SOFTDIRTY));
         |                          ^
   3 errors generated.
   make[3]: *** [scripts/Makefile.build:185: arch/arm/kernel/asm-offsets.s] Error 1
   make[3]: Target 'prepare' not remade because of errors.
   make[2]: *** [Makefile:1417: prepare0] Error 2
   make[2]: Target 'prepare' not remade because of errors.
   make[1]: *** [Makefile:248: __sub-make] Error 2
   make[1]: Target 'prepare' not remade because of errors.
   make: *** [Makefile:248: __sub-make] Error 2
   make: Target 'prepare' not remade because of errors.


vim +/pgtable_supports_soft_dirty +972 include/linux/mm.h

027232da7c7c1c Kiryl Shutsemau    2018-07-26  967  
bc292ab00f6c7a Suren Baghdasaryan 2023-01-26  968  /* Use when VMA is not part of the VMA tree and needs no locking */
bc292ab00f6c7a Suren Baghdasaryan 2023-01-26  969  static inline void vm_flags_init(struct vm_area_struct *vma,
bc292ab00f6c7a Suren Baghdasaryan 2023-01-26  970  				 vm_flags_t flags)
bc292ab00f6c7a Suren Baghdasaryan 2023-01-26  971  {
277a1ae3879a82 Chunyan Zhang      2025-11-13 @972  	VM_WARN_ON_ONCE(!pgtable_supports_soft_dirty() && (flags & VM_SOFTDIRTY));
9ea35a25d51b13 Lorenzo Stoakes    2025-11-25  973  	vma_flags_clear_all(&vma->flags);
9ea35a25d51b13 Lorenzo Stoakes    2025-11-25  974  	vma_flags_overwrite_word(&vma->flags, flags);
bc292ab00f6c7a Suren Baghdasaryan 2023-01-26  975  }
bc292ab00f6c7a Suren Baghdasaryan 2023-01-26  976  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-11-25 17:16 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 13:32 [PATCH 0/3] mm: fix soft-dirty false positives in mprotect() of large folios Shivank Garg
2026-11-25 13:32 ` [PATCH 1/3] mm: move the soft-dirty fallbacks up in pgtable.h Shivank Garg
2026-11-25 16:44   ` kernel test robot
2026-11-25 16:44   ` kernel test robot
2026-11-25 13:32 ` [PATCH 2/3] mm: don't let modify_prot_start_ptes() set soft-dirty on clean PTEs Shivank Garg
2026-11-25 13:32 ` [PATCH 3/3] selftests/mm: soft-dirty: check that mprotect() keeps PTE-mapped THPs clean Shivank Garg
2026-11-25 13:43 ` [PATCH 0/3] mm: fix soft-dirty false positives in mprotect() of large folios David Hildenbrand (Arm)
2026-11-25 14:16   ` Garg, Shivank
2026-11-25 15:42   ` Paul Gofman
2026-11-25 16:11     ` Garg, Shivank

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®