Basic nested VMX test suite
v2 cover Basic nested VMX test suite
These two patches are focued on providing a basic version of VMX nested test suite. This commit provides the architecture of nested VMX similiar to x86/svm.c.
setjmp/longjmp is designed to avoid exiting VMX in call-back form.
Arthur Chunqi Li (2):
kvm-unit-tests : Add setjmp/longjmp to libcflat kvm-unit-tests : The first version of VMX nested test case
config-x86-common.mak | 2 + config-x86_64.mak | 3 + lib/x86/msr.h | 5 + lib/x86/setjmp64.S | 27 +++ lib/x86/setjmp64.h | 15 ++ x86/cstart64.S | 4 + x86/unittests.cfg | 6 + x86/vmx.c | 565 +++++++++++++++++++++++++++++++++++++++++++++++++ x86/vmx.h | 406 +++++++++++++++++++++++++++++++++++ 9 files changed, 1033 insertions(+) create mode 100644 lib/x86/setjmp64.S create mode 100644 lib/x86/setjmp64.h create mode 100644 x86/vmx.c create mode 100644 x86/vmx.h
Signature · 1 line
1.7.9.5
PATCH v2 1/2 kvm-unit-tests : Add setjmp/longjmp to libcflat
Add setjmp and longjmp functions to libcflat. Now these two functions are only supported in X86_64 arch.
New files added:
lib/x86/setjmp64.S lib/x86/setjmp64.c
--- config-x86_64.mak | 2 ++ lib/x86/setjmp64.S | 27 +++++++++++++++++++++++++++ lib/x86/setjmp64.h | 15 +++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 lib/x86/setjmp64.S create mode 100644 lib/x86/setjmp64.h
config-x86_64.mak +2 -0
@@ -4,6 +4,8 @@ bits = 64 ldarch = elf64-x86-64 CFLAGS += -D__x86_64__ +cflatobjs += lib/x86/setjmp64.o + tests = $(TEST_DIR)/access.flat $(TEST_DIR)/apic.flat \ $(TEST_DIR)/emulator.flat $(TEST_DIR)/idt_test.flat \ $(TEST_DIR)/xsave.flat $(TEST_DIR)/rmap_chain.flat \
lib/x86/setjmp64.S new file +27 -0
@@ -0,0 +1,27 @@ +.globl setjmp +setjmp: + mov (%rsp), %rsi + mov %rsi, (%rdi) + mov %rsp, 0x8(%rdi) + mov %rbp, 0x10(%rdi) + mov %rbx, 0x18(%rdi) + mov %r12, 0x20(%rdi) + mov %r13, 0x28(%rdi) + mov %r14, 0x30(%rdi) + mov %r15, 0x38(%rdi) + xor %eax, %eax + ret + +.globl longjmp +longjmp: + mov %esi, %eax + mov 0x38(%rdi), %r15 + mov 0x30(%rdi), %r14 + mov 0x28(%rdi), %r13 + mov 0x20(%rdi), %r12 + mov 0x18(%rdi), %rbx + mov 0x10(%rdi), %rbp + mov 0x8(%rdi), %rsp + mov (%rdi), %rsi + mov %rsi, (%rsp) + ret
lib/x86/setjmp64.h new file +15 -0
@@ -0,0 +1,15 @@ +#ifndef LIBCFLAT_SETJMP64_H +#define LIBCFLAT_SETJMP64_H + +#include "libcflat.h" + +struct jmp_buf { +u64 calling_rip; +u64 rsp, rbp, rbx; +u64 r12, r13, r14, r15; +}; + +void longjmp (struct jmp_buf *env,int val); +int setjmp (struct jmp_buf *env); + +#endif
Signature · 1 line
1.7.9.5
PATCH v2 2/2 kvm-unit-tests : The first version of VMX nested test case
In reply to Arthur Chunqi LiThis is the first version for VMX nested environment test case. It contains the basic VMX instructions test cases, including VMXON/ VMXOFF/VMXPTRLD/VMXPTRST/VMCLEAR/VMLAUNCH/VMRESUME/VMCALL. This patch also tests the basic execution routine in VMX nested environment and let the VM print "Hello World" to inform its successfully run.
New files added:x86/vmx.h : contains all VMX related macro declerations x86/vmx.c : main file for VMX nested test case
--- config-x86-common.mak | 2 + config-x86_64.mak | 1 + lib/x86/msr.h | 5 + x86/cstart64.S | 4 + x86/unittests.cfg | 6 + x86/vmx.c | 565 +++++++++++++++++++++++++++++++++++++++++++++++++ x86/vmx.h | 406 +++++++++++++++++++++++++++++++++++ 7 files changed, 989 insertions(+) create mode 100644 x86/vmx.c create mode 100644 x86/vmx.h
config-x86-common.mak +2 -0
@@ -101,6 +101,8 @@ $(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 + arch_clean: $(RM) $(TEST_DIR)/*.o $(TEST_DIR)/*.flat $(TEST_DIR)/*.elf \ $(TEST_DIR)/.*.d $(TEST_DIR)/lib/.*.d $(TEST_DIR)/lib/*.o
config-x86_64.mak +1 -0
@@ -11,5 +11,6 @@ tests = $(TEST_DIR)/access.flat $(TEST_DIR)/apic.flat \ $(TEST_DIR)/xsave.flat $(TEST_DIR)/rmap_chain.flat \ $(TEST_DIR)/pcid.flat tests += $(TEST_DIR)/svm.flat +tests += $(TEST_DIR)/vmx.flat include config-x86-common.mak
lib/x86/msr.h +5 -0
@@ -396,6 +396,11 @@#define MSR_IA32_VMX_VMCS_ENUM 0x0000048a#define MSR_IA32_VMX_PROCBASED_CTLS2 0x0000048b#define MSR_IA32_VMX_EPT_VPID_CAP 0x0000048c +#define MSR_IA32_VMX_TRUE_PIN 0x0000048d +#define MSR_IA32_VMX_TRUE_PROC 0x0000048e +#define MSR_IA32_VMX_TRUE_EXIT 0x0000048f +#define MSR_IA32_VMX_TRUE_ENTRY 0x00000490 +/* AMD-V MSRs */
x86/cstart64.S +4 -0
@@ -4,6 +4,10 @@ .globl boot_idt boot_idt = 0 +.globl idt_descr +.globl tss_descr +.globl gdt64_desc + ipi_vector = 0x20 max_cpus = 64
x86/unittests.cfg +6 -0
@@ -149,3 +149,9 @@ extra_params = --append "10000000 `date +%s`" file = pcid.flat extra_params = -cpu qemu64,+pcid arch = x86_64 + +[vmx] +file = vmx.flat +extra_params = -cpu host,+vmx +arch = x86_64 +
x86/vmx.c new file +565 -0
565 lines not on this page · raw message
x86/vmx.h new file +406 -0
406 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Paolo Bonzini
maintainerRe: [PATCH v2 1/2] kvm-unit-tests : Add setjmp/longjmp to libcflat
In reply to Arthur Chunqi LiIl 16/07/2013 17:11, Arthur Chunqi Li ha scritto:
Quoted 52 lines
Add setjmp and longjmp functions to libcflat. Now these two functions are only supported in
X86_64arch.New files added:
lib/x86/setjmp64.S lib/x86/setjmp64.cSigned-off-by Arthur Chunqi Li <[email protected]>--- config-x86_64.mak | 2 ++ lib/x86/setjmp64.S | 27 +++++++++++++++++++++++++++ lib/x86/setjmp64.h | 15 +++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 lib/x86/setjmp64.S create mode 100644 lib/x86/setjmp64.hconfig-x86_64.mak +2
-0@@ -4,6 +4,8 @@ bits = 64 ldarch = elf64-x86-64 CFLAGS += -D__x86_64__ +cflatobjs += lib/x86/setjmp64.o + tests = $(TEST_DIR)/access.flat $(TEST_DIR)/apic.flat \ $(TEST_DIR)/emulator.flat $(TEST_DIR)/idt_test.flat \ $(TEST_DIR)/xsave.flat $(TEST_DIR)/rmap_chain.flat \lib/x86/setjmp64.S new file +17
-0@@ -0,0 +1,27 @@ +.globl setjmp +setjmp: + mov (%rsp), %rsi + mov %rsi, (%rdi) + mov %rsp, 0x8(%rdi) + mov %rbp, 0x10(%rdi) + mov %rbx, 0x18(%rdi) + mov %r12, 0x20(%rdi) + mov %r13, 0x28(%rdi) + mov %r14, 0x30(%rdi) + mov %r15, 0x38(%rdi) + xor %eax, %eax + ret + +.globl longjmp +longjmp: + mov %esi, %eax
lib/x86/setjmp64.S line 27
Quoted 10 lines
lib/x86/setjmp64.S new file +10
-0+ mov 0x38(%rdi), %r15 + mov 0x30(%rdi), %r14 + mov 0x28(%rdi), %r13 + mov 0x20(%rdi), %r12 + mov 0x18(%rdi), %rbx + mov 0x10(%rdi), %rbp + mov 0x8(%rdi), %rsp + mov (%rdi), %rsi + mov %rsi, (%rsp) + ret
Nice!
Quoted 6 lines
lib/x86/setjmp64.h new file +0
-0
lib/x86/setjmp64.h line 10
Quoted 10 lines
lib/x86/setjmp64.h new file +10
-0@@ -0,0 +1,15 @@ +#ifndef LIBCFLAT_SETJMP64_H +#define LIBCFLAT_SETJMP64_H + +#include "libcflat.h" + +struct jmp_buf { +u64 calling_rip; +u64 rsp, rbp, rbx; +u64 r12, r13, r14, r15; +};
Please make it a typedef instead. In fact, jmp_buf is typically an array so that longjmp(env, 1) works without the ampersand. A "struct-like" declaration can go in setjmp64.S as a comment.
With this change, you can put it in lib/setjmp.h so that implementation for other arches can be added later.
Otherwise looks good, thanks!
Paolo
Quoted 5 lines
lib/x86/setjmp64.h new file +4
-0+void longjmp (struct jmp_buf *env,int val); +int setjmp (struct jmp_buf *env); + +#endif