Re: [PATCH 00/27] KVM PPC PV framework v3

2010-08-05 Thread Alexander Graf

On 05.08.2010, at 09:57, Avi Kivity wrote:

 On 08/03/2010 07:16 PM, Scott Wood wrote:
 On Sun, 1 Aug 2010 22:21:37 +0200
 Alexander Grafag...@suse.de  wrote:
 
 On 01.08.2010, at 16:02, Avi Kivity wrote:
 
 Looks reasonable.  Since it's fair to say I understand nothing about 
 powerpc, I'd like someone who does to review it and ack, please, with an 
 emphasis on the interfaces.
 Sounds good. Preferably someone with access to the ePAPR spec :).
 The ePAPR-relevant stuff in patches 7, 16, and 17 looks reasonable.
 Did I miss any ePAPR-relevant stuff in the other patches?
 
 Shall I take this as an ACK?

Hollis wanted to take a look at it too. But given the fact that I have another 
~10 patches lying here I'd appreciate if things could get committed. If changes 
are so dramatic that they'd render things incompatible, we can always just 
release both patches for an actual kernel release, right?


Alex

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 00/27] KVM PPC PV framework v3

2010-08-05 Thread Avi Kivity

 On 08/05/2010 11:01 AM, Alexander Graf wrote:



Shall I take this as an ACK?

Hollis wanted to take a look at it too. But given the fact that I have another 
~10 patches lying here I'd appreciate if things could get committed. If changes 
are so dramatic that they'd render things incompatible, we can always just 
release both patches for an actual kernel release, right?


That's true, we have some time to get it right.

Hollis, please let us know either way once you've reviewed things.

--
error compiling committee.c: too many arguments to function

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 00/27] KVM PPC PV framework v3

2010-08-05 Thread Avi Kivity

 On 07/29/2010 03:47 PM, Alexander Graf wrote:

On PPC we run PR=0 (kernel mode) code in PR=1 (user mode) and don't use the
hypervisor extensions.

While that is all great to show that virtualization is possible, there are
quite some cases where the emulation overhead of privileged instructions is
killing performance.

This patchset tackles exactly that issue. It introduces a paravirtual framework
using which KVM and Linux share a page to exchange register state with. That
way we don't have to switch to the hypervisor just to change a value of a
privileged register.

To prove my point, I ran the same test I did for the MMU optimizations against
the PV framework. Here are the results:

[without]

debian-powerpc:~# time for i in {1..1000}; do /bin/echo hello  /dev/null; done

real0m14.659s
user0m8.967s
sys 0m5.688s

[with]

debian-powerpc:~# time for i in {1..1000}; do /bin/echo hello  /dev/null; done

real0m7.557s
user0m4.121s
sys 0m3.426s


So this is a significant performance improvement! I'm quite happy how fast this
whole thing becomes :)

I tried to take all comments I've heard from people so far about such a PV
framework into account. In case you told me something before that is a no-go
and I still did it, please just tell me again.

To make use of this whole thing you also need patches to qemu and openbios. I
have them in my queue, but want to see this set upstream first before I start
sending patches to the other projects.

Now go and have fun with fast VMs on PPC! Get yourself a G5 on ebay and start
experiencing the power yourself. - heh



Applied this and your follow on 7-part series, thanks.

--
error compiling committee.c: too many arguments to function

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 17/27] KVM: PPC: KVM PV guest stubs

2010-08-05 Thread Hollis Blanchard

On 07/29/2010 05:47 AM, Alexander Graf wrote:

We will soon start and replace instructions from the text section with
other, paravirtualized versions. To ease the readability of those patches
I split out the generic looping and magic page mapping code out.

This patch still only contains stubs. But at least it loops through the
text section :).

Signed-off-by: Alexander Grafag...@suse.de

---

v1 -  v2:

   - kvm guest patch framework: introduce patch_ins

v2 -  v3:

   - add self-test in guest code
   - remove superfluous new lines in generic guest code
---
  arch/powerpc/kernel/kvm.c |   95 +
  1 files changed, 95 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/kernel/kvm.c b/arch/powerpc/kernel/kvm.c
