aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/kvm/include/x86_64
diff options
context:
space:
mode:
authorSean Christopherson <seanjc@google.com>2022-06-02 10:30:06 -0700
committerPaolo Bonzini <pbonzini@redhat.com>2022-06-11 11:46:29 -0400
commit6ebfef83f03f216b25b09a386bef16d05796cdaa (patch)
treeeea6b4f4110cf5a1b59cd494af08f7f519bb97fb /tools/testing/selftests/kvm/include/x86_64
parentKVM: selftests: Rename MP_STATE and GUEST_DEBUG helpers for consistency (diff)
downloadlinux-dev-6ebfef83f03f216b25b09a386bef16d05796cdaa.tar.xz
linux-dev-6ebfef83f03f216b25b09a386bef16d05796cdaa.zip
KVM: selftest: Add proper helpers for x86-specific save/restore ioctls
Add helpers for the various one-off helpers used by x86's vCPU state save/restore helpers, and convert the other open coded ioctl()s to use existing helpers. Signed-off-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'tools/testing/selftests/kvm/include/x86_64')
-rw-r--r--tools/testing/selftests/kvm/include/x86_64/processor.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h
index 9145da0bc61e..0bb9ba955d18 100644
--- a/tools/testing/selftests/kvm/include/x86_64/processor.h
+++ b/tools/testing/selftests/kvm/include/x86_64/processor.h
@@ -432,6 +432,60 @@ const struct kvm_msr_list *kvm_get_feature_msr_index_list(void);
bool kvm_msr_is_in_save_restore_list(uint32_t msr_index);
uint64_t kvm_get_feature_msr(uint64_t msr_index);
+static inline void vcpu_msrs_get(struct kvm_vm *vm, uint32_t vcpuid,
+ struct kvm_msrs *msrs)
+{
+ int r = __vcpu_ioctl(vm, vcpuid, KVM_GET_MSRS, msrs);
+
+ TEST_ASSERT(r == msrs->nmsrs,
+ "KVM_GET_MSRS failed, r: %i (failed on MSR %x)",
+ r, r < 0 || r >= msrs->nmsrs ? -1 : msrs->entries[r].index);
+}
+static inline void vcpu_msrs_set(struct kvm_vm *vm, uint32_t vcpuid,
+ struct kvm_msrs *msrs)
+{
+ int r = __vcpu_ioctl(vm, vcpuid, KVM_SET_MSRS, msrs);
+
+ TEST_ASSERT(r == msrs->nmsrs,
+ "KVM_GET_MSRS failed, r: %i (failed on MSR %x)",
+ r, r < 0 || r >= msrs->nmsrs ? -1 : msrs->entries[r].index);
+}
+static inline void vcpu_debugregs_get(struct kvm_vm *vm, uint32_t vcpuid,
+ struct kvm_debugregs *debugregs)
+{
+ vcpu_ioctl(vm, vcpuid, KVM_GET_DEBUGREGS, debugregs);
+}
+static inline void vcpu_debugregs_set(struct kvm_vm *vm, uint32_t vcpuid,
+ struct kvm_debugregs *debugregs)
+{
+ vcpu_ioctl(vm, vcpuid, KVM_SET_DEBUGREGS, debugregs);
+}
+static inline void vcpu_xsave_get(struct kvm_vm *vm, uint32_t vcpuid,
+ struct kvm_xsave *xsave)
+{
+ vcpu_ioctl(vm, vcpuid, KVM_GET_XSAVE, xsave);
+}
+static inline void vcpu_xsave2_get(struct kvm_vm *vm, uint32_t vcpuid,
+ struct kvm_xsave *xsave)
+{
+ vcpu_ioctl(vm, vcpuid, KVM_GET_XSAVE2, xsave);
+}
+static inline void vcpu_xsave_set(struct kvm_vm *vm, uint32_t vcpuid,
+ struct kvm_xsave *xsave)
+{
+ vcpu_ioctl(vm, vcpuid, KVM_SET_XSAVE, xsave);
+}
+static inline void vcpu_xcrs_get(struct kvm_vm *vm, uint32_t vcpuid,
+ struct kvm_xcrs *xcrs)
+{
+ vcpu_ioctl(vm, vcpuid, KVM_GET_XCRS, xcrs);
+}
+static inline void vcpu_xcrs_set(struct kvm_vm *vm, uint32_t vcpuid,
+ struct kvm_xcrs *xcrs)
+{
+ vcpu_ioctl(vm, vcpuid, KVM_SET_XCRS, xcrs);
+}
+
struct kvm_cpuid2 *kvm_get_supported_cpuid(void);
struct kvm_cpuid2 *vcpu_get_cpuid(struct kvm_vm *vm, uint32_t vcpuid);