Commit 25408e5a authored by Axel Rasmussen's avatar Axel Rasmussen Committed by Paolo Bonzini

KVM: selftests: simplify setup_demand_paging error handling

A small cleanup. Our caller writes:

  r = setup_demand_paging(...);
  if (r < 0) exit(-r);

Since we're just going to exit anyway, instead of returning an error we
can just re-use TEST_ASSERT. This makes the caller simpler, as well as
the function itself - no need to write our branches, etc.
Signed-off-by: default avatarAxel Rasmussen <axelrasmussen@google.com>
Message-Id: <20210519200339.829146-3-axelrasmussen@google.com>
Reviewed-by: default avatarBen Gardon <bgardon@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 2aab4b35
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#define _GNU_SOURCE /* for pipe2 */ #define _GNU_SOURCE /* for pipe2 */
#include <inttypes.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
...@@ -198,42 +199,32 @@ static void *uffd_handler_thread_fn(void *arg) ...@@ -198,42 +199,32 @@ static void *uffd_handler_thread_fn(void *arg)
return NULL; return NULL;
} }
static int setup_demand_paging(struct kvm_vm *vm, static void setup_demand_paging(struct kvm_vm *vm,
pthread_t *uffd_handler_thread, int pipefd, pthread_t *uffd_handler_thread, int pipefd,
useconds_t uffd_delay, useconds_t uffd_delay,
struct uffd_handler_args *uffd_args, struct uffd_handler_args *uffd_args,
void *hva, uint64_t len) void *hva, uint64_t len)
{ {
int uffd; int uffd;
struct uffdio_api uffdio_api; struct uffdio_api uffdio_api;
struct uffdio_register uffdio_register; struct uffdio_register uffdio_register;
uffd = syscall(__NR_userfaultfd, O_CLOEXEC | O_NONBLOCK); uffd = syscall(__NR_userfaultfd, O_CLOEXEC | O_NONBLOCK);
if (uffd == -1) { TEST_ASSERT(uffd >= 0, "uffd creation failed, errno: %d", errno);
pr_info("uffd creation failed\n");
return -1;
}
uffdio_api.api = UFFD_API; uffdio_api.api = UFFD_API;
uffdio_api.features = 0; uffdio_api.features = 0;
if (ioctl(uffd, UFFDIO_API, &uffdio_api) == -1) { TEST_ASSERT(ioctl(uffd, UFFDIO_API, &uffdio_api) != -1,
pr_info("ioctl uffdio_api failed\n"); "ioctl UFFDIO_API failed: %" PRIu64,
return -1; (uint64_t)uffdio_api.api);
}
uffdio_register.range.start = (uint64_t)hva; uffdio_register.range.start = (uint64_t)hva;
uffdio_register.range.len = len; uffdio_register.range.len = len;
uffdio_register.mode = UFFDIO_REGISTER_MODE_MISSING; uffdio_register.mode = UFFDIO_REGISTER_MODE_MISSING;
if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register) == -1) { TEST_ASSERT(ioctl(uffd, UFFDIO_REGISTER, &uffdio_register) != -1,
pr_info("ioctl uffdio_register failed\n"); "ioctl UFFDIO_REGISTER failed");
return -1; TEST_ASSERT((uffdio_register.ioctls & UFFD_API_RANGE_IOCTLS) ==
} UFFD_API_RANGE_IOCTLS, "unexpected userfaultfd ioctl set");
if ((uffdio_register.ioctls & UFFD_API_RANGE_IOCTLS) !=
UFFD_API_RANGE_IOCTLS) {
pr_info("unexpected userfaultfd ioctl set\n");
return -1;
}
uffd_args->uffd = uffd; uffd_args->uffd = uffd;
uffd_args->pipefd = pipefd; uffd_args->pipefd = pipefd;
...@@ -243,8 +234,6 @@ static int setup_demand_paging(struct kvm_vm *vm, ...@@ -243,8 +234,6 @@ static int setup_demand_paging(struct kvm_vm *vm,
PER_VCPU_DEBUG("Created uffd thread for HVA range [%p, %p)\n", PER_VCPU_DEBUG("Created uffd thread for HVA range [%p, %p)\n",
hva, hva + len); hva, hva + len);
return 0;
} }
struct test_params { struct test_params {
...@@ -321,13 +310,10 @@ static void run_test(enum vm_guest_mode mode, void *arg) ...@@ -321,13 +310,10 @@ static void run_test(enum vm_guest_mode mode, void *arg)
O_CLOEXEC | O_NONBLOCK); O_CLOEXEC | O_NONBLOCK);
TEST_ASSERT(!r, "Failed to set up pipefd"); TEST_ASSERT(!r, "Failed to set up pipefd");
r = setup_demand_paging(vm, setup_demand_paging(vm, &uffd_handler_threads[vcpu_id],
&uffd_handler_threads[vcpu_id], pipefds[vcpu_id * 2], p->uffd_delay,
pipefds[vcpu_id * 2], &uffd_args[vcpu_id], vcpu_hva,
p->uffd_delay, &uffd_args[vcpu_id], vcpu_mem_size);
vcpu_hva, vcpu_mem_size);
if (r < 0)
exit(-r);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment