aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorAndrea Arcangeli <aarcange@redhat.com>2017-10-13 18:57:54 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2017-10-13 19:18:32 -0400
commit7ddd8faf4399ab4f4edad5604eab35f8a87caf02 (patch)
tree51d651f20cdf07d8e7f01f8e23e371b5809c352d /tools
parent064f0e9302af4f4ab5e9dca03a5a77d6bebfd35e (diff)
userfaultfd: selftest: exercise -EEXIST only in background transfer
I was stress testing some backports and with high load, after some time, the latest version of the selftest showed some false positive in connection with the uffdio_copy_retry. This seems to fix it while still exercising -EEXIST in the background transfer once in a while. The fork child will quit after the last UFFDIO_COPY is run, so a repeated UFFDIO_COPY may not return -EEXIST. This change restricts the -EEXIST stress to the background transfer where the memory can't go away from under it. Also updated uffdio_zeropage, so the interface is consistent. Link: http://lkml.kernel.org/r/20171004171541.1495-2-aarcange@redhat.com Signed-off-by: Andrea Arcangeli <aarcange@redhat.com> Cc: Pavel Emelyanov <xemul@virtuozzo.com> Cc: Mike Rapoport <rppt@linux.vnet.ibm.com> Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com> Cc: Mike Kravetz <mike.kravetz@oracle.com> Cc: Shuah Khan <shuah@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/testing/selftests/vm/userfaultfd.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c
index a2c53a3d223d..de2f9ec8a87f 100644
--- a/tools/testing/selftests/vm/userfaultfd.c
+++ b/tools/testing/selftests/vm/userfaultfd.c
@@ -397,7 +397,7 @@ static void retry_copy_page(int ufd, struct uffdio_copy *uffdio_copy,
397 } 397 }
398} 398}
399 399
400static int copy_page(int ufd, unsigned long offset) 400static int __copy_page(int ufd, unsigned long offset, bool retry)
401{ 401{
402 struct uffdio_copy uffdio_copy; 402 struct uffdio_copy uffdio_copy;
403 403
@@ -418,7 +418,7 @@ static int copy_page(int ufd, unsigned long offset)
418 fprintf(stderr, "UFFDIO_COPY unexpected copy %Ld\n", 418 fprintf(stderr, "UFFDIO_COPY unexpected copy %Ld\n",
419 uffdio_copy.copy), exit(1); 419 uffdio_copy.copy), exit(1);
420 } else { 420 } else {
421 if (test_uffdio_copy_eexist) { 421 if (test_uffdio_copy_eexist && retry) {
422 test_uffdio_copy_eexist = false; 422 test_uffdio_copy_eexist = false;
423 retry_copy_page(ufd, &uffdio_copy, offset); 423 retry_copy_page(ufd, &uffdio_copy, offset);
424 } 424 }
@@ -427,6 +427,16 @@ static int copy_page(int ufd, unsigned long offset)
427 return 0; 427 return 0;
428} 428}
429 429
430static int copy_page_retry(int ufd, unsigned long offset)
431{
432 return __copy_page(ufd, offset, true);
433}
434
435static int copy_page(int ufd, unsigned long offset)
436{
437 return __copy_page(ufd, offset, false);
438}
439
430static void *uffd_poll_thread(void *arg) 440static void *uffd_poll_thread(void *arg)
431{ 441{
432 unsigned long cpu = (unsigned long) arg; 442 unsigned long cpu = (unsigned long) arg;
@@ -544,7 +554,7 @@ static void *background_thread(void *arg)
544 for (page_nr = cpu * nr_pages_per_cpu; 554 for (page_nr = cpu * nr_pages_per_cpu;
545 page_nr < (cpu+1) * nr_pages_per_cpu; 555 page_nr < (cpu+1) * nr_pages_per_cpu;
546 page_nr++) 556 page_nr++)
547 copy_page(uffd, page_nr * page_size); 557 copy_page_retry(uffd, page_nr * page_size);
548 558
549 return NULL; 559 return NULL;
550} 560}
@@ -779,7 +789,7 @@ static void retry_uffdio_zeropage(int ufd,
779 } 789 }
780} 790}
781 791
782static int uffdio_zeropage(int ufd, unsigned long offset) 792static int __uffdio_zeropage(int ufd, unsigned long offset, bool retry)
783{ 793{
784 struct uffdio_zeropage uffdio_zeropage; 794 struct uffdio_zeropage uffdio_zeropage;
785 int ret; 795 int ret;
@@ -814,7 +824,7 @@ static int uffdio_zeropage(int ufd, unsigned long offset)
814 fprintf(stderr, "UFFDIO_ZEROPAGE unexpected %Ld\n", 824 fprintf(stderr, "UFFDIO_ZEROPAGE unexpected %Ld\n",
815 uffdio_zeropage.zeropage), exit(1); 825 uffdio_zeropage.zeropage), exit(1);
816 } else { 826 } else {
817 if (test_uffdio_zeropage_eexist) { 827 if (test_uffdio_zeropage_eexist && retry) {
818 test_uffdio_zeropage_eexist = false; 828 test_uffdio_zeropage_eexist = false;
819 retry_uffdio_zeropage(ufd, &uffdio_zeropage, 829 retry_uffdio_zeropage(ufd, &uffdio_zeropage,
820 offset); 830 offset);
@@ -830,6 +840,11 @@ static int uffdio_zeropage(int ufd, unsigned long offset)
830 return 0; 840 return 0;
831} 841}
832 842
843static int uffdio_zeropage(int ufd, unsigned long offset)
844{
845 return __uffdio_zeropage(ufd, offset, false);
846}
847
833/* exercise UFFDIO_ZEROPAGE */ 848/* exercise UFFDIO_ZEROPAGE */
834static int userfaultfd_zeropage_test(void) 849static int userfaultfd_zeropage_test(void)
835{ 850{