diff mbox series

[v4,2/2] selftests/mm: Smoke test UFFD_FEATURE_WP_UNPOPULATED

Message ID 20230309223711.823547-3-peterx@redhat.com (mailing list archive)
State New
Headers show
Series mm/uffd: Add feature bit UFFD_FEATURE_WP_UNPOPULATED | expand

Commit Message

Peter Xu March 9, 2023, 10:37 p.m. UTC
Enable it by default on the stress test, and add some smoke tests for the
pte markers on anonymous.

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 tools/testing/selftests/mm/userfaultfd.c | 45 ++++++++++++++++++++++--
 1 file changed, 43 insertions(+), 2 deletions(-)

Comments

David Hildenbrand March 20, 2023, 10:25 a.m. UTC | #1
On 09.03.23 23:37, Peter Xu wrote:
> Enable it by default on the stress test, and add some smoke tests for the
> pte markers on anonymous.

Would it make sense to make kernel support optional and test both paths 
-- once with the feature enabled (if available on the kernel we're 
testing) and once with the feature disabled?
Peter Xu March 20, 2023, 2:43 p.m. UTC | #2
On Mon, Mar 20, 2023 at 11:25:43AM +0100, David Hildenbrand wrote:
> On 09.03.23 23:37, Peter Xu wrote:
> > Enable it by default on the stress test, and add some smoke tests for the
> > pte markers on anonymous.
> 
> Would it make sense to make kernel support optional and test both paths --
> once with the feature enabled (if available on the kernel we're testing) and
> once with the feature disabled?

Yeah, I think the current uffd selftest is not friendly to old kernels so I
made it simple - IOW the test should fail already on old kernels AFAIK.
Maybe I can prepare some patches this week or next to cleanup some parts of
it.

Thanks,
David Hildenbrand March 20, 2023, 3:01 p.m. UTC | #3
On 20.03.23 15:43, Peter Xu wrote:
> On Mon, Mar 20, 2023 at 11:25:43AM +0100, David Hildenbrand wrote:
>> On 09.03.23 23:37, Peter Xu wrote:
>>> Enable it by default on the stress test, and add some smoke tests for the
>>> pte markers on anonymous.
>>
>> Would it make sense to make kernel support optional and test both paths --
>> once with the feature enabled (if available on the kernel we're testing) and
>> once with the feature disabled?
> 
> Yeah, I think the current uffd selftest is not friendly to old kernels so I
> made it simple - IOW the test should fail already on old kernels AFAIK.
> Maybe I can prepare some patches this week or next to cleanup some parts of
> it.

Some people to tend to run upstream selftests on older kernels, but I 
guess this is not high priority. Can always be added on top.
diff mbox series

Patch

diff --git a/tools/testing/selftests/mm/userfaultfd.c b/tools/testing/selftests/mm/userfaultfd.c
index 7f22844ed704..e030d63c031a 100644
--- a/tools/testing/selftests/mm/userfaultfd.c
+++ b/tools/testing/selftests/mm/userfaultfd.c
@@ -1444,6 +1444,43 @@  static int pagemap_test_fork(bool present)
 	return result;
 }
 
+static void userfaultfd_wp_unpopulated_test(int pagemap_fd)
+{
+	uint64_t value;
+
+	/* Test applying pte marker to anon unpopulated */
+	wp_range(uffd, (uint64_t)area_dst, page_size, true);
+	value = pagemap_read_vaddr(pagemap_fd, area_dst);
+	pagemap_check_wp(value, true);
+
+	/* Test unprotect on anon pte marker */
+	wp_range(uffd, (uint64_t)area_dst, page_size, false);
+	value = pagemap_read_vaddr(pagemap_fd, area_dst);
+	pagemap_check_wp(value, false);
+
+	/* Test zap on anon marker */
+	wp_range(uffd, (uint64_t)area_dst, page_size, true);
+	if (madvise(area_dst, page_size, MADV_DONTNEED))
+		err("madvise(MADV_DONTNEED) failed");
+	value = pagemap_read_vaddr(pagemap_fd, area_dst);
+	pagemap_check_wp(value, false);
+
+	/* Test fault in after marker removed */
+	*area_dst = 1;
+	value = pagemap_read_vaddr(pagemap_fd, area_dst);
+	pagemap_check_wp(value, false);
+	/* Drop it to make pte none again */
+	if (madvise(area_dst, page_size, MADV_DONTNEED))
+		err("madvise(MADV_DONTNEED) failed");
+
+	/* Test read-zero-page upon pte marker */
+	wp_range(uffd, (uint64_t)area_dst, page_size, true);
+	*(volatile char *)area_dst;
+	/* Drop it to make pte none again */
+	if (madvise(area_dst, page_size, MADV_DONTNEED))
+		err("madvise(MADV_DONTNEED) failed");
+}
+
 static void userfaultfd_pagemap_test(unsigned int test_pgsize)
 {
 	struct uffdio_register uffdio_register;
@@ -1462,7 +1499,7 @@  static void userfaultfd_pagemap_test(unsigned int test_pgsize)
 	/* Flush so it doesn't flush twice in parent/child later */
 	fflush(stdout);
 
-	uffd_test_ctx_init(0);
+	uffd_test_ctx_init(UFFD_FEATURE_WP_UNPOPULATED);
 
 	if (test_pgsize > page_size) {
 		/* This is a thp test */
@@ -1482,6 +1519,10 @@  static void userfaultfd_pagemap_test(unsigned int test_pgsize)
 
 	pagemap_fd = pagemap_open();
 
+	/* Smoke test WP_UNPOPULATED first when it's still empty */
+	if (test_pgsize == page_size)
+		userfaultfd_wp_unpopulated_test(pagemap_fd);
+
 	/* Touch the page */
 	*area_dst = 1;
 	wp_range(uffd, (uint64_t)area_dst, test_pgsize, true);
@@ -1526,7 +1567,7 @@  static int userfaultfd_stress(void)
 	struct uffdio_register uffdio_register;
 	struct uffd_stats uffd_stats[nr_cpus];
 
-	uffd_test_ctx_init(0);
+	uffd_test_ctx_init(UFFD_FEATURE_WP_UNPOPULATED);
 
 	if (posix_memalign(&area, page_size, page_size))
 		err("out of memory");