From 410f0020fe7330af4fc46dbc728eec0bd94c1c82 Mon Sep 17 00:00:00 2001 From: Maxim Levitsky Date: Mon, 28 Mar 2022 15:32:21 +0300 Subject: [PATCH 2/7] move some svm support functions into lib/x86/svm_lib.h --- lib/x86/svm_lib.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++ x86/svm.c | 35 +------------------------------ x86/svm.h | 18 ---------------- x86/svm_tests.c | 1 + 4 files changed, 55 insertions(+), 52 deletions(-) create mode 100644 lib/x86/svm_lib.h diff --git a/lib/x86/svm_lib.h b/lib/x86/svm_lib.h new file mode 100644 index 00000000..cdc93408 --- /dev/null +++ b/lib/x86/svm_lib.h @@ -0,0 +1,53 @@ +#ifndef SRC_LIB_X86_SVM_LIB_H_ +#define SRC_LIB_X86_SVM_LIB_H_ + +#include +#include "processor.h" + +static inline bool npt_supported(void) +{ + return this_cpu_has(X86_FEATURE_NPT); +} + +static inline bool vgif_supported(void) +{ + return this_cpu_has(X86_FEATURE_VGIF); +} + +static inline bool lbrv_supported(void) +{ + return this_cpu_has(X86_FEATURE_LBRV); +} + +static inline bool tsc_scale_supported(void) +{ + return this_cpu_has(X86_FEATURE_TSCRATEMSR); +} + +static inline bool pause_filter_supported(void) +{ + return this_cpu_has(X86_FEATURE_PAUSEFILTER); +} + +static inline bool pause_threshold_supported(void) +{ + return this_cpu_has(X86_FEATURE_PFTHRESHOLD); +} + +static inline void vmmcall(void) +{ + asm volatile ("vmmcall" : : : "memory"); +} + +static inline void stgi(void) +{ + asm volatile ("stgi"); +} + +static inline void clgi(void) +{ + asm volatile ("clgi"); +} + + +#endif /* SRC_LIB_X86_SVM_LIB_H_ */ diff --git a/x86/svm.c b/x86/svm.c index f6896f02..009d2d8c 100644 --- a/x86/svm.c +++ b/x86/svm.c @@ -14,6 +14,7 @@ #include "isr.h" #include "apic.h" #include "vmalloc.h" +#include "svm_lib.h" /* for the nested page table*/ u64 *pte[2048]; @@ -65,31 +66,6 @@ bool default_supported(void) return true; } -bool vgif_supported(void) -{ - return this_cpu_has(X86_FEATURE_VGIF); -} - -bool lbrv_supported(void) -{ - return this_cpu_has(X86_FEATURE_LBRV); -} - -bool tsc_scale_supported(void) -{ - return this_cpu_has(X86_FEATURE_TSCRATEMSR); -} - -bool pause_filter_supported(void) -{ - return this_cpu_has(X86_FEATURE_PAUSEFILTER); -} - -bool pause_threshold_supported(void) -{ - return this_cpu_has(X86_FEATURE_PFTHRESHOLD); -} - void default_prepare(struct svm_test *test) { @@ -105,10 +81,6 @@ bool default_finished(struct svm_test *test) return true; /* one vmexit */ } -bool npt_supported(void) -{ - return this_cpu_has(X86_FEATURE_NPT); -} int get_test_stage(struct svm_test *test) { @@ -139,11 +111,6 @@ static void vmcb_set_seg(struct vmcb_seg *seg, u16 selector, seg->base = base; } -inline void vmmcall(void) -{ - asm volatile ("vmmcall" : : : "memory"); -} - static test_guest_func guest_main; void test_set_guest(test_guest_func func) diff --git a/x86/svm.h b/x86/svm.h index ff5fa91e..1eb98de3 100644 --- a/x86/svm.h +++ b/x86/svm.h @@ -52,21 +52,14 @@ u64 *npt_get_pdpe(void); u64 *npt_get_pml4e(void); bool smp_supported(void); bool default_supported(void); -bool vgif_supported(void); -bool lbrv_supported(void); -bool tsc_scale_supported(void); -bool pause_filter_supported(void); -bool pause_threshold_supported(void); void default_prepare(struct svm_test *test); void default_prepare_gif_clear(struct svm_test *test); bool default_finished(struct svm_test *test); -bool npt_supported(void); int get_test_stage(struct svm_test *test); void set_test_stage(struct svm_test *test, int s); void inc_test_stage(struct svm_test *test); void vmcb_ident(struct vmcb *vmcb); struct regs get_regs(void); -void vmmcall(void); int __svm_vmrun(u64 rip); void __svm_bare_vmrun(void); int svm_vmrun(void); @@ -75,17 +68,6 @@ void test_set_guest(test_guest_func func); extern struct vmcb *vmcb; extern struct svm_test svm_tests[]; -static inline void stgi(void) -{ - asm volatile ("stgi"); -} - -static inline void clgi(void) -{ - asm volatile ("clgi"); -} - - #define SAVE_GPR_C \ "xchg %%rbx, regs+0x8\n\t" \ diff --git a/x86/svm_tests.c b/x86/svm_tests.c index 6a9b03bd..b6a0d5e6 100644 --- a/x86/svm_tests.c +++ b/x86/svm_tests.c @@ -10,6 +10,7 @@ #include "isr.h" #include "apic.h" #include "delay.h" +#include "svm_lib.h" #define SVM_EXIT_MAX_DR_INTERCEPT 0x3f -- 2.26.3