Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1815270pxj; Wed, 19 May 2021 14:47:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy77UTrU48I6m10GMi6nn6basfLNB7FQx//01CzkDwMFJhdRFefmgik5spNu9BhwK0AsYM9 X-Received: by 2002:a05:6402:3507:: with SMTP id b7mr1184351edd.101.1621460849528; Wed, 19 May 2021 14:47:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621460849; cv=none; d=google.com; s=arc-20160816; b=VwPavWTySrCJVYkUv7/rjJIVgSvJ1dFF+ZtDFD1tnOI+q2PWogcqEdiq0gryowA2GU 6OO6+WmCkPWXAooACVWR4Xwt5KPnaJiGOlMh9TTDy6CHhASrxl4a+7nL4PLrOUxBxATq 4nnss1nASfUO6LRKoIIq86cDyJo3GIyGF+rNeND1qb4R8SUkq1xBLvVB/1WkjGhbsVIV B2XFCLiVf3btAchlRKlafRl2TmqBQWqDNuyl9x4NUn3EFVrnHrha7uFP/x23iFjhSX3l kJn3oHeQtlTUidRaE9osVFvs8v+UNHMUAd+VcIZw2HKaVUeZZEAafLFgp7ZbyV468J3i xxKw== 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=n+MU5sQJyoUxoQR/RnPtWo1DwBMH6gtnYsN37Ax0beM=; b=gnRKn01Ov/CLR476lg7ACFUMom43Q9Admn6NmnrM37E9wHsDyWWeT1ig3afhyBrdeM QQmCN+KwqRxrSmrUkVZLIdc/lify6nsMq/9SvO7zu3Qj4Qn3Bxgbh7t4s4Uar/a9GKlD k3gO6/xWKrins0sbgwkjysL31/ATBBJUjLRHh2UBt3vbEb0nnsmM1PCyDVcRu1gW/dIh 756tLN/qdoN2dTqPL3sKjZznlUCAyE7wz0lkKbSjX1V1+Ylu5MtTPpn0Tf3Ks3t3CvAC 92Be7+uLcF7HxF5TwzkE+F2DR4plhvZ55GYKyhgRookfSvjx4uKO80kijnak/AvAwPbp ZZsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=mBB+1FV4; 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 w11si930598ejc.493.2021.05.19.14.47.05; Wed, 19 May 2021 14:47:29 -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=mBB+1FV4; 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 S229454AbhESVrN (ORCPT + 99 others); Wed, 19 May 2021 17:47:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229518AbhESVrN (ORCPT ); Wed, 19 May 2021 17:47:13 -0400 Received: from mail-il1-x134.google.com (mail-il1-x134.google.com [IPv6:2607:f8b0:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DD66C06175F for ; Wed, 19 May 2021 14:45:53 -0700 (PDT) Received: by mail-il1-x134.google.com with SMTP id j30so13478730ila.5 for ; Wed, 19 May 2021 14:45:53 -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=n+MU5sQJyoUxoQR/RnPtWo1DwBMH6gtnYsN37Ax0beM=; b=mBB+1FV4MtxiRwkKsGVfbsWWHrOfVTntJlUTN9QLTf0cSwRZbYx+7h3P6X8QYdpN8q 7MCCd8bs7mIuFt72Sk0WYO+mQtl7EX3g1hutzP7YrzBWI16poLAGSlY2Sy10GNTDMhUH CSya8+hnrmxugrw+xoi7htTIgtRknQUluubWU5LrdLH/pJBHFAULg1EJpMIXbfo1gA66 +qiUZSo/q/WKEDMKXNMv9MROhXmHzRtHogMhehD9sr7BgLRuaJMNLtAJl2jAL3sAftFU 8680Qmhs7/Mny5vfG+ypQUIvMZgcYHIUADYFgHqpxb/fJlORQb/79jpooKWO0oSbMMDM ENSQ== 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=n+MU5sQJyoUxoQR/RnPtWo1DwBMH6gtnYsN37Ax0beM=; b=OzVgTz1VSQ5sIGVR4pUYqrvQQ3ezCf4OxHWOE5FKDVheQt5pLRUMHx93dbWdSGvQl2 oowdrMCaKe9smbE4hcas8v3hTf4FX8yf75+fneGUvADv9se9DhDUdDvVgOobOQcSjhzA 5Kb4eQow18ETWo/BTxvvvwPxgfaFrXAxShR9inUbybd38YCST2osvhFdmuwFAHxGI7Gl q1exbtw8vCNb2N7/N5siJeXE98ZugrQbRtZKVFFonziWQmQvvpXLZMNAzg2p7WDPIu7m bN0tzKzZW9XcsHngStap3yjGc2bpoyhc3J63tAwtpZucaN6WJoUavwWkC4w8PhHCw0cU Cuww== X-Gm-Message-State: AOAM532rrNwmbEqJ69fesKd4oLO3kxFafqVqKUaxLt2mOc2T42XnfjHh 2pBV9Z/B9wcIWp/EoCBoVPozeKFnk5MGkFi+IenO/g== X-Received: by 2002:a05:6e02:13ec:: with SMTP id w12mr1414415ilj.285.1621460752580; Wed, 19 May 2021 14:45:52 -0700 (PDT) MIME-Version: 1.0 References: <20210519200339.829146-1-axelrasmussen@google.com> <20210519200339.829146-3-axelrasmussen@google.com> In-Reply-To: <20210519200339.829146-3-axelrasmussen@google.com> From: Ben Gardon Date: Wed, 19 May 2021 14:45:41 -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 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 > --- > .../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? > #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 >