index a5ece71..e93366f 100644
--- a/arch/powerpc/kernel/kvm.c
+++ b/arch/powerpc/kernel/kvm.c
@@ -33,6 +33,62 @@
  #define KVM_MAGIC_PAGE(-4096L)
  #define magic_var(x) KVM_MAGIC_PAGE + offsetof(struct kvm_vcpu_arch_shared, x)

+#define KVM_MASK_RT0x03e0
+
+static bool kvm_patching_worked = true;
+
+static inline void kvm_patch_ins(u32 *inst, u32 new_inst)
+{
+   *inst = new_inst;
+   flush_icache_range((ulong)inst, (ulong)inst + 4);
+}
+
+static void kvm_map_magic_page(void *data)
+{
+   kvm_hypercall2(KVM_HC_PPC_MAP_MAGIC_PAGE,
+  KVM_MAGIC_PAGE,  /* Physical Address */
+  KVM_MAGIC_PAGE); /* Effective Address */
+}
+
+static void kvm_check_ins(u32 *inst)
+{
+   u32 _inst = *inst;
+   u32 inst_no_rt = _inst  ~KVM_MASK_RT;
+   u32 inst_rt = _inst  KVM_MASK_RT;
+
+   switch (inst_no_rt) {
+   }
+
+   switch (_inst) {
+   }
+}
+
+static void kvm_use_magic_page(void)
+{
+   u32 *p;
+   u32 *start, *end;
+   u32 tmp;
+
+   /* Tell the host to map the magic page to -4096 on all CPUs */
+   on_each_cpu(kvm_map_magic_page, NULL, 1);
+
+   /* Quick self-test to see if the mapping works */
+   if (__get_user(tmp, (u32*)KVM_MAGIC_PAGE)) {
+   kvm_patching_worked = false;
+   return;
+   }
+
+   /* Now loop through all code and find instructions */
+   start = (void*)_stext;
+   end = (void*)_etext;
+
+   for (p = start; p  end; p++)
+   kvm_check_ins(p);
+
+   printk(KERN_INFO KVM: Live patching for a fast VM %s\n,
+kvm_patching_worked ? worked : failed);
+}
   
Rather than have the guest loop through every instruction in its text, 
why can't you use the existing cputable self-patching mechanism? The 
kernel already uses that in a number of places to patch itself at 
runtime in fast paths... see Documentation/powerpc/cpu_features.txt for 
some background.


Since we already know (at build time) the location of code that needs 
patching, we don't need to scan at all. (I also shudder to think of the 
number of page faults this scan will incur.)


Hollis Blanchard
Mentor Graphics, Embedded Systems Division

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 01/27] KVM: PPC: Introduce shared page

2010-08-05 Thread Hollis Blanchard

On 07/29/2010 05:47 AM, Alexander Graf wrote:

For transparent variable sharing between the hypervisor and guest, I introduce
a shared page. This shared page will contain all the registers the guest can
read and write safely without exiting guest context.

This patch only implements the stubs required for the basic structure of the
shared page. The actual register moving follows.

Signed-off-by: Alexander Grafag...@suse.de
---
  arch/powerpc/include/asm/kvm_host.h |2 ++
  arch/powerpc/include/asm/kvm_para.h |5 +
  arch/powerpc/kernel/asm-offsets.c   |1 +
  arch/powerpc/kvm/44x.c  |7 +++
  arch/powerpc/kvm/book3s.c   |9 -
  arch/powerpc/kvm/e500.c |7 +++
  6 files changed, 30 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_host.h 
b/arch/powerpc/include/asm/kvm_host.h
index b0b23c0..53edacd 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -25,6 +25,7 @@
  #includelinux/interrupt.h
  #includelinux/types.h
  #includelinux/kvm_types.h
+#includelinux/kvm_para.h
  #includeasm/kvm_asm.h

  #define KVM_MAX_VCPUS 1
