From: Axel Rasmussen <axelrasmussen@google.com>
To: Aaron Lewis <aaronlewis@google.com>,
Alexander Graf <graf@amazon.com>,
Andrew Jones <drjones@redhat.com>,
Andrew Morton <akpm@linux-foundation.org>,
Ben Gardon <bgardon@google.com>,
Emanuele Giuseppe Esposito <eesposit@redhat.com>,
Eric Auger <eric.auger@redhat.com>,
Jacob Xu <jacobhxu@google.com>,
Makarand Sonare <makarandsonare@google.com>,
Oliver Upton <oupton@google.com>,
Paolo Bonzini <pbonzini@redhat.com>, Peter Xu <peterx@redhat.com>,
Shuah Khan <shuah@kernel.org>,
Yanan Wang <wangyanan55@huawei.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org,
Axel Rasmussen <axelrasmussen@google.com>
Subject: [PATCH v2 02/10] KVM: selftests: simplify setup_demand_paging error handling
Date: Wed, 19 May 2021 13:03:31 -0700 [thread overview]
Message-ID: <20210519200339.829146-3-axelrasmussen@google.com> (raw)
In-Reply-To: <20210519200339.829146-1-axelrasmussen@google.com>
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: Axel Rasmussen <axelrasmussen@google.com>
---
.../selftests/kvm/demand_paging_test.c | 51 +++++++------------
1 file changed, 19 insertions(+), 32 deletions(-)
diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/selftests/kvm/demand_paging_test.c
index 9398ba6ef023..601a1df24dd2 100644
--- a/tools/testing/selftests/kvm/demand_paging_test.c
+++ b/tools/testing/selftests/kvm/demand_paging_test.c
@@ -9,6 +9,8 @@
#define _GNU_SOURCE /* for pipe2 */
+#include <inttypes.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
@@ -198,42 +200,32 @@ static void *uffd_handler_thread_fn(void *arg)
return NULL;
}
-static int setup_demand_paging(struct kvm_vm *vm,
- pthread_t *uffd_handler_thread, int pipefd,
- useconds_t uffd_delay,
- struct uffd_handler_args *uffd_args,
- void *hva, uint64_t len)
+static void setup_demand_paging(struct kvm_vm *vm,
+ pthread_t *uffd_handler_thread, int pipefd,
+ useconds_t uffd_delay,
+ struct uffd_handler_args *uffd_args,
+ void *hva, uint64_t len)
{
int uffd;
struct uffdio_api uffdio_api;
struct uffdio_register uffdio_register;
uffd = syscall(__NR_userfaultfd, O_CLOEXEC | O_NONBLOCK);
- if (uffd == -1) {
- pr_info("uffd creation failed\n");
- return -1;
- }
+ TEST_ASSERT(uffd >= 0, "uffd creation failed, errno: %d", errno);
uffdio_api.api = UFFD_API;
uffdio_api.features = 0;
- if (ioctl(uffd, UFFDIO_API, &uffdio_api) == -1) {
- pr_info("ioctl uffdio_api failed\n");
- return -1;
- }
+ TEST_ASSERT(ioctl(uffd, UFFDIO_API, &uffdio_api) != -1,
+ "ioctl UFFDIO_API failed: %" PRIu64,
+ (uint64_t)uffdio_api.api);
uffdio_register.range.start = (uint64_t)hva;
uffdio_register.range.len = len;
uffdio_register.mode = UFFDIO_REGISTER_MODE_MISSING;
- if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register) == -1) {
- pr_info("ioctl uffdio_register failed\n");
- return -1;
- }
-
- if ((uffdio_register.ioctls & UFFD_API_RANGE_IOCTLS) !=
- UFFD_API_RANGE_IOCTLS) {
- pr_info("unexpected userfaultfd ioctl set\n");
- return -1;
- }
+ TEST_ASSERT(ioctl(uffd, UFFDIO_REGISTER, &uffdio_register) != -1,
+ "ioctl UFFDIO_REGISTER failed");
+ TEST_ASSERT((uffdio_register.ioctls & UFFD_API_RANGE_IOCTLS) ==
+ UFFD_API_RANGE_IOCTLS, "unexpected userfaultfd ioctl set");
uffd_args->uffd = uffd;
uffd_args->pipefd = pipefd;
@@ -243,8 +235,6 @@ static int setup_demand_paging(struct kvm_vm *vm,
PER_VCPU_DEBUG("Created uffd thread for HVA range [%p, %p)\n",
hva, hva + len);
-
- return 0;
}
struct test_params {
@@ -321,13 +311,10 @@ static void run_test(enum vm_guest_mode mode, void *arg)
O_CLOEXEC | O_NONBLOCK);
TEST_ASSERT(!r, "Failed to set up pipefd");
- r = setup_demand_paging(vm,
- &uffd_handler_threads[vcpu_id],
- pipefds[vcpu_id * 2],
- p->uffd_delay, &uffd_args[vcpu_id],
- vcpu_hva, vcpu_mem_size);
- if (r < 0)
- exit(-r);
+ setup_demand_paging(vm, &uffd_handler_threads[vcpu_id],
+ pipefds[vcpu_id * 2], p->uffd_delay,
+ &uffd_args[vcpu_id], vcpu_hva,
+ vcpu_mem_size);
}
}
--
2.31.1.751.gd2f1c929bd-goog
next prev parent reply other threads:[~2021-05-19 20:03 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-19 20:03 [PATCH v2 00/10] KVM: selftests: exercise userfaultfd minor faults Axel Rasmussen
2021-05-19 20:03 ` [PATCH v2 01/10] KVM: selftests: trivial comment/logging fixes Axel Rasmussen
2021-05-19 21:41 ` Ben Gardon
2021-05-19 20:03 ` Axel Rasmussen [this message]
2021-05-19 21:45 ` [PATCH v2 02/10] KVM: selftests: simplify setup_demand_paging error handling Ben Gardon
2021-05-19 22:14 ` Axel Rasmussen
2021-05-19 22:23 ` Ben Gardon
2021-05-24 13:25 ` Paolo Bonzini
2021-05-19 20:03 ` [PATCH v2 03/10] KVM: selftests: print a message when skipping KVM tests Axel Rasmussen
2021-05-19 21:49 ` Ben Gardon
2021-05-24 13:23 ` Paolo Bonzini
2021-05-19 20:03 ` [PATCH v2 04/10] KVM: selftests: compute correct demand paging size Axel Rasmussen
2021-05-19 21:51 ` Ben Gardon
2021-05-19 20:03 ` [PATCH v2 05/10] KVM: selftests: allow different backing source types Axel Rasmussen
2021-05-19 21:53 ` Ben Gardon
2021-05-19 20:03 ` [PATCH v2 06/10] KVM: selftests: refactor vm_mem_backing_src_type flags Axel Rasmussen
2021-05-19 22:02 ` Ben Gardon
2021-05-19 22:16 ` Axel Rasmussen
2021-05-19 22:25 ` Ben Gardon
2021-05-19 20:03 ` [PATCH v2 07/10] KVM: selftests: add shmem backing source type Axel Rasmussen
2021-05-19 22:03 ` Ben Gardon
2021-05-19 20:03 ` [PATCH v2 08/10] KVM: selftests: create alias mappings when using shared memory Axel Rasmussen
2021-05-25 23:49 ` David Matlack
2021-05-26 17:22 ` Axel Rasmussen
2021-05-26 18:31 ` Paolo Bonzini
2021-05-19 20:03 ` [PATCH v2 09/10] KVM: selftests: allow using UFFD minor faults for demand paging Axel Rasmussen
2021-05-19 22:20 ` Ben Gardon
2021-05-19 22:34 ` Axel Rasmussen
2021-05-24 13:36 ` Paolo Bonzini
2021-05-19 20:03 ` [PATCH v2 10/10] KVM: selftests: add shared hugetlbfs backing source type Axel Rasmussen
2021-05-19 22:22 ` Ben Gardon
2021-05-24 13:38 ` [PATCH v2 00/10] KVM: selftests: exercise userfaultfd minor faults Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210519200339.829146-3-axelrasmussen@google.com \
--to=axelrasmussen@google.com \
--cc=aaronlewis@google.com \
--cc=akpm@linux-foundation.org \
--cc=bgardon@google.com \
--cc=drjones@redhat.com \
--cc=eesposit@redhat.com \
--cc=eric.auger@redhat.com \
--cc=graf@amazon.com \
--cc=jacobhxu@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=makarandsonare@google.com \
--cc=oupton@google.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=shuah@kernel.org \
--cc=wangyanan55@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).