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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73A4EC001B3 for ; Tue, 27 Jun 2023 09:16:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231284AbjF0JQk (ORCPT ); Tue, 27 Jun 2023 05:16:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230247AbjF0JQi (ORCPT ); Tue, 27 Jun 2023 05:16:38 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D466810C for ; Tue, 27 Jun 2023 02:16:36 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-986d8332f50so541803466b.0 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=O87uD13QRAaJD59tUakYj3+1FwsnOAhuDcHCV7Pg3tdrSUigrFFkNmWF3rMzLShm/Y nQjRbRW7AdaYQzUPi+bhhjunK9KS7Cm4Rw0hUFX9o/LsyXH3dNTAR61VYfJgB5ynMcwV Q20cD5X23EjEwYsbqHulasZoE/DN6GaagQBdxWnC9kiR15s2LFWdLIJBtDW9ntO8uV3i 1JSU+PeFXNt/PJzljF62q8GKvM7yuD37N83b2WntLD8FvqQUT45ODBOEp4Hjn0PsijVH ueKvGMTjCqJihwHdtbVc9AMIBy4+qlDDWYayKVyNPnafR38hn0m4tUWq0FouBEykBigV d0/Q== X-Gm-Message-State: AC+VfDwYZi/TvJ3QIdrVleNk5SwNvAFexCdUM31PC+MyhrJ7z+/K7IJE 7JV2QLKkW3vED4z2a/mKis2nPw== 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-doc@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