From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D1E36EB64DD for ; Tue, 27 Jun 2023 09:16:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=MpQyu58GwRGjj0M2tkrAQqx22sVFmBTpCT1zmht6UrE=; b=oXkpK6S52c5kw6 KcC158CCg06rDCwdmhyrR4AjO7C4Taxhx5oZ1OmjcfGu4EhzAgLpOVH9hG5rveRM+vmPidvmDI0O9 jIHadr8KnzltOHei3THAyBe4duhUuy+wnWjCEAbyrBYWKU5MeUiyYZhiLoMGFBgOiyTmAheUNdTS+ il2C1C2GoV0CbBYD4MfNTt7kqJAdL4z1VUrwW4v/Fta7M13QQnwWE2yFSbn52Pu/+WG6sinxZqgKk oEivdn1KSQbEJzWxuVN2Of4F2VSn0U69sXZi3axaN+7Mt2H6lBttLqb4y9ohjz1IwQpxUAkzh25xM rm8N1IiYX96XO715+Biw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qE4oS-00CfYb-2m; Tue, 27 Jun 2023 09:16:40 +0000 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qE4oP-00CfWc-0h for linux-riscv@lists.infradead.org; Tue, 27 Jun 2023 09:16:38 +0000 Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-991c786369cso242923866b.1 for ; Tue, 27 Jun 2023 02:16:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1687857395; x=1690449395; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=+MCoS/GbrEqpT4HJQ2GjfyBERH9spXNSgBlAnljQlo8=; b=hxzm0GKQS+eom3slcVJwuaQB9SbpkcfrgGFcNPoFyyIGNADZabL4nQv4gszNAGffMe lDvcAP3Ghl5j87LvIMP0tvxaDJO5dLmgCDIBMw4x2AqUk0Z06cXw2PHzxhdIva9WTfgT 6PYn64hxE1JpVa5KuCqgw60STT4o7kEIqeDbQXinO6DoHzf3XFrtxWiBLPireQe8lFEp 47eQyDKL7rL9U/8yuEQRbmm7dLdr4HIvaW63994gvfJXi7ogLu0onQXJPY+Zu8T638Bm toYA9lWto9yOvy9yDPITMK/s6pPZkTIqUdS2A76+SHKBmet/Q/CwNY5HMpBPoqI+rsAK HQ/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687857395; x=1690449395; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=+MCoS/GbrEqpT4HJQ2GjfyBERH9spXNSgBlAnljQlo8=; b=hriqycGT/8G7wijHQO0E1Cdo/2jojFTJ94C9aYoBr1S55PS2xKIEONmONKr4UFrwWk KEG4GhJhAoLshIcL6aKhiq66GlcB0hf+kU5RWKaf/z1CJ80eucK4sgqkI04B1ts9L0c9 3xR62sAUkRYnMFBrsmhH7gJBHeiNAONdh9Av0YjKQvxbIZtzAFKEi/x7s1MREIRV3Ktg hBaUq1n81resyf58MvrjuWWc655v4ekRjrYi8gd5OD/gU9WzG5PxoaSJFIM0QVB9BCvP /5J+ubFimN+bst0cp6kCOg67TYAI8V6v84Vek4FSq8mwu6sIvWH3gSmX+qCi/JBhXUOg E05Q== X-Gm-Message-State: AC+VfDz3S0MQXAGBPYzQLXNfvw0ORPLXa1EP5zZlp/NG/PNI1ztMcwyq HGKyFE5G8XY13JWqymhOPX7lzQ== X-Google-Smtp-Source: ACHHUZ575a/YzRNsfdhJWLZPMJ3YdSkM8BP8AyU7T0mt/iflGtaHCLSXzIB+tLAYyf2UCf7ECFnkfw== X-Received: by 2002:a17:906:eec1:b0:970:c9f:2db6 with SMTP id wu1-20020a170906eec100b009700c9f2db6mr24231824ejb.63.1687857395256; Tue, 27 Jun 2023 02:16:35 -0700 (PDT) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id n19-20020a170906841300b00988d0ad4477sm4283531ejx.29.2023.06.27.02.16.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 02:16:34 -0700 (PDT) Date: Tue, 27 Jun 2023 11:16:33 +0200 From: Andrew Jones To: Haibo Xu Cc: xiaobo55x@gmail.com, maz@kernel.org, oliver.upton@linux.dev, seanjc@google.com, Paolo Bonzini , Jonathan Corbet , Anup Patel , Atish Patra , Paul Walmsley , Palmer Dabbelt , Albert Ou , Shuah Khan , James Morse , Suzuki K Poulose , Zenghui Yu , David Matlack , Ben Gardon , Ricardo Koller , Vishal Annapurve , Vipin Sharma , Colton Lewis , kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev Subject: Re: [PATCH v4 11/12] KVM: riscv: selftests: Add finalize_vcpu check in run_test Message-ID: <20230627-feb5bf584a3fd16d2c0ffe66@orel> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230627_021637_254990_6A378905 X-CRM114-Status: GOOD ( 24.77 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On Fri, Jun 23, 2023 at 06:40:13PM +0800, Haibo Xu wrote: > Disable all vcpu extensions which were enabled by default > if they were available in the risc-v host, and only enable > the desired one for a vcpu_config. > > Suggested-by: Andrew Jones > Signed-off-by: Haibo Xu > --- > tools/testing/selftests/kvm/get-reg-list.c | 42 +++++++++++++++++++++- > 1 file changed, 41 insertions(+), 1 deletion(-) > > diff --git a/tools/testing/selftests/kvm/get-reg-list.c b/tools/testing/selftests/kvm/get-reg-list.c > index 3beb6b62de0a..612dabc61137 100644 > --- a/tools/testing/selftests/kvm/get-reg-list.c > +++ b/tools/testing/selftests/kvm/get-reg-list.c > @@ -138,11 +138,50 @@ static struct kvm_vcpu *vcpu_config_get_vcpu(struct vcpu_reg_list *c, struct kvm > prepare_vcpu_init(c, &init); > vcpu = __vm_vcpu_add(vm, 0); > aarch64_vcpu_setup(vcpu, &init); > - finalize_vcpu(vcpu, c); > > return vcpu; > } > #else > +static inline bool vcpu_has_ext(struct kvm_vcpu *vcpu, int ext) > +{ > + int ret; > + unsigned long value; > + > + ret = __vcpu_get_reg(vcpu, RISCV_ISA_EXT_REG(ext), &value); > + if (ret) { > + printf("Failed to get ext %d", ext); > + return false; > + } > + > + return !!value; > +} > + > +static void finalize_vcpu(struct kvm_vcpu *vcpu, struct vcpu_reg_list *c) > +{ > + struct vcpu_reg_sublist *s; > + > + /* > + * Disable all extensions which were enabled by default > + * if they were available in the risc-v host. > + */ > + for (int i = 0; i < KVM_RISCV_ISA_EXT_MAX; i++) { > + __vcpu_set_reg(vcpu, RISCV_ISA_EXT_REG(i), 0); > + } nit: can drop the {} > + > + for_each_sublist(c, s) { > + if (!s->feature) > + continue; > + > + /* Try to enable the desired extension */ > + __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), > + "%s: %s not available, skipping tests\n", > + config_name(c), s->name); > + } > +} > + > static struct kvm_vcpu *vcpu_config_get_vcpu(struct vcpu_reg_list *c, struct kvm_vm *vm) > { > return __vm_vcpu_add(vm, 0); > @@ -178,6 +217,7 @@ static void run_test(struct vcpu_reg_list *c) > > vm = vm_create_barebones(); > vcpu = vcpu_config_get_vcpu(c, vm); > + finalize_vcpu(vcpu, c); Now that both arm and riscv call finalize_vcpu() we could do the weak function trick for it and move the arch-specific implementations to their own arch-specific files. > > reg_list = vcpu_get_reg_list(vcpu); > > -- > 2.34.1 > Otherwise, Reviewed-by: Andrew Jones Thanks, drew _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv