[PATCH] fixup! selftests/mm: Move zeropage test into uffd unit tests

From: Peter Xu
Date: Mon Apr 03 2023 - 11:57:07 EST


Signed-off-by: Peter Xu <peterx@xxxxxxxxxx>
---
tools/testing/selftests/mm/uffd-unit-tests.c | 62 +++++++++++---------
1 file changed, 33 insertions(+), 29 deletions(-)

diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c
index 793931da5056..247700bb4dd0 100644
--- a/tools/testing/selftests/mm/uffd-unit-tests.c
+++ b/tools/testing/selftests/mm/uffd-unit-tests.c
@@ -711,54 +711,58 @@ static bool do_uffdio_zeropage(int ufd, bool has_zeropage)
return false;
}

+/*
+ * Registers a range with MISSING mode only for zeropage test. Return true
+ * if UFFDIO_ZEROPAGE supported, false otherwise. Can't use uffd_register()
+ * because we want to detect .ioctls along the way.
+ */
+static bool
+uffd_register_detect_zp(int uffd, void *addr, uint64_t len)
+{
+ struct uffdio_register uffdio_register = { 0 };
+ uint64_t mode = UFFDIO_REGISTER_MODE_MISSING;
+
+ uffdio_register.range.start = (unsigned long)addr;
+ uffdio_register.range.len = len;
+ uffdio_register.mode = mode;
+
+ if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register) == -1)
+ err("zeropage test register fail");
+
+ return uffdio_register.ioctls & (1 << _UFFDIO_ZEROPAGE);
+}
+
+
/* exercise UFFDIO_ZEROPAGE */
-static void uffd_zeropage_test_common(bool has_zeropage)
+static void uffd_zeropage_test(void)
{
- if (uffd_register(uffd, area_dst, page_size,
- true, false, false))
- err("register");
+ bool has_zeropage;
+ int i;

+ has_zeropage = uffd_register_detect_zp(uffd, area_dst, page_size);
if (area_dst_alias)
- if (uffd_register(uffd, area_dst_alias, page_size,
- true, false, false))
- err("register");
-
- if (do_uffdio_zeropage(uffd, has_zeropage)) {
- int i;
+ /* Ignore the retval; we already have it */
+ uffd_register_detect_zp(uffd, area_dst_alias, page_size);

+ if (do_uffdio_zeropage(uffd, has_zeropage))
for (i = 0; i < page_size; i++)
if (area_dst[i] != 0)
err("data non-zero at offset %d\n", i);
- }

+ if (uffd_unregister(uffd, area_dst, page_size))
+ err("unregister");

- if (uffd_unregister(uffd, area_dst, page_size * nr_pages))
+ if (area_dst_alias && uffd_unregister(uffd, area_dst_alias, page_size))
err("unregister");

uffd_test_pass();
}

-static void uffd_zeropage_test(void)
-{
- uffd_zeropage_test_common(true);
-}
-
-static void uffd_zeropage_hugetlb_test(void)
-{
- uffd_zeropage_test_common(false);
-}
-
uffd_test_case_t uffd_tests[] = {
{
.name = "zeropage",
.uffd_fn = uffd_zeropage_test,
- .mem_targets = MEM_ANON | MEM_SHMEM | MEM_SHMEM_PRIVATE,
- .uffd_feature_required = 0,
- },
- {
- .name = "zeropage-hugetlb",
- .uffd_fn = uffd_zeropage_hugetlb_test,
- .mem_targets = MEM_HUGETLB | MEM_HUGETLB_PRIVATE,
+ .mem_targets = MEM_ALL,
.uffd_feature_required = 0,
},
{
--
2.39.1


--/4lLZ6sttUXyfTXJ--