Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4717425rdb; Fri, 15 Sep 2023 10:05:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHR/lG84s9UCssDSXeHOP/Ksw6Y4Pe2E/dk7kToFtJdQaZ1zfGkKCb4ktylL5GhDCf+eh2G X-Received: by 2002:a05:6a00:1819:b0:68b:a137:372b with SMTP id y25-20020a056a00181900b0068ba137372bmr2650760pfa.19.1694797524886; Fri, 15 Sep 2023 10:05:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694797524; cv=none; d=google.com; s=arc-20160816; b=Dpn781Y4k7k9/Yjww6vj9AXxSSWQFoUYMRyQVmy01UAT1gsada84aPj1xA9XYctcVG NAV+MZlQkFJUoBywASttLE2E7HQDEB1FGSW3OfuoPUSNQziYvKEYq9Os3NF2m+XR1V3S LGQPJ+fLW2JW/r2FYHMNqRmM32C7uyXlNCOc8u/BFHwvG5vVyOwStLS3YLvpdB3ndMTB o10gZLg6mwmjiVOvKcjt0HK5eBVbcK1wUuCioZyu3DcR/sPntq32iJPULBmwIbNWWMak UBi9neHCR8r5Zpq/zOzgqT/gzdQjV+zhU7Ti0Tnmx8tNeZsVYdhiFANKS7txBoUo9upd PSiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=Bl/6t9mcAclJ4xtGmBPz2BA7FLMNa6WCNrJXbkl0XGU=; fh=40Gc+wykEPOYhjU7Q1XOpPHnE1ed8/px6rYxfyRq2sI=; b=yDMHH7eBjV3gVFo8xrlaX59G/qVqwWHt5F2us3nrnzzkvTwz0H5Mwdfq7b1PZXq2EL oUV2kjXTSTca42oSOOJfQ5yJYlqyJ1nkR/YRn1lutcKz/02cUX7SZmbJ2dUEtbuK7EAs /MmbxOv//Aoz/bVausgSrNYVcmELsUtkwNov+GiCPtTOQW5AOnpHtoVdXGnX5Fa74jsI +pSTN8fKwK8rZP0GNKaF5Jt7vxGBL0eh4PX6juZkCB2rm7xaQvLCCkOvjYG8uq7toox3 eRbwK29a6hYQ7uq+mmFIpEmk1Uly4URF0gx5cOCK9BI7594zdhZfexJQjq7nD1X1BCiq qNKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=gW9heNLw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id k26-20020a6568da000000b0057744d09d22si3573824pgt.85.2023.09.15.10.05.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 10:05:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=gW9heNLw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id BDABD8381EEE; Thu, 14 Sep 2023 23:14:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232243AbjIOGOg (ORCPT + 99 others); Fri, 15 Sep 2023 02:14:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232195AbjIOGOf (ORCPT ); Fri, 15 Sep 2023 02:14:35 -0400 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 198E42718; Thu, 14 Sep 2023 23:14:29 -0700 (PDT) Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-500c7796d8eso2956169e87.1; Thu, 14 Sep 2023 23:14:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694758467; x=1695363267; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Bl/6t9mcAclJ4xtGmBPz2BA7FLMNa6WCNrJXbkl0XGU=; b=gW9heNLweKuMlM9WxuQkoUQIdn26kA7bZ4ukaSf/Lekxo+NmGeUx0AWaRIW2be06Hc BruoWd9UdVPWxyETL3bMzZrk5EcuJty5F0O0+HkPrlPgDuQAPZJpoiSP/s9pqw9hQ/5M ch/Gh+G0dzooKjv7ppuuiLpuZ+uZ9ou43jcQe4orIU1JmRq47RT9UgxvK06+h9GSwche q/hwRvjwW12EUnLGwCd1HZq6COkK5B+IaZtqJ75p9HR5XcP4LeZNht9/AsJht3woheXH Pb6DAuABGnmdhJtfJ9MbBJB1BCVn18k8QdFB4dzeHwEXCqqppfILqA04e7ZEqy4UoZXz vNDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694758467; x=1695363267; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Bl/6t9mcAclJ4xtGmBPz2BA7FLMNa6WCNrJXbkl0XGU=; b=f6SDi8N40wIE63eH3Ngg6z2+J/DIcsHbFNYpKv7BbUaxQiTiDbnn9nsHKzmWu2ePhy Bn4xBRDMFj/PpCVGe1UqPJkBJvwRoimuEjtUDvb9quv0QlfcfV16gHHZyklde68yKfKv wgiJGxbNJvou7HGlKEgp3edfVCVI+4fpULdRpia8cEOUIAeuK4jsD1L4SI+nxV2UqM7N rBbi4bwxzhpkVBvyXveyfdn97936oMGnm81WrNdrYLZ9s/wmZrYW8lEP4Vadjv1f6iDM DZ0uSLLCHvWx3i+eD2Jin0fgUfpPIaIEeJpk8pyiKlNNeWIiKcHeENSHNLvmiwW4Gryj 7KoQ== X-Gm-Message-State: AOJu0YxsZwnDBSAywJIjvwjSepUtnTD6SezZAHJpc0Cw7X8CK/ylshYJ fRg24IbqfUpz/cQWX/k6rXQRi8a3zHFnQ9FJFyE= X-Received: by 2002:ac2:4831:0:b0:500:9dd4:2969 with SMTP id 17-20020ac24831000000b005009dd42969mr572676lft.59.1694758466969; Thu, 14 Sep 2023 23:14:26 -0700 (PDT) MIME-Version: 1.0 References: <20230914-d6645bbc5ac80999674e9685@orel> In-Reply-To: <20230914-d6645bbc5ac80999674e9685@orel> From: Haibo Xu Date: Fri, 15 Sep 2023 14:14:15 +0800 Message-ID: Subject: Re: [PATCH v3 8/9] KVM: riscv: selftests: Change vcpu_has_ext to a common function To: Andrew Jones Cc: Haibo Xu , Paul Walmsley , Palmer Dabbelt , Albert Ou , Paolo Bonzini , Shuah Khan , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Anup Patel , Atish Patra , Sean Christopherson , Ricardo Koller , Vishal Annapurve , Vitaly Kuznetsov , Vipin Sharma , David Matlack , Thomas Huth , Colton Lewis , Aaron Lewis , linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm-riscv@lists.infradead.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 14 Sep 2023 23:14:44 -0700 (PDT) On Thu, Sep 14, 2023 at 5:05=E2=80=AFPM Andrew Jones wrote: > > On Thu, Sep 14, 2023 at 09:37:02AM +0800, Haibo Xu wrote: > > Move vcpu_has_ext to the processor.c and rename it to __vcpu_has_ext > > so that other test cases can use it for vCPU extension check. > > > > Signed-off-by: Haibo Xu > > --- > > .../selftests/kvm/include/riscv/processor.h | 2 ++ > > .../testing/selftests/kvm/lib/riscv/processor.c | 9 +++++++++ > > tools/testing/selftests/kvm/riscv/get-reg-list.c | 16 +--------------- > > 3 files changed, 12 insertions(+), 15 deletions(-) > > > > diff --git a/tools/testing/selftests/kvm/include/riscv/processor.h b/to= ols/testing/selftests/kvm/include/riscv/processor.h > > index 2c975d9cead2..7d5517648ea7 100644 > > --- a/tools/testing/selftests/kvm/include/riscv/processor.h > > +++ b/tools/testing/selftests/kvm/include/riscv/processor.h > > @@ -42,6 +42,8 @@ static inline uint64_t __kvm_reg_id(uint64_t type, ui= nt64_t idx, > > #define RISCV_ISA_EXT_REG(idx) __kvm_reg_id(KVM_REG_RISCV_ISA_EX= T, \ > > idx, KVM_REG_SIZE_ULONG) > > > > +bool __vcpu_has_ext(struct kvm_vcpu *vcpu, int ext); > > + > > struct ex_regs { > > unsigned long ra; > > unsigned long sp; > > diff --git a/tools/testing/selftests/kvm/lib/riscv/processor.c b/tools/= testing/selftests/kvm/lib/riscv/processor.c > > index 39a1e9902dec..e527ad0abc30 100644 > > --- a/tools/testing/selftests/kvm/lib/riscv/processor.c > > +++ b/tools/testing/selftests/kvm/lib/riscv/processor.c > > @@ -15,6 +15,15 @@ > > > > static vm_vaddr_t exception_handlers; > > > > +bool __vcpu_has_ext(struct kvm_vcpu *vcpu, int ext) > > +{ > > + unsigned long value =3D 0; > > + > > + __vcpu_get_reg(vcpu, RISCV_ISA_EXT_REG(ext), &value); > > + > > + return !!value; > > I'd rather not assume that value will remain zero across a system call > which fails. Let's write this as > > unsigned long value =3D 0; > int ret; > > ret =3D __vcpu_get_reg(vcpu, RISCV_ISA_EXT_REG(ext), &value); > > return !ret && !!value; > Sure. Thanks for the suggestion! > > +} > > + > > static uint64_t page_align(struct kvm_vm *vm, uint64_t v) > > { > > return (v + vm->page_size) & ~(vm->page_size - 1); > > diff --git a/tools/testing/selftests/kvm/riscv/get-reg-list.c b/tools/t= esting/selftests/kvm/riscv/get-reg-list.c > > index d8ecacd03ecf..0dcff823f287 100644 > > --- a/tools/testing/selftests/kvm/riscv/get-reg-list.c > > +++ b/tools/testing/selftests/kvm/riscv/get-reg-list.c > > @@ -44,20 +44,6 @@ bool check_reject_set(int err) > > return err =3D=3D EINVAL; > > } > > > > -static inline bool vcpu_has_ext(struct kvm_vcpu *vcpu, int ext) > > -{ > > - int ret; > > - unsigned long value; > > - > > - ret =3D __vcpu_get_reg(vcpu, RISCV_ISA_EXT_REG(ext), &value); > > - if (ret) { > > - printf("Failed to get ext %d", ext); > > - return false; > > - } > > - > > - return !!value; > > -} > > - > > void finalize_vcpu(struct kvm_vcpu *vcpu, struct vcpu_reg_list *c) > > { > > struct vcpu_reg_sublist *s; > > @@ -77,7 +63,7 @@ void finalize_vcpu(struct kvm_vcpu *vcpu, struct vcpu= _reg_list *c) > > __vcpu_set_reg(vcpu, RISCV_ISA_EXT_REG(s->feature), 1); > > > > /* Double check whether the desired extension was enabled= */ > > - __TEST_REQUIRE(vcpu_has_ext(vcpu, s->feature), > > + __TEST_REQUIRE(__vcpu_has_ext(vcpu, s->feature), > > "%s not available, skipping tests\n", s->n= ame); > > } > > } > > -- > > 2.34.1 > > > > Otherwise, > > Reviewed-by: Andrew Jones > > Thanks, > drew