kvm-riscv.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Jones <ajones@ventanamicro.com>
To: kvm-riscv@lists.infradead.org
Subject: [PATCH v4 11/12] KVM: riscv: selftests: Add finalize_vcpu check in run_test
Date: Tue, 27 Jun 2023 11:16:33 +0200	[thread overview]
Message-ID: <20230627-feb5bf584a3fd16d2c0ffe66@orel> (raw)
In-Reply-To: <fa6b80b578553e561ccacaeb24091e0716975593.1687515463.git.haibo1.xu@intel.com>

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 <ajones@ventanamicro.com>
> Signed-off-by: Haibo Xu <haibo1.xu@intel.com>
> ---
>  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 <ajones@ventanamicro.com>

Thanks,
drew


  reply	other threads:[~2023-06-27  9:16 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-23 10:40 [PATCH v4 00/12] RISCV: Add KVM_GET_REG_LIST API Haibo Xu
2023-06-23 10:40 ` [PATCH v4 01/12] KVM: arm64: selftests: Replace str_with_index with strdup_printf Haibo Xu
2023-06-23 10:40 ` [PATCH v4 02/12] KVM: arm64: selftests: Drop SVE cap check in print_reg Haibo Xu
2023-06-23 10:40 ` [PATCH v4 03/12] KVM: arm64: selftests: Remove print_reg's dependency on vcpu_config Haibo Xu
2023-06-23 10:40 ` [PATCH v4 04/12] KVM: arm64: selftests: Rename vcpu_config and add to kvm_util.h Haibo Xu
2023-06-23 10:40 ` [PATCH v4 05/12] KVM: arm64: selftests: Delete core_reg_fixup Haibo Xu
2023-06-23 10:40 ` [PATCH v4 06/12] KVM: arm64: selftests: Split get-reg-list test code Haibo Xu
2023-06-23 10:40 ` [PATCH v4 07/12] KVM: arm64: selftests: Finish generalizing get-reg-list Haibo Xu
2023-06-23 10:40 ` [PATCH v4 08/12] KVM: arm64: selftests: Move reject_set check logic to a function Haibo Xu
2023-06-27  9:09   ` Andrew Jones
2023-06-28  5:58     ` Haibo Xu
2023-06-23 10:40 ` [PATCH v4 09/12] KVM: selftests: Only do get/set tests on present blessed list Haibo Xu
2023-06-27  9:11   ` Andrew Jones
2023-06-28  6:00     ` Haibo Xu
2023-06-23 10:40 ` [PATCH v4 10/12] KVM: riscv: Add KVM_GET_REG_LIST API support Haibo Xu
2023-06-23 10:40 ` [PATCH v4 11/12] KVM: riscv: selftests: Add finalize_vcpu check in run_test Haibo Xu
2023-06-27  9:16   ` Andrew Jones [this message]
2023-06-28 10:29     ` Haibo Xu
2023-06-23 10:40 ` [PATCH v4 12/12] KVM: riscv: selftests: Add get-reg-list test Haibo Xu
2023-06-27  9:25   ` Andrew Jones
2023-06-28 10:28     ` Haibo Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230627-feb5bf584a3fd16d2c0ffe66@orel \
    --to=ajones@ventanamicro.com \
    --cc=kvm-riscv@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).