Re: race between kvm-kmod-3.0 and kvm-kmod-3.3 // was: race condition in qemu-kvm-1.0.1

2012-07-03 Thread Avi Kivity
On 07/03/2012 04:15 PM, Peter Lieven wrote: > On 03.07.2012 15:13, Avi Kivity wrote: >> On 07/03/2012 04:01 PM, Peter Lieven wrote: >>> Further output from my testing. >>> >>> Working: >>> Linux 2.6.38 with included kvm module >>> Linux 3.0.0 w

Re: [Android-virt] [PATCH v9 16/16] ARM: KVM: Guest wait-for-interrupts (WFI) support

2012-07-03 Thread Avi Kivity
On 07/03/2012 04:14 PM, Peter Maydell wrote: > On 3 July 2012 14:10, Avi Kivity wrote: >> Or you could just call kvm_vcpu_block() here without having the >> variable. But eventually you'll need it since you want to expose wfi >> state to userspace for live migration.

Re: race between kvm-kmod-3.0 and kvm-kmod-3.3 // was: race condition in qemu-kvm-1.0.1

2012-07-03 Thread Avi Kivity
On 07/03/2012 04:01 PM, Peter Lieven wrote: > Further output from my testing. > > Working: > Linux 2.6.38 with included kvm module > Linux 3.0.0 with included kvm module > > Not-Working: > Linux 3.2.0 with included kvm module > Linux 2.6.28 with kvm-kmod 3.4 > Linux 3.0.0 with kvm-kmod 3.4 > Linu

Re: [PATCH v9 16/16] ARM: KVM: Guest wait-for-interrupts (WFI) support

2012-07-03 Thread Avi Kivity
On 07/03/2012 12:02 PM, Christoffer Dall wrote: > From: Christoffer Dall > > When the guest executes a WFI instruction the operation is trapped to > KVM, which emulates the instruction in software. There is no correlation > between a guest executing a WFI instruction and actually putting the > ha

Re: A question about how kvm switch context to guest

2012-07-03 Thread Avi Kivity
On 07/03/2012 12:50 PM, Zhengwang Ruan wrote: > Hi kashyapc & all, > > I see a piece of code in vmx_vcpu_run as below, is it used to switch > context to a guest? Kvm don't used "vmlaunch" or "vmresume" to launch or > resume a guest? You trimmed the bit that contains vmlaunch/vmresume. Why does

Re: [PATCH v9 12/16] ARM: KVM: World-switch implementation

2012-07-03 Thread Avi Kivity
On 07/03/2012 12:01 PM, Christoffer Dall wrote: > Provides complete world-switch implementation to switch to other guests > running in non-secure modes. Includes Hyp exception handlers that > capture necessary exception information and stores the information on > the VCPU and KVM structures. > > T

Re: [PATCH v3 0/3] kvm: KVM_IRQFD cleanup, docs, sanitize flags

2012-07-02 Thread Avi Kivity
On 07/02/2012 06:51 PM, Alex Williamson wrote: > On Fri, 2012-06-29 at 09:56 -0600, Alex Williamson wrote: >> Before we start fiddling with what we can and can't add to KVM_IRQFD >> we need to figure out if anyone has been sloppy in their use of the >> ioctl flags. This series has a minor cleanup

Re: race between kvm-kmod-3.0 and kvm-kmod-3.3 // was: race condition in qemu-kvm-1.0.1

2012-07-02 Thread Avi Kivity
On 06/28/2012 12:38 PM, Peter Lieven wrote: > does anyone know whats that here in handle_mmio? > > /* hack: Red Hat 7.1 generates these weird accesses. */ > if ((addr > 0xa-4 && addr <= 0xa) && kvm_run->mmio.len == 3) > return 0; > Just what it says. There is a 4-byte ac

Re: [PATCH v2 2/3] KVM: Use -cpu best as default on x86

2012-07-02 Thread Avi Kivity
On 06/26/2012 07:39 PM, Alexander Graf wrote: > When running QEMU without -cpu parameter, the user usually wants a sane > default. So far, we're using the qemu64/qemu32 CPU type, which basically > means "the maximum TCG can emulate". > > That's a really good default when using TCG, but when runnin

Re: [PATCH v2 1/3] KVM: Add new -cpu best

2012-07-02 Thread Avi Kivity
On 06/26/2012 07:39 PM, Alexander Graf wrote: > During discussions on whether to make -cpu host the default in SLE, I found > myself disagreeing to the thought, because it potentially opens a big can > of worms for potential bugs. But if I already am so opposed to it for SLE, how > can it possibly

Re: [PATCH v2 3/5] KVM: Flush TLB in mmu notifier without holding mmu_lock

