[PATCH] KVM: MMU: Disassociate direct maps from guest levels

2010-03-14 Thread Avi Kivity
Direct maps are linear translations for a section of memory, used for real mode or with large pages. As such, they are independent of the guest levels. Teach the mmu about this by making page-role.glevels = 0 for direct maps. This allows direct maps to be shared among real mode and the various

qemu-kvm crashes with Assertion ... failed.

2010-03-14 Thread André Weidemann
Hi, I cloned the qemu-kvm git repository today with git clone git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git qemu-kvm-2010-03-14, ran configure and compiled it and did a make install. Everything went fine without warnings or errors. For configure output take a look here:

Re: Make QEmu HPET disabled by default for KVM?

2010-03-14 Thread Dor Laor
On 03/14/2010 09:10 AM, Gleb Natapov wrote: On Sun, Mar 14, 2010 at 09:05:50AM +0200, Avi Kivity wrote: On 03/11/2010 09:08 PM, Marcelo Tosatti wrote: I have kept --no-hpet in my setup for months... Any details about the problems? HPET is important to some guests. As Gleb mentioned in

Re: Make QEmu HPET disabled by default for KVM?

2010-03-14 Thread Avi Kivity
On 03/14/2010 12:23 PM, Dor Laor wrote: On 03/14/2010 09:10 AM, Gleb Natapov wrote: On Sun, Mar 14, 2010 at 09:05:50AM +0200, Avi Kivity wrote: On 03/11/2010 09:08 PM, Marcelo Tosatti wrote: I have kept --no-hpet in my setup for months... Any details about the problems? HPET is

Re: Make QEmu HPET disabled by default for KVM?

2010-03-14 Thread Dor Laor
On 03/14/2010 12:27 PM, Avi Kivity wrote: On 03/14/2010 12:23 PM, Dor Laor wrote: On 03/14/2010 09:10 AM, Gleb Natapov wrote: On Sun, Mar 14, 2010 at 09:05:50AM +0200, Avi Kivity wrote: On 03/11/2010 09:08 PM, Marcelo Tosatti wrote: I have kept --no-hpet in my setup for months... Any

[PATCH v2 00/30] emulator cleanup

2010-03-14 Thread Gleb Natapov
This is the first series of patches that tries to cleanup emulator code. This is mix of bug fixes and moving code that does emulation from x86.c to emulator.c while making it KVM independent. The status of the patches: works for me. realtime.flat test now also pass where it failed before.

[PATCH v2 03/30] KVM: x86 emulator: check return value against correct define

2010-03-14 Thread Gleb Natapov
Check return value against correct define instead of open code the value. Signed-off-by: Gleb Natapov g...@redhat.com --- arch/x86/kvm/emulate.c |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 4dce805..670ca8f 100644

[PATCH v2 02/30] KVM: x86 emulator: fix RCX access during rep emulation

2010-03-14 Thread Gleb Natapov
During rep emulation access length to RCX depends on current address mode. Signed-off-by: Gleb Natapov g...@redhat.com --- arch/x86/kvm/emulate.c |4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 0b70a36..4dce805

[PATCH v2 01/30] KVM: x86 emulator: Fix DstAcc decoding.

2010-03-14 Thread Gleb Natapov
Set correct operation length. Add RAX (64bit) handling. Signed-off-by: Gleb Natapov g...@redhat.com --- arch/x86/kvm/emulate.c |7 +-- 1 files changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 2832a8c..0b70a36 100644 ---

[PATCH v2 05/30] KVM: Provide callback to get/set control registers in emulator ops.

2010-03-14 Thread Gleb Natapov
Use this callback instead of directly call kvm function. Also rename realmode_(set|get)_cr to emulator_(set|get)_cr since function has nothing to do with real mode. Signed-off-by: Gleb Natapov g...@redhat.com --- arch/x86/include/asm/kvm_emulate.h |3 +- arch/x86/include/asm/kvm_host.h|

[PATCH v2 11/30] KVM: x86 emulator: 0f (20|21|22|23) ignore mod bits.

