Commit 58606e60 authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

KVM: selftests: Convert xss_msr_test away from VCPU_ID

Convert xss_msr_test to use vm_create_with_one_vcpu() and pass around a
'struct kvm_vcpu' object instead of using a global VCPU_ID.  Note, this
is a "functional" change in the sense that the test now creates a vCPU
with vcpu_id==0 instead of vcpu_id==1.  The non-zero VCPU_ID was 100%
arbitrary and added little to no validation coverage.  If testing
non-zero vCPU IDs is desirable for generic tests, that can be done in the
future by tweaking the VM creation helpers.
Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 2494a6d8
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "kvm_util.h" #include "kvm_util.h"
#include "vmx.h" #include "vmx.h"
#define VCPU_ID 1
#define MSR_BITS 64 #define MSR_BITS 64
#define X86_FEATURE_XSAVES (1<<3) #define X86_FEATURE_XSAVES (1<<3)
...@@ -23,11 +22,12 @@ int main(int argc, char *argv[]) ...@@ -23,11 +22,12 @@ int main(int argc, char *argv[])
bool xss_supported = false; bool xss_supported = false;
bool xss_in_msr_list; bool xss_in_msr_list;
struct kvm_vm *vm; struct kvm_vm *vm;
struct kvm_vcpu *vcpu;
uint64_t xss_val; uint64_t xss_val;
int i, r; int i, r;
/* Create VM */ /* Create VM */
vm = vm_create_default(VCPU_ID, 0, 0); vm = vm_create_with_one_vcpu(&vcpu, NULL);
if (kvm_get_cpuid_max_basic() >= 0xd) { if (kvm_get_cpuid_max_basic() >= 0xd) {
entry = kvm_get_supported_cpuid_index(0xd, 1); entry = kvm_get_supported_cpuid_index(0xd, 1);
...@@ -38,11 +38,12 @@ int main(int argc, char *argv[]) ...@@ -38,11 +38,12 @@ int main(int argc, char *argv[])
exit(KSFT_SKIP); exit(KSFT_SKIP);
} }
xss_val = vcpu_get_msr(vm, VCPU_ID, MSR_IA32_XSS); xss_val = vcpu_get_msr(vm, vcpu->id, MSR_IA32_XSS);
TEST_ASSERT(xss_val == 0, TEST_ASSERT(xss_val == 0,
"MSR_IA32_XSS should be initialized to zero\n"); "MSR_IA32_XSS should be initialized to zero\n");
vcpu_set_msr(vm, VCPU_ID, MSR_IA32_XSS, xss_val); vcpu_set_msr(vm, vcpu->id, MSR_IA32_XSS, xss_val);
/* /*
* At present, KVM only supports a guest IA32_XSS value of 0. Verify * At present, KVM only supports a guest IA32_XSS value of 0. Verify
* that trying to set the guest IA32_XSS to an unsupported value fails. * that trying to set the guest IA32_XSS to an unsupported value fails.
...@@ -51,7 +52,7 @@ int main(int argc, char *argv[]) ...@@ -51,7 +52,7 @@ int main(int argc, char *argv[])
*/ */
xss_in_msr_list = kvm_msr_is_in_save_restore_list(MSR_IA32_XSS); xss_in_msr_list = kvm_msr_is_in_save_restore_list(MSR_IA32_XSS);
for (i = 0; i < MSR_BITS; ++i) { for (i = 0; i < MSR_BITS; ++i) {
r = _vcpu_set_msr(vm, VCPU_ID, MSR_IA32_XSS, 1ull << i); r = _vcpu_set_msr(vm, vcpu->id, MSR_IA32_XSS, 1ull << i);
/* /*
* Setting a list of MSRs returns the entry that "faulted", or * Setting a list of MSRs returns the entry that "faulted", or
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment