KVM: selftests: Allow many vCPUs and reader threads per UFFD in demand paging test
authorAnish Moorthy <amoorthy@google.com>
Thu, 15 Feb 2024 23:54:02 +0000 (23:54 +0000)
committerSean Christopherson <seanjc@google.com>
Tue, 9 Apr 2024 21:28:53 +0000 (14:28 -0700)
commitdf4ec5aada9da30486d5464f34ffc80acd0373d6
tree39a5f22255a72b2fb0a7da26f609f7e3a69b21ee
parent2ca76c12c48b7a2792b21a673ca01a6d8fb2e835
KVM: selftests: Allow many vCPUs and reader threads per UFFD in demand paging test

At the moment, demand_paging_test does not support profiling/testing
multiple vCPU threads concurrently faulting on a single uffd because

    (a) "-u" (run test in userfaultfd mode) creates a uffd for each vCPU's
        region, so that each uffd services a single vCPU thread.
    (b) "-u -o" (userfaultfd mode + overlapped vCPU memory accesses)
        simply doesn't work: the test tries to register the same memory
        to multiple uffds, causing an error.

Add support for many vcpus per uffd by
    (1) Keeping "-u" behavior unchanged.
    (2) Making "-u -a" create a single uffd for all of guest memory.
    (3) Making "-u -o" implicitly pass "-a", solving the problem in (b).
In cases (2) and (3) all vCPU threads fault on a single uffd.

With potentially multiple vCPUs per UFFD, it makes sense to allow
configuring the number of reader threads per UFFD as well: add the "-r"
flag to do so.

Signed-off-by: Anish Moorthy <amoorthy@google.com>
Acked-by: James Houghton <jthoughton@google.com>
Link: https://lore.kernel.org/r/20240215235405.368539-12-amoorthy@google.com
[sean: fix kernel style violations, use calloc() for arrays]
Signed-off-by: Sean Christopherson <seanjc@google.com>
tools/testing/selftests/kvm/aarch64/page_fault_test.c
tools/testing/selftests/kvm/demand_paging_test.c
tools/testing/selftests/kvm/include/userfaultfd_util.h
tools/testing/selftests/kvm/lib/userfaultfd_util.c