Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Copyright (C) 2019, Google LLC.
0004  *
0005  * Tests for the IA32_XSS MSR.
0006  */
0007 
0008 #define _GNU_SOURCE /* for program_invocation_short_name */
0009 #include <sys/ioctl.h>
0010 
0011 #include "test_util.h"
0012 #include "kvm_util.h"
0013 #include "vmx.h"
0014 
0015 #define MSR_BITS      64
0016 
0017 int main(int argc, char *argv[])
0018 {
0019     bool xss_in_msr_list;
0020     struct kvm_vm *vm;
0021     struct kvm_vcpu *vcpu;
0022     uint64_t xss_val;
0023     int i, r;
0024 
0025     /* Create VM */
0026     vm = vm_create_with_one_vcpu(&vcpu, NULL);
0027 
0028     TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_XSAVES));
0029 
0030     xss_val = vcpu_get_msr(vcpu, MSR_IA32_XSS);
0031     TEST_ASSERT(xss_val == 0,
0032             "MSR_IA32_XSS should be initialized to zero\n");
0033 
0034     vcpu_set_msr(vcpu, MSR_IA32_XSS, xss_val);
0035 
0036     /*
0037      * At present, KVM only supports a guest IA32_XSS value of 0. Verify
0038      * that trying to set the guest IA32_XSS to an unsupported value fails.
0039      * Also, in the future when a non-zero value succeeds check that
0040      * IA32_XSS is in the list of MSRs to save/restore.
0041      */
0042     xss_in_msr_list = kvm_msr_is_in_save_restore_list(MSR_IA32_XSS);
0043     for (i = 0; i < MSR_BITS; ++i) {
0044         r = _vcpu_set_msr(vcpu, MSR_IA32_XSS, 1ull << i);
0045 
0046         /*
0047          * Setting a list of MSRs returns the entry that "faulted", or
0048          * the last entry +1 if all MSRs were successfully written.
0049          */
0050         TEST_ASSERT(!r || r == 1, KVM_IOCTL_ERROR(KVM_SET_MSRS, r));
0051         TEST_ASSERT(r != 1 || xss_in_msr_list,
0052                 "IA32_XSS was able to be set, but was not in save/restore list");
0053     }
0054 
0055     kvm_vm_free(vm);
0056 }