On Fri, Sep 27, 2019 at 09:18:30AM -0700, Ben Gardon wrote:
The demand paging test is currently a simple page access test which, while potentially useful, doesn't add much versus the existing dirty logging test. To improve the demand paging test, add a basic userfaultfd demand paging implementation.
Signed-off-by: Ben Gardon bgardon@google.com
.../selftests/kvm/demand_paging_test.c | 157 ++++++++++++++++++ 1 file changed, 157 insertions(+)
diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/selftests/kvm/demand_paging_test.c index 5f214517ba1de..61ba4e6a8214a 100644 --- a/tools/testing/selftests/kvm/demand_paging_test.c +++ b/tools/testing/selftests/kvm/demand_paging_test.c @@ -11,11 +11,14 @@ #include <stdio.h> #include <stdlib.h> +#include <sys/syscall.h>
[1]
#include <unistd.h> #include <time.h> +#include <poll.h> #include <pthread.h> #include <linux/bitmap.h> #include <linux/bitops.h> +#include <linux/userfaultfd.h> #include "test_util.h" #include "kvm_util.h" @@ -29,6 +32,8 @@ /* Default guest test virtual memory offset */ #define DEFAULT_GUEST_TEST_MEM 0xc0000000 +#define __NR_userfaultfd 323
This line can be dropped if with [1] above?
[...]
+static void *uffd_handler_thread_fn(void *arg) +{
- struct uffd_handler_args *uffd_args = (struct uffd_handler_args *)arg;
- int uffd = uffd_args->uffd;
- int64_t pages = 0;
- while (!quit_uffd_thread) {
struct uffd_msg msg;
struct pollfd pollfd[1];
int r;
uint64_t addr;
pollfd[0].fd = uffd;
pollfd[0].events = POLLIN;
r = poll(pollfd, 1, 2000);
This may introduce an unecessary 2s delay when quit. Maybe we can refer to how userfaultfd selftest did with this (please see uffd_poll_thread() in selftests/vm/userfaultfd.c on usage of pipefd).
Thanks,