Skip to contentSkip to conversation

userfaultfd: selftests: Small fixes

PATCH Applied Peter Xu 1 participant 4 messages Dec 8, 2020

Subsystems (2)
lore
Share & tools
lore

Peter Xu

author
#0 lore raw

cover userfaultfd: selftests: Small fixes

There're some very trivial fixes that I kept locally to userfaultfd selftest program. Please have a look, thanks.

Peter Xu (3):
userfaultfd/selftests: Always dump something in modes userfaultfd/selftests: Fix retval check for userfaultfd_open() userfaultfd/selftests: Hint the test runner on required privilege

 tools/testing/selftests/vm/userfaultfd.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
Signature · 1 line
2.26.2
author
#1 lore raw

PATCH 1/3 userfaultfd/selftests: Always dump something in modes

BOUNCE_POLL is a special bit that if cleared it means "READ" instead. Dump that too otherwise we'll see tests with empty modes.

---
 tools/testing/selftests/vm/userfaultfd.c | 2 ++
 1 file changed, 2 insertions(+)
tools/testing/selftests/vm/userfaultfd.c +2 -0
index 61e5cfeb1350..31f470d12d0b 100644
@@ -1230,6 +1230,8 @@ static int userfaultfd_stress(void)
 			printf(" ver");
 		if (bounces & BOUNCE_POLL)
 			printf(" poll");
+		else
+			printf(" read");
 		printf(", ");
 		fflush(stdout);
 
Signature · 1 line
2.26.2
author
#2 lore raw

PATCH 2/3 userfaultfd/selftests: Fix retval check for userfaultfd_open()

In reply to Peter Xu

userfaultfd_open() returns 1 for errors rather than negatives. Fix it on all the callers so when UFFDIO_API failed the test will bail out.

---
 tools/testing/selftests/vm/userfaultfd.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tools/testing/selftests/vm/userfaultfd.c +4 -4
index 31f470d12d0b..f0647bfda366 100644
@@ -993,7 +993,7 @@ static int userfaultfd_zeropage_test(void)
 	if (uffd_test_ops->release_pages(area_dst))
 		return 1;
 
-	if (userfaultfd_open(0) < 0)
+	if (userfaultfd_open(0))
 		return 1;
 	uffdio_register.range.start = (unsigned long) area_dst;
 	uffdio_register.range.len = nr_pages * page_size;
@@ -1038,7 +1038,7 @@ static int userfaultfd_events_test(void)
 
 	features = UFFD_FEATURE_EVENT_FORK | UFFD_FEATURE_EVENT_REMAP |
 		UFFD_FEATURE_EVENT_REMOVE;
-	if (userfaultfd_open(features) < 0)
+	if (userfaultfd_open(features))
 		return 1;
 	fcntl(uffd, F_SETFL, uffd_flags | O_NONBLOCK);
 
@@ -1101,7 +1101,7 @@ static int userfaultfd_sig_test(void)
 		return 1;
 
 	features = UFFD_FEATURE_EVENT_FORK|UFFD_FEATURE_SIGBUS;
-	if (userfaultfd_open(features) < 0)
+	if (userfaultfd_open(features))
 		return 1;
 	fcntl(uffd, F_SETFL, uffd_flags | O_NONBLOCK);
 
@@ -1170,7 +1170,7 @@ static int userfaultfd_stress(void)
 	if (!area_dst)
 		return 1;
 
-	if (userfaultfd_open(0) < 0)
+	if (userfaultfd_open(0))
 		return 1;
 
 	count_verify = malloc(nr_pages * sizeof(unsigned long long));
Signature · 1 line
2.26.2
author
#3 lore raw

PATCH 3/3 userfaultfd/selftests: Hint the test runner on required privilege

In reply to Peter Xu

Now userfaultfd test program requires either root or ptrace privilege due to the signal/event tests. When UFFDIO_API failed, hint the test runner about this fact verbosely.

---
 tools/testing/selftests/vm/userfaultfd.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/vm/userfaultfd.c +2 -1
index f0647bfda366..27a1709099d0 100644
@@ -755,7 +755,8 @@ static int userfaultfd_open(int features)
 	uffdio_api.api = UFFD_API;
 	uffdio_api.features = features;
 	if (ioctl(uffd, UFFDIO_API, &uffdio_api)) {
-		fprintf(stderr, "UFFDIO_API\n");
+		fprintf(stderr, "UFFDIO_API failed.\nPlease make sure to "
+			"run with either root or ptrace capability.\n");
 		return 1;
 	}
 	if (uffdio_api.api != UFFD_API) {
Signature · 1 line
2.26.2