Re: [PATCH v2 5/5] kvm, mem-hotplug: Do not pin apic access page in memory.

2014-07-14 Thread Tang Chen
Hi Gleb, Thanks for the reply. Please see below. On 07/12/2014 04:04 PM, Gleb Natapov wrote: On Tue, Jul 08, 2014 at 09:01:32PM +0800, Tang Chen wrote: apic access page is pinned in memory. As a result, it cannot be migrated/hot-removed. Actually, it is not necessary to be pinned. The hpa

Re: [RESEND PATCH v2 4/5] kvm: Remove ept_identity_pagetable from struct kvm_arch.

2014-07-14 Thread Tang Chen
Hi Gleb, Please see below. On 07/12/2014 03:44 PM, Gleb Natapov wrote: On Wed, Jul 09, 2014 at 10:08:03AM +0800, Tang Chen wrote: kvm_arch-ept_identity_pagetable holds the ept identity pagetable page. But it is never used to refer to the page at all. In vcpu initialization, it indicates two

[PATCH] kvm: ppc: bookehv: Sync srr0/1 into GSRR0/1

2014-07-14 Thread Bharat Bhushan
This patch adds missing sync of SRR0/1 in set SREGS interface. Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com --- arch/powerpc/kvm/booke.c | 4 1 file changed, 4 insertions(+) diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c index c2471ed..368b48e 100644 ---

Re: [PATCH V5 1/2] perf ignore LBR and extra_regs

2014-07-14 Thread Peter Zijlstra
On Thu, Jul 10, 2014 at 03:59:43AM -0700, kan.li...@intel.com wrote: From: Kan Liang kan.li...@intel.com x86, perf: Protect LBR and extra_regs against KVM lying With -cpu host, KVM reports LBR and extra_regs support, if the host has support. When the guest perf driver tries to access LBR

Re: [PATCH V5 1/2] perf ignore LBR and extra_regs

