public inbox for kvm@vger.kernel.org
 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 01/13] KVM: arm64: selftests: Provide kvm_arch_vm_post_create() in library code
Date: Thu, 18 Sep 2025 10:25:58 +0900	[thread overview]
Message-ID: <aMtfpocXPg7mONac@vm4> (raw)
In-Reply-To: <20250917212044.294760-2-oliver.upton@linux.dev>

On Wed, Sep 17, 2025 at 02:20:31PM -0700, Oliver Upton wrote:
> In order to compel the default usage of EL2 in selftests, move
> kvm_arch_vm_post_create() to library code and expose an opt-in for using
> MTE by default.
> 
> Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
> ---
>  .../testing/selftests/kvm/arm64/set_id_regs.c | 19 +++++--------------
>  .../selftests/kvm/include/arm64/processor.h   |  2 ++
>  .../selftests/kvm/lib/arm64/processor.c       | 13 +++++++++++++
>  3 files changed, 20 insertions(+), 14 deletions(-)
> 
> diff --git a/tools/testing/selftests/kvm/arm64/set_id_regs.c b/tools/testing/selftests/kvm/arm64/set_id_regs.c
> index 189321e96925..a2d367a2c93c 100644
> --- a/tools/testing/selftests/kvm/arm64/set_id_regs.c
> +++ b/tools/testing/selftests/kvm/arm64/set_id_regs.c
> @@ -15,8 +15,6 @@
>  #include "test_util.h"
>  #include <linux/bitfield.h>
>  
> -bool have_cap_arm_mte;
> -
>  enum ftr_type {
>  	FTR_EXACT,			/* Use a predefined safe value */
>  	FTR_LOWER_SAFE,			/* Smaller value is safe */
> @@ -568,7 +566,9 @@ static void test_user_set_mte_reg(struct kvm_vcpu *vcpu)
>  	uint64_t mte_frac;
>  	int idx, err;
>  
> -	if (!have_cap_arm_mte) {
> +	val = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64PFR1_EL1));
> +	mte = FIELD_GET(ID_AA64PFR1_EL1_MTE, val);
> +	if (!mte) {
>  		ksft_test_result_skip("MTE capability not supported, nothing to test\n");
>  		return;
>  	}
> @@ -593,9 +593,6 @@ static void test_user_set_mte_reg(struct kvm_vcpu *vcpu)
>  	 * from unsupported (0xF) to supported (0).
>  	 *
>  	 */
> -	val = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64PFR1_EL1));
> -
> -	mte = FIELD_GET(ID_AA64PFR1_EL1_MTE, val);
>  	mte_frac = FIELD_GET(ID_AA64PFR1_EL1_MTE_frac, val);
>  	if (mte != ID_AA64PFR1_EL1_MTE_MTE2 ||
>  	    mte_frac != ID_AA64PFR1_EL1_MTE_frac_NI) {
> @@ -750,14 +747,6 @@ static void test_reset_preserves_id_regs(struct kvm_vcpu *vcpu)
>  	ksft_test_result_pass("%s\n", __func__);
>  }
>  
> -void kvm_arch_vm_post_create(struct kvm_vm *vm)
> -{
> -	if (vm_check_cap(vm, KVM_CAP_ARM_MTE)) {
> -		vm_enable_cap(vm, KVM_CAP_ARM_MTE, 0);
> -		have_cap_arm_mte = true;
> -	}
> -}
> -
>  int main(void)
>  {
>  	struct kvm_vcpu *vcpu;
> @@ -769,6 +758,8 @@ int main(void)
>  	TEST_REQUIRE(kvm_has_cap(KVM_CAP_ARM_SUPPORTED_REG_MASK_RANGES));
>  	TEST_REQUIRE(kvm_has_cap(KVM_CAP_ARM_WRITABLE_IMP_ID_REGS));
>  
> +	test_wants_mte();
> +
>  	vm = vm_create(1);
>  	vm_enable_cap(vm, KVM_CAP_ARM_WRITABLE_IMP_ID_REGS, 0);
>  	vcpu = vm_vcpu_add(vm, 0, guest_code);
> diff --git a/tools/testing/selftests/kvm/include/arm64/processor.h b/tools/testing/selftests/kvm/include/arm64/processor.h
> index 255fed769a8a..8370fc94041d 100644
> --- a/tools/testing/selftests/kvm/include/arm64/processor.h
> +++ b/tools/testing/selftests/kvm/include/arm64/processor.h
> @@ -300,4 +300,6 @@ void smccc_smc(uint32_t function_id, uint64_t arg0, uint64_t arg1,
>  /* Execute a Wait For Interrupt instruction. */
>  void wfi(void);
>  
> +void test_wants_mte(void);
> +
>  #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 eb115123d741..caed1998c7b3 100644
> --- a/tools/testing/selftests/kvm/lib/arm64/processor.c
> +++ b/tools/testing/selftests/kvm/lib/arm64/processor.c
> @@ -653,3 +653,16 @@ void wfi(void)
>  {
>  	asm volatile("wfi");
>  }
> +
> +static bool request_mte;
> +
> +void test_wants_mte(void)
> +{
> +	request_mte = true;
> +}
> +
> +void kvm_arch_vm_post_create(struct kvm_vm *vm)
> +{
> +	if (request_mte && vm_check_cap(vm, KVM_CAP_ARM_MTE))
> +		vm_enable_cap(vm, KVM_CAP_ARM_MTE, 0);
> +}
> -- 
> 2.47.3
>

Hi,
On FVP RevC with the kernel your series applied, I see set_id_regs fails
to execute.

# ./arm64/set_id_regs
Random seed: 0x6b8b4567
TAP version 13
1..102
ok 1 ID_AA64DFR0_EL1_DoubleLock
ok 2 ID_AA64DFR0_EL1_WRPs
ok 3 ID_AA64DFR0_EL1_PMUVer
ok 4 ID_AA64DFR0_EL1_DebugVer
ok 5 # SKIP ID_DFR0_EL1_PerfMon on AARCH64 only system
ok 6 # SKIP ID_DFR0_EL1_CopDbg on AARCH64 only system
ok 7 ID_AA64ISAR0_EL1_RNDR
ok 8 ID_AA64ISAR0_EL1_TLB
ok 9 ID_AA64ISAR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_AA64MMFR0_EL1_ECV
ok 51 ID_AA64MMFR0_EL1_EXS
==== Test Assertion Failure ====
  include/kvm_util.h:815: !ret
    pid=897 tid=897 errno=22 - Invalid argument
    sh: line 1: addr2line: command not found
      KVM_SET_ONE_REG failed, rc: -1 errno: 22 (Invalid argument)


  reply	other threads:[~2025-09-18  1:26 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 [this message]
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
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=aMtfpocXPg7mONac@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