2010-03-14 Thread Gleb Natapov
Resent spec says that for 0f (20|21|22|23) the 2 bits in the mod field are ignored. Interestingly enough older spec says that 11 is only valid encoding. Signed-off-by: Gleb Natapov g...@redhat.com --- arch/x86/kvm/emulate.c |8 1 files changed, 0 insertions(+), 8 deletions(-) diff

[PATCH v2 12/30] KVM: x86 emulator: inject #UD on access to non-existing CR

2010-03-14 Thread Gleb Natapov
Signed-off-by: Gleb Natapov g...@redhat.com --- arch/x86/kvm/emulate.c |7 +++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index fa4604e..836e97b 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -2520,6

[PATCH v2 14/30] KVM: x86 emulator: fix return values of syscall/sysenter/sysexit emulations

2010-03-14 Thread Gleb Natapov
Return X86EMUL_PROPAGATE_FAULT is fault was injected. Also inject #UD for those instruction when appropriate. Signed-off-by: Gleb Natapov g...@redhat.com --- arch/x86/kvm/emulate.c | 17 +++-- 1 files changed, 11 insertions(+), 6 deletions(-) diff --git a/arch/x86/kvm/emulate.c

[PATCH v2 16/30] KVM: x86 emulator: If LOCK prefix is used dest arg should be memory.

2010-03-14 Thread Gleb Natapov
If LOCK prefix is used dest arg should be memory, otherwise instruction should generate #UD. Signed-off-by: Gleb Natapov g...@redhat.com --- arch/x86/kvm/emulate.c |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index

[PATCH v2 06/30] KVM: remove realmode_lmsw function.

2010-03-14 Thread Gleb Natapov
Use (get|set)_cr callback to emulate lmsw inside emulator. Signed-off-by: Gleb Natapov g...@redhat.com --- arch/x86/include/asm/kvm_host.h |2 -- arch/x86/kvm/emulate.c |4 ++-- arch/x86/kvm/x86.c |7 --- 3 files changed, 2 insertions(+), 11 deletions(-)

[PATCH v2 04/30] KVM: Remove pointer to rflags from realmode_set_cr parameters.

2010-03-14 Thread Gleb Natapov
Mov reg, cr instruction doesn't change flags in any meaningful way, so no need to update rflags after instruction execution. Signed-off-by: Gleb Natapov g...@redhat.com --- arch/x86/include/asm/kvm_host.h |3 +-- arch/x86/kvm/emulate.c |3 +-- arch/x86/kvm/x86.c |

[PATCH v2 08/30] KVM: Provide current eip as part of emulator context.

2010-03-14 Thread Gleb Natapov
Eliminate the need to call back into KVM to get it from emulator. Signed-off-by: Gleb Natapov g...@redhat.com --- arch/x86/include/asm/kvm_emulate.h |3 ++- arch/x86/kvm/emulate.c | 12 ++-- arch/x86/kvm/x86.c |1 + 3 files changed, 9 insertions(+),

[PATCH v2 10/30] KVM: x86 emulator: fix 0f 01 /5 emulation

2010-03-14 Thread Gleb Natapov
It is undefined and should generate #UD. Signed-off-by: Gleb Natapov g...@redhat.com --- arch/x86/kvm/emulate.c |3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index c3b9334..7c7debb 100644 --- a/arch/x86/kvm/emulate.c

[PATCH v2 30/30] KVM: small kvm_arch_vcpu_ioctl_run() cleanup.

2010-03-14 Thread Gleb Natapov
Unify all conditions that get us back into emulator after returning from userspace. Signed-off-by: Gleb Natapov g...@redhat.com --- arch/x86/kvm/x86.c | 32 ++-- 1 files changed, 6 insertions(+), 26 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c

[PATCH v2 26/30] KVM: x86 emulator: Move string pio emulation into emulator.c

2010-03-14 Thread Gleb Natapov
Currently emulation is done outside of emulator so things like doing ins/outs to/from mmio are broken it also makes it hard (if not impossible) to implement single stepping in the future. The implementation in this patch is not efficient since it exits to userspace for each IO while previous

[PATCH v2 27/30] KVM: x86 emulator: remove saved_eip

