Merge tag 'linux-kselftest-5.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-microblaze.git] / tools / testing / selftests / kvm / include / x86_64 / svm_util.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * tools/testing/selftests/kvm/include/x86_64/svm_utils.h
4  * Header for nested SVM testing
5  *
6  * Copyright (C) 2020, Red Hat, Inc.
7  */
8
9 #ifndef SELFTEST_KVM_SVM_UTILS_H
10 #define SELFTEST_KVM_SVM_UTILS_H
11
12 #include <stdint.h>
13 #include "svm.h"
14 #include "processor.h"
15
16 #define CPUID_SVM_BIT           2
17 #define CPUID_SVM               BIT_ULL(CPUID_SVM_BIT)
18
19 #define SVM_EXIT_VMMCALL        0x081
20
21 struct svm_test_data {
22         /* VMCB */
23         struct vmcb *vmcb; /* gva */
24         void *vmcb_hva;
25         uint64_t vmcb_gpa;
26
27         /* host state-save area */
28         struct vmcb_save_area *save_area; /* gva */
29         void *save_area_hva;
30         uint64_t save_area_gpa;
31 };
32
33 struct svm_test_data *vcpu_alloc_svm(struct kvm_vm *vm, vm_vaddr_t *p_svm_gva);
34 void generic_svm_setup(struct svm_test_data *svm, void *guest_rip, void *guest_rsp);
35 void run_guest(struct vmcb *vmcb, uint64_t vmcb_gpa);
36 void nested_svm_check_supported(void);
37
38 static inline bool cpu_has_svm(void)
39 {
40         u32 eax = 0x80000001, ecx;
41
42         asm("cpuid" :
43             "=a" (eax), "=c" (ecx) : "0" (eax) : "ebx", "edx");
44
45         return ecx & CPUID_SVM;
46 }
47
48 #endif /* SELFTEST_KVM_SVM_UTILS_H */