Reconstruct VMX codes, add new test suites in a subdirectory. New test suites locates in x86/nvmx/. Add an empty test suite ctrl_fields in x86/nvmx/. Signed-off-by: Arthur Chunqi Li <yzt356@xxxxxxxxx> --- config-x86-common.mak | 7 +++++-- x86/nvmx/ctrl_fields.c | 10 ++++++++++ x86/nvmx/ctrl_fields.h | 7 +++++++ x86/vmx.c | 30 ++++++------------------------ x86/vmx.h | 38 ++++++++++++++++++++++++++++++++------ 5 files changed, 60 insertions(+), 32 deletions(-) create mode 100644 x86/nvmx/ctrl_fields.c create mode 100644 x86/nvmx/ctrl_fields.h diff --git a/config-x86-common.mak b/config-x86-common.mak index 34a41e1..a5f4d45 100644 --- a/config-x86-common.mak +++ b/config-x86-common.mak @@ -47,6 +47,8 @@ endif tests_and_config = $(TEST_DIR)/*.flat $(TEST_DIR)/unittests.cfg +nvmx_objs = $(TEST_DIR)/nvmx/ctrl_fields.o + test_cases: $(tests-common) $(tests) $(TEST_DIR)/%.o: CFLAGS += -std=gnu99 -ffreestanding -I lib -I lib/x86 @@ -101,11 +103,12 @@ $(TEST_DIR)/asyncpf.elf: $(cstart.o) $(TEST_DIR)/asyncpf.o $(TEST_DIR)/pcid.elf: $(cstart.o) $(TEST_DIR)/pcid.o -$(TEST_DIR)/vmx.elf: $(cstart.o) $(TEST_DIR)/vmx.o +$(TEST_DIR)/vmx.elf: $(cstart.o) $(TEST_DIR)/vmx.o $(nvmx_objs) arch_clean: $(RM) $(TEST_DIR)/*.o $(TEST_DIR)/*.flat $(TEST_DIR)/*.elf \ - $(TEST_DIR)/.*.d $(TEST_DIR)/lib/.*.d $(TEST_DIR)/lib/*.o + $(TEST_DIR)/.*.d $(TEST_DIR)/lib/.*.d $(TEST_DIR)/lib/*.o \ + $(TEST_DIR)/nvmx/*.o api/%.o: CFLAGS += -m32 diff --git a/x86/nvmx/ctrl_fields.c b/x86/nvmx/ctrl_fields.c new file mode 100644 index 0000000..7d9ea01 --- /dev/null +++ b/x86/nvmx/ctrl_fields.c @@ -0,0 +1,10 @@ +#include "../vmx.h" + +void ctrl_fields_main() +{ +} + +int ctrl_fields_exit_handler() +{ + return VMX_TEST_VMEXIT; +} diff --git a/x86/nvmx/ctrl_fields.h b/x86/nvmx/ctrl_fields.h new file mode 100644 index 0000000..7af6a2e --- /dev/null +++ b/x86/nvmx/ctrl_fields.h @@ -0,0 +1,7 @@ +#ifndef __CTRL_FIELDS_H +#define __CTRL_FIELDS_H + +void ctrl_fields_main(); +int ctrl_fields_exit_handler(); + +#endif diff --git a/x86/vmx.c b/x86/vmx.c index 082c3bb..f57c6d2 100644 --- a/x86/vmx.c +++ b/x86/vmx.c @@ -7,18 +7,7 @@ #include "smp.h" #include "io.h" -int fails = 0, tests = 0; -u32 *vmxon_region; -struct vmcs *vmcs_root; -u32 vpid_cnt; -void *guest_stack, *guest_syscall_stack; -u32 ctrl_pin, ctrl_enter, ctrl_exit, ctrl_cpu[2]; -ulong fix_cr0_set, fix_cr0_clr; -ulong fix_cr4_set, fix_cr4_clr; -struct regs regs; -struct vmx_test *current; -u64 hypercall_field = 0; -bool launched; +#include "nvmx/ctrl_fields.h" extern u64 gdt64_desc[]; extern u64 idt_descr[]; @@ -27,17 +16,6 @@ extern void *vmx_return; extern void *entry_sysenter; extern void *guest_entry; -static void report(const char *name, int result) -{ - ++tests; - if (result) - printf("PASS: %s\n", name); - else { - printf("FAIL: %s\n", name); - ++fails; - } -} - static int make_vmcs_current(struct vmcs *vmcs) { bool ret; @@ -80,7 +58,7 @@ static inline int vmx_off() return ret; } -static void print_vmexit_info() +void print_vmexit_info() { u64 guest_rip, guest_rsp; ulong reason = vmcs_read(EXI_REASON) & 0xff; @@ -636,6 +614,8 @@ static struct vmx_test vmx_tests[] = { basic_syscall_handler, {0} }, { "vmenter", basic_init, vmenter_main, vmenter_exit_handler, basic_syscall_handler, {0} }, + { "ctrl_fields", basic_init, ctrl_fields_main, ctrl_fields_exit_handler, + basic_syscall_handler, {0} }, }; int main(void) @@ -644,6 +624,8 @@ int main(void) setup_vm(); setup_idt(); + fails = tests = 0; + hypercall_field = 0; if (test_vmx_capability() != 0) { printf("ERROR : vmx not supported, check +vmx option\n"); diff --git a/x86/vmx.h b/x86/vmx.h index d80e000..305de1b 100644 --- a/x86/vmx.h +++ b/x86/vmx.h @@ -41,7 +41,7 @@ struct vmx_test { int exits; }; -static union vmx_basic { +union vmx_basic { u64 val; struct { u32 revision; @@ -55,35 +55,35 @@ static union vmx_basic { }; } basic; -static union vmx_ctrl_pin { +union vmx_ctrl_pin { u64 val; struct { u32 set, clr; }; } ctrl_pin_rev; -static union vmx_ctrl_cpu { +union vmx_ctrl_cpu { u64 val; struct { u32 set, clr; }; } ctrl_cpu_rev[2]; -static union vmx_ctrl_exit { +union vmx_ctrl_exit { u64 val; struct { u32 set, clr; }; } ctrl_exit_rev; -static union vmx_ctrl_ent { +union vmx_ctrl_ent { u64 val; struct { u32 set, clr; }; } ctrl_enter_rev; -static union vmx_ept_vpid { +union vmx_ept_vpid { u64 val; struct { u32:16, @@ -462,5 +462,31 @@ static inline int vmcs_save(struct vmcs **vmcs) return ret; } +int fails, tests; +u64 hypercall_field; +u32 *vmxon_region; +struct vmcs *vmcs_root; +u32 vpid_cnt; +void *guest_stack, *guest_syscall_stack; +u32 ctrl_pin, ctrl_enter, ctrl_exit, ctrl_cpu[2]; +ulong fix_cr0_set, fix_cr0_clr; +ulong fix_cr4_set, fix_cr4_clr; +struct regs regs; +struct vmx_test *current; +bool launched; + +static inline void report(const char *name, int result) +{ + ++tests; + if (result) + printf("PASS: %s\n", name); + else { + printf("FAIL: %s\n", name); + ++fails; + } +} + +void print_vmexit_info(); + #endif -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html