2014-07-14 Thread Peter Zijlstra
On Thu, Jul 10, 2014 at 03:59:43AM -0700, kan.li...@intel.com wrote: +/* + * Under certain circumstances, access certain MSR may cause #GP. + * The function tests if the input MSR can be safely accessed. + */ +static inline bool check_msr(unsigned long msr) +{ + u64 val_old, val_new,

[PATCH 08/19] KVM: emulate: move init_decode_cache to emulate.c

2014-07-14 Thread Paolo Bonzini
From: Bandan Das b...@redhat.com Core emulator functions all belong in emulator.c, x86 should have no knowledge of emulator internals Signed-off-by: Bandan Das b...@redhat.com Signed-off-by: Paolo Bonzini pbonz...@redhat.com --- arch/x86/include/asm/kvm_emulate.h | 1 + arch/x86/kvm/emulate.c

[PATCH 13/19] KVM: emulate: do not initialize memopp

2014-07-14 Thread Paolo Bonzini
From: Bandan Das b...@redhat.com rip_relative is only set if decode_modrm runs, and if you have ModRM you will also have a memopp. We can then access memopp unconditionally. Note that rip_relative cannot be hoisted up to decode_modrm, or you break mov $0, xyz(%rip). Also, move typecast on out

[PATCH 18/19] KVM: x86: ensure emulator fetches do not span multiple pages

2014-07-14 Thread Paolo Bonzini
When the CS base is not page-aligned, the linear address of the code could get close to the page boundary (e.g. 0x...ffe) even if the EIP value is not. So we need to first linearize the address, and only then compute the number of valid bytes that can be fetched. This happens relatively often

[PATCH resend 00/19] Emulator speedups for 3.17

2014-07-14 Thread Paolo Bonzini
These are the emulator speedup patches that have survived autotest and kvm-unit-tests. I dropped the patches for direct access to memory operands because they caused a failure in vmx.flat. These patches have been in kvm/queue for a while, but I've always left them out of kvm/next because they

[PATCH 17/19] KVM: emulate: put pointers in the fetch_cache

2014-07-14 Thread Paolo Bonzini
This simplifies the code a bit, especially the overflow checks. Signed-off-by: Paolo Bonzini pbonz...@redhat.com --- arch/x86/include/asm/kvm_emulate.h | 4 ++-- arch/x86/kvm/emulate.c | 34 +++--- arch/x86/kvm/trace.h | 6 +++--- 3 files

[PATCH 16/19] KVM: emulate: avoid per-byte copying in instruction fetches

2014-07-14 Thread Paolo Bonzini
We do not need a memory copying loop anymore in insn_fetch; we can use a byte-aligned pointer to access instruction fields directly from the fetch_cache. This eliminates 50-150 cycles (corresponding to a 5-10% improvement in performance) from each instruction. Signed-off-by: Paolo Bonzini

[PATCH 19/19] KVM: x86: use kvm_read_guest_page for emulator accesses

2014-07-14 Thread Paolo Bonzini
Emulator accesses are always done a page at a time, either by the emulator itself (for fetches) or because we need to query the MMU for address translations. Speed up these accesses by using kvm_read_guest_page and, in the case of fetches, by inlining kvm_read_guest_virt_helper and dropping the

[PATCH 09/19] KVM: emulate: Remove ctxt-intercept and ctxt-check_perm checks

2014-07-14 Thread Paolo Bonzini
From: Bandan Das b...@redhat.com The same information can be gleaned from ctxt-d and avoids having to zero/NULL initialize intercept and check_perm Signed-off-by: Bandan Das b...@redhat.com Signed-off-by: Paolo Bonzini pbonz...@redhat.com --- arch/x86/kvm/emulate.c | 8 1 file changed,

[PATCH 15/19] KVM: emulate: avoid repeated calls to do_insn_fetch_bytes

2014-07-14 Thread Paolo Bonzini
do_insn_fetch_bytes will only be called once in a given insn_fetch and insn_fetch_arr, because in fact it will only be called at most twice for any instruction and the first call is explicit in x86_decode_insn. This observation lets us hoist the call out of the memory copying loop. It does not buy

[PATCH 14/19] KVM: emulate: speed up do_insn_fetch

2014-07-14 Thread Paolo Bonzini
Hoist the common case up from do_insn_fetch_byte to do_insn_fetch, and prime the fetch_cache in x86_decode_insn. This helps a bit the compiler and the branch predictor, but above all it lays the ground for further changes in the next few patches. Signed-off-by: Paolo Bonzini pbonz...@redhat.com

[PATCH 11/19] KVM: emulate: clean up initializations in init_decode_cache

2014-07-14 Thread Paolo Bonzini
From: Bandan Das b...@redhat.com A lot of initializations are unnecessary as they get set to appropriate values before actually being used. Optimize placement of fields in x86_emulate_ctxt Signed-off-by: Bandan Das b...@redhat.com Signed-off-by: Paolo Bonzini pbonz...@redhat.com ---

[PATCH 12/19] KVM: emulate: rework seg_override

2014-07-14 Thread Paolo Bonzini
From: Bandan Das b...@redhat.com x86_decode_insn already sets a default for seg_override, so remove it from the zeroed area. Also replace set/get functions with direct access to the field. Signed-off-by: Bandan Das b...@redhat.com Signed-off-by: Paolo Bonzini pbonz...@redhat.com ---

[PATCH 07/19] KVM: emulate: simplify writeback

2014-07-14 Thread Paolo Bonzini
The if/return checks are useless, because we return X86EMUL_CONTINUE anyway if we do not return. Reviewed-by: Marcelo Tosatti mtosa...@redhat.com Signed-off-by: Paolo Bonzini pbonz...@redhat.com --- arch/x86/kvm/emulate.c | 28 +++- 1 file changed, 11 insertions(+), 17

[PATCH 10/19] KVM: emulate: cleanup decode_modrm

2014-07-14 Thread Paolo Bonzini
From: Bandan Das b...@redhat.com Remove the if conditional - that will help us avoid an else initialize to 0 Also, rearrange operators for slightly better code. Signed-off-by: Bandan Das b...@redhat.com Signed-off-by: Paolo Bonzini pbonz...@redhat.com --- arch/x86/kvm/emulate.c | 14

[PATCH 01/19] KVM: vmx: speed up emulation of invalid guest state

2014-07-14 Thread Paolo Bonzini
About 25% of the time spent in emulation of invalid guest state is wasted in checking whether emulation is required for the next instruction. However, this almost never changes except when a segment register (or TR or LDTR) changes, or when there is a mode transition (i.e. CR0 changes). In fact,

[PATCH 04/19] KVM: emulate: move around some checks

2014-07-14 Thread Paolo Bonzini
The only purpose of this patch is to make the next patch simpler to review. No semantic change. Signed-off-by: Paolo Bonzini pbonz...@redhat.com --- arch/x86/kvm/emulate.c | 17 ++--- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/emulate.c

[PATCH 02/19] KVM: x86: return all bits from get_interrupt_shadow

2014-07-14 Thread Paolo Bonzini
For the next patch we will need to know the full state of the interrupt shadow; we will then set KVM_REQ_EVENT when one bit is cleared. However, right now get_interrupt_shadow only returns the one corresponding to the emulated instruction, or an unconditional 0 if the emulated instruction does

[PATCH 03/19] KVM: x86: avoid useless set of KVM_REQ_EVENT after emulation

2014-07-14 Thread Paolo Bonzini
Despite the provisions to emulate up to 130 consecutive instructions, in practice KVM will emulate just one before exiting handle_invalid_guest_state, because x86_emulate_instruction always sets KVM_REQ_EVENT. However, we only need to do this if an interrupt could be injected, which happens a) if