2012-07-02 Thread Avi Kivity
On 07/02/2012 05:09 PM, Takuya Yoshikawa wrote: > On Mon, 02 Jul 2012 15:41:30 +0300 > Avi Kivity wrote: > >> kvm_mmu_slot_remove_write_access: same. It's hard to continue the loop >> after a lockbreak though. We can switch it to be rmap based instead. > > Sw

Re: [PATCH v8 11/15] ARM: KVM: World-switch implementation

2012-07-02 Thread Avi Kivity
On 06/21/2012 08:54 PM, Christoffer Dall wrote: >>> @@ -504,6 +514,13 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu >>> *vcpu, struct kvm_run *run) >>>*/ >>> preempt_disable(); >>> local_irq_disable(); >>> + >>> + if (check_new_vmid_gen(kvm))

Re: [PATCH v2 3/5] KVM: Flush TLB in mmu notifier without holding mmu_lock

2012-07-02 Thread Avi Kivity
On 07/02/2012 03:05 PM, Avi Kivity wrote: > We need something for lockbreaking too: > >def mmu_lockbreak(): >if not (contended or need_resched): >return False >remember flush counter >cond_resched_lock >return flush counter

Re: [PATCH v2 3/5] KVM: Flush TLB in mmu notifier without holding mmu_lock

