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 bool nested_svm_supported(void); 37 void nested_svm_check_supported(void); 38 39 static inline bool cpu_has_svm(void) 40 { 41 u32 eax = 0x80000001, ecx; 42 43 asm("cpuid" : 44 "=a" (eax), "=c" (ecx) : "0" (eax) : "ebx", "edx"); 45 46 return ecx & CPUID_SVM; 47 } 48 49 int open_sev_dev_path_or_exit(void); 50 51 #endif /* SELFTEST_KVM_SVM_UTILS_H */ 52