[PATCH 06/19] KVM: emulate: speed up emulated moves

2014-07-14 Thread Paolo Bonzini
We can just blindly move all 16 bytes of ctxt-src's value to ctxt-dst. write_register_operand will take care of writing only the lower bytes. Avoiding a call to memcpy (the compiler optimizes it out) gains about 200 cycles on kvm-unit-tests for register-to-register moves, and makes them about as

[PATCH 05/19] KVM: emulate: protect checks on ctxt-d by a common if (unlikely())

2014-07-14 Thread Paolo Bonzini
There are several checks for peculiar aspects of instructions in both x86_decode_insn and x86_emulate_insn. Group them together, and guard them with a single if that lets the processor quickly skip them all. Make this more effective by adding two more flag bits that say whether the .intercept and

Re: [PATCH V5 1/2] perf ignore LBR and extra_regs

2014-07-14 Thread Paolo Bonzini
Il 10/07/2014 12:59, kan.li...@intel.com ha scritto: From: Kan Liang kan.li...@intel.com x86, perf: Protect LBR and extra_regs against KVM lying With -cpu host, KVM reports LBR and extra_regs support, if the host has support. When the guest perf driver tries to access LBR or extra_regs MSR, it

Re: [PATCH V5 1/2] perf ignore LBR and extra_regs

2014-07-14 Thread Peter Zijlstra
On Mon, Jul 14, 2014 at 01:55:03PM +0200, Paolo Bonzini wrote: Il 10/07/2014 12:59, kan.li...@intel.com ha scritto: From: Kan Liang kan.li...@intel.com x86, perf: Protect LBR and extra_regs against KVM lying With -cpu host, KVM reports LBR and extra_regs support, if the host has support.

Re: [PATCH V5 1/2] perf ignore LBR and extra_regs

2014-07-14 Thread Paolo Bonzini
Il 14/07/2014 14:09, Peter Zijlstra ha scritto: On Mon, Jul 14, 2014 at 01:55:03PM +0200, Paolo Bonzini wrote: Il 10/07/2014 12:59, kan.li...@intel.com ha scritto: From: Kan Liang kan.li...@intel.com x86, perf: Protect LBR and extra_regs against KVM lying With -cpu host, KVM reports LBR and

Re: [PATCH V5 1/2] perf ignore LBR and extra_regs

2014-07-14 Thread Peter Zijlstra
On Mon, Jul 14, 2014 at 02:40:33PM +0200, Paolo Bonzini wrote: Hmmm, I thought rdmsr_safe was going to return zero, but it just returns whatever happened to be in edx:eax which maybe should also be fixed. Kan Liang, what happens if CONFIG_PARAVIRT=y? Do you get garbage or just no events

