Skip to content

Commit 7326348

Browse files
ouptonMarc Zyngier
authored andcommitted
KVM: arm64: selftests: Provide kvm_arch_vm_post_create() in library code
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> Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent b320789 commit 7326348

3 files changed

Lines changed: 20 additions & 14 deletions

File tree

tools/testing/selftests/kvm/arm64/set_id_regs.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#include "test_util.h"
1616
#include <linux/bitfield.h>
1717

18-
bool have_cap_arm_mte;
19-
2018
enum ftr_type {
2119
FTR_EXACT, /* Use a predefined safe value */
2220
FTR_LOWER_SAFE, /* Smaller value is safe */
@@ -568,7 +566,9 @@ static void test_user_set_mte_reg(struct kvm_vcpu *vcpu)
568566
uint64_t mte_frac;
569567
int idx, err;
570568

571-
if (!have_cap_arm_mte) {
569+
val = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64PFR1_EL1));
570+
mte = FIELD_GET(ID_AA64PFR1_EL1_MTE, val);
571+
if (!mte) {
572572
ksft_test_result_skip("MTE capability not supported, nothing to test\n");
573573
return;
574574
}
@@ -593,9 +593,6 @@ static void test_user_set_mte_reg(struct kvm_vcpu *vcpu)
593593
* from unsupported (0xF) to supported (0).
594594
*
595595
*/
596-
val = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64PFR1_EL1));
597-
598-
mte = FIELD_GET(ID_AA64PFR1_EL1_MTE, val);
599596
mte_frac = FIELD_GET(ID_AA64PFR1_EL1_MTE_frac, val);
600597
if (mte != ID_AA64PFR1_EL1_MTE_MTE2 ||
601598
mte_frac != ID_AA64PFR1_EL1_MTE_frac_NI) {
@@ -750,14 +747,6 @@ static void test_reset_preserves_id_regs(struct kvm_vcpu *vcpu)
750747
ksft_test_result_pass("%s\n", __func__);
751748
}
752749

753-
void kvm_arch_vm_post_create(struct kvm_vm *vm)
754-
{
755-
if (vm_check_cap(vm, KVM_CAP_ARM_MTE)) {
756-
vm_enable_cap(vm, KVM_CAP_ARM_MTE, 0);
757-
have_cap_arm_mte = true;
758-
}
759-
}
760-
761750
int main(void)
762751
{
763752
struct kvm_vcpu *vcpu;
@@ -769,6 +758,8 @@ int main(void)
769758
TEST_REQUIRE(kvm_has_cap(KVM_CAP_ARM_SUPPORTED_REG_MASK_RANGES));
770759
TEST_REQUIRE(kvm_has_cap(KVM_CAP_ARM_WRITABLE_IMP_ID_REGS));
771760

761+
test_wants_mte();
762+
772763
vm = vm_create(1);
773764
vm_enable_cap(vm, KVM_CAP_ARM_WRITABLE_IMP_ID_REGS, 0);
774765
vcpu = vm_vcpu_add(vm, 0, guest_code);

tools/testing/selftests/kvm/include/arm64/processor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,4 +300,6 @@ void smccc_smc(uint32_t function_id, uint64_t arg0, uint64_t arg1,
300300
/* Execute a Wait For Interrupt instruction. */
301301
void wfi(void);
302302

303+
void test_wants_mte(void);
304+
303305
#endif /* SELFTEST_KVM_PROCESSOR_H */

tools/testing/selftests/kvm/lib/arm64/processor.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,3 +653,16 @@ void wfi(void)
653653
{
654654
asm volatile("wfi");
655655
}
656+
657+
static bool request_mte;
658+
659+
void test_wants_mte(void)
660+
{
661+
request_mte = true;
662+
}
663+
664+
void kvm_arch_vm_post_create(struct kvm_vm *vm)
665+
{
666+
if (request_mte && vm_check_cap(vm, KVM_CAP_ARM_MTE))
667+
vm_enable_cap(vm, KVM_CAP_ARM_MTE, 0);
668+
}

0 commit comments

Comments
 (0)