Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1838889pxj; Wed, 19 May 2021 15:25:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytg1wGjzADdgRGL9lv/vY3AaSNslZn+R0bPym76CuACO6rYHnOwCzVtugalmcl4RPEQ+Ut X-Received: by 2002:aa7:c9cb:: with SMTP id i11mr1340636edt.331.1621463124657; Wed, 19 May 2021 15:25:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621463124; cv=none; d=google.com; s=arc-20160816; b=PBZllyNZNNaX5fK/EABykFyLwZ0uI0KzmSziZVODuJcUvqqJVsl2g3MAuDEPokUgxm KVFxfKpzTOKjRJ+2abruF84lBz8OuSH4zPbTvNVhtb42xbCCZyNerGJmdfruIZEaRthO rrAvt4EwSt6KnJbR+gAKcCnoWJzZN7QeJh13usg1A1xPZyaGrdRiGkiTKJgxLzYBcHQf aLPnPiN2/g9j9yXZmsgCBYExTiqo5e84Z65SwRAx4/KxjILmsJKWU+acMx7J/vUF26gc SIaZJ4UwhaTTxP244zTOxrm6C31y+p7KIaqYqQUvqRSQ2QEpSHJuhCoLoMWidDqCaXlt vDWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Rx88tQCGOYDOoqf7VThCQ35Bbq6JUkOg6xay93bQ/Kw=; b=L7RbODKs84f1klnb+u6pIrFJVCNs+jIbRVCjljjLloqhItu0gVfeZ/7BINyQe7FoZC 94wXkqZlkL30LS0EjqsuCBjbzO6AZxh9RfZxHr2e8fm07mAUm8CUkyi5+LtsEgsxTQN4 PRm/FmdboQ8TGDEIaLxb2SzkQc/QXAiU3+8prm2DWopyW5xWDKkj/giJAkNfRBI/QHMH EBPtET6vhdagU5BgyXgQONd3duMARPOcHqTcfukAcSxiAU0+/YDGQX/a6ho4JAXkQjzb 69F0NeHs/4RhjcXGILR7QgJD//Ki+RfRMrgxqGptvOGrSm1uC5zgeIoK2e7UCFgsTYQV i7UQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=cJtsAIQZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bv14si852638ejb.737.2021.05.19.15.25.00; Wed, 19 May 2021 15:25:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=cJtsAIQZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229932AbhESWZW (ORCPT + 99 others); Wed, 19 May 2021 18:25:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229465AbhESWZU (ORCPT ); Wed, 19 May 2021 18:25:20 -0400 Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A811C06175F for ; Wed, 19 May 2021 15:24:00 -0700 (PDT) Received: by mail-io1-xd2c.google.com with SMTP id k16so14601639ios.10 for ; Wed, 19 May 2021 15:24:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Rx88tQCGOYDOoqf7VThCQ35Bbq6JUkOg6xay93bQ/Kw=; b=cJtsAIQZTYB8JoeFmcaGZ/bFe0qN7YpY0zWnmqZxm/fcSJsCbDpYZ/XWiiLdDT5uKF Ne4jDon7qeLtRdpXjMMvc739xZhmuiu89fQtnXT6wuAlsf4FY7EQrC58GQCFgv69IRz9 KKROjdz+cb7D/GzNvjHnp/vC6P+hZAxGx2UmSWUBVTzfHX4QLTbqGvtIa2BL4kHUmD+J +eKK7pMHTGWfF46J26oIgrQ0qNrrH8fzUXcsBZeNK0iJofJl11mpUfGX4yYwLrcaqIh7 g4MoWKy7ohVlfyeYda+uyOfvXbcYqN8HcCQUOx4OK/St8oYthwgtO0BoYrZgHoaD9SSD T3GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Rx88tQCGOYDOoqf7VThCQ35Bbq6JUkOg6xay93bQ/Kw=; b=FQFR2np5oQODejAU1/T7pw3l3bLdEKHHqlgR9Jq5njMTFbLhDx9Nm4VbAxKE9VOxJN 3LLOitgRzdkd3qdZ0ekYMP8tAzIrAt+9uRRUToPu6N2mAaTWHV9KrVZCnQSky0hOJcWm mn/3pEyEcXo6vg1HoL3zdoGW+ArNM+loalBbKcrCFN3Yg744SB+1KUOfoOB1/IWrtKdD qoy9NVXpn1hNybXTfvkDaRofEPLMOKdEvQWQ14w2j7gVVrxNjcsjGdBdFLqePbtqjNuT j91vHAtCnLoTB1P3nKjp/Kp8PEJ7EV/ozTRBaLrdVh7iqP9MvTMUQurN1AdD/2kiFGUc 7jTg== X-Gm-Message-State: AOAM531R7WEXbZiNIyRC2+QfXI9nX7mTuyJOrvj3G/L6Qjld0eY9WSgt FtPCi2ohGEIKU5pNdn+DVx3GsKz3vZjR4anKlAjc8A== X-Received: by 2002:a05:6602:3427:: with SMTP id n39mr2079015ioz.157.1621463039499; Wed, 19 May 2021 15:23:59 -0700 (PDT) MIME-Version: 1.0 References: <20210519200339.829146-1-axelrasmussen@google.com> <20210519200339.829146-3-axelrasmussen@google.com> In-Reply-To: From: Ben Gardon Date: Wed, 19 May 2021 15:23:49 -0700 Message-ID: Subject: Re: [PATCH v2 02/10] KVM: selftests: simplify setup_demand_paging error handling To: Axel Rasmussen Cc: Aaron Lewis , Alexander Graf , Andrew Jones , Andrew Morton , Emanuele Giuseppe Esposito , Eric Auger , Jacob Xu , Makarand Sonare , Oliver Upton , Paolo Bonzini , Peter Xu , Shuah Khan , Yanan Wang , kvm , LKML , linux-kselftest@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 19, 2021 at 3:14 PM Axel Rasmussen wrote: > > On Wed, May 19, 2021 at 2:45 PM Ben Gardon wrote: > > > > On Wed, May 19, 2021 at 1:03 PM Axel Rasmussen wrote: > > > > > > 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 Reviewed-by: Ben Gardon > > > --- > > > .../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 > > > +#include > > > > Why do the includes need to change in this commit? Is it for the PRIu64 below? > > Right, I didn't actually try compiling without these, but inttypes.h > defines PRIu64 and stdint.h defines uint64_t. In general I tend to > prefer including things like this because we're using their > definitions directly, even if we might be picking them up transiently > some other way. Makes sense to me. > > > > > > #include > > > #include > > > #include > > > @@ -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 > > >