Re: [Qemu-devel] [PATCH v5 00/12] KVM Support for MIPS32 Processors

2014-07-14 Thread James Hogan
Hi Peter, On 10/07/14 13:17, Peter Maydell wrote: On 17 June 2014 23:10, James Hogan james.ho...@imgtec.com wrote: The patchset depends on v4 of target-mips: implement UserLocal Register. I'm aiming for QEMU 2.1, hopefully it isn't too late to get some final review. Thanks to everybody who

RE: [PATCH V5 1/2] perf ignore LBR and extra_regs

2014-07-14 Thread Liang, Kan
For reproducing the issue, please build the kernel with CONFIG_KVM_INTEL = y (for host kernel). And CONFIG_PARAVIRT = n and CONFIG_KVM_GUEST = n (for guest kernel). I'm not sure this is a useful patch. This is #GP'ing just because of a limitation in the PMU; just compile the

Re: [PATCH V5 1/2] perf ignore LBR and extra_regs

2014-07-14 Thread Paolo Bonzini
Il 14/07/2014 15:36, Liang, Kan ha scritto: Kan Liang, what happens if CONFIG_PARAVIRT=y? Do you get garbage or just no events reported? Guest rdmsr/wrmsr will eventually call rdmsr_safe/wrmsr_safe. They will handle the #GP. So there is no error report in guest. Yeah, but what's the

RE: [PATCH V5 1/2] perf ignore LBR and extra_regs

2014-07-14 Thread Liang, Kan
-Original Message- From: Paolo Bonzini [mailto:pbonz...@redhat.com] Sent: Monday, July 14, 2014 9:40 AM To: Liang, Kan; Peter Zijlstra Cc: a...@firstfloor.org; linux-ker...@vger.kernel.org; kvm@vger.kernel.org Subject: Re: [PATCH V5 1/2] perf ignore LBR and extra_regs Il

Re: [PATCH V5 1/2] perf ignore LBR and extra_regs

2014-07-14 Thread Paolo Bonzini
Il 14/07/2014 14:48, Peter Zijlstra ha scritto: In fact there's no reason why LBR cannot be virtualized (though it does need support from the processor), and it may even be possible to support OFFCORE_RSP_X in the KVM virtual PMU. But its not, so something needs to be done, right? A first

Re: [PATCH 0/6] IRQFD without IRQ routing, enabled for XICS

2014-07-14 Thread Cornelia Huck
On Mon, 30 Jun 2014 20:51:08 +1000 Paul Mackerras pau...@samba.org wrote: I would like to see this go into 3.17. FWIW: I've given this a whirl on s390 (with a dataplane disk), and everything seems to work as before. The only thing which is I think worth mentioning is that embedding the routing

Re: [RESEND PATCH v2 4/5] kvm: Remove ept_identity_pagetable from struct kvm_arch.

2014-07-14 Thread Gleb Natapov
On Mon, Jul 14, 2014 at 05:17:04PM +0800, Tang Chen wrote: On 07/12/2014 03:44 PM, Gleb Natapov wrote: On Wed, Jul 09, 2014 at 10:08:03AM +0800, Tang Chen wrote: kvm_arch-ept_identity_pagetable holds the ept identity pagetable page. But it is never used to refer to the page at all. In vcpu

RE: [PATCH V5 1/2] perf ignore LBR and extra_regs

