Re: [PATCH v2] kvm-unit-tests : Basic architecture of VMX nested test case
On Fri, Jul 26, 2013 at 12:32:55AM +0800, Arthur Chunqi Li wrote: This is the first version of VMX nested environment. It contains the basic VMX instructions test cases, including VMXON/VMXOFF/VMXPTRLD/ VMXPTRST/VMCLEAR/VMLAUNCH/VMRESUME/VMCALL. This patchalso tests the basic execution routine in VMX nested environment andlet the VM print Hello World to inform its successfully run. The first release also includes a test suite for vmenter (vmlaunch and vmresume). Besides, hypercall mechanism is included and currently it is used to invoke VM normal exit. New files added: x86/vmx.h : contains all VMX related macro declerations x86/vmx.c : main file for VMX nested test case Overall looks good. Some minor nits about code placement and an idea how to simplify vmx_run() below. Signed-off-by: Arthur Chunqi Li yzt...@gmail.com --- 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 | 712 + x86/vmx.h | 474 7 files changed, 1204 insertions(+) create mode 100644 x86/vmx.c create mode 100644 x86/vmx.h diff --git a/config-x86-common.mak b/config-x86-common.mak index 455032b..34a41e1 100644 --- a/config-x86-common.mak +++ b/config-x86-common.mak @@ -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 diff --git a/config-x86_64.mak b/config-x86_64.mak index 4e525f5..bb8ee89 100644 --- a/config-x86_64.mak +++ b/config-x86_64.mak @@ -9,5 +9,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 diff --git a/lib/x86/msr.h b/lib/x86/msr.h index 509a421..281255a 100644 --- a/lib/x86/msr.h +++ b/lib/x86/msr.h @@ -396,6 +396,11 @@ #define MSR_IA32_VMX_VMCS_ENUM 0x048a #define MSR_IA32_VMX_PROCBASED_CTLS20x048b #define MSR_IA32_VMX_EPT_VPID_CAP 0x048c +#define MSR_IA32_VMX_TRUE_PIN0x048d +#define MSR_IA32_VMX_TRUE_PROC 0x048e +#define MSR_IA32_VMX_TRUE_EXIT 0x048f +#define MSR_IA32_VMX_TRUE_ENTRY 0x0490 + /* AMD-V MSRs */ diff --git a/x86/cstart64.S b/x86/cstart64.S index 24df5f8..0fe76da 100644 --- a/x86/cstart64.S +++ b/x86/cstart64.S @@ -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 diff --git a/x86/unittests.cfg b/x86/unittests.cfg index bc9643e..85c36aa 100644 --- a/x86/unittests.cfg +++ b/x86/unittests.cfg @@ -149,3 +149,9 @@ extra_params = --append 1000 `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 + diff --git a/x86/vmx.c b/x86/vmx.c new file mode 100644 index 000..af694e1 --- /dev/null +++ b/x86/vmx.c @@ -0,0 +1,712 @@ +#include libcflat.h +#include processor.h +#include vm.h +#include desc.h +#include vmx.h +#include msr.h +#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 = 0; + +extern u64 gdt64_desc[]; +extern u64 idt_descr[]; +extern u64 tss_descr[]; +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 vmcs_clear(struct vmcs *vmcs) +{ + bool ret; + asm volatile (vmclear %1; setbe %0 : =q (ret) : m (vmcs) : cc); + return ret; +} + +static u64 vmcs_read(enum Encoding enc) +{ + u64 val; + asm volatile (vmread %1, %0 : =rm (val) : r ((u64)enc) : cc); + return val; +} + +static int vmcs_write(enum Encoding enc, u64 val) +{ + bool ret; + asm volatile (vmwrite %1, %2; setbe %0 + : =q(ret) : rm (val), r ((u64)enc) : cc); + return ret; +} + +static int make_vmcs_current(struct vmcs *vmcs) +{ + bool ret; + + asm volatile (vmptrld %1;
Re: [PATCH v2] kvm-unit-tests : Basic architecture of VMX nested test case
On Sun, Jul 28, 2013 at 6:53 PM, Gleb Natapov g...@redhat.com wrote: On Fri, Jul 26, 2013 at 12:32:55AM +0800, Arthur Chunqi Li wrote: This is the first version of VMX nested environment. It contains the basic VMX instructions test cases, including VMXON/VMXOFF/VMXPTRLD/ VMXPTRST/VMCLEAR/VMLAUNCH/VMRESUME/VMCALL. This patchalso tests the basic execution routine in VMX nested environment andlet the VM print Hello World to inform its successfully run. The first release also includes a test suite for vmenter (vmlaunch and vmresume). Besides, hypercall mechanism is included and currently it is used to invoke VM normal exit. New files added: x86/vmx.h : contains all VMX related macro declerations x86/vmx.c : main file for VMX nested test case Overall looks good. Some minor nits about code placement and an idea how to simplify vmx_run() below. Signed-off-by: Arthur Chunqi Li yzt...@gmail.com --- 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 | 712 + x86/vmx.h | 474 7 files changed, 1204 insertions(+) create mode 100644 x86/vmx.c create mode 100644 x86/vmx.h diff --git a/config-x86-common.mak b/config-x86-common.mak index 455032b..34a41e1 100644 --- a/config-x86-common.mak +++ b/config-x86-common.mak @@ -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 diff --git a/config-x86_64.mak b/config-x86_64.mak index 4e525f5..bb8ee89 100644 --- a/config-x86_64.mak +++ b/config-x86_64.mak @@ -9,5 +9,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 diff --git a/lib/x86/msr.h b/lib/x86/msr.h index 509a421..281255a 100644 --- a/lib/x86/msr.h +++ b/lib/x86/msr.h @@ -396,6 +396,11 @@ #define MSR_IA32_VMX_VMCS_ENUM 0x048a #define MSR_IA32_VMX_PROCBASED_CTLS20x048b #define MSR_IA32_VMX_EPT_VPID_CAP 0x048c +#define MSR_IA32_VMX_TRUE_PIN0x048d +#define MSR_IA32_VMX_TRUE_PROC 0x048e +#define MSR_IA32_VMX_TRUE_EXIT 0x048f +#define MSR_IA32_VMX_TRUE_ENTRY 0x0490 + /* AMD-V MSRs */ diff --git a/x86/cstart64.S b/x86/cstart64.S index 24df5f8..0fe76da 100644 --- a/x86/cstart64.S +++ b/x86/cstart64.S @@ -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 diff --git a/x86/unittests.cfg b/x86/unittests.cfg index bc9643e..85c36aa 100644 --- a/x86/unittests.cfg +++ b/x86/unittests.cfg @@ -149,3 +149,9 @@ extra_params = --append 1000 `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 + diff --git a/x86/vmx.c b/x86/vmx.c new file mode 100644 index 000..af694e1 --- /dev/null +++ b/x86/vmx.c @@ -0,0 +1,712 @@ +#include libcflat.h +#include processor.h +#include vm.h +#include desc.h +#include vmx.h +#include msr.h +#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 = 0; + +extern u64 gdt64_desc[]; +extern u64 idt_descr[]; +extern u64 tss_descr[]; +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 vmcs_clear(struct vmcs *vmcs) +{ + bool ret; + asm volatile (vmclear %1; setbe %0 : =q (ret) : m (vmcs) : cc); + return ret; +} + +static u64 vmcs_read(enum Encoding enc) +{ + u64 val; + asm volatile (vmread %1, %0 : =rm (val) : r ((u64)enc) : cc); + return val; +} + +static int vmcs_write(enum Encoding enc, u64 val) +{ + bool ret; + asm volatile (vmwrite %1, %2; setbe %0 + : =q(ret) : rm (val), r ((u64)enc) : cc); + return ret; +} + +static int make_vmcs_current(struct vmcs *vmcs)
Re: [PATCH v2] kvm-unit-tests : Basic architecture of VMX nested test case
On Sun, Jul 28, 2013 at 08:18:25PM +0800, Arthur Chunqi Li wrote: + +#define SEL_NULL_DESC0x0 +#define SEL_KERN_CODE_64 0x8 +#define SEL_KERN_DATA_64 0x10 +#define SEL_USER_CODE_64 0x18 +#define SEL_USER_DATA_64 0x20 +#define SEL_CODE_32 0x28 +#define SEL_DATA_32 0x30 +#define SEL_CODE_16 0x38 +#define SEL_DATA_16 0x40 +#define SEL_TSS_RUN 0x48 + This need too be move to the common header file. Which header file do you think is suitable to contain these selector defines? It should correspond to the defines in x86/cstart64.S (x86/cstart.S for 32 bit). lib/x86/processor.h may be suitable, but this file only contains inline functions now. They are VM related, so lib/x86/vm.h should be a good place. -- Gleb. -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v3] kvm-unit-tests : Basic architecture of VMX nested test case
This is the first version of VMX nested environment. It contains the basic VMX instructions test cases, including VMXON/VMXOFF/VMXPTRLD/ VMXPTRST/VMCLEAR/VMLAUNCH/VMRESUME/VMCALL. This patchalso tests the basic execution routine in VMX nested environment andlet the VM print Hello World to inform its successfully run. The first release also includes a test suite for vmenter (vmlaunch and vmresume). Besides, hypercall mechanism is included and currently it is used to invoke VM normal exit. New files added: x86/vmx.h : contains all VMX related macro declerations x86/vmx.c : main file for VMX nested test case Signed-off-by: Arthur Chunqi Li yzt...@gmail.com --- ChangeLog: 1. Refine codes in function vmx_run() 2. Fix bug of setting GUEST_RFLAGS 3. Move defines of selectors to lib/x86/vm.h 4. Move CR0/4 defines to lib/x86/vm.h, so as some defines in lib/x86/vm.c 5. Move some inline functions to lib/x86/processor.h 6. Move some inline functions (vmcs related) to x86/vmx.h --- config-x86-common.mak |2 + config-x86_64.mak |1 + lib/x86/msr.h |5 + lib/x86/processor.h | 15 ++ lib/x86/vm.c |4 - lib/x86/vm.h | 21 ++ x86/cstart64.S|4 + x86/unittests.cfg |6 + x86/vmx.c | 674 + x86/vmx.h | 466 ++ 10 files changed, 1194 insertions(+), 4 deletions(-) create mode 100644 x86/vmx.c create mode 100644 x86/vmx.h diff --git a/config-x86-common.mak b/config-x86-common.mak index 455032b..34a41e1 100644 --- a/config-x86-common.mak +++ b/config-x86-common.mak @@ -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 diff --git a/config-x86_64.mak b/config-x86_64.mak index 4e525f5..bb8ee89 100644 --- a/config-x86_64.mak +++ b/config-x86_64.mak @@ -9,5 +9,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 diff --git a/lib/x86/msr.h b/lib/x86/msr.h index 509a421..281255a 100644 --- a/lib/x86/msr.h +++ b/lib/x86/msr.h @@ -396,6 +396,11 @@ #define MSR_IA32_VMX_VMCS_ENUM 0x048a #define MSR_IA32_VMX_PROCBASED_CTLS20x048b #define MSR_IA32_VMX_EPT_VPID_CAP 0x048c +#define MSR_IA32_VMX_TRUE_PIN 0x048d +#define MSR_IA32_VMX_TRUE_PROC 0x048e +#define MSR_IA32_VMX_TRUE_EXIT 0x048f +#define MSR_IA32_VMX_TRUE_ENTRY0x0490 + /* AMD-V MSRs */ diff --git a/lib/x86/processor.h b/lib/x86/processor.h index e46d8d0..f0c11cc 100644 --- a/lib/x86/processor.h +++ b/lib/x86/processor.h @@ -307,4 +307,19 @@ static inline void safe_halt(void) { asm volatile(sti; hlt); } + +#ifdef __x86_64__ +static inline u64 read_rflags(void) +{ + u64 r; + asm volatile(pushf; pop %0\n\t : =q(r) : : cc); + return r; +} + +static inline void write_rflags(u64 r) +{ + asm volatile(push %0; popf\n\t : : q(r) : cc); +} +#endif + #endif diff --git a/lib/x86/vm.c b/lib/x86/vm.c index 260ec45..188bf57 100644 --- a/lib/x86/vm.c +++ b/lib/x86/vm.c @@ -9,10 +9,6 @@ #define LARGE_PAGE_SIZE (1024 * PAGE_SIZE) #endif -#define X86_CR0_PE 0x0001 -#define X86_CR0_WP 0x0001 -#define X86_CR0_PG 0x8000 -#define X86_CR4_PSE 0x0010 static void *free = 0; static void *vfree_top = 0; diff --git a/lib/x86/vm.h b/lib/x86/vm.h index 0b5b5c7..eff6f72 100644 --- a/lib/x86/vm.h +++ b/lib/x86/vm.h @@ -16,6 +16,27 @@ #define PTE_USER(1ull 2) #define PTE_ADDR(0xff000ull) +#define X86_CR0_PE 0x0001 +#define X86_CR0_WP 0x0001 +#define X86_CR0_PG 0x8000 +#define X86_CR4_VMXE 0x0001 +#define X86_CR4_PSE 0x0010 +#define X86_CR4_PAE 0x0020 +#define X86_CR4_PCIDE 0x0002 + +#ifdef __x86_64__ +#define SEL_NULL_DESC 0x0 +#define SEL_KERN_CODE_64 0x8 +#define SEL_KERN_DATA_64 0x10 +#define SEL_USER_CODE_64 0x18 +#define SEL_USER_DATA_64 0x20 +#define SEL_CODE_320x28 +#define SEL_DATA_320x30 +#define SEL_CODE_160x38 +#define SEL_DATA_160x40 +#define SEL_TSS_RUN0x48 +#endif + void setup_vm(); void *vmalloc(unsigned long size); diff --git a/x86/cstart64.S b/x86/cstart64.S index 24df5f8..0fe76da 100644 --- a/x86/cstart64.S +++ b/x86/cstart64.S @@ -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 diff --git a/x86/unittests.cfg
[Bug 60642] New: guest uses 100% and completely hangs
https://bugzilla.kernel.org/show_bug.cgi?id=60642 Bug ID: 60642 Summary: guest uses 100% and completely hangs Product: Virtualization Version: unspecified Kernel Version: guest: 3.10, host: 3.10 Hardware: x86-64 OS: Linux Tree: Mainline Status: NEW Severity: normal Priority: P1 Component: kvm Assignee: virtualization_...@kernel-bugs.osdl.org Reporter: folk...@vanheusden.com Regression: No Situation: pc with 3 vms running. 2 run fine, 1 jumps to 100% cpu and completely hangs minutes after start this vm has a virtual serial port connected to /dev/ttyUMTS0 which is an umts stick. as soon as wvdial successfully started a ppp session, the guest hangs The last thing top shows in the guest is: 3 root 20 0 000 R 40.2 0.0 0:00.86 ksoftirqd/0 2320 root 20 0 21476 1648 1260 R 36.0 0.7 0:02.14 tincd 132 root 20 0 000 R 27.7 0.0 0:01.18 kworker/0:2 strace on the kvm process in the host gives me: [pid 9418] write(5, `, 1)= -1 EAGAIN (Resource temporarily unavailable) [pid 9418] write(5, `, 1)= -1 EAGAIN (Resource temporarily unavailable) [pid 9418] write(5, `, 1)= -1 EAGAIN (Resource temporarily unavailable) [pid 9418] write(5, `, 1)= -1 EAGAIN (Resource temporarily unavailable) [pid 9418] write(5, `, 1)= -1 EAGAIN (Resource temporarily unavailable) fd 5 is the /dev/ttyUMTS0 device. gdb says: #0 __lll_lock_wait () at ../nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:135 #1 0x7f69ced73f3c in _L_lock_974 () from /lib/x86_64-linux-gnu/libpthread.so.0 #2 0x7f69ced73d8b in __GI___pthread_mutex_lock (mutex=0x7f69d3acfa80 qemu_global_mutex) at pthread_mutex_lock.c:64 #3 0x7f69d2daedc9 in ?? () #4 0x7f69d2d83c98 in ?? () #5 0x7f69d2c93973 in main () There's absolutely _no_ logging regarding this issue in dmesg on the host. I did some googling and tried replacing utc-clock by local clock, I also tried adding clocksource=acpi_pm but none of those helped. versions: root@neo:/sys/bus/usb/devices# dpkg --list | grep -e qemu -e kvm | awk '{ print $1\t$2\t$3\t$4; }' ii ipxe-qemu 1.0.0+git-20120202.f6840ba-3all ii kvm 1:1.1.2+dfsg-6 amd64 ii qemu1.1.2+dfsg-6a amd64 ii qemu-keymaps1.1.2+dfsg-6a all ii qemu-kvm1.1.2+dfsg-6amd64 ii qemu-system 1.1.2+dfsg-6a amd64 ii qemu-user 1.1.2+dfsg-6a amd64 ii qemu-utils 1.1.2+dfsg-6a amd64 After a restart of the vm, the exact same problem happens after 10 seconds so it is 100% reproducible here. -- You are receiving this mail because: You are watching the assignee of the bug. -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3] kvm-unit-tests : Basic architecture of VMX nested test case
Hi Gleb, It suddenly occured to me that this patch also fails to handle GUEST_RFLAGS when VMRESUME. I decide to remove rflags in struct regs since rflags can be read and set via vmcs_read/vmcs_write in test suited defined functions (init and exit_handler), and other general registers can only be set in the framework code. Then I will wait for Paolo and Gleb's furthur feedback and commit the final patch. Arthur On Sun, Jul 28, 2013 at 10:00 PM, Arthur Chunqi Li yzt...@gmail.com wrote: This is the first version of VMX nested environment. It contains the basic VMX instructions test cases, including VMXON/VMXOFF/VMXPTRLD/ VMXPTRST/VMCLEAR/VMLAUNCH/VMRESUME/VMCALL. This patchalso tests the basic execution routine in VMX nested environment andlet the VM print Hello World to inform its successfully run. The first release also includes a test suite for vmenter (vmlaunch and vmresume). Besides, hypercall mechanism is included and currently it is used to invoke VM normal exit. New files added: x86/vmx.h : contains all VMX related macro declerations x86/vmx.c : main file for VMX nested test case Signed-off-by: Arthur Chunqi Li yzt...@gmail.com --- ChangeLog: 1. Refine codes in function vmx_run() 2. Fix bug of setting GUEST_RFLAGS 3. Move defines of selectors to lib/x86/vm.h 4. Move CR0/4 defines to lib/x86/vm.h, so as some defines in lib/x86/vm.c 5. Move some inline functions to lib/x86/processor.h 6. Move some inline functions (vmcs related) to x86/vmx.h --- config-x86-common.mak |2 + config-x86_64.mak |1 + lib/x86/msr.h |5 + lib/x86/processor.h | 15 ++ lib/x86/vm.c |4 - lib/x86/vm.h | 21 ++ x86/cstart64.S|4 + x86/unittests.cfg |6 + x86/vmx.c | 674 + x86/vmx.h | 466 ++ 10 files changed, 1194 insertions(+), 4 deletions(-) create mode 100644 x86/vmx.c create mode 100644 x86/vmx.h diff --git a/config-x86-common.mak b/config-x86-common.mak index 455032b..34a41e1 100644 --- a/config-x86-common.mak +++ b/config-x86-common.mak @@ -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 diff --git a/config-x86_64.mak b/config-x86_64.mak index 4e525f5..bb8ee89 100644 --- a/config-x86_64.mak +++ b/config-x86_64.mak @@ -9,5 +9,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 diff --git a/lib/x86/msr.h b/lib/x86/msr.h index 509a421..281255a 100644 --- a/lib/x86/msr.h +++ b/lib/x86/msr.h @@ -396,6 +396,11 @@ #define MSR_IA32_VMX_VMCS_ENUM 0x048a #define MSR_IA32_VMX_PROCBASED_CTLS20x048b #define MSR_IA32_VMX_EPT_VPID_CAP 0x048c +#define MSR_IA32_VMX_TRUE_PIN 0x048d +#define MSR_IA32_VMX_TRUE_PROC 0x048e +#define MSR_IA32_VMX_TRUE_EXIT 0x048f +#define MSR_IA32_VMX_TRUE_ENTRY0x0490 + /* AMD-V MSRs */ diff --git a/lib/x86/processor.h b/lib/x86/processor.h index e46d8d0..f0c11cc 100644 --- a/lib/x86/processor.h +++ b/lib/x86/processor.h @@ -307,4 +307,19 @@ static inline void safe_halt(void) { asm volatile(sti; hlt); } + +#ifdef __x86_64__ +static inline u64 read_rflags(void) +{ + u64 r; + asm volatile(pushf; pop %0\n\t : =q(r) : : cc); + return r; +} + +static inline void write_rflags(u64 r) +{ + asm volatile(push %0; popf\n\t : : q(r) : cc); +} +#endif + #endif diff --git a/lib/x86/vm.c b/lib/x86/vm.c index 260ec45..188bf57 100644 --- a/lib/x86/vm.c +++ b/lib/x86/vm.c @@ -9,10 +9,6 @@ #define LARGE_PAGE_SIZE (1024 * PAGE_SIZE) #endif -#define X86_CR0_PE 0x0001 -#define X86_CR0_WP 0x0001 -#define X86_CR0_PG 0x8000 -#define X86_CR4_PSE 0x0010 static void *free = 0; static void *vfree_top = 0; diff --git a/lib/x86/vm.h b/lib/x86/vm.h index 0b5b5c7..eff6f72 100644 --- a/lib/x86/vm.h +++ b/lib/x86/vm.h @@ -16,6 +16,27 @@ #define PTE_USER(1ull 2) #define PTE_ADDR(0xff000ull) +#define X86_CR0_PE 0x0001 +#define X86_CR0_WP 0x0001 +#define X86_CR0_PG 0x8000 +#define X86_CR4_VMXE 0x0001 +#define X86_CR4_PSE 0x0010 +#define X86_CR4_PAE 0x0020 +#define X86_CR4_PCIDE 0x0002 + +#ifdef __x86_64__ +#define SEL_NULL_DESC 0x0 +#define SEL_KERN_CODE_64 0x8 +#define SEL_KERN_DATA_64 0x10 +#define
[Bug 60642] guest uses 100% and completely hangs
https://bugzilla.kernel.org/show_bug.cgi?id=60642 --- Comment #1 from Folkert van Heusden folk...@vanheusden.com --- In the console of the guest I see: [sched_delayed] sched: RT throttling activated -- You are receiving this mail because: You are watching the assignee of the bug. -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3] kvm-unit-tests : Basic architecture of VMX nested test case
On Sun, Jul 28, 2013 at 10:24 PM, Arthur Chunqi Li yzt...@gmail.com wrote: Hi Gleb, It suddenly occured to me that this patch also fails to handle GUEST_RFLAGS when VMRESUME. I decide to remove rflags in struct regs since rflags can be read and set via vmcs_read/vmcs_write in test suited defined functions (init and exit_handler), and other general registers can only be set in the framework code. Besides, I previously used regs.rflags as host rflags (in vmx_run()), so I changed it to regs.host_rflags and avoid confusion. In the previous version, regs.rflags is also not used in SAVE_GPR and LOAD_GPR, so it is reasonable to leave it for user to set up. Arthur Then I will wait for Paolo and Gleb's furthur feedback and commit the final patch. Arthur On Sun, Jul 28, 2013 at 10:00 PM, Arthur Chunqi Li yzt...@gmail.com wrote: This is the first version of VMX nested environment. It contains the basic VMX instructions test cases, including VMXON/VMXOFF/VMXPTRLD/ VMXPTRST/VMCLEAR/VMLAUNCH/VMRESUME/VMCALL. This patchalso tests the basic execution routine in VMX nested environment andlet the VM print Hello World to inform its successfully run. The first release also includes a test suite for vmenter (vmlaunch and vmresume). Besides, hypercall mechanism is included and currently it is used to invoke VM normal exit. New files added: x86/vmx.h : contains all VMX related macro declerations x86/vmx.c : main file for VMX nested test case Signed-off-by: Arthur Chunqi Li yzt...@gmail.com --- ChangeLog: 1. Refine codes in function vmx_run() 2. Fix bug of setting GUEST_RFLAGS 3. Move defines of selectors to lib/x86/vm.h 4. Move CR0/4 defines to lib/x86/vm.h, so as some defines in lib/x86/vm.c 5. Move some inline functions to lib/x86/processor.h 6. Move some inline functions (vmcs related) to x86/vmx.h --- config-x86-common.mak |2 + config-x86_64.mak |1 + lib/x86/msr.h |5 + lib/x86/processor.h | 15 ++ lib/x86/vm.c |4 - lib/x86/vm.h | 21 ++ x86/cstart64.S|4 + x86/unittests.cfg |6 + x86/vmx.c | 674 + x86/vmx.h | 466 ++ 10 files changed, 1194 insertions(+), 4 deletions(-) create mode 100644 x86/vmx.c create mode 100644 x86/vmx.h diff --git a/config-x86-common.mak b/config-x86-common.mak index 455032b..34a41e1 100644 --- a/config-x86-common.mak +++ b/config-x86-common.mak @@ -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 diff --git a/config-x86_64.mak b/config-x86_64.mak index 4e525f5..bb8ee89 100644 --- a/config-x86_64.mak +++ b/config-x86_64.mak @@ -9,5 +9,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 diff --git a/lib/x86/msr.h b/lib/x86/msr.h index 509a421..281255a 100644 --- a/lib/x86/msr.h +++ b/lib/x86/msr.h @@ -396,6 +396,11 @@ #define MSR_IA32_VMX_VMCS_ENUM 0x048a #define MSR_IA32_VMX_PROCBASED_CTLS20x048b #define MSR_IA32_VMX_EPT_VPID_CAP 0x048c +#define MSR_IA32_VMX_TRUE_PIN 0x048d +#define MSR_IA32_VMX_TRUE_PROC 0x048e +#define MSR_IA32_VMX_TRUE_EXIT 0x048f +#define MSR_IA32_VMX_TRUE_ENTRY0x0490 + /* AMD-V MSRs */ diff --git a/lib/x86/processor.h b/lib/x86/processor.h index e46d8d0..f0c11cc 100644 --- a/lib/x86/processor.h +++ b/lib/x86/processor.h @@ -307,4 +307,19 @@ static inline void safe_halt(void) { asm volatile(sti; hlt); } + +#ifdef __x86_64__ +static inline u64 read_rflags(void) +{ + u64 r; + asm volatile(pushf; pop %0\n\t : =q(r) : : cc); + return r; +} + +static inline void write_rflags(u64 r) +{ + asm volatile(push %0; popf\n\t : : q(r) : cc); +} +#endif + #endif diff --git a/lib/x86/vm.c b/lib/x86/vm.c index 260ec45..188bf57 100644 --- a/lib/x86/vm.c +++ b/lib/x86/vm.c @@ -9,10 +9,6 @@ #define LARGE_PAGE_SIZE (1024 * PAGE_SIZE) #endif -#define X86_CR0_PE 0x0001 -#define X86_CR0_WP 0x0001 -#define X86_CR0_PG 0x8000 -#define X86_CR4_PSE 0x0010 static void *free = 0; static void *vfree_top = 0; diff --git a/lib/x86/vm.h b/lib/x86/vm.h index 0b5b5c7..eff6f72 100644 --- a/lib/x86/vm.h +++ b/lib/x86/vm.h @@ -16,6 +16,27 @@ #define PTE_USER(1ull 2) #define PTE_ADDR(0xff000ull) +#define X86_CR0_PE 0x0001 +#define
Re: [PATCH v3] kvm-unit-tests : Basic architecture of VMX nested test case
On Sun, Jul 28, 2013 at 10:24:34PM +0800, Arthur Chunqi Li wrote: Hi Gleb, It suddenly occured to me that this patch also fails to handle GUEST_RFLAGS when VMRESUME. As you are saying below if test wants to change rflags in a middle of the run it can use vmcs_write, so this is not a big deal. I decide to remove rflags in struct regs since rflags can be read and set via vmcs_read/vmcs_write in test suited defined functions (init and exit_handler), and other general registers can only be set in the framework code. The code that prints vmlaunch/vmresume error in vmx_run() relies on rflags been saved by assembly code, so be careful. Then I will wait for Paolo and Gleb's furthur feedback and commit the final patch. Yes please wait for Paolo comments. I want to hear his opinion on assembly code. Will not be surprised if he will find the reason it cannot work :) Arthur On Sun, Jul 28, 2013 at 10:00 PM, Arthur Chunqi Li yzt...@gmail.com wrote: This is the first version of VMX nested environment. It contains the basic VMX instructions test cases, including VMXON/VMXOFF/VMXPTRLD/ VMXPTRST/VMCLEAR/VMLAUNCH/VMRESUME/VMCALL. This patchalso tests the basic execution routine in VMX nested environment andlet the VM print Hello World to inform its successfully run. The first release also includes a test suite for vmenter (vmlaunch and vmresume). Besides, hypercall mechanism is included and currently it is used to invoke VM normal exit. New files added: x86/vmx.h : contains all VMX related macro declerations x86/vmx.c : main file for VMX nested test case Signed-off-by: Arthur Chunqi Li yzt...@gmail.com --- ChangeLog: 1. Refine codes in function vmx_run() 2. Fix bug of setting GUEST_RFLAGS 3. Move defines of selectors to lib/x86/vm.h 4. Move CR0/4 defines to lib/x86/vm.h, so as some defines in lib/x86/vm.c 5. Move some inline functions to lib/x86/processor.h 6. Move some inline functions (vmcs related) to x86/vmx.h --- config-x86-common.mak |2 + config-x86_64.mak |1 + lib/x86/msr.h |5 + lib/x86/processor.h | 15 ++ lib/x86/vm.c |4 - lib/x86/vm.h | 21 ++ x86/cstart64.S|4 + x86/unittests.cfg |6 + x86/vmx.c | 674 + x86/vmx.h | 466 ++ 10 files changed, 1194 insertions(+), 4 deletions(-) create mode 100644 x86/vmx.c create mode 100644 x86/vmx.h diff --git a/config-x86-common.mak b/config-x86-common.mak index 455032b..34a41e1 100644 --- a/config-x86-common.mak +++ b/config-x86-common.mak @@ -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 diff --git a/config-x86_64.mak b/config-x86_64.mak index 4e525f5..bb8ee89 100644 --- a/config-x86_64.mak +++ b/config-x86_64.mak @@ -9,5 +9,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 diff --git a/lib/x86/msr.h b/lib/x86/msr.h index 509a421..281255a 100644 --- a/lib/x86/msr.h +++ b/lib/x86/msr.h @@ -396,6 +396,11 @@ #define MSR_IA32_VMX_VMCS_ENUM 0x048a #define MSR_IA32_VMX_PROCBASED_CTLS20x048b #define MSR_IA32_VMX_EPT_VPID_CAP 0x048c +#define MSR_IA32_VMX_TRUE_PIN 0x048d +#define MSR_IA32_VMX_TRUE_PROC 0x048e +#define MSR_IA32_VMX_TRUE_EXIT 0x048f +#define MSR_IA32_VMX_TRUE_ENTRY0x0490 + /* AMD-V MSRs */ diff --git a/lib/x86/processor.h b/lib/x86/processor.h index e46d8d0..f0c11cc 100644 --- a/lib/x86/processor.h +++ b/lib/x86/processor.h @@ -307,4 +307,19 @@ static inline void safe_halt(void) { asm volatile(sti; hlt); } + +#ifdef __x86_64__ +static inline u64 read_rflags(void) +{ + u64 r; + asm volatile(pushf; pop %0\n\t : =q(r) : : cc); + return r; +} + +static inline void write_rflags(u64 r) +{ + asm volatile(push %0; popf\n\t : : q(r) : cc); +} +#endif + #endif diff --git a/lib/x86/vm.c b/lib/x86/vm.c index 260ec45..188bf57 100644 --- a/lib/x86/vm.c +++ b/lib/x86/vm.c @@ -9,10 +9,6 @@ #define LARGE_PAGE_SIZE (1024 * PAGE_SIZE) #endif -#define X86_CR0_PE 0x0001 -#define X86_CR0_WP 0x0001 -#define X86_CR0_PG 0x8000 -#define X86_CR4_PSE 0x0010 static void *free = 0; static void *vfree_top = 0; diff --git
[PATCH] nVMX: reset rflags register cache during nested vmentry.
During nested vmentry into vm86 mode a vcpu state is found to be incorrect because rflags does not have VM flag set since it is read from the cache and has L1's value instead of L2's. If emulate_invalid_guest_state=1 L0 KVM tries to emulate it, but emulation does not work for nVMX and it never should happen anyway. Fix that by using vmx_set_rflags() to set rflags during nested vmentry which takes care of updating register cache. Signed-off-by: Gleb Natapov g...@redhat.com diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 66d9233..b276483 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -7550,7 +7550,7 @@ static void prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) vmcs12-guest_interruptibility_info); vmcs_write32(GUEST_SYSENTER_CS, vmcs12-guest_sysenter_cs); kvm_set_dr(vcpu, 7, vmcs12-guest_dr7); - vmcs_writel(GUEST_RFLAGS, vmcs12-guest_rflags); + vmx_set_rflags(vcpu, vmcs12-guest_rflags); vmcs_writel(GUEST_PENDING_DBG_EXCEPTIONS, vmcs12-guest_pending_dbg_exceptions); vmcs_writel(GUEST_SYSENTER_ESP, vmcs12-guest_sysenter_esp); -- Gleb. -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [Qemu-devel] [PATCH qom-cpu v9] target-i386: Move hyperv_* static globals to X86CPU
Am 08.07.2013 14:40, schrieb Igor Mammedov: On Mon, 8 Jul 2013 03:03:54 +0200 Andreas Färber afaer...@suse.de wrote: From: Igor Mammedov imamm...@redhat.com - since hyperv_* helper functions are used only in target-i386/kvm.c move them there as static helpers Requested-by: Eduardo Habkost ehabk...@redhat.com Signed-off-by: Igor Mammedov imamm...@redhat.com Signed-off-by: Andreas Färber afaer...@suse.de I'm not tested it yet, but it looks good to me. Being from you originally and me having confidence in my changes on top, I'm queuing this on qom-cpu-next: https://github.com/afaerber/qemu-cpu/commits/qom-cpu-next Andreas --- v8 (imammedo) - v9: * Use X86CPU instead of CPUX86State (only used in KVM) * Changed helper functions to X86CPU argument * Moved field initialization to QOM instance_init * Fixed subject (not today's CPUState) target-i386/Makefile.objs | 2 +- target-i386/cpu-qom.h | 4 +++ target-i386/cpu.c | 16 target-i386/cpu.h | 4 +++ target-i386/hyperv.c | 64 --- target-i386/hyperv.h | 45 - target-i386/kvm.c | 36 ++ 7 files changed, 46 insertions(+), 125 deletions(-) delete mode 100644 target-i386/hyperv.c delete mode 100644 target-i386/hyperv.h -- SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/4] arm64: KVM: let other tasks run when hitting WFE
On Mon, Jul 22, 2013 at 07:27:58PM +0530, Raghavendra K T wrote: On 07/22/2013 06:21 PM, Christoffer Dall wrote: On 22 July 2013 10:53, Raghavendra KT raghavendra.kt.li...@gmail.com wrote: On Fri, Jul 19, 2013 at 7:23 PM, Marc Zyngier marc.zyng...@arm.com wrote: So far, when a guest executes WFE (like when waiting for a spinlock to become unlocked), we don't do a thing and let it run uninterrupted. Another option is to trap a blocking WFE and offer the opportunity to the scheduler to switch to another task, potentially giving the vcpu holding the spinlock a chance to run sooner. Idea looks to be correct from my experiments on x86. It does bring some percentage of benefits in overcommitted guests. Infact, https://lkml.org/lkml/2013/7/22/41 tries to do the same thing for x86. (this results in using ple handler heuristics in vcpu_block pach). What about the adverse effect in the non-overcommitted case? Ideally is should fail to schedule any other task and comeback to halt loop. This should not hurt AFAICS. But I agree that, numbers needed to support this argument. So if two VCPUs are scheduled on two PCPUs and the waiting VCPU would normally wait, say, 1000 cycles to grab the lock, the latency for grabbing the lock will now be (at least) a couple of thousand cycles even for a tight switch back into the host and back into the guest (on currently available hardware). For x86, I had seen no side effects with the experiments. I suspect some workloads on x86 would indeed show some side effects, but much smaller on ARM, since x86 has a much more hardware-optimized VMEXIT cycle time on relatively recent CPUs. -Christoffer -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
vfio vga-current
i found out that you offer two new up to date git repos. i cloned both to my hdd and compiled them worked fine. but i still get an BSOD (0x116) this error only occurs if the display driver cant reset the card. now i would like to know since i guess i have done everything correctly how can i check if i have not made a mistake by accident. i cloned the git repos by: git clone git://github.com/awilliam/linux-vfio -b vga-current and similar to qemu. im using the ubuntu 13.10 seabios (1.7.3) ty for your help... -- Adiumentum GmbH Gf. Martin Wolf Banderbacherstraße 76 90513 Zirndorf 0911 / 9601470 mw...@adiumentum.com -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html