KVM: selftests: Skip tests that require EPT when it is not available
PATCH v2 1/1 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.
Specifically, this commit causes vmx_dirty_log_test and dirty_log_perf_test -n to be skipped instead of failing on hosts where kvm_intel.ept=N.
---
v2:
- Use kvm_get_feature_msr() instead of vcpu_get_msr() [Sean]
- Force each test to call TEST_REQUIRE() [Sean]
v1: https://lore.kernel.org/kvm/[email protected]/
tools/testing/selftests/kvm/include/x86_64/vmx.h | 1 + .../selftests/kvm/lib/x86_64/perf_test_util.c | 1 + tools/testing/selftests/kvm/lib/x86_64/vmx.c | 14 ++++++++++++++ .../selftests/kvm/x86_64/vmx_dirty_log_test.c | 1 + 4 files changed, 17 insertions(+)
tools/testing/selftests/kvm/include/x86_64/vmx.h +1 -0
@@ -617,6 +617,7 @@ void nested_map_memslot(struct vmx_pages *vmx, struct kvm_vm *vm, uint32_t memslot);void nested_identity_map_1g (struct vmx_pages *vmx,struct kvm_vm *vm,uint64_t addr,uint64_t size); +bool kvm_cpu_has_ept (void );void prepare_eptp (struct vmx_pages *vmx,struct kvm_vm *vm,uint32_t eptp_memslot);void prepare_virtualize_apic_accesses (struct vmx_pages *vmx,struct kvm_vm *vm);
tools/testing/selftests/kvm/lib/x86_64/perf_test_util.c +1 -0
@@ -85,6 +85,7 @@ void perf_test_setup_nested(struct kvm_vm *vm, int nr_vcpus, struct kvm_vcpu *vcint vcpu_id;TEST_REQUIRE (kvm_cpu_has (X86_FEATURE_VMX )); +TEST_REQUIRE (kvm_cpu_has_ept ());for (vcpu_id =0 ; vcpu_id < nr_vcpus; vcpu_id++) { vmx =vcpu_alloc_vmx (vm, &vmx_gva);
tools/testing/selftests/kvm/lib/x86_64/vmx.c +14 -0
@@ -5,6 +5,8 @@* Copyright (C) 2018, Google LLC. */ +#include <asm/msr-index.h> +#include "test_util.h" #include "kvm_util.h" #include "processor.h"
@@ -542,6 +544,18 @@ void nested_identity_map_1g(struct vmx_pages *vmx, struct kvm_vm *vm,__nested_map (vmx, vm, addr, addr, size,PG_LEVEL_1G ); } +bool kvm_cpu_has_ept (void ) +{ +uint64_t ctrl; + + ctrl =kvm_get_feature_msr (MSR_IA32_VMX_TRUE_PROCBASED_CTLS ) >>32 ; +if (!(ctrl &CPU_BASED_ACTIVATE_SECONDARY_CONTROLS )) +return false; + + ctrl =kvm_get_feature_msr (MSR_IA32_VMX_PROCBASED_CTLS2 ) >>32 ; +return ctrl &SECONDARY_EXEC_ENABLE_EPT ; +} +void prepare_eptp (struct vmx_pages *vmx,struct kvm_vm *vm,uint32_t eptp_memslot) {
tools/testing/selftests/kvm/x86_64/vmx_dirty_log_test.c +1 -0
@@ -78,6 +78,7 @@ int main(int argc, char *argv[])bool done = false;TEST_REQUIRE (kvm_cpu_has (X86_FEATURE_VMX )); +TEST_REQUIRE (kvm_cpu_has_ept ());/* Create VM */ vm =vm_create_with_one_vcpu (&vcpu, l1_guest_code);
base-commit: 372d07084593dc7a399bf9bee815711b1fb1bcf2
prerequisite-patch-id: 2e3661ba8856c29b769499bac525b6943d9284b8
prerequisite-patch-id: 93031262de7b1f7fab1ad31ea5d6ef812c139179
Signature · 1 line
2.37.3.998.g577e59143f-goog
Quoted 11 lines · David Matlack
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.
Specifically, this commit causes
vmx_dirty_log_testanddirty_log_perf_test-n to be skipped instead of failing on hosts where kvm_intel.ept=N.Signed-off-by David Matlack <[email protected]>---
Need to sync with Paolo on who is grabbing what. In case it's Paolo...