[PATCH v2 3/5] userfaultfd/selftests: Dropping VERIFY check in locking_thread

From: Peter Xu
Date: Mon Apr 12 2021 - 19:28:06 EST


It tries to check against all zeros and looped for quite a few times. However
after that we'll verify the same page with count_verify, while count_verify can
never be zero. So it means if it's a zero page we'll detect it anyways with
below code.

There's yet another place we conditionally check the fault flag - just do it
unconditionally.

Reviewed-by: Axel Rasmussen <axelrasmussen@xxxxxxxxxx>
Signed-off-by: Peter Xu <peterx@xxxxxxxxxx>
---
tools/testing/selftests/vm/userfaultfd.c | 55 +-----------------------
1 file changed, 1 insertion(+), 54 deletions(-)

diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c
index 5cae66e27171..387b9360ae64 100644
--- a/tools/testing/selftests/vm/userfaultfd.c
+++ b/tools/testing/selftests/vm/userfaultfd.c
@@ -430,58 +430,6 @@ static void *locking_thread(void *arg)
} else
page_nr += 1;
page_nr %= nr_pages;
-
- if (bounces & BOUNCE_VERIFY) {
- count = *area_count(area_dst, page_nr);
- if (!count) {
- fprintf(stderr,
- "page_nr %lu wrong count %Lu %Lu\n",
- page_nr, count,
- count_verify[page_nr]);
- exit(1);
- }
-
-
- /*
- * We can't use bcmp (or memcmp) because that
- * returns 0 erroneously if the memory is
- * changing under it (even if the end of the
- * page is never changing and always
- * different).
- */
-#if 1
- if (!my_bcmp(area_dst + page_nr * page_size, zeropage,
- page_size)) {
- fprintf(stderr,
- "my_bcmp page_nr %lu wrong count %Lu %Lu\n",
- page_nr, count, count_verify[page_nr]);
- exit(1);
- }
-#else
- unsigned long loops;
-
- loops = 0;
- /* uncomment the below line to test with mutex */
- /* pthread_mutex_lock(area_mutex(area_dst, page_nr)); */
- while (!bcmp(area_dst + page_nr * page_size, zeropage,
- page_size)) {
- loops += 1;
- if (loops > 10)
- break;
- }
- /* uncomment below line to test with mutex */
- /* pthread_mutex_unlock(area_mutex(area_dst, page_nr)); */
- if (loops) {
- fprintf(stderr,
- "page_nr %lu all zero thread %lu %p %lu\n",
- page_nr, cpu, area_dst + page_nr * page_size,
- loops);
- if (loops > 10)
- exit(1);
- }
-#endif
- }
-
pthread_mutex_lock(area_mutex(area_dst, page_nr));
count = *area_count(area_dst, page_nr);
if (count != count_verify[page_nr]) {
@@ -613,8 +561,7 @@ static void uffd_handle_page_fault(struct uffd_msg *msg,
stats->minor_faults++;
} else {
/* Missing page faults */
- if (bounces & BOUNCE_VERIFY &&
- msg->arg.pagefault.flags & UFFD_PAGEFAULT_FLAG_WRITE) {
+ if (msg->arg.pagefault.flags & UFFD_PAGEFAULT_FLAG_WRITE) {
fprintf(stderr, "unexpected write fault\n");
exit(1);
}
--
2.26.2