1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2019, Google LLC.
5 * Tests for the IA32_XSS MSR.
8 #define _GNU_SOURCE /* for program_invocation_short_name */
11 #include "test_util.h"
18 #define X86_FEATURE_XSAVES (1<<3)
20 bool is_supported_msr(u32 msr_index
)
22 struct kvm_msr_list
*list
;
26 list
= kvm_get_msr_index_list();
27 for (i
= 0; i
< list
->nmsrs
; ++i
) {
28 if (list
->indices
[i
] == msr_index
) {
38 int main(int argc
, char *argv
[])
40 struct kvm_cpuid_entry2
*entry
;
41 bool xss_supported
= false;
47 vm
= vm_create_default(VCPU_ID
, 0, 0);
49 if (kvm_get_cpuid_max_basic() >= 0xd) {
50 entry
= kvm_get_supported_cpuid_index(0xd, 1);
51 xss_supported
= entry
&& !!(entry
->eax
& X86_FEATURE_XSAVES
);
54 print_skip("IA32_XSS is not supported by the vCPU");
58 xss_val
= vcpu_get_msr(vm
, VCPU_ID
, MSR_IA32_XSS
);
59 TEST_ASSERT(xss_val
== 0,
60 "MSR_IA32_XSS should be initialized to zero\n");
62 vcpu_set_msr(vm
, VCPU_ID
, MSR_IA32_XSS
, xss_val
);
64 * At present, KVM only supports a guest IA32_XSS value of 0. Verify
65 * that trying to set the guest IA32_XSS to an unsupported value fails.
66 * Also, in the future when a non-zero value succeeds check that
67 * IA32_XSS is in the KVM_GET_MSR_INDEX_LIST.
69 for (i
= 0; i
< MSR_BITS
; ++i
) {
70 r
= _vcpu_set_msr(vm
, VCPU_ID
, MSR_IA32_XSS
, 1ull << i
);
71 TEST_ASSERT(r
== 0 || is_supported_msr(MSR_IA32_XSS
),
72 "IA32_XSS was able to be set, but was not found in KVM_GET_MSR_INDEX_LIST.\n");