2014-07-14 Thread Liang, Kan
diff --git a/arch/x86/kernel/cpu/perf_event.h b/arch/x86/kernel/cpu/perf_event.h index 3b2f9bd..992c678 100644 --- a/arch/x86/kernel/cpu/perf_event.h +++ b/arch/x86/kernel/cpu/perf_event.h @@ -464,6 +464,12 @@ struct x86_pmu { */ struct extra_reg *extra_regs;

Re: [Qemu-devel] [PATCH v5 00/12] KVM Support for MIPS32 Processors

2014-07-14 Thread Peter Maydell
On 14 July 2014 14:33, James Hogan james.ho...@imgtec.com wrote: On 10/07/14 13:17, Peter Maydell wrote: More generally, there doesn't really seem to be provision in the KVM KVM_EXIT_MMIO API for returning this access failed. I guess in theory userspace could do all the figure out how to

Re: [PATCH v2 5/5] kvm, mem-hotplug: Do not pin apic access page in memory.

2014-07-14 Thread Gleb Natapov
CCing Jan to check my nested kvm findings below. On Mon, Jul 14, 2014 at 03:57:09PM +0800, Tang Chen wrote: Hi Gleb, Thanks for the reply. Please see below. On 07/12/2014 04:04 PM, Gleb Natapov wrote: On Tue, Jul 08, 2014 at 09:01:32PM +0800, Tang Chen wrote: apic access page is pinned

Re: [Qemu-devel] [PATCH v5 00/12] KVM Support for MIPS32 Processors

2014-07-14 Thread James Hogan
On 14/07/14 15:35, Peter Maydell wrote: On 14 July 2014 14:33, James Hogan james.ho...@imgtec.com wrote: On 10/07/14 13:17, Peter Maydell wrote: More generally, there doesn't really seem to be provision in the KVM KVM_EXIT_MMIO API for returning this access failed. I guess in theory userspace

Re: [PATCH V5 1/2] perf ignore LBR and extra_regs

2014-07-14 Thread Peter Zijlstra
so once more; and then I'm going to route your emails to /dev/null, wrap text at 78 chars. On Mon, Jul 14, 2014 at 02:28:36PM +, Liang, Kan wrote: +++ b/arch/x86/kernel/cpu/perf_event.h @@ -464,6 +464,12 @@ struct x86_pmu { */ struct extra_reg *extra_regs; unsigned int

[PATCH 3/3] KVM: PPC: Book3S: Provide different CAPs based on HV or PR mode

2014-07-14 Thread Alexander Graf
With Book3S KVM we can create both PR and HV VMs in parallel on the same machine. That gives us new challenges on the CAPs we return - both have different capabilities. When we get asked about CAPs on the kvm fd, there's nothing we can do. We can try to be smart and assume we're running HV if HV

[PATCH 0/3] KVM: Make KVM_CHECK_EXTENSION a VM ioctl

2014-07-14 Thread Alexander Graf
On PowerPC we have a small problem :). We can run both HV and PR style VMs on the same kvm fd. While this is great, it means that anything that's different between the two needs to have a token in form of a VM fd to find out which one we're asking for. The one thing where this bites us are CAPs.

[PATCH 1/3] KVM: Rename and add argument to check_extension

2014-07-14 Thread Alexander Graf
In preparation to make the check_extension function available to VM scope we add a struct kvm * argument to the function header and rename the function accordingly. It will still be called from the /dev/kvm fd, but with a NULL argument for struct kvm *. Signed-off-by: Alexander Graf ag...@suse.de

[PATCH 2/3] KVM: Allow KVM_CHECK_EXTENSION on the vm fd

2014-07-14 Thread Alexander Graf
The KVM_CHECK_EXTENSION is only available on the kvm fd today. Unfortunately on PPC some of the capabilities change depending on the way a VM was created. So instead we need a way to expose capabilities as VM ioctl, so that we can see which VM type we're using (HV or PR). To enable this, add the

Re: [PATCH 2/3] KVM: Allow KVM_CHECK_EXTENSION on the vm fd

2014-07-14 Thread Alexander Graf
On 14.07.14 19:03, Alexander Graf wrote: The KVM_CHECK_EXTENSION is only available on the kvm fd today. Unfortunately on PPC some of the capabilities change depending on the way a VM was created. So instead we need a way to expose capabilities as VM ioctl, so that we can see which VM type

[PATCH v2 2/3] KVM: Allow KVM_CHECK_EXTENSION on the vm fd

2014-07-14 Thread Alexander Graf
The KVM_CHECK_EXTENSION is only available on the kvm fd today. Unfortunately on PPC some of the capabilities change depending on the way a VM was created. So instead we need a way to expose capabilities as VM ioctl, so that we can see which VM type we're using (HV or PR). To enable this, add the

