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

KVM: selftests: Skip tests that require EPT when it is not available

Skip selftests that require EPT support in the VM when it is not
available. For example, if running on a machine where kvm_intel.ept=N
since KVM does not offer EPT support to guests if EPT is not supported
on the host.

This commit causes vmx_dirty_log_test to be skipped instead of failing
on hosts where kvm_intel.ept=N.

Signed-off-by: David Matlack <dmatlack@google.com>
Message-Id: <20220926171457.532542-1-dmatlack@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

authored by

David Matlack and committed by
Paolo Bonzini
0f816e02 69604fe7

+21
+1
tools/testing/selftests/kvm/include/x86_64/vmx.h
··· 617 617 uint32_t memslot); 618 618 void nested_identity_map_1g(struct vmx_pages *vmx, struct kvm_vm *vm, 619 619 uint64_t addr, uint64_t size); 620 + bool kvm_vm_has_ept(struct kvm_vm *vm); 620 621 void prepare_eptp(struct vmx_pages *vmx, struct kvm_vm *vm, 621 622 uint32_t eptp_memslot); 622 623 void prepare_virtualize_apic_accesses(struct vmx_pages *vmx, struct kvm_vm *vm);
+20
tools/testing/selftests/kvm/lib/x86_64/vmx.c
··· 5 5 * Copyright (C) 2018, Google LLC. 6 6 */ 7 7 8 + #include <asm/msr-index.h> 9 + 8 10 #include "test_util.h" 9 11 #include "kvm_util.h" 10 12 #include "processor.h" ··· 544 542 __nested_map(vmx, vm, addr, addr, size, PG_LEVEL_1G); 545 543 } 546 544 545 + bool kvm_vm_has_ept(struct kvm_vm *vm) 546 + { 547 + struct kvm_vcpu *vcpu; 548 + uint64_t ctrl; 549 + 550 + vcpu = list_first_entry(&vm->vcpus, struct kvm_vcpu, list); 551 + TEST_ASSERT(vcpu, "Cannot determine EPT support without vCPUs.\n"); 552 + 553 + ctrl = vcpu_get_msr(vcpu, MSR_IA32_VMX_TRUE_PROCBASED_CTLS) >> 32; 554 + if (!(ctrl & CPU_BASED_ACTIVATE_SECONDARY_CONTROLS)) 555 + return false; 556 + 557 + ctrl = vcpu_get_msr(vcpu, MSR_IA32_VMX_PROCBASED_CTLS2) >> 32; 558 + return ctrl & SECONDARY_EXEC_ENABLE_EPT; 559 + } 560 + 547 561 void prepare_eptp(struct vmx_pages *vmx, struct kvm_vm *vm, 548 562 uint32_t eptp_memslot) 549 563 { 564 + TEST_REQUIRE(kvm_vm_has_ept(vm)); 565 + 550 566 vmx->eptp = (void *)vm_vaddr_alloc_page(vm); 551 567 vmx->eptp_hva = addr_gva2hva(vm, (uintptr_t)vmx->eptp); 552 568 vmx->eptp_gpa = addr_gva2gpa(vm, (uintptr_t)vmx->eptp);