2010-03-14 Thread Gleb Natapov
c-eip is never written back in case of emulation failure, so no need to set it to old value. Signed-off-by: Gleb Natapov g...@redhat.com --- arch/x86/kvm/emulate.c |9 + 1 files changed, 1 insertions(+), 8 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c

[PATCH v2 09/30] KVM: x86 emulator: fix mov r/m, sreg emulation.

2010-03-14 Thread Gleb Natapov
mov r/m, sreg generates #UD ins sreg is incorrect. Signed-off-by: Gleb Natapov g...@redhat.com --- arch/x86/kvm/emulate.c |7 +++ 1 files changed, 3 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 2c27aa4..c3b9334 100644 ---

[PATCH v2 28/30] KVM: x86 emulator: restart string instruction without going back to a guest.

2010-03-14 Thread Gleb Natapov
Currently when string instruction is only partially complete we go back to a guest mode, guest tries to reexecute instruction and exits again and at this point emulation continues. Avoid all of this by restarting instruction without going back to a guest mode, but return to a guest mode on each

[PATCH v2 29/30] KVM: x86 emulator: introduce pio in string read ahead.

2010-03-14 Thread Gleb Natapov
To optimize rep ins instruction do IO in big chunks ahead of time instead of doing it only when required during instruction emulation. Signed-off-by: Gleb Natapov g...@redhat.com --- arch/x86/include/asm/kvm_emulate.h |7 +++ arch/x86/kvm/emulate.c | 35

[PATCH v2 25/30] KVM: x86 emulator: fix in/out emulation.

2010-03-14 Thread Gleb Natapov
in/out emulation is broken now. The breakage is different depending on where IO device resides. If it is in userspace emulator reports emulation failure since it incorrectly interprets kvm_emulate_pio() return value. If IO device is in the kernel emulation of 'in' will do nothing since

[PATCH v2 22/30] KVM: x86 emulator: populate OP_MEM operand during decoding.

2010-03-14 Thread Gleb Natapov
All struct operand fields are initialized during decoding for all operand types except OP_MEM, but there is no reason for that. Move OP_MEM operand initialization into decoding stage for consistency. Signed-off-by: Gleb Natapov g...@redhat.com --- arch/x86/kvm/emulate.c | 62

[PATCH v2 21/30] KVM: Use task switch from emulator.c

2010-03-14 Thread Gleb Natapov
Remove old task switch code from x86.c Signed-off-by: Gleb Natapov g...@redhat.com --- arch/x86/kvm/x86.c | 557 ++-- 1 files changed, 17 insertions(+), 540 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index c30e81d..3c5ffa2

[PATCH v2 18/30] KVM: x86 emulator: Provide more callbacks for x86 emulator.

2010-03-14 Thread Gleb Natapov
Provide get_cached_descriptor(), set_cached_descriptor(), get_segment_selector(), set_segment_selector(), get_gdt(), write_std() callbacks. Signed-off-by: Gleb Natapov g...@redhat.com --- arch/x86/include/asm/kvm_emulate.h | 16 + arch/x86/kvm/x86.c | 130

[PATCH v2 15/30] KVM: x86 emulator: do not call writeback if msr access fails.

2010-03-14 Thread Gleb Natapov
Signed-off-by: Gleb Natapov g...@redhat.com --- arch/x86/kvm/emulate.c |4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 1393bf0..b89a8f2 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -2563,7

[PATCH v2 20/30] KVM: x86 emulator: Use load_segment_descriptor() instead of kvm_load_segment_descriptor()

2010-03-14 Thread Gleb Natapov
Signed-off-by: Gleb Natapov g...@redhat.com --- arch/x86/kvm/emulate.c | 10 +- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index cc1bb20..40370b2 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@

[PATCH v2 24/30] KVM: x86 emulator: during rep emulation decrement ECX only if emulation succeeded

2010-03-14 Thread Gleb Natapov
Signed-off-by: Gleb Natapov g...@redhat.com --- arch/x86/kvm/emulate.c |4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 12c630c..8f5e4c8 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -2474,7

[PATCH v2 17/30] KVM: x86 emulator: cleanup grp3 return value

