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 <asm/svm.h>
13 
14 #include <stdint.h>
15 #include "svm.h"
16 #include "processor.h"
17 
18 struct svm_test_data {
19 	/* VMCB */
20 	struct vmcb *vmcb; /* gva */
21 	void *vmcb_hva;
22 	uint64_t vmcb_gpa;
23 
24 	/* host state-save area */
25 	struct vmcb_save_area *save_area; /* gva */
26 	void *save_area_hva;
27 	uint64_t save_area_gpa;
28 
29 	/* MSR-Bitmap */
30 	void *msr; /* gva */
31 	void *msr_hva;
32 	uint64_t msr_gpa;
33 };
34 
35 #define stgi()			\
36 	__asm__ __volatile__(	\
37 		"stgi\n"	\
38 		)
39 
40 #define clgi()			\
41 	__asm__ __volatile__(	\
42 		"clgi\n"	\
43 		)
44 
45 struct svm_test_data *vcpu_alloc_svm(struct kvm_vm *vm, vm_vaddr_t *p_svm_gva);
46 void generic_svm_setup(struct svm_test_data *svm, void *guest_rip, void *guest_rsp);
47 void run_guest(struct vmcb *vmcb, uint64_t vmcb_gpa);
48 
49 int open_sev_dev_path_or_exit(void);
50 
51 #endif /* SELFTEST_KVM_SVM_UTILS_H */
52