Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Oliver Upton and committed by
Marc Zyngier
73263482 b320789d

+20 -14
+5 -14
tools/testing/selftests/kvm/arm64/set_id_regs.c
··· 15 15 #include "test_util.h" 16 16 #include <linux/bitfield.h> 17 17 18 - bool have_cap_arm_mte; 19 - 20 18 enum ftr_type { 21 19 FTR_EXACT, /* Use a predefined safe value */ 22 20 FTR_LOWER_SAFE, /* Smaller value is safe */ ··· 566 568 uint64_t mte_frac; 567 569 int idx, err; 568 570 569 - if (!have_cap_arm_mte) { 571 + val = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64PFR1_EL1)); 572 + mte = FIELD_GET(ID_AA64PFR1_EL1_MTE, val); 573 + if (!mte) { 570 574 ksft_test_result_skip("MTE capability not supported, nothing to test\n"); 571 575 return; 572 576 } ··· 593 593 * from unsupported (0xF) to supported (0). 594 594 * 595 595 */ 596 - val = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64PFR1_EL1)); 597 - 598 - mte = FIELD_GET(ID_AA64PFR1_EL1_MTE, val); 599 596 mte_frac = FIELD_GET(ID_AA64PFR1_EL1_MTE_frac, val); 600 597 if (mte != ID_AA64PFR1_EL1_MTE_MTE2 || 601 598 mte_frac != ID_AA64PFR1_EL1_MTE_frac_NI) { ··· 747 750 ksft_test_result_pass("%s\n", __func__); 748 751 } 749 752 750 - void kvm_arch_vm_post_create(struct kvm_vm *vm) 751 - { 752 - if (vm_check_cap(vm, KVM_CAP_ARM_MTE)) { 753 - vm_enable_cap(vm, KVM_CAP_ARM_MTE, 0); 754 - have_cap_arm_mte = true; 755 - } 756 - } 757 - 758 753 int main(void) 759 754 { 760 755 struct kvm_vcpu *vcpu; ··· 757 768 758 769 TEST_REQUIRE(kvm_has_cap(KVM_CAP_ARM_SUPPORTED_REG_MASK_RANGES)); 759 770 TEST_REQUIRE(kvm_has_cap(KVM_CAP_ARM_WRITABLE_IMP_ID_REGS)); 771 + 772 + test_wants_mte(); 760 773 761 774 vm = vm_create(1); 762 775 vm_enable_cap(vm, KVM_CAP_ARM_WRITABLE_IMP_ID_REGS, 0);
+2
tools/testing/selftests/kvm/include/arm64/processor.h
··· 300 300 /* Execute a Wait For Interrupt instruction. */ 301 301 void wfi(void); 302 302 303 + void test_wants_mte(void); 304 + 303 305 #endif /* SELFTEST_KVM_PROCESSOR_H */
+13
tools/testing/selftests/kvm/lib/arm64/processor.c
··· 653 653 { 654 654 asm volatile("wfi"); 655 655 } 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 + }