Skip to content

Commit 666a418

Browse files
bonzinigregkh
authored andcommitted
selftests: kvm: fix state save/load on processors without XSAVE
[ Upstream commit 54577e5 ] state_test and smm_test are failing on older processors that do not have xcr0. This is because on those processor KVM does provide support for KVM_GET/SET_XSAVE (to avoid having to rely on the older KVM_GET/SET_FPU) but not for KVM_GET/SET_XCRS. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent dd53d83 commit 666a418

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

‎tools/testing/selftests/kvm/lib/x86_64/processor.c‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,9 +1059,11 @@ struct kvm_x86_state *vcpu_save_state(struct kvm_vm *vm, uint32_t vcpuid)
10591059
TEST_ASSERT(r == 0, "Unexpected result from KVM_GET_XSAVE, r: %i",
10601060
r);
10611061

1062-
r = ioctl(vcpu->fd, KVM_GET_XCRS, &state->xcrs);
1063-
TEST_ASSERT(r == 0, "Unexpected result from KVM_GET_XCRS, r: %i",
1064-
r);
1062+
if (kvm_check_cap(KVM_CAP_XCRS)) {
1063+
r = ioctl(vcpu->fd, KVM_GET_XCRS, &state->xcrs);
1064+
TEST_ASSERT(r == 0, "Unexpected result from KVM_GET_XCRS, r: %i",
1065+
r);
1066+
}
10651067

10661068
r = ioctl(vcpu->fd, KVM_GET_SREGS, &state->sregs);
10671069
TEST_ASSERT(r == 0, "Unexpected result from KVM_GET_SREGS, r: %i",
@@ -1102,9 +1104,11 @@ void vcpu_load_state(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_x86_state *s
11021104
TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_XSAVE, r: %i",
11031105
r);
11041106

1105-
r = ioctl(vcpu->fd, KVM_SET_XCRS, &state->xcrs);
1106-
TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_XCRS, r: %i",
1107-
r);
1107+
if (kvm_check_cap(KVM_CAP_XCRS)) {
1108+
r = ioctl(vcpu->fd, KVM_SET_XCRS, &state->xcrs);
1109+
TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_XCRS, r: %i",
1110+
r);
1111+
}
11081112

11091113
r = ioctl(vcpu->fd, KVM_SET_SREGS, &state->sregs);
11101114
TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_SREGS, r: %i",

0 commit comments

Comments
 (0)