2010-03-14 Thread Gleb Natapov
When x86_emulate_insn() does not know how to emulate instruction it exits via cannot_emulate label in all cases except when emulating grp3. Fix that. Signed-off-by: Gleb Natapov g...@redhat.com --- arch/x86/kvm/emulate.c | 12 1 files changed, 4 insertions(+), 8 deletions(-) diff

[PATCH v2 19/30] KVM: x86 emulator: Emulate task switch in emulator.c

2010-03-14 Thread Gleb Natapov
Implement emulation of 16/32 bit task switch in emulator.c Signed-off-by: Gleb Natapov g...@redhat.com --- arch/x86/include/asm/kvm_emulate.h |5 + arch/x86/kvm/emulate.c | 564 2 files changed, 569 insertions(+), 0 deletions(-) diff --git

[PATCH v2 23/30] KVM: x86 emulator: add decoding of X,Y parameters from Intel SDM

2010-03-14 Thread Gleb Natapov
Add decoding of X,Y parameters from Intel SDM which are used by string instruction to specify source and destination. Use this new decoding to implement movs, cmps, stos, lods in a generic way. Signed-off-by: Gleb Natapov g...@redhat.com --- arch/x86/kvm/emulate.c | 125

[PATCH v2 07/30] KVM: Provide x86_emulate_ctxt callback to get current cpl

2010-03-14 Thread Gleb Natapov
Signed-off-by: Gleb Natapov g...@redhat.com --- arch/x86/include/asm/kvm_emulate.h |1 + arch/x86/kvm/emulate.c | 15 --- arch/x86/kvm/x86.c |6 ++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git

Re: [PATCH v2 24/30] KVM: x86 emulator: during rep emulation decrement ECX only if emulation succeeded

2010-03-14 Thread Avi Kivity
On 03/14/2010 06:21 PM, Gleb Natapov wrote: @@ -2943,6 +2942,9 @@ writeback: c-regs[VCPU_REGS_RDI]); } + if (c-rep_prefix) + register_address_increment(c,c-regs[VCPU_REGS_RCX], -1); + Should be really (c-rep_prefix

Re: [PATCH v2 25/30] KVM: x86 emulator: fix in/out emulation.

2010-03-14 Thread Avi Kivity
On 03/14/2010 06:21 PM, Gleb Natapov wrote: in/out emulation is broken now. The breakage is different depending on where IO device resides. If it is in userspace emulator reports emulation failure since it incorrectly interprets kvm_emulate_pio() return value. If IO device is in the kernel

Re: [PATCH v2 28/30] KVM: x86 emulator: restart string instruction without going back to a guest.

2010-03-14 Thread Avi Kivity
On 03/14/2010 06:21 PM, Gleb Natapov wrote: Currently when string instruction is only partially complete we go back to a guest mode, guest tries to reexecute instruction and exits again and at this point emulation continues. Avoid all of this by restarting instruction without going back to a

Re: [PATCH v2 25/30] KVM: x86 emulator: fix in/out emulation.

2010-03-14 Thread Gleb Natapov
On Sun, Mar 14, 2010 at 06:54:11PM +0200, Avi Kivity wrote: On 03/14/2010 06:21 PM, Gleb Natapov wrote: in/out emulation is broken now. The breakage is different depending on where IO device resides. If it is in userspace emulator reports emulation failure since it incorrectly interprets

Re: [PATCH v2 28/30] KVM: x86 emulator: restart string instruction without going back to a guest.

2010-03-14 Thread Gleb Natapov
On Sun, Mar 14, 2010 at 06:56:37PM +0200, Avi Kivity wrote: On 03/14/2010 06:21 PM, Gleb Natapov wrote: Currently when string instruction is only partially complete we go back to a guest mode, guest tries to reexecute instruction and exits again and at this point emulation continues. Avoid all

Re: [PATCH 15/18] KVM: MMU: Propagate the right fault back to the guest after gva_to_gpa

2010-03-14 Thread Daniel K.
Joerg Roedel wrote: diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 2883ce8..9f8b02d 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -314,6 +314,19 @@ void kvm_inject_page_fault(struct kvm_vcpu *vcpu, unsigned long addr, kvm_queue_exception_e(vcpu, PF_VECTOR,