Assert that clearing the "{load/clear IA32_BNDCFGS" bits is preserved across KVM_SET_CPUID2. Signed-off-by: Oliver Upton <oupton@xxxxxxxxxx> --- .../selftests/kvm/include/x86_64/vmx.h | 2 + .../kvm/x86_64/vmx_capability_msrs_test.c | 37 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/tools/testing/selftests/kvm/include/x86_64/vmx.h b/tools/testing/selftests/kvm/include/x86_64/vmx.h index 583ceb0d1457..811c66d9be74 100644 --- a/tools/testing/selftests/kvm/include/x86_64/vmx.h +++ b/tools/testing/selftests/kvm/include/x86_64/vmx.h @@ -80,6 +80,7 @@ #define VM_EXIT_SAVE_IA32_EFER 0x00100000 #define VM_EXIT_LOAD_IA32_EFER 0x00200000 #define VM_EXIT_SAVE_VMX_PREEMPTION_TIMER 0x00400000 +#define VM_EXIT_CLEAR_BNDCFGS 0x00800000 #define VM_EXIT_ALWAYSON_WITHOUT_TRUE_MSR 0x00036dff @@ -90,6 +91,7 @@ #define VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL 0x00002000 #define VM_ENTRY_LOAD_IA32_PAT 0x00004000 #define VM_ENTRY_LOAD_IA32_EFER 0x00008000 +#define VM_ENTRY_LOAD_BNDCFGS 0x00010000 #define VM_ENTRY_ALWAYSON_WITHOUT_TRUE_MSR 0x000011ff diff --git a/tools/testing/selftests/kvm/x86_64/vmx_capability_msrs_test.c b/tools/testing/selftests/kvm/x86_64/vmx_capability_msrs_test.c index 8a1a545e658b..a0851b1224aa 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_capability_msrs_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_capability_msrs_test.c @@ -67,6 +67,42 @@ static void load_perf_global_ctrl_test(struct kvm_vm *vm) "\"load IA32_PERF_GLOBAL_CTRL\" VM-Exit bit set"); } +/* + * Test to assert that clearing the "load IA32_BNDCFGS" and "clear IA32_BNDCFGS" + * control capability bits is preserved across a KVM_SET_CPUID2. + */ +static void bndcfgs_ctrl_test(struct kvm_vm *vm) +{ + uint32_t entry_low, entry_high, exit_low, exit_high; + struct kvm_cpuid2 *cpuid; + + get_vmx_capability_msr(vm, MSR_IA32_VMX_TRUE_ENTRY_CTLS, &entry_low, &entry_high); + get_vmx_capability_msr(vm, MSR_IA32_VMX_TRUE_EXIT_CTLS, &exit_low, &exit_high); + + if (!(entry_high & VM_ENTRY_LOAD_BNDCFGS) || !(exit_high & VM_EXIT_CLEAR_BNDCFGS)) { + print_skip("\"{load,clear} IA32_BNDCFGS\" controls not supported"); + return; + } + + entry_high &= ~VM_ENTRY_LOAD_BNDCFGS; + exit_high &= ~VM_EXIT_CLEAR_BNDCFGS; + + set_vmx_capability_msr(vm, MSR_IA32_VMX_TRUE_ENTRY_CTLS, entry_low, entry_high); + set_vmx_capability_msr(vm, MSR_IA32_VMX_TRUE_EXIT_CTLS, exit_low, exit_high); + + cpuid = kvm_get_supported_cpuid(); + vcpu_set_cpuid(vm, VCPU_ID, cpuid); + + get_vmx_capability_msr(vm, MSR_IA32_VMX_TRUE_ENTRY_CTLS, &entry_low, &entry_high); + get_vmx_capability_msr(vm, MSR_IA32_VMX_TRUE_EXIT_CTLS, &exit_low, &exit_high); + + TEST_ASSERT(!(entry_high & VM_ENTRY_LOAD_BNDCFGS), + "\"load IA32_BNDCFGS\" VM-Entry bit set"); + TEST_ASSERT(!(exit_high & VM_EXIT_CLEAR_BNDCFGS), + "\"clear IA32_BNDCFGS\" VM-Exit bit set"); +} + + int main(void) { struct kvm_vm *vm; @@ -77,6 +113,7 @@ int main(void) vm = vm_create_default(VCPU_ID, 0, NULL); load_perf_global_ctrl_test(vm); + bndcfgs_ctrl_test(vm); kvm_vm_free(vm); } -- 2.35.0.rc2.247.g8bbb082509-goog