* [PATCH v2 1/2] fs/proc/task_mmu: reset walk_end before each pagemap walk
2026-11-18 0:26 ` Matthew Salsamendi
@ 2026-11-18 0:26 ` Matthew Salsamendi
-1 siblings, 0 replies; 8+ messages in thread
From: Matthew Salsamendi via B4 Relay @ 2026-11-18 0:26 UTC (permalink / raw)
To: Andrew Morton, Liam R. Howlett, Lorenzo Stoakes
Cc: Chris Down, Vlastimil Babka, Muhammad Usama Anjum, linux-mm,
linux-kernel, matthewsalsamendi, Jann Horn, Pedro Falcato,
linux-fsdevel, stable
From: Matthew Salsamendi <matthewsalsamendi@gmail.com>
When PAGEMAP_SCAN resumes after filling its buffer, it can return ranges
beyond a stale walk_end. This aborts a production game server during
dirty-page tracking.
Reset walk_end before each walk so a completed scan reports the end and
a partial HugeTLB write-protect request keeps its retry address.
Codex assisted with diagnosis, validation and this message.
Fixes: 52526ca7fdb9 ("fs/proc/task_mmu: implement IOCTL to get and optionally clear info about PTEs")
Suggested-by: Chris Down <chris@chrisdown.name>
Suggested-by: Lorenzo Stoakes <ljs@kernel.org>
Cc: stable@vger.kernel.org # 6.7+
Signed-off-by: Matthew Salsamendi <matthewsalsamendi@gmail.com>
---
v2: Use the per-walk reset suggested by Chris and Lorenzo.
Verified the 513-range refill and 2 MiB HugeTLB retry on x86-64.
Stable: The bug is present in v6.7. The hunk needs a context adjustment
on v6.7 and applies unchanged to v6.8.
fs/proc/task_mmu.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index b87d3e86442d..8723ffbff77c 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -3155,6 +3155,7 @@ static long do_pagemap_scan(struct mm_struct *mm, unsigned long uarg)
mmu_notifier_invalidate_range_start(&range);
}
+ p.arg.walk_end = 0; /* Reset partial walks. */
ret = walk_page_range(mm, walk_start, p.arg.end,
&pagemap_scan_ops, &p);
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 0/2] fs/proc: fix PAGEMAP_SCAN walk_end after a buffer refill
@ 2026-11-18 0:26 ` Matthew Salsamendi
0 siblings, 0 replies; 8+ messages in thread
From: Matthew Salsamendi via B4 Relay @ 2026-11-18 0:26 UTC (permalink / raw)
To: Andrew Morton, Liam R. Howlett, Lorenzo Stoakes,
David Hildenbrand, Shuah Khan
Cc: Chris Down, Vlastimil Babka, Muhammad Usama Anjum, linux-mm,
linux-kernel, matthewsalsamendi, Jann Horn, Pedro Falcato,
linux-fsdevel, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
linux-kselftest
Hey all,
Thanks for the feedback. I agree with the proposed change to the patch.
Apologies for the delayed reply.
You'll find the updated patch and the requested selftest below.
On x86-64, the refill test fails on the unpatched kernel and the
HugeTLB retry test fails on v1. All 121 tests pass on v2.
Matt
v1: https://lore.kernel.org/linux-mm/CAMPWk9NE_epOdOCbs1PGh8OQP4wjTObvjU-1Wopmu7SSNAMXhw@mail.gmail.com/
Matthew Salsamendi (2):
fs/proc/task_mmu: reset walk_end before each pagemap walk
selftests/mm: cover PAGEMAP_SCAN refill and HugeTLB retry
fs/proc/task_mmu.c | 1 +
tools/testing/selftests/mm/pagemap_ioctl.c | 61 +++++++++++++++++++++-
2 files changed, 61 insertions(+), 1 deletion(-)
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 2/2] selftests/mm: cover PAGEMAP_SCAN refill and HugeTLB retry
2026-11-18 0:26 ` Matthew Salsamendi
@ 2026-11-18 0:26 ` Matthew Salsamendi
-1 siblings, 0 replies; 8+ messages in thread
From: Matthew Salsamendi via B4 Relay @ 2026-11-18 0:26 UTC (permalink / raw)
To: Andrew Morton, Liam R. Howlett, Lorenzo Stoakes,
David Hildenbrand, Shuah Khan
Cc: Chris Down, Vlastimil Babka, Muhammad Usama Anjum, linux-mm,
linux-kernel, matthewsalsamendi, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, linux-kselftest
From: Matthew Salsamendi <matthewsalsamendi@gmail.com>
Check that scanning 513 disjoint dirty pages returns every range and
sets walk_end to the end of the scan. For a written HugeTLB page, limit
the scan to one base page, then retry from walk_end and check that the
whole page is returned and write-protected.
Codex assisted with the selftests, validation and this message.
Suggested-by: Andrew Morton <akpm@linux-foundation.org>
Suggested-by: Chris Down <chris@chrisdown.name>
Signed-off-by: Matthew Salsamendi <matthewsalsamendi@gmail.com>
---
tools/testing/selftests/mm/pagemap_ioctl.c | 61 +++++++++++++++++++++-
1 file changed, 60 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/mm/pagemap_ioctl.c b/tools/testing/selftests/mm/pagemap_ioctl.c
index 03898b4f6cda..02062b178aa5 100644
--- a/tools/testing/selftests/mm/pagemap_ioctl.c
+++ b/tools/testing/selftests/mm/pagemap_ioctl.c
@@ -682,6 +682,62 @@ static int sanity_tests_sd(void)
return 0;
}
+static void test_walk_end_after_refill(void)
+{
+ /* One more range than the internal buffer holds on x86-64. */
+ struct page_region vec[513];
+ size_t len = 2 * ARRAY_SIZE(vec) * page_size;
+ long ret, walk_end;
+ char *mem;
+ bool ok;
+ size_t i;
+
+ mem = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ if (mem == MAP_FAILED)
+ ksft_exit_fail_msg("mmap: %s\n", strerror(errno));
+ if (madvise(mem, len, MADV_NOHUGEPAGE) && errno != EINVAL)
+ ksft_exit_fail_msg("MADV_NOHUGEPAGE: %s\n", strerror(errno));
+
+ wp_init(mem, len);
+ for (i = 0; i < ARRAY_SIZE(vec); i++)
+ mem[2 * i * page_size] = 1;
+
+ ret = pagemap_ioc(mem, len, vec, ARRAY_SIZE(vec), 0, 0,
+ PAGE_IS_WRITTEN, 0, 0, PAGE_IS_WRITTEN, &walk_end);
+ ok = ret == ARRAY_SIZE(vec) && walk_end == (long)(mem + len);
+ for (i = 0; ok && i < ARRAY_SIZE(vec); i++) {
+ uintptr_t addr = (uintptr_t)(mem + 2 * i * page_size);
+
+ ok = vec[i].start == addr && vec[i].end == addr + page_size;
+ }
+ ksft_test_result(ok, "PAGEMAP_SCAN walk_end after buffer refill\n");
+
+ wp_free(mem, len);
+ munmap(mem, len);
+}
+
+static void test_hugetlb_walk_end(char *mem, size_t len)
+{
+ const int flags = PM_SCAN_WP_MATCHING | PM_SCAN_CHECK_WPASYNC;
+ struct page_region range;
+ long ret, walk_end;
+ bool ok;
+
+ mem[0] = 1;
+ ret = pagemap_ioc(mem, len, &range, 1, flags, 1, PAGE_IS_WRITTEN,
+ 0, 0, PAGE_IS_WRITTEN, &walk_end);
+ ok = ret == 0 && walk_end == (long)mem &&
+ !(pagemap_get_entry(pagemap_fd, mem) & PM_UFFD_WP);
+ if (ok) {
+ ret = pagemap_ioc((void *)walk_end, len, &range, 1, flags, len / page_size,
+ PAGE_IS_WRITTEN, 0, 0, PAGE_IS_WRITTEN, &walk_end);
+ ok = ret == 1 && walk_end == (long)(mem + len) &&
+ range.start == (uintptr_t)mem && range.end == (uintptr_t)(mem + len) &&
+ (pagemap_get_entry(pagemap_fd, mem) & PM_UFFD_WP);
+ }
+ ksft_test_result(ok, "PAGEMAP_SCAN HugeTLB write-protect retry\n");
+}
+
static int base_tests(char *prefix, char *mem, size_t mem_size, int skip)
{
size_t vec_size;
@@ -1661,7 +1717,7 @@ int main(int __attribute__((unused)) argc, char *argv[])
if (!hugetlb_setup_default(4))
ksft_print_msg("HugeTLB test will be skipped\n");
- ksft_set_plan(119);
+ ksft_set_plan(121);
pagemap_fd = open(PAGEMAP, O_RDONLY);
if (pagemap_fd < 0)
@@ -1669,6 +1725,7 @@ int main(int __attribute__((unused)) argc, char *argv[])
/* 1. Sanity testing */
sanity_tests_sd();
+ test_walk_end_after_refill();
/* 2. Normal page testing */
mem_size = 10 * page_size;
@@ -1730,10 +1787,12 @@ int main(int __attribute__((unused)) argc, char *argv[])
wp_addr_range(mem, mem_size);
base_tests("Hugetlb mem testing:", mem, mem_size, 0);
+ test_hugetlb_walk_end(mem, mem_size);
wp_free(mem, mem_size);
} else {
base_tests("Hugetlb mem testing:", NULL, 0, 1);
+ ksft_test_result_skip("PAGEMAP_SCAN HugeTLB write-protect retry: no huge page\n");
}
/* 7. File Hugetlb testing */
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 0/2] fs/proc: fix PAGEMAP_SCAN walk_end after a buffer refill
@ 2026-11-18 0:26 ` Matthew Salsamendi
0 siblings, 0 replies; 8+ messages in thread
From: Matthew Salsamendi @ 2026-11-18 0:26 UTC (permalink / raw)
To: Andrew Morton, Liam R. Howlett, Lorenzo Stoakes,
David Hildenbrand, Shuah Khan
Cc: Chris Down, Vlastimil Babka, Muhammad Usama Anjum, linux-mm,
linux-kernel, matthewsalsamendi, Jann Horn, Pedro Falcato,
linux-fsdevel, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
linux-kselftest
Hey all,
Thanks for the feedback. I agree with the proposed change to the patch.
Apologies for the delayed reply.
You'll find the updated patch and the requested selftest below.
On x86-64, the refill test fails on the unpatched kernel and the
HugeTLB retry test fails on v1. All 121 tests pass on v2.
Matt
v1: https://lore.kernel.org/linux-mm/CAMPWk9NE_epOdOCbs1PGh8OQP4wjTObvjU-1Wopmu7SSNAMXhw@mail.gmail.com/
Matthew Salsamendi (2):
fs/proc/task_mmu: reset walk_end before each pagemap walk
selftests/mm: cover PAGEMAP_SCAN refill and HugeTLB retry
fs/proc/task_mmu.c | 1 +
tools/testing/selftests/mm/pagemap_ioctl.c | 61 +++++++++++++++++++++-
2 files changed, 61 insertions(+), 1 deletion(-)
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 1/2] fs/proc/task_mmu: reset walk_end before each pagemap walk
@ 2026-11-18 0:26 ` Matthew Salsamendi
0 siblings, 0 replies; 8+ messages in thread
From: Matthew Salsamendi @ 2026-11-18 0:26 UTC (permalink / raw)
To: Andrew Morton, Liam R. Howlett, Lorenzo Stoakes
Cc: Chris Down, Vlastimil Babka, Muhammad Usama Anjum, linux-mm,
linux-kernel, matthewsalsamendi, Jann Horn, Pedro Falcato,
linux-fsdevel, stable
When PAGEMAP_SCAN resumes after filling its buffer, it can return ranges
beyond a stale walk_end. This aborts a production game server during
dirty-page tracking.
Reset walk_end before each walk so a completed scan reports the end and
a partial HugeTLB write-protect request keeps its retry address.
Codex assisted with diagnosis, validation and this message.
Fixes: 52526ca7fdb9 ("fs/proc/task_mmu: implement IOCTL to get and optionally clear info about PTEs")
Suggested-by: Chris Down <chris@chrisdown.name>
Suggested-by: Lorenzo Stoakes <ljs@kernel.org>
Cc: stable@vger.kernel.org # 6.7+
Signed-off-by: Matthew Salsamendi <matthewsalsamendi@gmail.com>
---
v2: Use the per-walk reset suggested by Chris and Lorenzo.
Verified the 513-range refill and 2 MiB HugeTLB retry on x86-64.
Stable: The bug is present in v6.7. The hunk needs a context adjustment
on v6.7 and applies unchanged to v6.8.
fs/proc/task_mmu.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index b87d3e86442d..8723ffbff77c 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -3155,6 +3155,7 @@ static long do_pagemap_scan(struct mm_struct *mm, unsigned long uarg)
mmu_notifier_invalidate_range_start(&range);
}
+ p.arg.walk_end = 0; /* Reset partial walks. */
ret = walk_page_range(mm, walk_start, p.arg.end,
&pagemap_scan_ops, &p);
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 2/2] selftests/mm: cover PAGEMAP_SCAN refill and HugeTLB retry
@ 2026-11-18 0:26 ` Matthew Salsamendi
0 siblings, 0 replies; 8+ messages in thread
From: Matthew Salsamendi @ 2026-11-18 0:26 UTC (permalink / raw)
To: Andrew Morton, Liam R. Howlett, Lorenzo Stoakes,
David Hildenbrand, Shuah Khan
Cc: Chris Down, Vlastimil Babka, Muhammad Usama Anjum, linux-mm,
linux-kernel, matthewsalsamendi, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, linux-kselftest
Check that scanning 513 disjoint dirty pages returns every range and
sets walk_end to the end of the scan. For a written HugeTLB page, limit
the scan to one base page, then retry from walk_end and check that the
whole page is returned and write-protected.
Codex assisted with the selftests, validation and this message.
Suggested-by: Andrew Morton <akpm@linux-foundation.org>
Suggested-by: Chris Down <chris@chrisdown.name>
Signed-off-by: Matthew Salsamendi <matthewsalsamendi@gmail.com>
---
tools/testing/selftests/mm/pagemap_ioctl.c | 61 +++++++++++++++++++++-
1 file changed, 60 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/mm/pagemap_ioctl.c b/tools/testing/selftests/mm/pagemap_ioctl.c
index 03898b4f6cda..02062b178aa5 100644
--- a/tools/testing/selftests/mm/pagemap_ioctl.c
+++ b/tools/testing/selftests/mm/pagemap_ioctl.c
@@ -682,6 +682,62 @@ static int sanity_tests_sd(void)
return 0;
}
+static void test_walk_end_after_refill(void)
+{
+ /* One more range than the internal buffer holds on x86-64. */
+ struct page_region vec[513];
+ size_t len = 2 * ARRAY_SIZE(vec) * page_size;
+ long ret, walk_end;
+ char *mem;
+ bool ok;
+ size_t i;
+
+ mem = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ if (mem == MAP_FAILED)
+ ksft_exit_fail_msg("mmap: %s\n", strerror(errno));
+ if (madvise(mem, len, MADV_NOHUGEPAGE) && errno != EINVAL)
+ ksft_exit_fail_msg("MADV_NOHUGEPAGE: %s\n", strerror(errno));
+
+ wp_init(mem, len);
+ for (i = 0; i < ARRAY_SIZE(vec); i++)
+ mem[2 * i * page_size] = 1;
+
+ ret = pagemap_ioc(mem, len, vec, ARRAY_SIZE(vec), 0, 0,
+ PAGE_IS_WRITTEN, 0, 0, PAGE_IS_WRITTEN, &walk_end);
+ ok = ret == ARRAY_SIZE(vec) && walk_end == (long)(mem + len);
+ for (i = 0; ok && i < ARRAY_SIZE(vec); i++) {
+ uintptr_t addr = (uintptr_t)(mem + 2 * i * page_size);
+
+ ok = vec[i].start == addr && vec[i].end == addr + page_size;
+ }
+ ksft_test_result(ok, "PAGEMAP_SCAN walk_end after buffer refill\n");
+
+ wp_free(mem, len);
+ munmap(mem, len);
+}
+
+static void test_hugetlb_walk_end(char *mem, size_t len)
+{
+ const int flags = PM_SCAN_WP_MATCHING | PM_SCAN_CHECK_WPASYNC;
+ struct page_region range;
+ long ret, walk_end;
+ bool ok;
+
+ mem[0] = 1;
+ ret = pagemap_ioc(mem, len, &range, 1, flags, 1, PAGE_IS_WRITTEN,
+ 0, 0, PAGE_IS_WRITTEN, &walk_end);
+ ok = ret == 0 && walk_end == (long)mem &&
+ !(pagemap_get_entry(pagemap_fd, mem) & PM_UFFD_WP);
+ if (ok) {
+ ret = pagemap_ioc((void *)walk_end, len, &range, 1, flags, len / page_size,
+ PAGE_IS_WRITTEN, 0, 0, PAGE_IS_WRITTEN, &walk_end);
+ ok = ret == 1 && walk_end == (long)(mem + len) &&
+ range.start == (uintptr_t)mem && range.end == (uintptr_t)(mem + len) &&
+ (pagemap_get_entry(pagemap_fd, mem) & PM_UFFD_WP);
+ }
+ ksft_test_result(ok, "PAGEMAP_SCAN HugeTLB write-protect retry\n");
+}
+
static int base_tests(char *prefix, char *mem, size_t mem_size, int skip)
{
size_t vec_size;
@@ -1661,7 +1717,7 @@ int main(int __attribute__((unused)) argc, char *argv[])
if (!hugetlb_setup_default(4))
ksft_print_msg("HugeTLB test will be skipped\n");
- ksft_set_plan(119);
+ ksft_set_plan(121);
pagemap_fd = open(PAGEMAP, O_RDONLY);
if (pagemap_fd < 0)
@@ -1669,6 +1725,7 @@ int main(int __attribute__((unused)) argc, char *argv[])
/* 1. Sanity testing */
sanity_tests_sd();
+ test_walk_end_after_refill();
/* 2. Normal page testing */
mem_size = 10 * page_size;
@@ -1730,10 +1787,12 @@ int main(int __attribute__((unused)) argc, char *argv[])
wp_addr_range(mem, mem_size);
base_tests("Hugetlb mem testing:", mem, mem_size, 0);
+ test_hugetlb_walk_end(mem, mem_size);
wp_free(mem, mem_size);
} else {
base_tests("Hugetlb mem testing:", NULL, 0, 1);
+ ksft_test_result_skip("PAGEMAP_SCAN HugeTLB write-protect retry: no huge page\n");
}
/* 7. File Hugetlb testing */
^ permalink raw reply related [flat|nested] 8+ messages in thread
* + fs-proc-task_mmu-reset-walk_end-before-each-pagemap-walk.patch added to mm-new branch
2026-11-18 0:26 ` Matthew Salsamendi
(?)
@ 2026-11-25 2:19 ` Andrew Morton
-1 siblings, 0 replies; 8+ messages in thread
From: Andrew Morton @ 2026-11-25 2:19 UTC (permalink / raw)
To: mm-commits, vbabka, usama.anjum, stable, pfalcato, ljs, liam,
jannh, chris, matthewsalsamendi, akpm
The patch titled
Subject: fs/proc/task_mmu: reset walk_end before each pagemap walk
has been added to the -mm mm-new branch. Its filename is
fs-proc-task_mmu-reset-walk_end-before-each-pagemap-walk.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/fs-proc-task_mmu-reset-walk_end-before-each-pagemap-walk.patch
This patch will later appear in the mm-new branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Note, mm-new is a provisional staging ground for work-in-progress
patches, and acceptance into mm-new is a notification for others take
notice and to finish up reviews. Please do not hesitate to respond to
review feedback and post updated versions to replace or incrementally
fixup patches in mm-new.
The mm-new branch of mm.git is not included in linux-next
If a few days of testing in mm-new is successful, the patch will me moved
into mm.git's mm-unstable branch, which is included in linux-next
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Matthew Salsamendi <matthewsalsamendi@gmail.com>
Subject: fs/proc/task_mmu: reset walk_end before each pagemap walk
Date: Tue, 17 Nov 2026 16:26:17 -0800
Patch series "fs/proc: fix PAGEMAP_SCAN walk_end after a buffer refill",
v2.
This patch (of 2):
When PAGEMAP_SCAN resumes after filling its buffer, it can return ranges
beyond a stale walk_end. This aborts a production game server during
dirty-page tracking.
Reset walk_end before each walk so a completed scan reports the end and
a partial HugeTLB write-protect request keeps its retry address.
Codex assisted with diagnosis, validation and this message.
Link: https://lore.kernel.org/20261118-pagemap-walk-end-v2-0-94cd92d838b3@gmail.com
Link: https://patch.msgid.link/20261118-pagemap-walk-end-v2-1-94cd92d838b3@gmail.com
Fixes: 52526ca7fdb9 ("fs/proc/task_mmu: implement IOCTL to get and optionally clear info about PTEs")
Signed-off-by: Matthew Salsamendi <matthewsalsamendi@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Suggested-by: Chris Down <chris@chrisdown.name>
Suggested-by: Lorenzo Stoakes <ljs@kernel.org>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Vlastimil Babka <vbabka@kernel.org>
Cc: Muhammad Usama Anjum <usama.anjum@arm.com>
Cc: Jann Horn <jannh@google.com>
Cc: Pedro Falcato <pfalcato@suse.de>
Cc: <stable@vger.kernel.org> # 6.7+
fs/proc/task_mmu.c | 1 +
1 file changed, 1 insertion(+)
--- a/fs/proc/task_mmu.c~fs-proc-task_mmu-reset-walk_end-before-each-pagemap-walk
+++ a/fs/proc/task_mmu.c
@@ -3199,6 +3199,7 @@ static long do_pagemap_scan(struct mm_st
mmu_notifier_invalidate_range_start(&range);
}
+ p.arg.walk_end = 0; /* Reset partial walks. */
ret = walk_page_range(mm, walk_start, p.arg.end,
&pagemap_scan_ops, &p);
_
Patches currently in -mm which might be from matthewsalsamendi@gmail.com are
fs-proc-task_mmu-reset-walk_end-before-each-pagemap-walk.patch
selftests-mm-cover-pagemap_scan-refill-and-hugetlb-retry.patch
^ permalink raw reply [flat|nested] 8+ messages in thread
* + selftests-mm-cover-pagemap_scan-refill-and-hugetlb-retry.patch added to mm-new branch
2026-11-18 0:26 ` Matthew Salsamendi
(?)
@ 2026-11-25 2:19 ` Andrew Morton
-1 siblings, 0 replies; 8+ messages in thread
From: Andrew Morton @ 2026-11-25 2:19 UTC (permalink / raw)
To: mm-commits, vbabka, usama.anjum, surenb, shuah, rppt, mhocko, ljs,
liam, david, chris, akpm, matthewsalsamendi
The patch titled
Subject: selftests/mm: cover PAGEMAP_SCAN refill and HugeTLB retry
has been added to the -mm mm-new branch. Its filename is
selftests-mm-cover-pagemap_scan-refill-and-hugetlb-retry.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/selftests-mm-cover-pagemap_scan-refill-and-hugetlb-retry.patch
This patch will later appear in the mm-new branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Note, mm-new is a provisional staging ground for work-in-progress
patches, and acceptance into mm-new is a notification for others take
notice and to finish up reviews. Please do not hesitate to respond to
review feedback and post updated versions to replace or incrementally
fixup patches in mm-new.
The mm-new branch of mm.git is not included in linux-next
If a few days of testing in mm-new is successful, the patch will me moved
into mm.git's mm-unstable branch, which is included in linux-next
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Matthew Salsamendi <matthewsalsamendi@gmail.com>
Subject: selftests/mm: cover PAGEMAP_SCAN refill and HugeTLB retry
Date: Tue, 17 Nov 2026 16:26:17 -0800
Check that scanning 513 disjoint dirty pages returns every range and sets
walk_end to the end of the scan. For a written HugeTLB page, limit the
scan to one base page, then retry from walk_end and check that the whole
page is returned and write-protected.
Codex assisted with the selftests, validation and this message.
Link: https://patch.msgid.link/20261118-pagemap-walk-end-v2-2-94cd92d838b3@gmail.com
Signed-off-by: Matthew Salsamendi <matthewsalsamendi@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Suggested-by: Andrew Morton <akpm@linux-foundation.org>
Suggested-by: Chris Down <chris@chrisdown.name>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Vlastimil Babka <vbabka@kernel.org>
Cc: Muhammad Usama Anjum <usama.anjum@arm.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Michal Hocko <mhocko@suse.com>
tools/testing/selftests/mm/pagemap_ioctl.c | 61 ++++++++++++++++++-
1 file changed, 60 insertions(+), 1 deletion(-)
--- a/tools/testing/selftests/mm/pagemap_ioctl.c~selftests-mm-cover-pagemap_scan-refill-and-hugetlb-retry
+++ a/tools/testing/selftests/mm/pagemap_ioctl.c
@@ -682,6 +682,62 @@ static int sanity_tests_sd(void)
return 0;
}
+static void test_walk_end_after_refill(void)
+{
+ /* One more range than the internal buffer holds on x86-64. */
+ struct page_region vec[513];
+ size_t len = 2 * ARRAY_SIZE(vec) * page_size;
+ long ret, walk_end;
+ char *mem;
+ bool ok;
+ size_t i;
+
+ mem = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ if (mem == MAP_FAILED)
+ ksft_exit_fail_msg("mmap: %s\n", strerror(errno));
+ if (madvise(mem, len, MADV_NOHUGEPAGE) && errno != EINVAL)
+ ksft_exit_fail_msg("MADV_NOHUGEPAGE: %s\n", strerror(errno));
+
+ wp_init(mem, len);
+ for (i = 0; i < ARRAY_SIZE(vec); i++)
+ mem[2 * i * page_size] = 1;
+
+ ret = pagemap_ioc(mem, len, vec, ARRAY_SIZE(vec), 0, 0,
+ PAGE_IS_WRITTEN, 0, 0, PAGE_IS_WRITTEN, &walk_end);
+ ok = ret == ARRAY_SIZE(vec) && walk_end == (long)(mem + len);
+ for (i = 0; ok && i < ARRAY_SIZE(vec); i++) {
+ uintptr_t addr = (uintptr_t)(mem + 2 * i * page_size);
+
+ ok = vec[i].start == addr && vec[i].end == addr + page_size;
+ }
+ ksft_test_result(ok, "PAGEMAP_SCAN walk_end after buffer refill\n");
+
+ wp_free(mem, len);
+ munmap(mem, len);
+}
+
+static void test_hugetlb_walk_end(char *mem, size_t len)
+{
+ const int flags = PM_SCAN_WP_MATCHING | PM_SCAN_CHECK_WPASYNC;
+ struct page_region range;
+ long ret, walk_end;
+ bool ok;
+
+ mem[0] = 1;
+ ret = pagemap_ioc(mem, len, &range, 1, flags, 1, PAGE_IS_WRITTEN,
+ 0, 0, PAGE_IS_WRITTEN, &walk_end);
+ ok = ret == 0 && walk_end == (long)mem &&
+ !(pagemap_get_entry(pagemap_fd, mem) & PM_UFFD_WP);
+ if (ok) {
+ ret = pagemap_ioc((void *)walk_end, len, &range, 1, flags, len / page_size,
+ PAGE_IS_WRITTEN, 0, 0, PAGE_IS_WRITTEN, &walk_end);
+ ok = ret == 1 && walk_end == (long)(mem + len) &&
+ range.start == (uintptr_t)mem && range.end == (uintptr_t)(mem + len) &&
+ (pagemap_get_entry(pagemap_fd, mem) & PM_UFFD_WP);
+ }
+ ksft_test_result(ok, "PAGEMAP_SCAN HugeTLB write-protect retry\n");
+}
+
static int base_tests(char *prefix, char *mem, size_t mem_size, int skip)
{
size_t vec_size;
@@ -1661,7 +1717,7 @@ int main(int __attribute__((unused)) arg
if (!hugetlb_setup_default(4))
ksft_print_msg("HugeTLB test will be skipped\n");
- ksft_set_plan(119);
+ ksft_set_plan(121);
pagemap_fd = open(PAGEMAP, O_RDONLY);
if (pagemap_fd < 0)
@@ -1669,6 +1725,7 @@ int main(int __attribute__((unused)) arg
/* 1. Sanity testing */
sanity_tests_sd();
+ test_walk_end_after_refill();
/* 2. Normal page testing */
mem_size = 10 * page_size;
@@ -1730,10 +1787,12 @@ int main(int __attribute__((unused)) arg
wp_addr_range(mem, mem_size);
base_tests("Hugetlb mem testing:", mem, mem_size, 0);
+ test_hugetlb_walk_end(mem, mem_size);
wp_free(mem, mem_size);
} else {
base_tests("Hugetlb mem testing:", NULL, 0, 1);
+ ksft_test_result_skip("PAGEMAP_SCAN HugeTLB write-protect retry: no huge page\n");
}
/* 7. File Hugetlb testing */
_
Patches currently in -mm which might be from matthewsalsamendi@gmail.com are
fs-proc-task_mmu-reset-walk_end-before-each-pagemap-walk.patch
selftests-mm-cover-pagemap_scan-refill-and-hugetlb-retry.patch
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-11-25 2:19 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 0:26 [PATCH v2 0/2] fs/proc: fix PAGEMAP_SCAN walk_end after a buffer refill Matthew Salsamendi via B4 Relay
2026-11-18 0:26 ` Matthew Salsamendi
2026-11-18 0:26 ` [PATCH v2 1/2] fs/proc/task_mmu: reset walk_end before each pagemap walk Matthew Salsamendi via B4 Relay
2026-11-18 0:26 ` Matthew Salsamendi
2026-11-25 2:19 ` + fs-proc-task_mmu-reset-walk_end-before-each-pagemap-walk.patch added to mm-new branch Andrew Morton
2026-11-18 0:26 ` [PATCH v2 2/2] selftests/mm: cover PAGEMAP_SCAN refill and HugeTLB retry Matthew Salsamendi via B4 Relay
2026-11-18 0:26 ` Matthew Salsamendi
2026-11-25 2:19 ` + selftests-mm-cover-pagemap_scan-refill-and-hugetlb-retry.patch added to mm-new branch Andrew Morton
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.