@@ -290,6 +291,7 @@ struct kvm_vcpu_arch {
struct tasklet_struct tasklet;
u64 dec_jiffies;
unsigned long pending_exceptions;
+   struct kvm_vcpu_arch_shared *shared;

  #ifdef CONFIG_PPC_BOOK3S
struct hlist_head hpte_hash_pte[HPTEG_HASH_NUM_PTE];
diff --git a/arch/powerpc/include/asm/kvm_para.h 
b/arch/powerpc/include/asm/kvm_para.h
index 2d48f6a..1485ba8 100644
--- a/arch/powerpc/include/asm/kvm_para.h
+++ b/arch/powerpc/include/asm/kvm_para.h
@@ -20,6 +20,11 @@
  #ifndef __POWERPC_KVM_PARA_H__
  #define __POWERPC_KVM_PARA_H__

+#includelinux/types.h
+
+struct kvm_vcpu_arch_shared {
+};
+
  #ifdef __KERNEL__

  static inline int kvm_para_available(void)
diff --git a/arch/powerpc/kernel/asm-offsets.c 
b/arch/powerpc/kernel/asm-offsets.c
index 496cc5b..944f593 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -400,6 +400,7 @@ int main(void)
DEFINE(VCPU_SPRG6, offsetof(struct kvm_vcpu, arch.sprg6));
DEFINE(VCPU_SPRG7, offsetof(struct kvm_vcpu, arch.sprg7));
DEFINE(VCPU_SHADOW_PID, offsetof(struct kvm_vcpu, arch.shadow_pid));
+   DEFINE(VCPU_SHARED, offsetof(struct kvm_vcpu, arch.shared));

/* book3s */
  #ifdef CONFIG_PPC_BOOK3S
diff --git a/arch/powerpc/kvm/44x.c b/arch/powerpc/kvm/44x.c
index 73c0a3f..e7b1f3f 100644
--- a/arch/powerpc/kvm/44x.c
+++ b/arch/powerpc/kvm/44x.c
@@ -123,8 +123,14 @@ struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, 
unsigned int id)
if (err)
goto free_vcpu;

+   vcpu-arch.shared = (void*)__get_free_page(GFP_KERNEL|__GFP_ZERO);
+   if (!vcpu-arch.shared)
+   goto uninit_vcpu;
+
return vcpu;

+uninit_vcpu:
+   kvm_vcpu_uninit(vcpu);
  free_vcpu:
kmem_cache_free(kvm_vcpu_cache, vcpu_44x);
  out:
@@ -135,6 +141,7 @@ void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu)
  {
struct kvmppc_vcpu_44x *vcpu_44x = to_44x(vcpu);

+   free_page((unsigned long)vcpu-arch.shared);
kvm_vcpu_uninit(vcpu);
kmem_cache_free(kvm_vcpu_cache, vcpu_44x);
  }
diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index a3cef30..b3385dd 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -1242,6 +1242,10 @@ struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm 
*kvm, unsigned int id)
if (err)
goto free_shadow_vcpu;

+   vcpu-arch.shared = (void*)__get_free_page(GFP_KERNEL|__GFP_ZERO);
+   if (!vcpu-arch.shared)
+   goto uninit_vcpu;
+
vcpu-arch.host_retip = kvm_return_point;
vcpu-arch.host_msr = mfmsr();
  #ifdef CONFIG_PPC_BOOK3S_64
@@ -1268,10 +1272,12 @@ struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm 
*kvm, unsigned int id)

err = kvmppc_mmu_init(vcpu);
if (err  0)
-   goto free_shadow_vcpu;
+   goto uninit_vcpu;

return vcpu;

+uninit_vcpu:
+   kvm_vcpu_uninit(vcpu);
  free_shadow_vcpu:
kfree(vcpu_book3s-shadow_vcpu);
  free_vcpu:
@@ -1284,6 +1290,7 @@ void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu)
  {
struct kvmppc_vcpu_book3s *vcpu_book3s = to_book3s(vcpu);

+   free_page((unsigned long)vcpu-arch.shared);
kvm_vcpu_uninit(vcpu);
kfree(vcpu_book3s-shadow_vcpu);
vfree(vcpu_book3s);
diff --git a/arch/powerpc/kvm/e500.c b/arch/powerpc/kvm/e500.c
index e8a00b0..71750f2 100644
--- a/arch/powerpc/kvm/e500.c
+++ b/arch/powerpc/kvm/e500.c
@@ -117,8 +117,14 @@ struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, 
unsigned int id)
if (err)
goto uninit_vcpu;

+   vcpu-arch.shared = (void*)__get_free_page(GFP_KERNEL|__GFP_ZERO);
+   if (!vcpu-arch.shared)
+   goto uninit_tlb;
+
return vcpu;

+uninit_tlb:
+