57 lines
1.4 KiB
C
Raw Normal View History

2022-04-02 18:24:21 +05:00
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2019, Google LLC.
*
* Tests for the IA32_XSS MSR.
*/
#define _GNU_SOURCE /* for program_invocation_short_name */
#include <sys/ioctl.h>
#include "test_util.h"
#include "kvm_util.h"
#include "vmx.h"
#define MSR_BITS 64
int main(int argc, char *argv[])
{
2022-09-09 14:21:57 +05:00
bool xss_in_msr_list;
2022-04-02 18:24:21 +05:00
struct kvm_vm *vm;
2022-09-09 14:21:57 +05:00
struct kvm_vcpu *vcpu;
2022-04-02 18:24:21 +05:00
uint64_t xss_val;
int i, r;
/* Create VM */
2022-09-09 14:21:57 +05:00
vm = vm_create_with_one_vcpu(&vcpu, NULL);
2022-04-02 18:24:21 +05:00
2022-09-09 14:21:57 +05:00
TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_XSAVES));
2022-04-02 18:24:21 +05:00
2022-09-09 14:21:57 +05:00
xss_val = vcpu_get_msr(vcpu, MSR_IA32_XSS);
2022-04-02 18:24:21 +05:00
TEST_ASSERT(xss_val == 0,
"MSR_IA32_XSS should be initialized to zero\n");
2022-09-09 14:21:57 +05:00
vcpu_set_msr(vcpu, MSR_IA32_XSS, xss_val);
2022-04-02 18:24:21 +05:00
/*
* 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.
* Also, in the future when a non-zero value succeeds check that
2022-09-09 14:21:57 +05:00
* IA32_XSS is in the list of MSRs to save/restore.
2022-04-02 18:24:21 +05:00
*/
2022-09-09 14:21:57 +05:00
xss_in_msr_list = kvm_msr_is_in_save_restore_list(MSR_IA32_XSS);
2022-04-02 18:24:21 +05:00
for (i = 0; i < MSR_BITS; ++i) {
2022-09-09 14:21:57 +05:00
r = _vcpu_set_msr(vcpu, MSR_IA32_XSS, 1ull << i);
/*
* Setting a list of MSRs returns the entry that "faulted", or
* the last entry +1 if all MSRs were successfully written.
*/
TEST_ASSERT(!r || r == 1, KVM_IOCTL_ERROR(KVM_SET_MSRS, r));
TEST_ASSERT(r != 1 || xss_in_msr_list,
"IA32_XSS was able to be set, but was not in save/restore list");
2022-04-02 18:24:21 +05:00
}
kvm_vm_free(vm);
}