[PATCH V6 1/2] perf ignore LBR and extra_rsp

2014-07-14 Thread kan . liang
From: Kan Liang kan.li...@intel.com x86, perf: Protect LBR and extra_regs against KVM lying With -cpu host, KVM reports LBR and extra_regs support, if the host has support. When the guest perf driver tries to access LBR or extra_regs MSR, it #GPs all MSR accesses,since KVM doesn't handle LBR and

[PATCH V6 2/2] kvm: ignore LBR and extra rsp

2014-07-14 Thread kan . liang
From: Kan Liang kan.li...@intel.com With -cpu host KVM reports LBR and extra_regs support, so the perf driver may accesses the LBR and extra_regs MSRs. However, there is no LBR and extra_regs virtualization support yet. This could causes guest to crash. As a workaround, KVM just simply ignore the

KVM HV crash

2014-07-14 Thread Alexander Graf
Hi Paul, I've just seen a crash on POWER7 in HV KVM on a host where I run HV and PR KVM VMs in parallel based on the latest code (linus/master merged with for-3.16 merged with kvm-ppc-queue plus some PR patches): Unable to handle kernel paging request for data at address 0x000c Faulting

Re: [PATCH 0/6] IRQFD without IRQ routing, enabled for XICS

2014-07-14 Thread Cornelia Huck
On Mon, 30 Jun 2014 20:51:08 +1000 Paul Mackerras pau...@samba.org wrote: I would like to see this go into 3.17. FWIW: I've given this a whirl on s390 (with a dataplane disk), and everything seems to work as before. The only thing which is I think worth mentioning is that embedding the routing

[PATCH 1/3] KVM: Rename and add argument to check_extension

2014-07-14 Thread Alexander Graf
In preparation to make the check_extension function available to VM scope we add a struct kvm * argument to the function header and rename the function accordingly. It will still be called from the /dev/kvm fd, but with a NULL argument for struct kvm *. Signed-off-by: Alexander Graf ag...@suse.de

[PATCH 0/3] KVM: Make KVM_CHECK_EXTENSION a VM ioctl

2014-07-14 Thread Alexander Graf
On PowerPC we have a small problem :). We can run both HV and PR style VMs on the same kvm fd. While this is great, it means that anything that's different between the two needs to have a token in form of a VM fd to find out which one we're asking for. The one thing where this bites us are CAPs.

[PATCH 3/3] KVM: PPC: Book3S: Provide different CAPs based on HV or PR mode

2014-07-14 Thread Alexander Graf
With Book3S KVM we can create both PR and HV VMs in parallel on the same machine. That gives us new challenges on the CAPs we return - both have different capabilities. When we get asked about CAPs on the kvm fd, there's nothing we can do. We can try to be smart and assume we're running HV if HV

Re: KVM HV crash

2014-07-14 Thread Alexander Graf
On 14.07.14 13:24, Alexander Graf wrote: Hi Paul, I've just seen a crash on POWER7 in HV KVM on a host where I run HV and PR KVM VMs in parallel based on the latest code (linus/master merged with for-3.16 merged with kvm-ppc-queue plus some PR patches): I guess I must have used an older

[PATCH 2/3] KVM: Allow KVM_CHECK_EXTENSION on the vm fd

2014-07-14 Thread Alexander Graf
The KVM_CHECK_EXTENSION is only available on the kvm fd today. Unfortunately on PPC some of the capabilities change depending on the way a VM was created. So instead we need a way to expose capabilities as VM ioctl, so that we can see which VM type we're using (HV or PR). To enable this, add the

[PATCH v2 2/3] KVM: Allow KVM_CHECK_EXTENSION on the vm fd

2014-07-14 Thread Alexander Graf
The KVM_CHECK_EXTENSION is only available on the kvm fd today. Unfortunately on PPC some of the capabilities change depending on the way a VM was created. So instead we need a way to expose capabilities as VM ioctl, so that we can see which VM type we're using (HV or PR). To enable this, add the