linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Itaru Kitayama <itaru.kitayama@linux.dev>
To: Oliver Upton <oliver.upton@linux.dev>
Cc: kvmarm@lists.linux.dev, Marc Zyngier <maz@kernel.org>,
	Joey Gouly <joey.gouly@arm.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Zenghui Yu <yuzenghui@huawei.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Sean Christopherson <seanjc@google.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Janosch Frank <frankja@linux.ibm.com>,
	Claudio Imbrenda <imbrenda@linux.ibm.com>,
	David Hildenbrand <david@redhat.com>,
	linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org
Subject: Re: [PATCH 07/13] KVM: arm64: selftests: Provide helper for getting default vCPU target
Date: Thu, 18 Sep 2025 06:56:27 +0900	[thread overview]
Message-ID: <aMsui6JZ0q1z4pSc@vm4> (raw)
In-Reply-To: <20250917212044.294760-8-oliver.upton@linux.dev>

On Wed, Sep 17, 2025 at 02:20:37PM -0700, Oliver Upton wrote:
> The default vCPU target in KVM selftests is pretty boring in that it
> doesn't enable any vCPU features. Expose a helper for getting the
> default target to prepare for cramming in more features. Call
> KVM_ARM_PREFERRED_TARGET directly from get-reg-list as it needs
> fine-grained control over feature flags.
> 
> Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
> ---
>  tools/testing/selftests/kvm/arm64/psci_test.c   |  2 +-
>  .../testing/selftests/kvm/arm64/smccc_filter.c  |  2 +-
>  .../selftests/kvm/arm64/vpmu_counter_access.c   |  4 ++--
>  tools/testing/selftests/kvm/get-reg-list.c      |  9 ++++++---
>  .../selftests/kvm/include/arm64/processor.h     |  2 ++
>  .../testing/selftests/kvm/lib/arm64/processor.c | 17 +++++++++++------
>  6 files changed, 23 insertions(+), 13 deletions(-)
> 
> diff --git a/tools/testing/selftests/kvm/arm64/psci_test.c b/tools/testing/selftests/kvm/arm64/psci_test.c
> index cf208390fd0e..0d4680da66d1 100644
> --- a/tools/testing/selftests/kvm/arm64/psci_test.c
> +++ b/tools/testing/selftests/kvm/arm64/psci_test.c
> @@ -89,7 +89,7 @@ static struct kvm_vm *setup_vm(void *guest_code, struct kvm_vcpu **source,
>  
>  	vm = vm_create(2);
>  
> -	vm_ioctl(vm, KVM_ARM_PREFERRED_TARGET, &init);
> +	kvm_get_default_vcpu_target(vm, &init);
>  	init.features[0] |= (1 << KVM_ARM_VCPU_PSCI_0_2);
>  
>  	*source = aarch64_vcpu_add(vm, 0, &init, guest_code);

I wonder if the ioctl() can be called unconditionally in the 
aarch64_vcpu_add() function. If the intention is that the kvm selftest
code needs to write this way I am fine with that.

Reviewed-by: Itaru Kitayama <itaru.kitayama@fujitsu.com>

> diff --git a/tools/testing/selftests/kvm/arm64/smccc_filter.c b/tools/testing/selftests/kvm/arm64/smccc_filter.c
> index eb5551d21dbe..a8e22d866ea7 100644
> --- a/tools/testing/selftests/kvm/arm64/smccc_filter.c
> +++ b/tools/testing/selftests/kvm/arm64/smccc_filter.c
> @@ -64,7 +64,7 @@ static struct kvm_vm *setup_vm(struct kvm_vcpu **vcpu)
>  	struct kvm_vm *vm;
>  
>  	vm = vm_create(1);
> -	vm_ioctl(vm, KVM_ARM_PREFERRED_TARGET, &init);
> +	kvm_get_default_vcpu_target(vm, &init);
>  
>  	/*
>  	 * Enable in-kernel emulation of PSCI to ensure that calls are denied
> diff --git a/tools/testing/selftests/kvm/arm64/vpmu_counter_access.c b/tools/testing/selftests/kvm/arm64/vpmu_counter_access.c
> index 36a3a8b4e0b5..2a8f31c8e59f 100644
> --- a/tools/testing/selftests/kvm/arm64/vpmu_counter_access.c
> +++ b/tools/testing/selftests/kvm/arm64/vpmu_counter_access.c
> @@ -430,7 +430,7 @@ static void create_vpmu_vm(void *guest_code)
>  	}
>  
>  	/* Create vCPU with PMUv3 */
> -	vm_ioctl(vpmu_vm.vm, KVM_ARM_PREFERRED_TARGET, &init);
> +	kvm_get_default_vcpu_target(vpmu_vm.vm, &init);
>  	init.features[0] |= (1 << KVM_ARM_VCPU_PMU_V3);
>  	vpmu_vm.vcpu = aarch64_vcpu_add(vpmu_vm.vm, 0, &init, guest_code);
>  	vcpu_init_descriptor_tables(vpmu_vm.vcpu);
> @@ -525,7 +525,7 @@ static void run_access_test(uint64_t pmcr_n)
>  	 * Reset and re-initialize the vCPU, and run the guest code again to
>  	 * check if PMCR_EL0.N is preserved.
>  	 */
> -	vm_ioctl(vpmu_vm.vm, KVM_ARM_PREFERRED_TARGET, &init);
> +	kvm_get_default_vcpu_target(vpmu_vm.vm, &init);
>  	init.features[0] |= (1 << KVM_ARM_VCPU_PMU_V3);
>  	aarch64_vcpu_setup(vcpu, &init);
>  	vcpu_init_descriptor_tables(vcpu);
> diff --git a/tools/testing/selftests/kvm/get-reg-list.c b/tools/testing/selftests/kvm/get-reg-list.c
> index 91f05f78e824..f4644c9d2d3b 100644
> --- a/tools/testing/selftests/kvm/get-reg-list.c
> +++ b/tools/testing/selftests/kvm/get-reg-list.c
> @@ -116,10 +116,13 @@ void __weak finalize_vcpu(struct kvm_vcpu *vcpu, struct vcpu_reg_list *c)
>  }
>  
>  #ifdef __aarch64__
> -static void prepare_vcpu_init(struct vcpu_reg_list *c, struct kvm_vcpu_init *init)
> +static void prepare_vcpu_init(struct kvm_vm *vm, struct vcpu_reg_list *c,
> +			      struct kvm_vcpu_init *init)
>  {
>  	struct vcpu_reg_sublist *s;
>  
> +	vm_ioctl(vm, KVM_ARM_PREFERRED_TARGET, init);
> +
>  	for_each_sublist(c, s)
>  		if (s->capability)
>  			init->features[s->feature / 32] |= 1 << (s->feature % 32);
> @@ -127,10 +130,10 @@ static void prepare_vcpu_init(struct vcpu_reg_list *c, struct kvm_vcpu_init *ini
>  
>  static struct kvm_vcpu *vcpu_config_get_vcpu(struct vcpu_reg_list *c, struct kvm_vm *vm)
>  {
> -	struct kvm_vcpu_init init = { .target = -1, };
> +	struct kvm_vcpu_init init;
>  	struct kvm_vcpu *vcpu;
>  
> -	prepare_vcpu_init(c, &init);
> +	prepare_vcpu_init(vm, c, &init);
>  	vcpu = __vm_vcpu_add(vm, 0);
>  	aarch64_vcpu_setup(vcpu, &init);
>  
> diff --git a/tools/testing/selftests/kvm/include/arm64/processor.h b/tools/testing/selftests/kvm/include/arm64/processor.h
> index 5a4b29c1b965..87f50efed720 100644
> --- a/tools/testing/selftests/kvm/include/arm64/processor.h
> +++ b/tools/testing/selftests/kvm/include/arm64/processor.h
> @@ -357,4 +357,6 @@ static __always_inline u64 ctxt_reg_alias(struct kvm_vcpu *vcpu, u32 encoding)
>  	return KVM_ARM64_SYS_REG(alias);
>  }
>  
> +void kvm_get_default_vcpu_target(struct kvm_vm *vm, struct kvm_vcpu_init *init);
> +
>  #endif /* SELFTEST_KVM_PROCESSOR_H */
> diff --git a/tools/testing/selftests/kvm/lib/arm64/processor.c b/tools/testing/selftests/kvm/lib/arm64/processor.c
> index 311660a9f655..5ae65fefd48c 100644
> --- a/tools/testing/selftests/kvm/lib/arm64/processor.c
> +++ b/tools/testing/selftests/kvm/lib/arm64/processor.c
> @@ -267,19 +267,24 @@ void virt_arch_dump(FILE *stream, struct kvm_vm *vm, uint8_t indent)
>  	}
>  }
>  
> +void kvm_get_default_vcpu_target(struct kvm_vm *vm, struct kvm_vcpu_init *init)
> +{
> +	struct kvm_vcpu_init preferred = {};
> +
> +	vm_ioctl(vm, KVM_ARM_PREFERRED_TARGET, &preferred);
> +
> +	*init = preferred;
> +}
> +
>  void aarch64_vcpu_setup(struct kvm_vcpu *vcpu, struct kvm_vcpu_init *init)
>  {
>  	struct kvm_vcpu_init default_init = { .target = -1, };
>  	struct kvm_vm *vm = vcpu->vm;
>  	uint64_t sctlr_el1, tcr_el1, ttbr0_el1;
>  
> -	if (!init)
> +	if (!init) {
> +		kvm_get_default_vcpu_target(vm, &default_init);
>  		init = &default_init;
> -
> -	if (init->target == -1) {
> -		struct kvm_vcpu_init preferred;
> -		vm_ioctl(vm, KVM_ARM_PREFERRED_TARGET, &preferred);
> -		init->target = preferred.target;
>  	}
>  
>  	vcpu_ioctl(vcpu, KVM_ARM_VCPU_INIT, init);
> -- 
> 2.47.3
> 


  reply	other threads:[~2025-09-17 21:59 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-17 21:20 [PATCH 00/13] KVM: arm64: selftests: Run selftests in VHE EL2 Oliver Upton
2025-09-17 21:20 ` [PATCH 01/13] KVM: arm64: selftests: Provide kvm_arch_vm_post_create() in library code Oliver Upton
2025-09-18  1:25   ` Itaru Kitayama
2025-09-17 21:20 ` [PATCH 02/13] KVM: arm64: selftests: Initialize VGICv3 only once Oliver Upton
2025-09-18 10:44   ` Zenghui Yu
2025-09-17 21:20 ` [PATCH 03/13] KVM: arm64: selftests: Add helper to check for VGICv3 support Oliver Upton
2025-09-18  1:45   ` Itaru Kitayama
2025-09-17 21:20 ` [PATCH 04/13] KVM: arm64: selftests: Add unsanitised helpers for VGICv3 creation Oliver Upton
2025-09-17 21:20 ` [PATCH 05/13] KVM: arm64: selftests: Create a VGICv3 for 'default' VMs Oliver Upton
2025-09-17 21:20 ` [PATCH 06/13] KVM: arm64: selftests: Alias EL1 registers to EL2 counterparts Oliver Upton
2025-09-17 21:20 ` [PATCH 07/13] KVM: arm64: selftests: Provide helper for getting default vCPU target Oliver Upton
2025-09-17 21:56   ` Itaru Kitayama [this message]
2025-09-17 22:00     ` Oliver Upton
2025-09-17 21:20 ` [PATCH 08/13] KVM: arm64: selftests: Select SMCCC conduit based on current EL Oliver Upton
2025-09-17 21:20 ` [PATCH 09/13] KVM: arm64: selftests: Use hyp timer IRQs when test runs at EL2 Oliver Upton
2025-09-17 21:20 ` [PATCH 10/13] KVM: arm64: selftests: Use the vCPU attr for setting nr of PMU counters Oliver Upton
2025-09-17 21:20 ` [PATCH 11/13] KVM: arm64: selftests: Initialize HCR_EL2 Oliver Upton
2025-09-17 21:20 ` [PATCH 12/13] KVM: arm64: selftests: Enable EL2 by default Oliver Upton
2025-09-17 21:20 ` [PATCH 13/13] KVM: arm64: selftests: Add basic test for running in VHE EL2 Oliver Upton
2025-09-24 18:37 ` [PATCH 00/13] KVM: arm64: selftests: Run selftests " Marc Zyngier

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=aMsui6JZ0q1z4pSc@vm4 \
    --to=itaru.kitayama@linux.dev \
    --cc=borntraeger@linux.ibm.com \
    --cc=david@redhat.com \
    --cc=frankja@linux.ibm.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=joey.gouly@arm.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=maz@kernel.org \
    --cc=oliver.upton@linux.dev \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=suzuki.poulose@arm.com \
    --cc=yuzenghui@huawei.com \
    /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).