2012-07-02 Thread Avi Kivity
Revisiting after hiatus. On 05/21/2012 11:58 PM, Marcelo Tosatti wrote: > On Thu, May 17, 2012 at 01:24:42PM +0300, Avi Kivity wrote: >> Signed-off-by: Avi Kivity >> --- >> virt/kvm/kvm_main.c | 16 >> 1 file changed, 8 insertions(+), 8 deletions(

Re: plan for device assignment upstream

2012-07-02 Thread Avi Kivity
On 07/02/2012 12:30 PM, Jan Kiszka wrote: > On 2012-07-02 11:18, Michael S. Tsirkin wrote: >> I've been thinking hard about Jan's patches for device >> assignment. Basically while I thought it makes sense >> to make all devices: assignment and not - behave the >> same and use same APIs for injectin

Re: plan for device assignment upstream

2012-07-02 Thread Avi Kivity
On 07/02/2012 12:18 PM, Michael S. Tsirkin wrote: > I've been thinking hard about Jan's patches for device > assignment. Basically while I thought it makes sense > to make all devices: assignment and not - behave the > same and use same APIs for injecting irqs, Anthony thinks there is huge > value

Re: [PATCH 0/8] KVM: Optimize MMU notifier's THP page invalidation -v4

2012-07-02 Thread Avi Kivity
KVM: MMU: Add memslot parameter to hva handlers > KVM: MMU: Push trace_kvm_age_page() into kvm_age_rmapp() > KVM: MMU: Avoid handling same rmap_pde in kvm_handle_hva_range() > Reviewed-by: Avi Kivity -- error compiling committee.c: too many arguments to function -- To unsubscri

Re: [PATCH v3 2/7] memory: Flush coalesced MMIO on selected region access

2012-07-02 Thread Avi Kivity
On 07/02/2012 12:07 PM, Avi Kivity wrote: > > Reviewed-by: Avi Kivity (for the entire patchset) -- error compiling committee.c: too many arguments to function -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger

Re: [PATCH v3 2/7] memory: Flush coalesced MMIO on selected region access

2012-07-02 Thread Avi Kivity
but can also applied to other regions, e.g. > of the same device, by calling memory_region_set_flush_coalesced. Looks fine. I have a hard time deciding whether this should go through the kvm tree or memory tree. Anthony, perhaps you can commit it directly to avoid the livelock? Reviewed

Re: [PATCH v4] KVM: x86: Implement PCID/INVPCID for guests with EPT

2012-07-02 Thread Avi Kivity
On 07/02/2012 03:32 AM, Mao, Junjie wrote: >> > I think this means I can replace the code here with a check in >> nested_vmx_run. Do I understand correctly? >> >> Correct, but the check already exists: >> if (!vmx_control_verify(vmcs12->cpu_based_vm_exec_control, >> nested_vmx_procba

Re: [PATCH 6/6] KVM: MMU: Avoid handling same rmap_pde in kvm_handle_hva_range()

2012-07-01 Thread Avi Kivity
On 07/01/2012 04:18 PM, Takuya Yoshikawa wrote: > On Sun, 01 Jul 2012 10:41:05 +0300 > Avi Kivity wrote: > >> >> > Note: in the new code we could not use trace_kvm_age_page(), so we just >> >> > dropped the point from kvm_handle_hva_range(). >> >

Re: linux-next: Tree for June 29 (kvm)

2012-07-01 Thread Avi Kivity
On 07/01/2012 12:44 PM, Michael S. Tsirkin wrote: > On Sun, Jul 01, 2012 at 12:41:45PM +0300, Avi Kivity wrote: >> On 06/29/2012 09:05 PM, Randy Dunlap wrote: >> > On 06/29/2012 12:53 AM, Stephen Rothwell wrote: >> > >> >> Hi all, >> >> >

Re: linux-next: Tree for June 29 (kvm)

2012-07-01 Thread Avi Kivity
On 06/29/2012 09:05 PM, Randy Dunlap wrote: > On 06/29/2012 12:53 AM, Stephen Rothwell wrote: > >> Hi all, >> >> Changes since 20120628: > > > > on i386: > > arch/x86/built-in.o: In function `kvm_guest_apic_eoi_write': > kvm.c:(.text+0x3561f): undefined reference to `apic' > > > Full randco

Re: qemu-kvm-1.0.1 - unable to exit if vcpu is in infinite loop

2012-07-01 Thread Avi Kivity
On 06/28/2012 10:27 PM, Peter Lieven wrote: > > Am 28.06.2012 um 18:32 schrieb Avi Kivity: > >> On 06/28/2012 07:29 PM, Peter Lieven wrote: >>>> Yes. A signal is sent, and KVM returns from the guest to userspace on >>>> pending signals. >> >>

Re: [PATCH 6/6] KVM: MMU: Avoid handling same rmap_pde in kvm_handle_hva_range()

2012-07-01 Thread Avi Kivity
On 06/29/2012 04:46 AM, Takuya Yoshikawa wrote: > On Thu, 28 Jun 2012 20:53:47 +0300 > Avi Kivity wrote: > >> > Note: in the new code we could not use trace_kvm_age_page(), so we just >> > dropped the point from kvm_handle_hva_range(). >> > >> >>

Re: [RFC PATCH 00/18] KVM: x86: CPU isolation and direct interrupts handling by guests

2012-06-29 Thread Avi Kivity
On 06/29/2012 12:25 PM, Tomoki Sekiyama wrote: > Hi, thanks for your comments. > > On 2012/06/29 2:34, Avi Kivity wrote: > > On 06/28/2012 08:26 PM, Jan Kiszka wrote: > >>> This is both impressive and scary. What is the target scenario here? > >>> Part

Re: [PATCH v4] KVM: x86: Implement PCID/INVPCID for guests with EPT

2012-06-29 Thread Avi Kivity
On 06/29/2012 05:37 AM, Mao, Junjie wrote: > > > > > > > > static void vmx_set_supported_cpuid(u32 func, struct kvm_cpuid_entry2 > > > *entry) @@ -6610,6 +6641,9 @@ static void prepare_vmcs02(struct > > kvm_vcpu *vcpu, struct vmcs12 *vmcs12) > > > page_to_phys(vmx->nes

Re: [PATCH 6/6] KVM: MMU: Avoid handling same rmap_pde in kvm_handle_hva_range()

2012-06-28 Thread Avi Kivity
On 06/28/2012 05:02 AM, Takuya Yoshikawa wrote: > When we invalidate a THP page, we call the handler with the same > rmap_pde argument 512 times in the following loop: > > for each guest page in the range > for each level > unmap using rmap > > This patch avoids these extra handler ca

Re: [PATCH 5/6] KVM: Separate rmap_pde from kvm_lpage_info->write_count

2012-06-28 Thread Avi Kivity
On 06/28/2012 06:45 AM, Takuya Yoshikawa wrote: > On Thu, 28 Jun 2012 11:12:51 +0800 > Xiao Guangrong wrote: > >> > struct kvm_arch_memory_slot { >> > + unsigned long *rmap_pde[KVM_NR_PAGE_SIZES - 1]; >> >struct kvm_lpage_info *lpage_info[KVM_NR_PAGE_SIZES - 1]; >> > }; >> > >> >> It loo

Re: [RFC PATCH 00/18] KVM: x86: CPU isolation and direct interrupts handling by guests

2012-06-28 Thread Avi Kivity
On 06/28/2012 08:26 PM, Jan Kiszka wrote: >> >> This is both impressive and scary. What is the target scenario here? >> Partitioning? I don't see this working for generic consolidation. >> > > From my POV, partitioning - including hard realtime partitions - would > provide some use cases. But,

Re: [RFC PATCH 06/18] KVM: Add facility to run guests on slave CPUs

2012-06-28 Thread Avi Kivity
On 06/28/2012 09:07 AM, Tomoki Sekiyama wrote: > Add path to migrate execution of vcpu_enter_guest to a slave CPU when > vcpu->arch.slave_cpu is set. > > After moving to the slave CPU, it goes back to the online CPU when the > guest is exited by reasons that cannot be handled by the slave CPU only

Re: [RFC PATCH 00/18] KVM: x86: CPU isolation and direct interrupts handling by guests

2012-06-28 Thread Avi Kivity
On 06/28/2012 09:07 AM, Tomoki Sekiyama wrote: > Hello, > > This RFC patch series provides facility to dedicate CPUs to KVM guests > and enable the guests to handle interrupts from passed-through PCI devices > directly (without VM exit and relay by the host). > > With this feature, we can improve

Re: [RFC PATCH 16/18] KVM: add kvm_arch_vcpu_prevent_run to prevent VM ENTER when NMI is received

2012-06-28 Thread Avi Kivity
On 06/28/2012 09:08 AM, Tomoki Sekiyama wrote: > Since NMI can not be disabled around VM enter, there is a race between > receiving NMI to kick a guest and entering the guests on slave CPUs.If the > NMI is received just before entering VM, after the NMI handler is invoked, > it continues entering t

Re: [RFC PATCH 18/18] x86: request TLB flush to slave CPU using NMI

2012-06-28 Thread Avi Kivity
On 06/28/2012 09:08 AM, Tomoki Sekiyama wrote: > For slave CPUs, it is inapropriate to request TLB flush using IPI. > because the IPI may be sent to a KVM guest when the slave CPU is running > the guest with direct interrupt routing. > > Instead, it registers a TLB flush request in per-cpu bitmask

Re: qemu-kvm-1.0.1 - unable to exit if vcpu is in infinite loop

2012-06-28 Thread Avi Kivity
On 06/28/2012 07:29 PM, Peter Lieven wrote: >> Yes. A signal is sent, and KVM returns from the guest to userspace on >> pending signals. > is there a description available how this process exactly works? The kernel part is in vcpu_enter_guest(), see the check for signal_pending(). But this hasn'

Re: [PATCH 4/4][RFC] kvm: eoi_eventfd

2012-06-28 Thread Avi Kivity
On 06/24/2012 06:02 PM, Alex Williamson wrote: > On Sun, 2012-06-24 at 15:56 +0300, Avi Kivity wrote: >> On 06/23/2012 01:16 AM, Alex Williamson wrote: >> > I think we're probably also going to need something like this. >> > When running in non-accelerated qemu, we

Re: [PATCH v2 0/7] kvm: Get coalesced MMIO flushing out of the hot-path

2012-06-28 Thread Avi Kivity
On 06/27/2012 07:27 PM, Jan Kiszka wrote: > Changes in v2: > - added memory_region_clear_flush_coalesced > - call memory_region_clear_flush_coalesced from >memory_region_clear_coalescing > - wrap all region manipulations via memory_region_transaction_begin/ >commit internally > - flush

Re: [PATCH v2 2/7] memory: Flush coalesced MMIO on selected region access

2012-06-28 Thread Avi Kivity
On 06/27/2012 07:27 PM, Jan Kiszka wrote: > Instead of flushing pending coalesced MMIO requests on every vmexit, > this provides a mechanism to selectively flush when memory regions > related to the coalesced one are accessed. This first of all includes > the coalesced region itself but can also ap

Re: [PATCH v4] KVM: x86: Implement PCID/INVPCID for guests with EPT

2012-06-28 Thread Avi Kivity
On 06/28/2012 06:49 PM, Avi Kivity wrote: > On 06/14/2012 05:04 AM, Mao, Junjie wrote: >> This patch handles PCID/INVPCID for guests. >> >> Process-context identifiers (PCIDs) are a facility by which a logical >> processor >> may cache information for multiple

Re: [PATCH v4] KVM: x86: Implement PCID/INVPCID for guests with EPT

2012-06-28 Thread Avi Kivity
On 06/14/2012 05:04 AM, Mao, Junjie wrote: > This patch handles PCID/INVPCID for guests. > > Process-context identifiers (PCIDs) are a facility by which a logical > processor > may cache information for multiple linear-address spaces so that the processor > may retain cached information when soft

Re: [Qemu-devel] [PATCH] kvm: First step to push iothread lock out of inner run loop

2012-06-28 Thread Avi Kivity
On 06/28/2012 05:10 PM, Anthony Liguori wrote: >> >> 1. read_lock(memmap_lock) >> 2. MemoryRegionSection mrs = lookup(addr) >> 3. qom_ref(mrs.mr->dev) >> 4. read_unlock(memmap_lock) >> >> 5. mutex_lock(dev->lock) >> 6. dispatch(&mrs, addr, data, size) >> 7. mutex_unlock(dev->lock) > > Just

Re: [PATCH v2 6/6] kvm: Level IRQ de-assert for KVM_IRQFD

2012-06-28 Thread Avi Kivity
On 06/27/2012 08:10 AM, Alex Williamson wrote: > This is an alternate level irqfd de-assert mode that's potentially > useful for emulated drivers. It's included here to show how easy it > is to implement with the new level irqfd and eoifd support. It's > possible this mode might also prove intere

Re: [PATCH v2 4/6] kvm: Extend irqfd to support level interrupts

2012-06-28 Thread Avi Kivity
On 06/28/2012 12:19 AM, Alex Williamson wrote: >> > @@ -302,6 +385,7 @@ kvm_irqfd_deassign(struct kvm *kvm, struct kvm_irqfd >> > *args) >> > { >> >struct _irqfd *irqfd, *tmp; >> >struct eventfd_ctx *eventfd; >> > + bool is_level = (args->flags & KVM_IRQFD_FLAG_LEVEL) != 0; >> >> != 0 i

Re: [PATCH v2 3/6] kvm: Sanitize KVM_IRQFD flags

2012-06-28 Thread Avi Kivity
On 06/27/2012 12:21 PM, Michael S. Tsirkin wrote: > On Tue, Jun 26, 2012 at 11:09:32PM -0600, Alex Williamson wrote: >> We only know of one so far. >> >> Signed-off-by: Alex Williamson > > Ugh. So we have a bug: we should have sanitized the fields. > If there's buggy userspace that only set the

[PATCH v3 03/26] KVM: x86 emulator: change ->get_cpuid() accessor to use the x86 semantics

2012-06-27 Thread Avi Kivity
Instead of getting an exact leaf, follow the spec and fall back to the last main leaf instead. This lets us easily emulate the cpuid instruction in the emulator. Signed-off-by: Avi Kivity --- arch/x86/include/asm/kvm_emulate.h | 4 +-- arch/x86/kvm/emulate.c | 53

[PATCH v3 06/26] KVM: x86 emulator: fix LIDT/LGDT in long mode

2012-06-27 Thread Avi Kivity
The operand size for these instructions is 8 bytes in long mode, even without a REX prefix. Set it explicitly. Triggered while booting Linux with emulate_invalid_guest_state=1. Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 4 1 file changed, 4 insertions(+) diff --git a/arch

[PATCH v3 11/26] KVM: Fix SS default ESP/EBP based addressing

2012-06-27 Thread Avi Kivity
We correctly default to SS when BP is used as a base in 16-bit address mode, but we don't do that for 32-bit mode. Fix by adjusting the default to SS when either ESP or EBP is used as the base register. Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 17 ++--- 1 file ch

[PATCH v3 05/26] KVM: x86 emulator: allow loading null SS in long mode

2012-06-27 Thread Avi Kivity
Null SS is valid in long mode; allow loading it. Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 12 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index db95a55..fe4340f 100644 --- a/arch/x86/kvm/emulate.c +++ b

[PATCH v3 10/26] KVM: x86 emulator: initialize memop

2012-06-27 Thread Avi Kivity
memop is not initialized; this can lead to a two-byte operation following a 4-byte operation to see garbage values. Usually truncation fixes things fot us later on, but at least in one case (call abs) it doesn't. Fix by moving memop to the auto-initialized field area. Signed-off-by: Avi K

[PATCH v3 26/26] KVM: VMX: Emulate invalid guest state by default

2012-06-27 Thread Avi Kivity
Our emulation should be complete enough that we can emulate guests while they are in big real mode, or in a mode transition that is not virtualizable without unrestricted guest support. Signed-off-by: Avi Kivity --- arch/x86/kvm/vmx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff

[PATCH v3 20/26] KVM: VMX: Improve error reporting during invalid guest state emulation

2012-06-27 Thread Avi Kivity
If instruction emulation fails, report it properly to userspace. Signed-off-by: Avi Kivity --- arch/x86/kvm/vmx.c | 6 +- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 661df185..591dcea 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch

[PATCH v3 17/26] KVM: x86 emulator: split push logic from push opcode emulation

2012-06-27 Thread Avi Kivity
This allows us to reuse the code without populating ctxt->src and overriding ctxt->op_bytes. Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 11 --- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 3

[PATCH v3 13/26] KVM: VMX: Fix interrupt exit condition during emulation

2012-06-27 Thread Avi Kivity
Checking EFLAGS.IF is incorrect as we might be in interrupt shadow. If that is the case, the main loop will notice that and not inject the interrupt, causing an endless loop. Fix by using vmx_interrupt_allowed() to check if we can inject an interrupt instead. Signed-off-by: Avi Kivity

[PATCH v3 14/26] KVM: VMX: Continue emulating after batch exhausted

2012-06-27 Thread Avi Kivity
If we return early from an invalid guest state emulation loop, make sure we return to it later if the guest state is still invalid. Signed-off-by: Avi Kivity --- arch/x86/kvm/vmx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index

[PATCH v3 24/26] KVM: x86 emulator: make loading TR set the busy bit

2012-06-27 Thread Avi Kivity
Guest software doesn't actually depend on it, but vmx will refuse us entry if we don't. Set the bit in both the cached segment and memory, just to be nice. Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 8 +++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git

[PATCH v3 25/26] KVM: x86 emulator: implement LTR

2012-06-27 Thread Avi Kivity
Opcode 0F 00 /3. Encountered during Windows XP secondary processor bringup. Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 11 ++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 92a1add..97d9a99 100644 --- a

[PATCH v3 22/26] KVM: x86 emulator: emulate LLDT

2012-06-27 Thread Avi Kivity
Opcode 0F 00 /2. Used by isolinux durign the protected mode transition. Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 11 ++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index cfa5cc3..7b575ad 100644 --- a/arch

[PATCH v3 23/26] KVM: x86 emulator: make read_segment_descriptor() return the address

2012-06-27 Thread Avi Kivity
Some operations want to modify the descriptor later on, so save the address for future use. Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 13 - 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 7b575ad

[PATCH v3 21/26] KVM: x86 emulator: emulate BSWAP

2012-06-27 Thread Avi Kivity
Opcodes 0F C8 - 0F CF. Used by the SeaBIOS cdrom code (though not in big real mode). Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 20 ++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index b4b326e

[PATCH v3 19/26] KVM: VMX: Stop invalid guest state emulation on pending event

2012-06-27 Thread Avi Kivity
Process the event, possibly injecting an interrupt, before continuing. Signed-off-by: Avi Kivity --- arch/x86/kvm/vmx.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 26e6bdf..661df185 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c

[PATCH v3 18/26] KVM: x86 emulator: implement ENTER

2012-06-27 Thread Avi Kivity
Opcode C8. Only ENTER with lexical nesting depth 0 is implemented, since others are very rare. We'll fail emulation if nonzero lexical depth is used so data is not corrupted. Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 28 +++- 1 file changed, 27 inser

[PATCH v3 16/26] KVM: x86 emulator: fix byte-sized MOVZX/MOVSX

2012-06-27 Thread Avi Kivity
== 1. Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 90b549e..30f4912 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -4517,12 +4517,12 @@ int

[PATCH v3 15/26] KVM: x86 emulator: emulate LAHF

2012-06-27 Thread Avi Kivity
Opcode 9F. Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 9 - 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 5053e9e..90b549e 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -3227,6 +3227,13

[PATCH v3 12/26] KVM: x86 emulator: emulate SGDT/SIDT

2012-06-27 Thread Avi Kivity
Opcodes 0F 01 /0 and 0F 01 /1 Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 33 +++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 7552c0a..5053e9e 100644 --- a/arch/x86/kvm/emulate.c

[PATCH v3 09/26] KVM: x86 emulator: emulate LEAVE

2012-06-27 Thread Avi Kivity
Opcode c9; used by some variants of Windows during boot, in big real mode. Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 25 - 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 24c8425..33ccd75

[PATCH v3 08/26] KVM: VMX: Limit iterations with emulator_invalid_guest_state

2012-06-27 Thread Avi Kivity
Otherwise, if the guest ends up looping, we never exit the srcu critical section, which causes synchronize_srcu() to hang. Signed-off-by: Avi Kivity --- arch/x86/kvm/vmx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index a9c0e40

[PATCH v3 07/26] KVM: VMX: Relax check on unusable segment

2012-06-27 Thread Avi Kivity
Some userspace (e.g. QEMU 1.1) munge the d and g bits of segment descriptors, causing us not to recognize them as unusable segments with emulate_invalid_guest_state=1. Relax the check by testing for segment not present (a non-present segment cannot be usable). Signed-off-by: Avi Kivity

[PATCH v3 04/26] KVM: x86 emulator: emulate cpuid

2012-06-27 Thread Avi Kivity
Opcode 0F A2. Used by Linux during the mode change trampoline while in a state that is not virtualizable on vmx without unrestricted_guest, so we need to emulate it is emulate_invalid_guest_state=1. Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 16 +++- 1 file changed, 15

[PATCH v3 02/26] KVM: Split cpuid register access from computation

2012-06-27 Thread Avi Kivity
-off-by: Avi Kivity --- arch/x86/kvm/cpuid.c | 38 -- arch/x86/kvm/cpuid.h | 1 + 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 7df1c6d..44476fb 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86

[PATCH v3 00/26] Big big real mode improvements

2012-06-27 Thread Avi Kivity
!=RPL (noted by Kevin) - fix SS base for ESP/EBP addressing without SIB - more testing Avi Kivity (26): KVM: VMX: Return correct CPL during transition to protected mode KVM: Split cpuid register access from computation KVM: x86 emulator: change ->get_cpuid() accessor to use the

[PATCH v3 01/26] KVM: VMX: Return correct CPL during transition to protected mode

2012-06-27 Thread Avi Kivity
x27;t 100% correct since we don't set the CPL cache on a far jump, but since protected mode transition will always jump to a segment with RPL=0, it will always work. Signed-off-by: Avi Kivity --- arch/x86/kvm/vmx.c | 15 +-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --

Re: [PATCH v2 00/26] Big big real mode improvements

2012-06-27 Thread Avi Kivity
On 06/27/2012 06:18 PM, Avi Kivity wrote: > This patchset fixes several bugs in the emulator and in vmx invalid guest > state emulation. They are sufficient to boot several Linux and Windows > guests, so the last patch turns vmx invalid guest state emulation on by > default. > &g

[PATCH 2/5] KVM: x86 emulator: emulate LLDT

2012-06-27 Thread Avi Kivity
Opcode 0F 00 /2. Used by isolinux durign the protected mode transition. Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 11 ++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 4eea1e4..85f7a5f 100644 --- a/arch

[PATCH 4/5] KVM: x86 emulator: make loading TR set the busy bit

2012-06-27 Thread Avi Kivity
Guest software doesn't actually depend on it, but vmx will refuse us entry if we don't. Set the bit in both the cached segment and memory, just to be nice. Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c |8 +++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --

[PATCH v2 08/26] KVM: VMX: Limit iterations with emulator_invalid_guest_state

2012-06-27 Thread Avi Kivity
Otherwise, if the guest ends up looping, we never exit the srcu critical section, which causes synchronize_srcu() to hang. Signed-off-by: Avi Kivity --- arch/x86/kvm/vmx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index a9c0e40

[PATCH v2 12/26] KVM: x86 emulator: emulate SGDT/SIDT

2012-06-27 Thread Avi Kivity
Opcodes 0F 01 /0 and 0F 01 /1 Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 33 +++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 7552c0a..5053e9e 100644 --- a/arch/x86/kvm/emulate.c

[PATCH v2 22/26] KVM: x86 emulator: emulate LLDT

2012-06-27 Thread Avi Kivity
Opcode 0F 00 /2. Used by isolinux durign the protected mode transition. Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 11 ++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index cfa5cc3..7b575ad 100644 --- a/arch

[PATCH v2 23/26] KVM: x86 emulator: make read_segment_descriptor() return the address

2012-06-27 Thread Avi Kivity
Some operations want to modify the descriptor later on, so save the address for future use. Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 13 - 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 7b575ad

[PATCH v2 26/26] KVM: VMX: Emulate invalid guest state by default

2012-06-27 Thread Avi Kivity
Our emulation should be complete enough that we can emulate guests while they are in big real mode, or in a mode transition that is not virtualizable without unrestricted guest support. Signed-off-by: Avi Kivity --- arch/x86/kvm/vmx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff

[PATCH v2 25/26] KVM: x86 emulator: implement LTR

2012-06-27 Thread Avi Kivity
Opcode 0F 00 /3. Encountered during Windows XP secondary processor bringup. Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 11 ++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 92a1add..97d9a99 100644 --- a

[PATCH v2 21/26] KVM: x86 emulator: emulate BSWAP

2012-06-27 Thread Avi Kivity
Opcodes 0F C8 - 0F CF. Used by the SeaBIOS cdrom code (though not in big real mode). Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 20 ++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index b4b326e

[PATCH v2 06/26] KVM: x86 emulator: fix LIDT/LGDT in long mode

2012-06-27 Thread Avi Kivity
The operand size for these instructions is 8 bytes in long mode, even without a REX prefix. Set it explicitly. Triggered while booting Linux with emulate_invalid_guest_state=1. Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 4 1 file changed, 4 insertions(+) diff --git a/arch

[PATCH 1/5] KVM: x86 emulator: emulate BSWAP

2012-06-27 Thread Avi Kivity
Opcodes 0F C8 - 0F CF. Used by the SeaBIOS cdrom code (though not in big real mode). Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 20 ++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index c804db2

[PATCH v2 24/26] KVM: x86 emulator: make loading TR set the busy bit

2012-06-27 Thread Avi Kivity
Guest software doesn't actually depend on it, but vmx will refuse us entry if we don't. Set the bit in both the cached segment and memory, just to be nice. Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 8 +++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git

[PATCH v2 20/26] KVM: VMX: Improve error reporting during invalid guest state emulation

2012-06-27 Thread Avi Kivity
If instruction emulation fails, report it properly to userspace. Signed-off-by: Avi Kivity --- arch/x86/kvm/vmx.c | 6 +- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 661df185..591dcea 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch

[PATCH v2 19/26] KVM: VMX: Stop invalid guest state emulation on pending event

2012-06-27 Thread Avi Kivity
Process the event, possibly injecting an interrupt, before continuing. Signed-off-by: Avi Kivity --- arch/x86/kvm/vmx.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 26e6bdf..661df185 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c

[PATCH v2 18/26] KVM: x86 emulator: implement ENTER

2012-06-27 Thread Avi Kivity
Opcode C8. Only ENTER with lexical nesting depth 0 is implemented, since others are very rare. We'll fail emulation if nonzero lexical depth is used so data is not corrupted. Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 28 +++- 1 file changed, 27 inser

[PATCH v2 17/26] KVM: x86 emulator: split push logic from push opcode emulation

2012-06-27 Thread Avi Kivity
This allows us to reuse the code without populating ctxt->src and overriding ctxt->op_bytes. Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 11 --- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 3

[PATCH v2 16/26] KVM: x86 emulator: fix byte-sized MOVZX/MOVSX

2012-06-27 Thread Avi Kivity
== 1. Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 90b549e..30f4912 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -4517,12 +4517,12 @@ int

[PATCH v2 15/26] KVM: x86 emulator: emulate LAHF

2012-06-27 Thread Avi Kivity
Opcode 9F. Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 9 - 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 5053e9e..90b549e 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -3227,6 +3227,13

[PATCH v2 14/26] KVM: VMX: Continue emulating after batch exhausted

2012-06-27 Thread Avi Kivity
If we return early from an invalid guest state emulation loop, make sure we return to it later if the guest state is still invalid. Signed-off-by: Avi Kivity --- arch/x86/kvm/vmx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index

[PATCH v2 13/26] KVM: VMX: Fix interrupt exit condition during emulation

2012-06-27 Thread Avi Kivity
Checking EFLAGS.IF is incorrect as we might be in interrupt shadow. If that is the case, the main loop will notice that and not inject the interrupt, causing an endless loop. Fix by using vmx_interrupt_allowed() to check if we can inject an interrupt instead. Signed-off-by: Avi Kivity

[PATCH v2 11/26] KVM: Fix SS default ESP/EBP based addressing

2012-06-27 Thread Avi Kivity
We correctly default to SS when BP is used as a base in 16-bit address mode, but we don't do that for 32-bit mode. Fix by adjusting the default to SS when either ESP or EBP is used as the base register. Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 17 ++--- 1 file ch

[PATCH v2 10/26] KVM: x86 emulator: initialize memop

2012-06-27 Thread Avi Kivity
memop is not initialized; this can lead to a two-byte operation following a 4-byte operation to see garbage values. Usually truncation fixes things fot us later on, but at least in one case (call abs) it doesn't. Fix by moving memop to the auto-initialized field area. Signed-off-by: Avi K

[PATCH v2 09/26] KVM: x86 emulator: emulate LEAVE

2012-06-27 Thread Avi Kivity
Opcode c9; used by some variants of Windows during boot, in big real mode. Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 25 - 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 24c8425..33ccd75

[PATCH v2 07/26] KVM: VMX: Relax check on unusable segment

2012-06-27 Thread Avi Kivity
Some userspace (e.g. QEMU 1.1) munge the d and g bits of segment descriptors, causing us not to recognize them as unusable segments with emulate_invalid_guest_state=1. Relax the check by testing for segment not present (a non-present segment cannot be usable). Signed-off-by: Avi Kivity

[PATCH 5/5] KVM: x86 emulator: implement LTR

2012-06-27 Thread Avi Kivity
Opcode 0F 00 /3. Encountered during Windows XP secondary processor bringup. Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 11 ++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index dff416f..218e731 100644 --- a

[PATCH v2 05/26] KVM: x86 emulator: allow loading null SS in long mode

2012-06-27 Thread Avi Kivity
Null SS is valid in long mode; allow loading it. Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 12 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index db95a55..fe4340f 100644 --- a/arch/x86/kvm/emulate.c +++ b

[PATCH v2 04/26] KVM: x86 emulator: emulate cpuid

2012-06-27 Thread Avi Kivity
Opcode 0F A2. Used by Linux during the mode change trampoline while in a state that is not virtualizable on vmx without unrestricted_guest, so we need to emulate it is emulate_invalid_guest_state=1. Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 16 +++- 1 file changed, 15

[PATCH 3/5] KVM: x86 emulator: make read_segment_descriptor() return the address

2012-06-27 Thread Avi Kivity
Some operations want to modify the descriptor later on, so save the address for future use. Signed-off-by: Avi Kivity --- arch/x86/kvm/emulate.c | 13 - 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 85f7a5f

<    5   6   7   8   9   10   11   12   13   14   >