Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp17447339rwd; Tue, 27 Jun 2023 03:12:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6RzOCtTrOdg0v9/EQ0/VKkBo6frPv37/e9gCCTzV4K2r6WYkM5cQBHg8m/gHR6vhNBRNxn X-Received: by 2002:a05:6a00:228a:b0:666:eaaf:a2af with SMTP id f10-20020a056a00228a00b00666eaafa2afmr41249441pfe.14.1687860747490; Tue, 27 Jun 2023 03:12:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687860747; cv=none; d=google.com; s=arc-20160816; b=0iGY61+8ij/KlOuO18YM+4/i1BXAw8wOWC+/wJPUr7nU4W+ZAAJ3xFzE3vBF69A1TJ 0VsiZ8ps34NRj8OdXQVfSotWavEzfVv4cQ2GmPrmM2LdekgKPYcOXIvl3DlNomW+wKl4 A+fkzSGENZv0JCGSDcVgbXr3YAcsD3KUA5YRnjnLSmf/wbJeOs8es7oLVyQqw5kf271T vmp40K4iLeo1zmbtx8PzlAEcd4Teq/N1PJfxxi3de8+p5iHdqbAEDELdfJ+G6lWSG3Ur 9AnRs5n/3R/IIk3sWwu4Np/v0Cw4JovocbBoSqNP4L+Jopbiy4DO+881uPTI6Rf3z+52 axQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=+MCoS/GbrEqpT4HJQ2GjfyBERH9spXNSgBlAnljQlo8=; fh=KrqAfnlW7fTfA1uz4MFAxW2LN2bnHdakzefSdC+VdQQ=; b=MmohfglxwsU5AkNCRTaKoDzqNoKvZ8kTgrEtR1yiw0lnhpS3Twtdy9yZXv3fsMZWzj 5R9FtvvC5EdSkYS3tKHlqIiKEyXeGvpY/mRr9XSjOlEIizFAVDZhXxfs7q9LsyibI/e2 zEw2mXybXYD6/r6VCksmFoyxl7ffN+NA1XS/IqEf5TolqUu0PSpFuCYbxuOuimoOAshe wsd0l+FGmSDvEGmjHJSi8/VXMNdx77/zaqsO0K9LpbapKZ7+3+XHRJG7d4TTIa1rShGE V6PdRrY3ZPPZqOc74HY86f2me9iBoMctl2DOHAq6C0w5z2DzfYv/VUMFQ8WKC5tWA9t9 KfPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=hxzm0GKQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id eh8-20020a056a00808800b006683174a49csi4013281pfb.198.2023.06.27.03.12.08; Tue, 27 Jun 2023 03:12:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=hxzm0GKQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231478AbjF0JQn (ORCPT + 99 others); Tue, 27 Jun 2023 05:16:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229819AbjF0JQi (ORCPT ); Tue, 27 Jun 2023 05:16:38 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3EC6FD for ; Tue, 27 Jun 2023 02:16:36 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-98e1b1d1698so362514066b.2 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=WeKN7JXuZYbIAlIx48AYuEDrX1X+lfXS0vsJ8Vh8PWyrHvsToDTMtKW9UW/aPfV/Tb kiSeGXfzWVx3bDti6yLUw2+6RJ9Necs+AUA7xE8wdmLVZWvMrOlFI7Rz8XsAKw0gOaME snHwU9GJXjBifcOgjAZqU/+kLyCLWSknMLlfIjPxHTJmRMPK9VLGyesYAhV373CLZiId lzgEG/xScMJqFmCWbv/HJ7VoL/i+27lzp3Rm+Z4ZRDOpGqiAlLk3JObVGwWbsKkz5Epk VqXZLecHj+K3bHuiXAXKrv/hJ5LT6amQjOM9NTNIyYDoTpYyh/LRA9vRFhc+bJ8T31mv eE/w== X-Gm-Message-State: AC+VfDzVxzne6iDI4CdUmmBZbx7U70hw14/ie4+R61bh7zSUX3/HO3S/ hlFO60Q4GLnQgEf6vyqck9+ieQ== 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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