[PATCH v6 1/4] KVM: PPC: epapr: Factor out the epapr init

2012-02-23 Thread Liu Yu
from the kvm guest paravirt init code.

Signed-off-by: Liu Yu yu@freescale.com
---
v6:
1. rename epapr_para to epapr_paravirt
2. remove redundant warnings
3. remove unnecessary init

 arch/powerpc/include/asm/epapr_hcalls.h |2 +
 arch/powerpc/kernel/Makefile|1 +
 arch/powerpc/kernel/epapr_hcalls.S  |   25 ++
 arch/powerpc/kernel/epapr_paravirt.c|   54 +++
 arch/powerpc/kernel/kvm.c   |   28 ++--
 arch/powerpc/kernel/kvm_emul.S  |   10 --
 arch/powerpc/platforms/Kconfig  |9 +
 7 files changed, 94 insertions(+), 35 deletions(-)
 create mode 100644 arch/powerpc/kernel/epapr_hcalls.S
 create mode 100644 arch/powerpc/kernel/epapr_paravirt.c

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index f3b0c2c..2173d4c 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -148,6 +148,8 @@
 #define EV_HCALL_CLOBBERS2 EV_HCALL_CLOBBERS3, r5
 #define EV_HCALL_CLOBBERS1 EV_HCALL_CLOBBERS2, r4
 
+extern bool epapr_paravirt_enabled;
+extern u32 epapr_hypercall_start[];
 
 /*
  * We use uintptr_t to define a register because it's guaranteed to be a
diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index ee728e4..ba8fa43 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -136,6 +136,7 @@ ifneq ($(CONFIG_XMON)$(CONFIG_KEXEC),)
 obj-y  += ppc_save_regs.o
 endif
 
+obj-$(CONFIG_EPAPR_PARAVIRT)   += epapr_paravirt.o epapr_hcalls.o
 obj-$(CONFIG_KVM_GUEST)+= kvm.o kvm_emul.o
 
 # Disable GCOV in odd or sensitive code
diff --git a/arch/powerpc/kernel/epapr_hcalls.S 
b/arch/powerpc/kernel/epapr_hcalls.S
new file mode 100644
index 000..697b390
--- /dev/null
+++ b/arch/powerpc/kernel/epapr_hcalls.S
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2012 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include linux/threads.h
+#include asm/reg.h
+#include asm/page.h
+#include asm/cputable.h
+#include asm/thread_info.h
+#include asm/ppc_asm.h
+#include asm/asm-offsets.h
+
+/* Hypercall entry point. Will be patched with device tree instructions. */
+.global epapr_hypercall_start
+epapr_hypercall_start:
+   li  r3, -1
+   nop
+   nop
+   nop
+   blr
diff --git a/arch/powerpc/kernel/epapr_paravirt.c 
b/arch/powerpc/kernel/epapr_paravirt.c
new file mode 100644
index 000..45eb439
--- /dev/null
+++ b/arch/powerpc/kernel/epapr_paravirt.c
@@ -0,0 +1,54 @@
+/*
+ * ePAPR para-virtualization support.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Copyright (C) 2012 Freescale Semiconductor, Inc.
+ */
+
+#include linux/of.h
+#include asm/epapr_hcalls.h
+#include asm/cacheflush.h
+#include asm/code-patching.h
+
+bool epapr_paravirt_enabled;
+
+static int __init epapr_paravirt_init(void)
+{
+   struct device_node *hyper_node;
+   const u32 *insts;
+   int len, i;
+
+   hyper_node = of_find_node_by_path(/hypervisor);
+   if (!hyper_node)
+   return -ENODEV;
+
+   insts = of_get_property(hyper_node, hcall-instructions, len);
+   if (!insts)
+   return 0;
+
+   if (!(len % 4)  len = (4 * 4)) {
+   for (i = 0; i  (len / 4); i++)
+   patch_instruction(epapr_hypercall_start + i, insts[i]);
+
+   epapr_paravirt_enabled = true;
+   } else {
+   printk(KERN_WARNING
+  ePAPR paravirt: hcall-instructions format error\n);
+   }
+
+   return 0;
+}
+
+early_initcall(epapr_paravirt_init);
diff --git a/arch/powerpc/kernel/kvm.c b/arch/powerpc/kernel/kvm.c
index 62bdf23..1c13307 100644
--- a/arch/powerpc/kernel/kvm.c
+++ b/arch/powerpc/kernel/kvm.c
@@ -31,6 +31,7 @@
 #include asm/cacheflush.h
 #include asm/disassemble.h
 #include asm/ppc-opcode.h
+#include asm/epapr_hcalls.h
 
 #define KVM_MAGIC_PAGE (-4096L)
 #define magic_var(x) KVM_MAGIC_PAGE + offsetof(struct kvm_vcpu_arch_shared, x)
@@ -726,7 +727,7 @@ unsigned long

[PATCH v6 2/4] KVM: PPC: epapr: Add idle hcall support for host

2012-02-23 Thread Liu Yu
And add a new flag definition in kvm_ppc_pvinfo to indicate
whether host support EV_IDLE hcall.

Signed-off-by: Liu Yu yu@freescale.com
---
v6: no change

 arch/powerpc/include/asm/Kbuild |1 +
 arch/powerpc/include/asm/kvm_para.h |   14 --
 arch/powerpc/kvm/powerpc.c  |6 ++
 include/linux/kvm.h |2 ++
 4 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/include/asm/Kbuild b/arch/powerpc/include/asm/Kbuild
index 7e313f1..13d6b7b 100644
--- a/arch/powerpc/include/asm/Kbuild
+++ b/arch/powerpc/include/asm/Kbuild
@@ -34,5 +34,6 @@ header-y += termios.h
 header-y += types.h
 header-y += ucontext.h
 header-y += unistd.h
+header-y += epapr_hcalls.h
 
 generic-y += rwsem.h
diff --git a/arch/powerpc/include/asm/kvm_para.h 
b/arch/powerpc/include/asm/kvm_para.h
index 7b754e7..81a34c9 100644
--- a/arch/powerpc/include/asm/kvm_para.h
+++ b/arch/powerpc/include/asm/kvm_para.h
@@ -75,9 +75,19 @@ struct kvm_vcpu_arch_shared {
 };
 
 #define KVM_SC_MAGIC_R00x4b564d21 /* KVM! */
-#define HC_VENDOR_KVM  (42  16)
+
+#include asm/epapr_hcalls.h
+
+/* ePAPR Hypercall Vendor ID */
+#define HC_VENDOR_EPAPR(EV_EPAPR_VENDOR_ID  16)
+#define HC_VENDOR_KVM  (EV_KVM_VENDOR_ID  16)
+
+/* ePAPR Hypercall Token */
+#define HC_EV_IDLE EV_IDLE
+
+/* ePAPR Hypercall Return Codes */
 #define HC_EV_SUCCESS  0
-#define HC_EV_UNIMPLEMENTED12
+#define HC_EV_UNIMPLEMENTEDEV_UNIMPLEMENTED
 
 #define KVM_FEATURE_MAGIC_PAGE 1
 
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 0e21d15..7098840 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -81,6 +81,10 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
 
/* Second return value is in r4 */
break;
+   case HC_VENDOR_EPAPR | HC_EV_IDLE:
+   r = HC_EV_SUCCESS;
+   kvm_vcpu_block(vcpu);
+   break;
default:
r = HC_EV_UNIMPLEMENTED;
break;
@@ -746,6 +750,8 @@ static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo 
*pvinfo)
pvinfo-hcall[2] = inst_sc;
pvinfo-hcall[3] = inst_nop;
 
+   pvinfo-flags = KVM_PPC_PVINFO_FLAGS_EV_IDLE;
+
return 0;
 }
 
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index acbe429..6b2c70e 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -449,6 +449,8 @@ struct kvm_ppc_pvinfo {
__u8  pad[108];
 };
 
+#define KVM_PPC_PVINFO_FLAGS_EV_IDLE   (10)
+
 #define KVMIO 0xAE
 
 /* machine type bits, to be used as argument to KVM_CREATE_VM */
-- 
1.7.0.4


--
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


[PATCH v6 4/4] KVM: PPC: epapr: Update other hypercall invoking

2012-02-23 Thread Liu Yu
Discard the old way that invoke hypercall,
instead, use epapr paravirt.

Signed-off-by: Liu Yu yu@freescale.com
---
v6:
select epapr_paravirt when enable fsl_hv driver

 arch/powerpc/include/asm/epapr_hcalls.h |   22 +-
 arch/powerpc/include/asm/fsl_hcalls.h   |   36 +++---
 drivers/virt/Kconfig|1 +
 3 files changed, 30 insertions(+), 29 deletions(-)

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index 78460ac..b95758d 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -189,7 +189,7 @@ static inline unsigned int ev_int_set_config(unsigned int 
interrupt,
r5  = priority;
r6  = destination;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4), +r (r5), +r (r6)
: : EV_HCALL_CLOBBERS4
);
@@ -218,7 +218,7 @@ static inline unsigned int ev_int_get_config(unsigned int 
interrupt,
r11 = EV_HCALL_TOKEN(EV_INT_GET_CONFIG);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4), =r (r5), =r (r6)
: : EV_HCALL_CLOBBERS4
);
@@ -248,7 +248,7 @@ static inline unsigned int ev_int_set_mask(unsigned int 
interrupt,
r3 = interrupt;
r4 = mask;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -273,7 +273,7 @@ static inline unsigned int ev_int_get_mask(unsigned int 
interrupt,
r11 = EV_HCALL_TOKEN(EV_INT_GET_MASK);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -301,7 +301,7 @@ static inline unsigned int ev_int_eoi(unsigned int 
interrupt)
r11 = EV_HCALL_TOKEN(EV_INT_EOI);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -340,7 +340,7 @@ static inline unsigned int ev_byte_channel_send(unsigned 
int handle,
r7 = be32_to_cpu(p[2]);
r8 = be32_to_cpu(p[3]);
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3),
  +r (r4), +r (r5), +r (r6), +r (r7), +r (r8)
: : EV_HCALL_CLOBBERS6
@@ -379,7 +379,7 @@ static inline unsigned int ev_byte_channel_receive(unsigned 
int handle,
r3 = handle;
r4 = *count;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4),
  =r (r5), =r (r6), =r (r7), =r (r8)
: : EV_HCALL_CLOBBERS6
@@ -417,7 +417,7 @@ static inline unsigned int ev_byte_channel_poll(unsigned 
int handle,
r11 = EV_HCALL_TOKEN(EV_BYTE_CHANNEL_POLL);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4), =r (r5)
: : EV_HCALL_CLOBBERS3
);
@@ -450,7 +450,7 @@ static inline unsigned int ev_int_iack(unsigned int handle,
r11 = EV_HCALL_TOKEN(EV_INT_IACK);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -474,7 +474,7 @@ static inline unsigned int ev_doorbell_send(unsigned int 
handle)
r11 = EV_HCALL_TOKEN(EV_DOORBELL_SEND);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -494,7 +494,7 @@ static inline unsigned int ev_idle(void)
 
r11 = EV_HCALL_TOKEN(EV_IDLE);
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), =r (r3)
: : EV_HCALL_CLOBBERS1
);
diff --git a/arch/powerpc/include/asm/fsl_hcalls.h 
b/arch/powerpc/include/asm/fsl_hcalls.h
index 922d9b5..3abb583 100644
--- a/arch/powerpc/include/asm/fsl_hcalls.h
+++ b/arch/powerpc/include/asm/fsl_hcalls.h
@@ -96,7 +96,7 @@ static inline unsigned int fh_send_nmi(unsigned int vcpu_mask)
r11 = FH_HCALL_TOKEN(FH_SEND_NMI);
r3 = vcpu_mask;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -151,7 +151,7 @@ static inline unsigned int fh_partition_get_dtprop(int 
handle

RE: [PATCH v5 1/4] KVM: PPC: epapr: Factor out the epapr init

2012-02-21 Thread Liu Yu-B13201


 -Original Message-
 From: Wood Scott-B07421
 Sent: Wednesday, February 22, 2012 5:56 AM
 To: Liu Yu-B13201
 Cc: ag...@suse.de; kvm-ppc@vger.kernel.org; k...@vger.kernel.org;
 linuxppc-...@ozlabs.org; Wood Scott-B07421
 Subject: Re: [PATCH v5 1/4] KVM: PPC: epapr: Factor out the epapr init
 
 On 02/20/2012 10:46 PM, Liu Yu wrote:
  from the kvm guest paravirt init code.
 
  Signed-off-by: Liu Yu yu@freescale.com
  ---
  v5:
  1. fix the if test
  2. use patch_instruction()
  3. code cleanup
  4. rename the files
  5. make epapr paravirt user-selectable
 
   arch/powerpc/include/asm/epapr_hcalls.h |2 +
   arch/powerpc/kernel/Makefile|1 +
   arch/powerpc/kernel/epapr_hcalls.S  |   25 ++
   arch/powerpc/kernel/epapr_paravirt.c|   54
 +++
   arch/powerpc/kernel/kvm.c   |   28 ++--
   arch/powerpc/kernel/kvm_emul.S  |   10 --
   arch/powerpc/platforms/Kconfig  |7 
   7 files changed, 92 insertions(+), 35 deletions(-)  create mode
  100644 arch/powerpc/kernel/epapr_hcalls.S
   create mode 100644 arch/powerpc/kernel/epapr_paravirt.c
 
  diff --git a/arch/powerpc/include/asm/epapr_hcalls.h
  b/arch/powerpc/include/asm/epapr_hcalls.h
  index f3b0c2c..0ff3f24 100644
  --- a/arch/powerpc/include/asm/epapr_hcalls.h
  +++ b/arch/powerpc/include/asm/epapr_hcalls.h
  @@ -148,6 +148,8 @@
   #define EV_HCALL_CLOBBERS2 EV_HCALL_CLOBBERS3, r5
   #define EV_HCALL_CLOBBERS1 EV_HCALL_CLOBBERS2, r4
 
  +extern bool epapr_para_enabled;
  +extern u32 epapr_hypercall_start[];
 
 I asked for s/epapr_para/epapr_paravirt/, at least in anything that is
 exposed beyond a single file.
 
   /*
* We use uintptr_t to define a register because it's guaranteed to
  be a diff --git a/arch/powerpc/kernel/Makefile
  b/arch/powerpc/kernel/Makefile index ee728e4..ba8fa43 100644
  --- a/arch/powerpc/kernel/Makefile
  +++ b/arch/powerpc/kernel/Makefile
  @@ -136,6 +136,7 @@ ifneq ($(CONFIG_XMON)$(CONFIG_KEXEC),)
   obj-y  += ppc_save_regs.o
   endif
 
  +obj-$(CONFIG_EPAPR_PARAVIRT)   += epapr_paravirt.o epapr_hcalls.o
   obj-$(CONFIG_KVM_GUEST)+= kvm.o kvm_emul.o
 
   # Disable GCOV in odd or sensitive code diff --git
  a/arch/powerpc/kernel/epapr_hcalls.S
  b/arch/powerpc/kernel/epapr_hcalls.S
  new file mode 100644
  index 000..697b390
  --- /dev/null
  +++ b/arch/powerpc/kernel/epapr_hcalls.S
  @@ -0,0 +1,25 @@
  +/*
  + * Copyright (C) 2012 Freescale Semiconductor, Inc.
  + *
  + * This program is free software; you can redistribute it and/or
  + * modify it under the terms of the GNU General Public License
  + * as published by the Free Software Foundation; either version
  + * 2 of the License, or (at your option) any later version.
  + */
  +
  +#include linux/threads.h
  +#include asm/reg.h
  +#include asm/page.h
  +#include asm/cputable.h
  +#include asm/thread_info.h
  +#include asm/ppc_asm.h
  +#include asm/asm-offsets.h
  +
  +/* Hypercall entry point. Will be patched with device tree
  +instructions. */ .global epapr_hypercall_start
  +epapr_hypercall_start:
  +   li  r3, -1
  +   nop
  +   nop
  +   nop
  +   blr
  diff --git a/arch/powerpc/kernel/epapr_paravirt.c
  b/arch/powerpc/kernel/epapr_paravirt.c
  new file mode 100644
  index 000..e601da7
  --- /dev/null
  +++ b/arch/powerpc/kernel/epapr_paravirt.c
  @@ -0,0 +1,54 @@
  +/*
  + * ePAPR para-virtualization support.
  + *
  + * This program is free software; you can redistribute it and/or
  +modify
  + * it under the terms of the GNU General Public License, version 2,
  +as
  + * published by the Free Software Foundation.
  + *
  + * This program is distributed in the hope that it will be useful,
  + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  + * GNU General Public License for more details.
  + *
  + * You should have received a copy of the GNU General Public License
  + * along with this program; if not, write to the Free Software
  + * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 USA.
  + *
  + * Copyright (C) 2012 Freescale Semiconductor, Inc.
  + */
  +
  +#include linux/of.h
  +#include asm/epapr_hcalls.h
  +#include asm/cacheflush.h
  +#include asm/code-patching.h
  +
  +bool epapr_para_enabled = false;
 
 No need to explicitly initialize to false.

Why not make code more readable?

 
  +static int __init epapr_para_init(void) {
  +   struct device_node *hyper_node;
  +   const u32 *insts;
  +   int len, i;
  +
  +   hyper_node = of_find_node_by_path(/hypervisor);
  +   if (!hyper_node) {
  +   printk(KERN_WARNING
  +  ePAPR paravirt disabled: No hypervisor node found\n);
  +   return -ENODEV;
  +   }
  +
  +   insts = of_get_property(hyper_node, hcall-instructions, len);
  +   if (insts  !(len % 4)  len = (4 * 4

RE: [PATCH v5 4/4] KVM: PPC: epapr: Update other hypercall invoking

2012-02-21 Thread Liu Yu-B13201


 -Original Message-
 From: Wood Scott-B07421
 Sent: Wednesday, February 22, 2012 5:58 AM
 To: Liu Yu-B13201
 Cc: ag...@suse.de; kvm-ppc@vger.kernel.org; k...@vger.kernel.org;
 linuxppc-...@ozlabs.org; Wood Scott-B07421
 Subject: Re: [PATCH v5 4/4] KVM: PPC: epapr: Update other hypercall
 invoking
 
 On 02/20/2012 10:46 PM, Liu Yu wrote:
  Discard the old way that invoke hypercall, instead, use epapr
  paravirt.
 
  Signed-off-by: Liu Yu yu@freescale.com
  ---
  v5: new patch
 
   arch/powerpc/include/asm/epapr_hcalls.h |   22 +-
   arch/powerpc/include/asm/fsl_hcalls.h   |   36 +++
 ---
   2 files changed, 29 insertions(+), 29 deletions(-)
 
 Make sure all the Topaz/ePAPR drivers that use this select EPAPR_PARAVIRT.
 
 Have you tested with Topaz?
 

Not yet test.

Thanks,
Yu


[PATCH v5 2/4] KVM: PPC: epapr: Add idle hcall support for host

2012-02-20 Thread Liu Yu
And add a new flag definition in kvm_ppc_pvinfo to indicate
whether host support EV_IDLE hcall.

Signed-off-by: Liu Yu yu@freescale.com
---
v5:
1. remove the ifdef
2. add epapr_hcalls.h into headers install list

 arch/powerpc/include/asm/Kbuild |1 +
 arch/powerpc/include/asm/kvm_para.h |   14 --
 arch/powerpc/kvm/powerpc.c  |6 ++
 include/linux/kvm.h |2 ++
 4 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/include/asm/Kbuild b/arch/powerpc/include/asm/Kbuild
index 7e313f1..13d6b7b 100644
--- a/arch/powerpc/include/asm/Kbuild
+++ b/arch/powerpc/include/asm/Kbuild
@@ -34,5 +34,6 @@ header-y += termios.h
 header-y += types.h
 header-y += ucontext.h
 header-y += unistd.h
+header-y += epapr_hcalls.h
 
 generic-y += rwsem.h
diff --git a/arch/powerpc/include/asm/kvm_para.h 
b/arch/powerpc/include/asm/kvm_para.h
index 7b754e7..81a34c9 100644
--- a/arch/powerpc/include/asm/kvm_para.h
+++ b/arch/powerpc/include/asm/kvm_para.h
@@ -75,9 +75,19 @@ struct kvm_vcpu_arch_shared {
 };
 
 #define KVM_SC_MAGIC_R00x4b564d21 /* KVM! */
-#define HC_VENDOR_KVM  (42  16)
+
+#include asm/epapr_hcalls.h
+
+/* ePAPR Hypercall Vendor ID */
+#define HC_VENDOR_EPAPR(EV_EPAPR_VENDOR_ID  16)
+#define HC_VENDOR_KVM  (EV_KVM_VENDOR_ID  16)
+
+/* ePAPR Hypercall Token */
+#define HC_EV_IDLE EV_IDLE
+
+/* ePAPR Hypercall Return Codes */
 #define HC_EV_SUCCESS  0
-#define HC_EV_UNIMPLEMENTED12
+#define HC_EV_UNIMPLEMENTEDEV_UNIMPLEMENTED
 
 #define KVM_FEATURE_MAGIC_PAGE 1
 
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 0e21d15..7098840 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -81,6 +81,10 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
 
/* Second return value is in r4 */
break;
+   case HC_VENDOR_EPAPR | HC_EV_IDLE:
+   r = HC_EV_SUCCESS;
+   kvm_vcpu_block(vcpu);
+   break;
default:
r = HC_EV_UNIMPLEMENTED;
break;
@@ -746,6 +750,8 @@ static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo 
*pvinfo)
pvinfo-hcall[2] = inst_sc;
pvinfo-hcall[3] = inst_nop;
 
+   pvinfo-flags = KVM_PPC_PVINFO_FLAGS_EV_IDLE;
+
return 0;
 }
 
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index acbe429..6b2c70e 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -449,6 +449,8 @@ struct kvm_ppc_pvinfo {
__u8  pad[108];
 };
 
+#define KVM_PPC_PVINFO_FLAGS_EV_IDLE   (10)
+
 #define KVMIO 0xAE
 
 /* machine type bits, to be used as argument to KVM_CREATE_VM */
-- 
1.7.0.4


--
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


[PATCH v5 1/4] KVM: PPC: epapr: Factor out the epapr init

2012-02-20 Thread Liu Yu
from the kvm guest paravirt init code.

Signed-off-by: Liu Yu yu@freescale.com
---
v5:
1. fix the if test
2. use patch_instruction()
3. code cleanup
4. rename the files
5. make epapr paravirt user-selectable

 arch/powerpc/include/asm/epapr_hcalls.h |2 +
 arch/powerpc/kernel/Makefile|1 +
 arch/powerpc/kernel/epapr_hcalls.S  |   25 ++
 arch/powerpc/kernel/epapr_paravirt.c|   54 +++
 arch/powerpc/kernel/kvm.c   |   28 ++--
 arch/powerpc/kernel/kvm_emul.S  |   10 --
 arch/powerpc/platforms/Kconfig  |7 
 7 files changed, 92 insertions(+), 35 deletions(-)
 create mode 100644 arch/powerpc/kernel/epapr_hcalls.S
 create mode 100644 arch/powerpc/kernel/epapr_paravirt.c

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index f3b0c2c..0ff3f24 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -148,6 +148,8 @@
 #define EV_HCALL_CLOBBERS2 EV_HCALL_CLOBBERS3, r5
 #define EV_HCALL_CLOBBERS1 EV_HCALL_CLOBBERS2, r4
 
+extern bool epapr_para_enabled;
+extern u32 epapr_hypercall_start[];
 
 /*
  * We use uintptr_t to define a register because it's guaranteed to be a
diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index ee728e4..ba8fa43 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -136,6 +136,7 @@ ifneq ($(CONFIG_XMON)$(CONFIG_KEXEC),)
 obj-y  += ppc_save_regs.o
 endif
 
+obj-$(CONFIG_EPAPR_PARAVIRT)   += epapr_paravirt.o epapr_hcalls.o
 obj-$(CONFIG_KVM_GUEST)+= kvm.o kvm_emul.o
 
 # Disable GCOV in odd or sensitive code
diff --git a/arch/powerpc/kernel/epapr_hcalls.S 
b/arch/powerpc/kernel/epapr_hcalls.S
new file mode 100644
index 000..697b390
--- /dev/null
+++ b/arch/powerpc/kernel/epapr_hcalls.S
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2012 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include linux/threads.h
+#include asm/reg.h
+#include asm/page.h
+#include asm/cputable.h
+#include asm/thread_info.h
+#include asm/ppc_asm.h
+#include asm/asm-offsets.h
+
+/* Hypercall entry point. Will be patched with device tree instructions. */
+.global epapr_hypercall_start
+epapr_hypercall_start:
+   li  r3, -1
+   nop
+   nop
+   nop
+   blr
diff --git a/arch/powerpc/kernel/epapr_paravirt.c 
b/arch/powerpc/kernel/epapr_paravirt.c
new file mode 100644
index 000..e601da7
--- /dev/null
+++ b/arch/powerpc/kernel/epapr_paravirt.c
@@ -0,0 +1,54 @@
+/*
+ * ePAPR para-virtualization support.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Copyright (C) 2012 Freescale Semiconductor, Inc.
+ */
+
+#include linux/of.h
+#include asm/epapr_hcalls.h
+#include asm/cacheflush.h
+#include asm/code-patching.h
+
+bool epapr_para_enabled = false;
+
+static int __init epapr_para_init(void)
+{
+   struct device_node *hyper_node;
+   const u32 *insts;
+   int len, i;
+
+   hyper_node = of_find_node_by_path(/hypervisor);
+   if (!hyper_node) {
+   printk(KERN_WARNING
+  ePAPR paravirt disabled: No hypervisor node found\n);
+   return -ENODEV;
+   }
+
+   insts = of_get_property(hyper_node, hcall-instructions, len);
+   if (insts  !(len % 4)  len = (4 * 4)) {
+   for (i = 0; i  (len / 4); i++)
+   patch_instruction(epapr_hypercall_start + i, insts[i]);
+
+   epapr_para_enabled = true;
+   } else {
+   printk(KERN_WARNING
+  ePAPR paravirt disabled: No hypervisor inst found\n);
+   }
+
+   return 0;
+}
+
+early_initcall(epapr_para_init);
diff --git a/arch/powerpc/kernel/kvm.c b/arch/powerpc/kernel/kvm.c
index 62bdf23..9dfc24a 100644
--- a/arch/powerpc/kernel/kvm.c
+++ b/arch/powerpc/kernel/kvm.c
@@ -31,6 +31,7 @@
 #include asm/cacheflush.h
 #include asm/disassemble.h
 #include asm/ppc-opcode.h
+#include asm/epapr_hcalls.h
 
 #define KVM_MAGIC_PAGE (-4096L)
 #define magic_var(x

[PATCH v5 3/4] KVM: PPC: epapr: install ev_idle hcall for e500 guest

2012-02-20 Thread Liu Yu
If the guest hypervisor node contains has-idle property.

Signed-off-by: Liu Yu yu@freescale.com
---
v5: no change

 arch/powerpc/kernel/epapr_hcalls.S   |   29 +
 arch/powerpc/kernel/epapr_paravirt.c |   11 ++-
 2 files changed, 39 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/kernel/epapr_hcalls.S 
b/arch/powerpc/kernel/epapr_hcalls.S
index 697b390..72fa234 100644
--- a/arch/powerpc/kernel/epapr_hcalls.S
+++ b/arch/powerpc/kernel/epapr_hcalls.S
@@ -15,6 +15,35 @@
 #include asm/ppc_asm.h
 #include asm/asm-offsets.h
 
+#define HC_VENDOR_EPAPR(1  16)
+#define HC_EV_IDLE 16
+
+_GLOBAL(epapr_ev_idle)
+epapr_ev_idle:
+   rlwinm  r3,r1,0,0,31-THREAD_SHIFT   /* current thread_info */
+   lwz r4,TI_LOCAL_FLAGS(r3)   /* set napping bit */
+   ori r4,r4,_TLF_NAPPING  /* so when we take an exception */
+   stw r4,TI_LOCAL_FLAGS(r3)   /* it will return to our caller */
+
+   wrteei  1
+
+idle_loop:
+   LOAD_REG_IMMEDIATE(r11, HC_VENDOR_EPAPR | HC_EV_IDLE)
+
+.global epapr_ev_idle_start
+epapr_ev_idle_start:
+   li  r3, -1
+   nop
+   nop
+   nop
+
+   /*
+* Guard against spurious wakeups from a hypervisor --
+* only interrupt will cause us to return to LR due to
+* _TLF_NAPPING.
+*/
+   b   idle_loop
+
 /* Hypercall entry point. Will be patched with device tree instructions. */
 .global epapr_hypercall_start
 epapr_hypercall_start:
diff --git a/arch/powerpc/kernel/epapr_paravirt.c 
b/arch/powerpc/kernel/epapr_paravirt.c
index e601da7..43d875e 100644
--- a/arch/powerpc/kernel/epapr_paravirt.c
+++ b/arch/powerpc/kernel/epapr_paravirt.c
@@ -21,6 +21,10 @@
 #include asm/epapr_hcalls.h
 #include asm/cacheflush.h
 #include asm/code-patching.h
+#include asm/machdep.h
+
+extern void epapr_ev_idle(void);
+extern u32 epapr_ev_idle_start[];
 
 bool epapr_para_enabled = false;
 
@@ -39,8 +43,13 @@ static int __init epapr_para_init(void)
 
insts = of_get_property(hyper_node, hcall-instructions, len);
if (insts  !(len % 4)  len = (4 * 4)) {
-   for (i = 0; i  (len / 4); i++)
+   for (i = 0; i  (len / 4); i++) {
patch_instruction(epapr_hypercall_start + i, insts[i]);
+   patch_instruction(epapr_ev_idle_start + i, insts[i]);
+   }
+
+   if (of_get_property(hyper_node, has-idle, NULL))
+   ppc_md.power_save = epapr_ev_idle;
 
epapr_para_enabled = true;
} else {
-- 
1.7.0.4


--
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


[PATCH v5 4/4] KVM: PPC: epapr: Update other hypercall invoking

2012-02-20 Thread Liu Yu
Discard the old way that invoke hypercall,
instead, use epapr paravirt.

Signed-off-by: Liu Yu yu@freescale.com
---
v5: new patch

 arch/powerpc/include/asm/epapr_hcalls.h |   22 +-
 arch/powerpc/include/asm/fsl_hcalls.h   |   36 +++---
 2 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index 0ff3f24..42f2328 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -188,7 +188,7 @@ static inline unsigned int ev_int_set_config(unsigned int 
interrupt,
r5  = priority;
r6  = destination;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4), +r (r5), +r (r6)
: : EV_HCALL_CLOBBERS4
);
@@ -217,7 +217,7 @@ static inline unsigned int ev_int_get_config(unsigned int 
interrupt,
r11 = EV_HCALL_TOKEN(EV_INT_GET_CONFIG);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4), =r (r5), =r (r6)
: : EV_HCALL_CLOBBERS4
);
@@ -247,7 +247,7 @@ static inline unsigned int ev_int_set_mask(unsigned int 
interrupt,
r3 = interrupt;
r4 = mask;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -272,7 +272,7 @@ static inline unsigned int ev_int_get_mask(unsigned int 
interrupt,
r11 = EV_HCALL_TOKEN(EV_INT_GET_MASK);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -300,7 +300,7 @@ static inline unsigned int ev_int_eoi(unsigned int 
interrupt)
r11 = EV_HCALL_TOKEN(EV_INT_EOI);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -339,7 +339,7 @@ static inline unsigned int ev_byte_channel_send(unsigned 
int handle,
r7 = be32_to_cpu(p[2]);
r8 = be32_to_cpu(p[3]);
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3),
  +r (r4), +r (r5), +r (r6), +r (r7), +r (r8)
: : EV_HCALL_CLOBBERS6
@@ -378,7 +378,7 @@ static inline unsigned int ev_byte_channel_receive(unsigned 
int handle,
r3 = handle;
r4 = *count;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4),
  =r (r5), =r (r6), =r (r7), =r (r8)
: : EV_HCALL_CLOBBERS6
@@ -416,7 +416,7 @@ static inline unsigned int ev_byte_channel_poll(unsigned 
int handle,
r11 = EV_HCALL_TOKEN(EV_BYTE_CHANNEL_POLL);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4), =r (r5)
: : EV_HCALL_CLOBBERS3
);
@@ -449,7 +449,7 @@ static inline unsigned int ev_int_iack(unsigned int handle,
r11 = EV_HCALL_TOKEN(EV_INT_IACK);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -473,7 +473,7 @@ static inline unsigned int ev_doorbell_send(unsigned int 
handle)
r11 = EV_HCALL_TOKEN(EV_DOORBELL_SEND);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -493,7 +493,7 @@ static inline unsigned int ev_idle(void)
 
r11 = EV_HCALL_TOKEN(EV_IDLE);
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), =r (r3)
: : EV_HCALL_CLOBBERS1
);
diff --git a/arch/powerpc/include/asm/fsl_hcalls.h 
b/arch/powerpc/include/asm/fsl_hcalls.h
index 922d9b5..3abb583 100644
--- a/arch/powerpc/include/asm/fsl_hcalls.h
+++ b/arch/powerpc/include/asm/fsl_hcalls.h
@@ -96,7 +96,7 @@ static inline unsigned int fh_send_nmi(unsigned int vcpu_mask)
r11 = FH_HCALL_TOKEN(FH_SEND_NMI);
r3 = vcpu_mask;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -151,7 +151,7 @@ static inline unsigned int fh_partition_get_dtprop(int 
handle,
r9 = (uint32_t)propvalue_addr;
r10 = *propvalue_len;
 
-   __asm__

RE: [PATCH v4 1/3] KVM: PPC: epapr: Factor out the epapr init

2012-02-17 Thread Liu Yu-B13201


 -Original Message-
 From: Wood Scott-B07421
 Sent: Friday, February 17, 2012 1:13 AM
 To: Liu Yu-B13201
 Cc: ag...@suse.de; kvm-ppc@vger.kernel.org; k...@vger.kernel.org;
 linuxppc-...@ozlabs.org; Wood Scott-B07421
 Subject: Re: [PATCH v4 1/3] KVM: PPC: epapr: Factor out the epapr init
 
 On 02/16/2012 03:26 AM, Liu Yu wrote:
  from the kvm guest paravirt init code.
 
  Signed-off-by: Liu Yu yu@freescale.com
  ---
  v4:
  1. code cleanup
  2. move kvm_hypercall_start() to epapr_hypercall_start()
 
   arch/powerpc/Kconfig|4 ++
   arch/powerpc/include/asm/epapr_hcalls.h |2 +
   arch/powerpc/kernel/Makefile|1 +
   arch/powerpc/kernel/epapr.S |   25 
   arch/powerpc/kernel/epapr_para.c|   49
 +++
   arch/powerpc/kernel/kvm.c   |   28 ++
   arch/powerpc/kernel/kvm_emul.S  |   10 --
   arch/powerpc/kvm/Kconfig|1 +
   8 files changed, 85 insertions(+), 35 deletions(-)  create mode
  100644 arch/powerpc/kernel/epapr.S  create mode 100644
  arch/powerpc/kernel/epapr_para.c
 
 The comment about spelling out paravirt wasnn't meant to be restricted
 to the kconfig symbol.  There are lots of words that begin with para,
 and ePAPR isn't just about virtualization.

What do you mean? Do you suggest that we should name it epapr_paravirt.c?

Thanks,
Yu


[PATCH v4 3/3] KVM: PPC: epapr: install ev_idle hcall for e500 guest

2012-02-16 Thread Liu Yu
If the guest hypervisor node contains has-idle property.

Signed-off-by: Liu Yu yu@freescale.com
---
v4:
1. discard the CONFIG_E500 to make code for all powerpc platform
2. code cleanup

 arch/powerpc/kernel/epapr.S  |   29 +
 arch/powerpc/kernel/epapr_para.c |   13 -
 2 files changed, 41 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/kernel/epapr.S b/arch/powerpc/kernel/epapr.S
index 697b390..f06d636 100644
--- a/arch/powerpc/kernel/epapr.S
+++ b/arch/powerpc/kernel/epapr.S
@@ -15,6 +15,35 @@
 #include asm/ppc_asm.h
 #include asm/asm-offsets.h
 
+#define HC_VENDOR_EPAPR(1  16)
+#define HC_EV_IDLE 16
+
+_GLOBAL(epapr_ev_idle)
+epapr_ev_idle:
+   rlwinm  r3,r1,0,0,31-THREAD_SHIFT   /* current thread_info */
+   lwz r4,TI_LOCAL_FLAGS(r3)   /* set napping bit */
+   ori r4,r4,_TLF_NAPPING  /* so when we take an exception */
+   stw r4,TI_LOCAL_FLAGS(r3)   /* it will return to our caller */
+
+   wrteei  1
+
+idle_loop:
+   LOAD_REG_IMMEDIATE(r11, HC_VENDOR_EPAPR | HC_EV_IDLE)
+
+.global epapr_ev_idle_start
+epapr_ev_idle_start:
+   li  r3, -1
+   nop
+   nop
+   nop
+
+   /*
+* Guard against spurious wakeups (e.g. from a hypervisor) --
+* any real interrupt will cause us to return to LR due to
+* _TLF_NAPPING.
+*/
+   b   idle_loop
+
 /* Hypercall entry point. Will be patched with device tree instructions. */
 .global epapr_hypercall_start
 epapr_hypercall_start:
diff --git a/arch/powerpc/kernel/epapr_para.c b/arch/powerpc/kernel/epapr_para.c
index ea13cac..adee4f1 100644
--- a/arch/powerpc/kernel/epapr_para.c
+++ b/arch/powerpc/kernel/epapr_para.c
@@ -20,6 +20,10 @@
 #include linux/of.h
 #include asm/epapr_hcalls.h
 #include asm/cacheflush.h
+#include asm/machdep.h
+
+extern void epapr_ev_idle(void);
+extern u32 epapr_ev_idle_start[];
 
 bool epapr_para_enabled = false;
 
@@ -35,10 +39,17 @@ static int __init epapr_para_init(void)
 
insts = of_get_property(hyper_node, hcall-instructions, len);
if (!(len % 4)  (len = (4 * 4))) {
-   for (i = 0; i  (len / 4); i++)
+   for (i = 0; i  (len / 4); i++) {
epapr_hypercall_start[i] = insts[i];
+   epapr_ev_idle_start[i] = insts[i];
+   }
flush_icache_range((ulong)epapr_hypercall_start,
   (ulong)epapr_hypercall_start + len);
+   flush_icache_range((ulong)epapr_ev_idle_start,
+  (ulong)epapr_ev_idle_start + len);
+
+   if (of_get_property(hyper_node, has-idle, NULL))
+   ppc_md.power_save = epapr_ev_idle;
 
epapr_para_enabled = true;
}
-- 
1.7.0.4


--
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 v4 2/3] KVM: PPC: epapr: Add idle hcall support for host

2012-02-16 Thread Liu Yu-B13201


 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de]
 Sent: Thursday, February 16, 2012 6:20 PM
 To: Liu Yu-B13201
 Cc: kvm-ppc@vger.kernel.org; k...@vger.kernel.org; linuxppc-
 d...@ozlabs.org; Wood Scott-B07421; Liu Yu-B13201
 Subject: Re: [PATCH v4 2/3] KVM: PPC: epapr: Add idle hcall support for
 host
 
 
 
 On 16.02.2012, at 10:26, Liu Yu yu@freescale.com wrote:
 
  And add a new flag definition in kvm_ppc_pvinfo to indicate whether
  host support EV_IDLE hcall.
 
  Signed-off-by: Liu Yu yu@freescale.com
  ---
  v4:
  no change
 
  arch/powerpc/include/asm/kvm_para.h |   14 --
  arch/powerpc/kvm/powerpc.c  |8 
  include/linux/kvm.h |2 ++
  3 files changed, 22 insertions(+), 2 deletions(-)
 
  diff --git a/arch/powerpc/include/asm/kvm_para.h
  b/arch/powerpc/include/asm/kvm_para.h
  index 7b754e7..81a34c9 100644
  --- a/arch/powerpc/include/asm/kvm_para.h
  +++ b/arch/powerpc/include/asm/kvm_para.h
  @@ -75,9 +75,19 @@ struct kvm_vcpu_arch_shared { };
 
  #define KVM_SC_MAGIC_R00x4b564d21 /* KVM! */
  -#define HC_VENDOR_KVM(42  16)
  +
  +#include asm/epapr_hcalls.h
  +
  +/* ePAPR Hypercall Vendor ID */
  +#define HC_VENDOR_EPAPR(EV_EPAPR_VENDOR_ID  16)
  +#define HC_VENDOR_KVM(EV_KVM_VENDOR_ID  16)
  +
  +/* ePAPR Hypercall Token */
  +#define HC_EV_IDLEEV_IDLE
  +
  +/* ePAPR Hypercall Return Codes */
  #define HC_EV_SUCCESS0
  -#define HC_EV_UNIMPLEMENTED12
  +#define HC_EV_UNIMPLEMENTEDEV_UNIMPLEMENTED
 
  #define KVM_FEATURE_MAGIC_PAGE1
 
  diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
  index 0e21d15..03ebd5d 100644
  --- a/arch/powerpc/kvm/powerpc.c
  +++ b/arch/powerpc/kvm/powerpc.c
  @@ -81,6 +81,10 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
 
 /* Second return value is in r4 */
 break;
  +case HC_VENDOR_EPAPR | HC_EV_IDLE:
  +r = HC_EV_SUCCESS;
  +kvm_vcpu_block(vcpu);
  +break;
 default:
 r = HC_EV_UNIMPLEMENTED;
 break;
  @@ -746,6 +750,10 @@ static int kvm_vm_ioctl_get_pvinfo(struct
 kvm_ppc_pvinfo *pvinfo)
 pvinfo-hcall[2] = inst_sc;
 pvinfo-hcall[3] = inst_nop;
 
  +#ifdef CONFIG_BOOKE
  +pvinfo-flags |= KVM_PPC_PVINFO_FLAGS_EV_IDLE; #endif
  +
 return 0;
  } 

 Why limit it to booke? The less ifdefs our code has, the better :)

The code here tells userspace that kvm support ev_idle.
But I'm not sure if the ev_idle code works for other platforms.

So I think we should keep the ifdef until other platform test the code :)

Thanks,
Yu


--
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 v3 1/3] KVM: PPC: epapr: Factor out the epapr init

2012-02-12 Thread Liu Yu-B13201


 -Original Message-
 From: Wood Scott-B07421
 Sent: Saturday, February 11, 2012 2:40 AM
 To: Liu Yu-B13201
 Cc: ag...@suse.de; kvm-ppc@vger.kernel.org; k...@vger.kernel.org;
 linuxppc-...@ozlabs.org; Wood Scott-B07421
 Subject: Re: [PATCH v3 1/3] KVM: PPC: epapr: Factor out the epapr init
 
 On 02/10/2012 04:02 AM, Liu Yu wrote:
  from the kvm guest paravirt init code.
 
  Signed-off-by: Liu Yu yu@freescale.com
  ---
  v3:
  apply the epapr init for all ppc platform
 
   arch/powerpc/Kconfig|4 +++
   arch/powerpc/include/asm/epapr_hcalls.h |8 +
   arch/powerpc/kernel/Makefile|1 +
   arch/powerpc/kernel/epapr_para.c|   46
 +++
   arch/powerpc/kernel/kvm.c   |   13 +++--
   arch/powerpc/kvm/Kconfig|1 +
   6 files changed, 64 insertions(+), 9 deletions(-)  create mode 100644
  arch/powerpc/kernel/epapr_para.c
 
  diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index
  47682b6..00bd508 100644
  --- a/arch/powerpc/Kconfig
  +++ b/arch/powerpc/Kconfig
  @@ -196,6 +196,10 @@ config EPAPR_BOOT
Used to allow a board to specify it wants an ePAPR compliant
 wrapper.
  default n
 
  +config EPAPR_PARA
  +   bool
  +   default n
 
 EPAPR_PARAVIRT
 
   config DEFAULT_UIMAGE
  bool
  help
  diff --git a/arch/powerpc/include/asm/epapr_hcalls.h
  b/arch/powerpc/include/asm/epapr_hcalls.h
  index f3b0c2c..c4b86e4 100644
  --- a/arch/powerpc/include/asm/epapr_hcalls.h
  +++ b/arch/powerpc/include/asm/epapr_hcalls.h
  @@ -148,6 +148,14 @@
   #define EV_HCALL_CLOBBERS2 EV_HCALL_CLOBBERS3, r5
   #define EV_HCALL_CLOBBERS1 EV_HCALL_CLOBBERS2, r4
 
  +extern u32 *epapr_hcall_insts;
  +extern int epapr_hcall_insts_len;
  +
  +static inline void epapr_get_hcall_insts(u32 **instp, int *lenp) {
  +   *instp = epapr_hcall_insts;
  +   *lenp = epapr_hcall_insts_len;
  +}
 
 Why do we need a function for this?  Why is the public interface anything
 other than invoke a hypercall?
 
  +static int __init epapr_para_init(void) {
  +   struct device_node *hyper_node;
  +   u32 *insts;
  +   int len;
  +
  +   hyper_node = of_find_node_by_path(/hypervisor);
  +   if (!hyper_node)
  +   return -ENODEV;
  +
  +   insts = (u32*)of_get_property(hyper_node, hcall-instructions,
  +len);
 
 Do not cast away that const.
 
  @@ -535,18 +536,12 @@ EXPORT_SYMBOL_GPL(kvm_hypercall);  static int
  kvm_para_setup(void)  {
  extern u32 kvm_hypercall_start;
  -   struct device_node *hyper_node;
  u32 *insts;
  int len, i;
 
  -   hyper_node = of_find_node_by_path(/hypervisor);
  -   if (!hyper_node)
  -   return -1;
  -
  -   insts = (u32*)of_get_property(hyper_node, hcall-instructions,
 len);
  -   if (len % 4)
  -   return -1;
  -   if (len  (4 * 4))
  +   insts = epapr_hcall_insts;
  +   len = epapr_hcall_insts_len;
  +   if (insts == NULL)
  return -1;
 
  for (i = 0; i  (len / 4); i++)
 
 Why are you still doing the patching inside kvm.c?
 

Do you mean we should move kvm_hypercall_start() into epapr bit?

Thanks,
Yu


[PATCH v3 1/3] KVM: PPC: epapr: Factor out the epapr init

2012-02-10 Thread Liu Yu
from the kvm guest paravirt init code.

Signed-off-by: Liu Yu yu@freescale.com
---
v3:
apply the epapr init for all ppc platform

 arch/powerpc/Kconfig|4 +++
 arch/powerpc/include/asm/epapr_hcalls.h |8 +
 arch/powerpc/kernel/Makefile|1 +
 arch/powerpc/kernel/epapr_para.c|   46 +++
 arch/powerpc/kernel/kvm.c   |   13 +++--
 arch/powerpc/kvm/Kconfig|1 +
 6 files changed, 64 insertions(+), 9 deletions(-)
 create mode 100644 arch/powerpc/kernel/epapr_para.c

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 47682b6..00bd508 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -196,6 +196,10 @@ config EPAPR_BOOT
  Used to allow a board to specify it wants an ePAPR compliant wrapper.
default n
 
+config EPAPR_PARA
+   bool
+   default n
+
 config DEFAULT_UIMAGE
bool
help
diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index f3b0c2c..c4b86e4 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -148,6 +148,14 @@
 #define EV_HCALL_CLOBBERS2 EV_HCALL_CLOBBERS3, r5
 #define EV_HCALL_CLOBBERS1 EV_HCALL_CLOBBERS2, r4
 
+extern u32 *epapr_hcall_insts;
+extern int epapr_hcall_insts_len;
+
+static inline void epapr_get_hcall_insts(u32 **instp, int *lenp)
+{
+   *instp = epapr_hcall_insts;
+   *lenp = epapr_hcall_insts_len;
+}
 
 /*
  * We use uintptr_t to define a register because it's guaranteed to be a
diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index ce4f7f1..1e41c76 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -134,6 +134,7 @@ ifneq ($(CONFIG_XMON)$(CONFIG_KEXEC),)
 obj-y  += ppc_save_regs.o
 endif
 
+obj-$(CONFIG_EPAPR_PARA)   += epapr_para.o
 obj-$(CONFIG_KVM_GUEST)+= kvm.o kvm_emul.o
 
 # Disable GCOV in odd or sensitive code
diff --git a/arch/powerpc/kernel/epapr_para.c b/arch/powerpc/kernel/epapr_para.c
new file mode 100644
index 000..7e1561a
--- /dev/null
+++ b/arch/powerpc/kernel/epapr_para.c
@@ -0,0 +1,46 @@
+/*
+ * ePAPR para-virtualization support.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Copyright (C) 2012 Freescale Semiconductor, Inc.
+ */
+
+#include linux/of.h
+#include asm/epapr_hcalls.h
+#include asm/cacheflush.h
+
+u32 *epapr_hcall_insts;
+int epapr_hcall_insts_len;
+
+static int __init epapr_para_init(void)
+{
+   struct device_node *hyper_node;
+   u32 *insts;
+   int len;
+
+   hyper_node = of_find_node_by_path(/hypervisor);
+   if (!hyper_node)
+   return -ENODEV;
+
+   insts = (u32*)of_get_property(hyper_node, hcall-instructions, len);
+   if (!(len % 4)  (len = (4 * 4))) {
+   epapr_hcall_insts = insts;
+   epapr_hcall_insts_len = len;
+   }
+
+   return 0;
+}
+
+early_initcall(epapr_para_init);
diff --git a/arch/powerpc/kernel/kvm.c b/arch/powerpc/kernel/kvm.c
index b06bdae..2e03ab8 100644
--- a/arch/powerpc/kernel/kvm.c
+++ b/arch/powerpc/kernel/kvm.c
@@ -28,6 +28,7 @@
 #include asm/sections.h
 #include asm/cacheflush.h
 #include asm/disassemble.h
+#include asm/epapr_hcalls.h
 
 #define KVM_MAGIC_PAGE (-4096L)
 #define magic_var(x) KVM_MAGIC_PAGE + offsetof(struct kvm_vcpu_arch_shared, x)
@@ -535,18 +536,12 @@ EXPORT_SYMBOL_GPL(kvm_hypercall);
 static int kvm_para_setup(void)
 {
extern u32 kvm_hypercall_start;
-   struct device_node *hyper_node;
u32 *insts;
int len, i;
 
-   hyper_node = of_find_node_by_path(/hypervisor);
-   if (!hyper_node)
-   return -1;
-
-   insts = (u32*)of_get_property(hyper_node, hcall-instructions, len);
-   if (len % 4)
-   return -1;
-   if (len  (4 * 4))
+   insts = epapr_hcall_insts;
+   len = epapr_hcall_insts_len;
+   if (insts == NULL)
return -1;
 
for (i = 0; i  (len / 4); i++)
diff --git a/arch/powerpc/kvm/Kconfig b/arch/powerpc/kvm/Kconfig
index 78133de..cd1ee68 100644
--- a/arch/powerpc/kvm/Kconfig
+++ b/arch/powerpc/kvm/Kconfig
@@ -20,6 +20,7 @@ config KVM
bool
select PREEMPT_NOTIFIERS
select ANON_INODES
+   select EPAPR_PARA

[PATCH v3 3/3] KVM: PPC: epapr: install ev_idle hcall for e500 guest

2012-02-10 Thread Liu Yu
If the guest hypervisor node contains has-idle property.

Signed-off-by: Liu Yu yu@freescale.com
---
v3:
1. apply the hcall idle for all ppc platform
2. add a loop to prevent spurious wakeups

 arch/powerpc/kernel/Makefile |2 +-
 arch/powerpc/kernel/epapr.S  |   47 ++
 arch/powerpc/kernel/epapr_para.c |   14 ++-
 3 files changed, 61 insertions(+), 2 deletions(-)
 create mode 100644 arch/powerpc/kernel/epapr.S

diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index 1e41c76..65e24be 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -134,7 +134,7 @@ ifneq ($(CONFIG_XMON)$(CONFIG_KEXEC),)
 obj-y  += ppc_save_regs.o
 endif
 
-obj-$(CONFIG_EPAPR_PARA)   += epapr_para.o
+obj-$(CONFIG_EPAPR_PARA)   += epapr_para.o epapr.o
 obj-$(CONFIG_KVM_GUEST)+= kvm.o kvm_emul.o
 
 # Disable GCOV in odd or sensitive code
diff --git a/arch/powerpc/kernel/epapr.S b/arch/powerpc/kernel/epapr.S
new file mode 100644
index 000..34cc54f
--- /dev/null
+++ b/arch/powerpc/kernel/epapr.S
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2012 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include linux/threads.h
+#include asm/reg.h
+#include asm/page.h
+#include asm/cputable.h
+#include asm/thread_info.h
+#include asm/ppc_asm.h
+#include asm/asm-offsets.h
+
+#define HC_VENDOR_EPAPR(1  16)
+#define HC_EV_IDLE 16
+
+_GLOBAL(epapr_ev_idle)
+epapr_ev_idle:
+#ifdef CONFIG_E500
+   rlwinm  r3,r1,0,0,31-THREAD_SHIFT   /* current thread_info */
+   lwz r4,TI_LOCAL_FLAGS(r3)   /* set napping bit */
+   ori r4,r4,_TLF_NAPPING  /* so when we take an exception */
+   stw r4,TI_LOCAL_FLAGS(r3)   /* it will return to our caller */
+#endif
+   wrteei  1
+
+idle_loop:
+   LOAD_REG_IMMEDIATE(r11, HC_VENDOR_EPAPR | HC_EV_IDLE)
+
+/* Hypercall entry point. Will be patched with device tree instructions. */
+.global epapr_hypercall_start
+epapr_hypercall_start:
+   li  r3, -1
+   nop
+   nop
+   nop
+
+   /*
+* Guard against spurious wakeups (e.g. from a hypervisor) --
+* any real interrupt will cause us to return to LR due to
+* _TLF_NAPPING.
+*/
+   b   idle_loop
diff --git a/arch/powerpc/kernel/epapr_para.c b/arch/powerpc/kernel/epapr_para.c
index 7e1561a..ff8fb78 100644
--- a/arch/powerpc/kernel/epapr_para.c
+++ b/arch/powerpc/kernel/epapr_para.c
@@ -20,6 +20,10 @@
 #include linux/of.h
 #include asm/epapr_hcalls.h
 #include asm/cacheflush.h
+#include asm/machdep.h
+
+extern void epapr_ev_idle(void);
+extern u32 epapr_hypercall_start[];
 
 u32 *epapr_hcall_insts;
 int epapr_hcall_insts_len;
@@ -28,7 +32,7 @@ static int __init epapr_para_init(void)
 {
struct device_node *hyper_node;
u32 *insts;
-   int len;
+   int len, i;
 
hyper_node = of_find_node_by_path(/hypervisor);
if (!hyper_node)
@@ -38,8 +42,16 @@ static int __init epapr_para_init(void)
if (!(len % 4)  (len = (4 * 4))) {
epapr_hcall_insts = insts;
epapr_hcall_insts_len = len;
+
+   for (i = 0; i  (len / 4); i++)
+   epapr_hypercall_start[i] = insts[i];
+   flush_icache_range((ulong)epapr_hypercall_start,
+  (ulong)epapr_hypercall_start + len);
}
 
+   if (of_get_property(hyper_node, has-idle, NULL))
+   ppc_md.power_save = epapr_ev_idle;
+
return 0;
 }
 
-- 
1.7.0.4


--
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


[PATCH v2 2/3] KVM: PPC: epapr: Add idle hcall support for host

2012-01-05 Thread Liu Yu
And add a new flag definition in kvm_ppc_pvinfo to indicate
whether host support EV_IDLE hcall.

Signed-off-by: Liu Yu yu@freescale.com
---
v2:
1. instead of adding new field in kvm_ppc_pvinfo, use flags.
2. expose hcall definitions to userspace

 arch/powerpc/include/asm/kvm_para.h |   14 --
 arch/powerpc/kvm/powerpc.c  |8 
 include/linux/kvm.h |2 ++
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_para.h 
b/arch/powerpc/include/asm/kvm_para.h
index 50533f9..e8632b6 100644
--- a/arch/powerpc/include/asm/kvm_para.h
+++ b/arch/powerpc/include/asm/kvm_para.h
@@ -41,9 +41,19 @@ struct kvm_vcpu_arch_shared {
 };
 
 #define KVM_SC_MAGIC_R00x4b564d21 /* KVM! */
-#define HC_VENDOR_KVM  (42  16)
+
+#include asm/epapr_hcalls.h
+
+/* ePAPR Hypercall Vendor ID */
+#define HC_VENDOR_EPAPR(EV_EPAPR_VENDOR_ID  16)
+#define HC_VENDOR_KVM  (EV_KVM_VENDOR_ID  16)
+
+/* ePAPR Hypercall Token */
+#define HC_EV_IDLE EV_IDLE
+
+/* ePAPR Hypercall Return Codes */
 #define HC_EV_SUCCESS  0
-#define HC_EV_UNIMPLEMENTED12
+#define HC_EV_UNIMPLEMENTEDEV_UNIMPLEMENTED
 
 #define KVM_FEATURE_MAGIC_PAGE 1
 
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index c33f6a7..1242ee1 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -81,6 +81,10 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
 
/* Second return value is in r4 */
break;
+   case HC_VENDOR_EPAPR | HC_EV_IDLE:
+   r = HC_EV_SUCCESS;
+   kvm_vcpu_block(vcpu);
+   break;
default:
r = HC_EV_UNIMPLEMENTED;
break;
@@ -772,6 +776,10 @@ static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo 
*pvinfo)
pvinfo-hcall[2] = inst_sc;
pvinfo-hcall[3] = inst_nop;
 
+#ifdef CONFIG_BOOKE
+   pvinfo-flags |= KVM_PPC_PVINFO_FLAGS_EV_IDLE;
+#endif
+
return 0;
 }
 
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index c107fae..501712d 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -429,6 +429,8 @@ struct kvm_ppc_pvinfo {
__u8  pad[108];
 };
 
+#define KVM_PPC_PVINFO_FLAGS_EV_IDLE   (10)
+
 #define KVMIO 0xAE
 
 /*
-- 
1.6.4


--
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


[PATCH 1/2] KVM: PPC: epapr: Add idle hcall support for host

2011-12-30 Thread Liu Yu
Add a new field opt_feature in struct kvm_ppc_pvinfo
to tell userspace whether it support hcall idle.

Signed-off-by: Liu Yu yu@freescale.com
---
 arch/powerpc/include/asm/kvm_para.h |   18 ++
 arch/powerpc/kvm/powerpc.c  |9 +
 include/linux/kvm.h |5 -
 3 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_para.h 
b/arch/powerpc/include/asm/kvm_para.h
index 50533f9..0686377 100644
--- a/arch/powerpc/include/asm/kvm_para.h
+++ b/arch/powerpc/include/asm/kvm_para.h
@@ -40,17 +40,27 @@ struct kvm_vcpu_arch_shared {
__u32 sr[16];
 };
 
+#ifdef __KERNEL__
+
 #define KVM_SC_MAGIC_R00x4b564d21 /* KVM! */
-#define HC_VENDOR_KVM  (42  16)
+
+#include asm/epapr_hcalls.h
+
+/* ePAPR Hypercall Vendor ID */
+#define HC_VENDOR_EPAPR(EV_EPAPR_VENDOR_ID  16)
+#define HC_VENDOR_KVM  (EV_KVM_VENDOR_ID  16)
+
+/* ePAPR Hypercall Token */
+#define HC_EV_IDLE EV_IDLE
+
+/* ePAPR Hypercall Return Codes */
 #define HC_EV_SUCCESS  0
-#define HC_EV_UNIMPLEMENTED12
+#define HC_EV_UNIMPLEMENTEDEV_UNIMPLEMENTED
 
 #define KVM_FEATURE_MAGIC_PAGE 1
 
 #define KVM_MAGIC_FEAT_SR  (1  0)
 
-#ifdef __KERNEL__
-
 #ifdef CONFIG_KVM_GUEST
 
 #include linux/of.h
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index c33f6a7..786b34b 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -81,6 +81,10 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
 
/* Second return value is in r4 */
break;
+   case HC_VENDOR_EPAPR | HC_EV_IDLE:
+   r = HC_EV_SUCCESS;
+   kvm_vcpu_block(vcpu);
+   break;
default:
r = HC_EV_UNIMPLEMENTED;
break;
@@ -772,6 +776,11 @@ static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo 
*pvinfo)
pvinfo-hcall[2] = inst_sc;
pvinfo-hcall[3] = inst_nop;
 
+   pvinfo-opt_features = 0;
+#ifdef CONFIG_BOOKE
+   pvinfo-opt_features |= KVM_PPC_PVINFO_HAS_EV_IDLE;
+#endif
+
return 0;
 }
 
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index c107fae..5af21f3 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -426,9 +426,12 @@ struct kvm_ppc_pvinfo {
/* out */
__u32 flags;
__u32 hcall[4];
-   __u8  pad[108];
+   __u32 opt_features;
+   __u8  pad[104];
 };
 
+#define KVM_PPC_PVINFO_HAS_EV_IDLE   (10)
+
 #define KVMIO 0xAE
 
 /*
-- 
1.6.4


--
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


[PATCH 2/2] KVM: PPC: epapr: Install ev_idle hcall for paravirt guest linux

2011-12-30 Thread Liu Yu
If the guest hypervisor node contains has-idle property.

Signed-off-by: Liu Yu yu@freescale.com
---
 arch/powerpc/kernel/kvm.c |   29 +
 1 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/kernel/kvm.c b/arch/powerpc/kernel/kvm.c
index b06bdae..258f129 100644
--- a/arch/powerpc/kernel/kvm.c
+++ b/arch/powerpc/kernel/kvm.c
@@ -28,6 +28,7 @@
 #include asm/sections.h
 #include asm/cacheflush.h
 #include asm/disassemble.h
+#include asm/machdep.h
 
 #define KVM_MAGIC_PAGE (-4096L)
 #define magic_var(x) KVM_MAGIC_PAGE + offsetof(struct kvm_vcpu_arch_shared, x)
@@ -571,6 +572,30 @@ static __init void kvm_free_tmp(void)
}
 }
 
+static void kvm_hcall_ev_idle(void)
+{
+   ulong in[8];
+   ulong out[8];
+
+   current_thread_info()-local_flags |= _TLF_NAPPING;
+   local_irq_enable();
+   kvm_hypercall(in, out, HC_VENDOR_EPAPR | HC_EV_IDLE);
+}
+
+static int kvm_para_ev_has_idle(void)
+{
+   struct device_node *hyper_node;
+
+   hyper_node = of_find_node_by_path(/hypervisor);
+   if (!hyper_node)
+   return 0;
+
+   if (of_get_property(hyper_node, has-idle, NULL))
+   return 1;
+
+   return 0;
+}
+
 static int __init kvm_guest_init(void)
 {
if (!kvm_para_available())
@@ -587,6 +612,10 @@ static int __init kvm_guest_init(void)
powersave_nap = 1;
 #endif
 
+   /* Install hcall EV_IDLE based power_save for guest kernel */
+   if (kvm_para_ev_has_idle())
+   ppc_md.power_save = kvm_hcall_ev_idle;
+
 free_tmp:
kvm_free_tmp();
 
-- 
1.6.4


--
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


[PATCH v2] KVM: PPC: Avoid patching paravirt template code

2011-12-01 Thread Liu Yu
Currently we patch the whole code include paravirt template code.
This isn't safe for scratch area and has impact to performance.

Signed-off-by: Liu Yu yu@freescale.com
---
v2:
exclude the entire template region in the main loop

 arch/powerpc/kernel/kvm.c  |9 -
 arch/powerpc/kernel/kvm_emul.S |6 ++
 2 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/kernel/kvm.c b/arch/powerpc/kernel/kvm.c
index 3953fbd..a63b371 100644
--- a/arch/powerpc/kernel/kvm.c
+++ b/arch/powerpc/kernel/kvm.c
@@ -665,6 +665,9 @@ static void kvm_check_ins(u32 *inst, u32 features)
}
 }
 
+extern u32 kvm_template_start[];
+extern u32 kvm_template_end[];
+
 static void kvm_use_magic_page(void)
 {
u32 *p;
@@ -692,8 +695,12 @@ static void kvm_use_magic_page(void)
 */
local_irq_disable();
 
-   for (p = start; p  end; p++)
+   for (p = start; p  end; p++) {
+   /* Avoid patching the template code */
+   if (p = kvm_template_start  p  kvm_template_end)
+   p = kvm_template_end;
kvm_check_ins(p, features);
+   }
 
local_irq_enable();
 
diff --git a/arch/powerpc/kernel/kvm_emul.S b/arch/powerpc/kernel/kvm_emul.S
index 801058d..e291cf3 100644
--- a/arch/powerpc/kernel/kvm_emul.S
+++ b/arch/powerpc/kernel/kvm_emul.S
@@ -66,6 +66,9 @@ kvm_hypercall_start:
   shared-critical == r1 and r2 is always != r1 */ \
STL64(r2, KVM_MAGIC_PAGE + KVM_MAGIC_CRITICAL, 0);
 
+.global kvm_template_start
+kvm_template_start:
+
 .global kvm_emulate_mtmsrd
 kvm_emulate_mtmsrd:
 
@@ -350,3 +353,6 @@ kvm_emulate_mtsrin_orig_ins_offs:
 .global kvm_emulate_mtsrin_len
 kvm_emulate_mtsrin_len:
.long (kvm_emulate_mtsrin_end - kvm_emulate_mtsrin) / 4
+
+.global kvm_template_end
+kvm_template_end:
-- 
1.6.4


--
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


[PATCH v3] KVM: PPC: Avoid patching paravirt template code

2011-12-01 Thread Liu Yu
Currently we patch the whole code include paravirt template code.
This isn't safe for scratch area and has impact to performance.

Signed-off-by: Liu Yu yu@freescale.com
---
v2:
exclude the entire template region in the main loop

v3:
make the boundary test more safe

 arch/powerpc/kernel/kvm.c  |   11 ++-
 arch/powerpc/kernel/kvm_emul.S |6 ++
 2 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/kernel/kvm.c b/arch/powerpc/kernel/kvm.c
index 3953fbd..55e999d 100644
--- a/arch/powerpc/kernel/kvm.c
+++ b/arch/powerpc/kernel/kvm.c
@@ -665,6 +665,9 @@ static void kvm_check_ins(u32 *inst, u32 features)
}
 }
 
+extern u32 kvm_template_start[];
+extern u32 kvm_template_end[];
+
 static void kvm_use_magic_page(void)
 {
u32 *p;
@@ -692,8 +695,14 @@ static void kvm_use_magic_page(void)
 */
local_irq_disable();
 
-   for (p = start; p  end; p++)
+   for (p = start; p  end; p++) {
+   /* Avoid patching the template code */
+   if (p = kvm_template_start  p  kvm_template_end) {
+   p = kvm_template_end - 1;
+   continue;
+   }
kvm_check_ins(p, features);
+   }
 
local_irq_enable();
 
diff --git a/arch/powerpc/kernel/kvm_emul.S b/arch/powerpc/kernel/kvm_emul.S
index 801058d..e291cf3 100644
--- a/arch/powerpc/kernel/kvm_emul.S
+++ b/arch/powerpc/kernel/kvm_emul.S
@@ -66,6 +66,9 @@ kvm_hypercall_start:
   shared-critical == r1 and r2 is always != r1 */ \
STL64(r2, KVM_MAGIC_PAGE + KVM_MAGIC_CRITICAL, 0);
 
+.global kvm_template_start
+kvm_template_start:
+
 .global kvm_emulate_mtmsrd
 kvm_emulate_mtmsrd:
 
@@ -350,3 +353,6 @@ kvm_emulate_mtsrin_orig_ins_offs:
 .global kvm_emulate_mtsrin_len
 kvm_emulate_mtsrin_len:
.long (kvm_emulate_mtsrin_end - kvm_emulate_mtsrin) / 4
+
+.global kvm_template_end
+kvm_template_end:
-- 
1.6.4


--
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] KVM: PPC: Apply paravirt to all vcpu

2011-11-22 Thread Liu Yu-B13201
 

 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de] 
 Sent: Tuesday, November 22, 2011 7:14 PM
 To: Liu Yu-B13201
 Cc: kvm-ppc@vger.kernel.org; Liu Yu-B13201
 Subject: Re: [PATCH] KVM: PPC: Apply paravirt to all vcpu
 
 
 On 22.11.2011, at 10:55, Liu Yu yu@freescale.com wrote:
 
  Previously, only primary vcpu get enabled paravirt.
 
 Please fix it the other way around. Thd hypercall is CPU 
 local and should stay that way, so we have to call it on each 
 vcpu inside the guest.
 

The guest kernel already use on_each_cpu()
But seems it doesn't work.
The place primary cpu do hypercall is still in early_init
where secondary cpus don't get kicked.

Thanks,
Yu
--
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


[PATCH] KVM: PPC: Apply paravirt to all vcpu

2011-11-22 Thread Liu Yu
Previously, only primary vcpu get enabled paravirt.

Signed-off-by: Liu Yu yu@freescale.com
---
 arch/powerpc/kvm/powerpc.c |9 +++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 73508e7..a727064 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -78,8 +78,13 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
switch (nr) {
case HC_VENDOR_KVM | KVM_HC_PPC_MAP_MAGIC_PAGE:
{
-   vcpu-arch.magic_page_pa = param1;
-   vcpu-arch.magic_page_ea = param2;
+   struct kvm *kvm = vcpu-kvm;
+   struct kvm_vcpu *v;
+
+   kvm_for_each_vcpu(r, v, kvm) {
+   v-arch.magic_page_pa = param1;
+   v-arch.magic_page_ea = param2;
+   }
 
r2 = KVM_MAGIC_FEAT_SR | KVM_MAGIC_FEAT_MAS0_TO_SPRG7;
 
-- 
1.6.4


--
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 v2] Fix DEC truncation for greater than 0xffff_ffff/1000

2011-10-30 Thread Liu Yu-B13201
 

 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de] 
 Sent: Monday, October 31, 2011 12:21 AM
 To: Bhushan Bharat-R65777
 Cc: Liu Yu-B13201; kvm-ppc@vger.kernel.org; bharatb.ya...@gmail.com
 Subject: Re: [PATCH v2] Fix DEC truncation for greater than 
 0x_/1000
 
 
 On 20.10.2011, at 09:18, Bhushan Bharat-R65777 wrote:
 
  
  
  -Original Message-
  From: Liu Yu-B13201
  Sent: Thursday, October 20, 2011 12:35 PM
  To: Bhushan Bharat-R65777; ag...@suse.de
  Cc: kvm-ppc@vger.kernel.org; bharatb.ya...@gmail.com
  Subject: RE: [PATCH v2] Fix DEC truncation for greater than
  0x_/1000
  
  
  
  -Original Message-
  From: Bhushan Bharat-R65777
  Sent: Thursday, October 20, 2011 2:41 PM
  To: Liu Yu-B13201; ag...@suse.de
  Cc: kvm-ppc@vger.kernel.org; bharatb.ya...@gmail.com
  Subject: RE: [PATCH v2] Fix DEC truncation for greater than
  0x_/1000
  
  
  
  -Original Message-
  From: Liu Yu-B13201
  Sent: Wednesday, October 19, 2011 4:28 PM
  To: Bhushan Bharat-R65777; ag...@suse.de
  Cc: kvm-ppc@vger.kernel.org; bharatb.ya...@gmail.com;
  Bhushan Bharat-
  R65777
  Subject: RE: [PATCH v2] Fix DEC truncation for greater than
  0x_/1000
  
  
  
  -Original Message-
  From: kvm-ppc-ow...@vger.kernel.org
  [mailto:kvm-ppc-ow...@vger.kernel.org] On Behalf Of 
 Bharat Bhushan
  Sent: Wednesday, October 19, 2011 12:16 PM
  To: ag...@suse.de
  Cc: kvm-ppc@vger.kernel.org; bharatb.ya...@gmail.com; Bhushan
  Bharat-R65777
  Subject: [PATCH v2] Fix DEC truncation for greater than
  0x_/1000
  
  kvmppc_emulate_dec() uses dec_nsec of type unsigned 
 long and does
  below calculation:
  
 dec_nsec = vcpu-arch.dec;
 dec_nsec *= 1000;
  This will truncate if DEC value vcpu-arch.dec is greater than
  0x_/1000.
  For example : For tb_ticks_per_usec = 4a, we can not set
  decrementer
  more than ~58ms.
  
  Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
  ---
  arch/powerpc/kvm/emulate.c |   12 +++-
  1 files changed, 7 insertions(+), 5 deletions(-)
  
  diff --git a/arch/powerpc/kvm/emulate.c
  b/arch/powerpc/kvm/emulate.c
  index 8af3bad..e7f3da4 100644
  --- a/arch/powerpc/kvm/emulate.c
  +++ b/arch/powerpc/kvm/emulate.c
  @@ -84,6 +84,7 @@ static bool kvmppc_dec_enabled(struct kvm_vcpu
  *vcpu)  void kvmppc_emulate_dec(struct kvm_vcpu *vcpu)  {
  unsigned long dec_nsec;
  +   unsigned long long dec_time;
  
  pr_debug(mtDEC: %x\n, vcpu-arch.dec);  #ifdef
  CONFIG_PPC_BOOK3S @@ -103,11 +104,12 @@ void
  kvmppc_emulate_dec(struct
  kvm_vcpu *vcpu)
   * host ticks. */
  
  hrtimer_try_to_cancel(vcpu-arch.dec_timer);
  -   dec_nsec = vcpu-arch.dec;
  -   dec_nsec *= 1000;
  -   dec_nsec /= tb_ticks_per_usec;
  -   hrtimer_start(vcpu-arch.dec_timer,
  ktime_set(0, dec_nsec),
  - HRTIMER_MODE_REL);
  +   dec_time = vcpu-arch.dec;
  +   dec_time *= 1000;
  +   do_div(dec_time, tb_ticks_per_usec);
  +   dec_nsec = do_div(dec_time, NSEC_PER_SEC);
  +   hrtimer_start(vcpu-arch.dec_timer,
  +   ktime_set(dec_time, dec_nsec),
  HRTIMER_MODE_REL);
  vcpu-arch.dec_jiffies = get_tb();
  } else {
  hrtimer_try_to_cancel(vcpu-arch.dec_timer);
  --
  1.7.0.4
  
  
  How does this impact performance?
  64bits multiplication and division looks slow.
  
  
  I tried running below test as guest, with and without 
 this patch and
  tried to find latency added by this patch. Also I run 
 this for a list
  of timeouts (1, 2 , 4, 8, 16, 32ms) one by one.
  
  - get TB (say a).
  - set decrementer in auto reload mode.
  - wait for 1000 timebase interrupts.
  - Get timebase delta (b = get_tb - a).
  
(b1 -   b2)  = b1 with this patch and b2
  without this patch. And roughly I found any impact. For example:
  For 1ms =  ( 48a19d8 -  48a1459)  = 0x57f  = .0018% For 32ms =
  (90fdfa23 - 90fdfe79)  = -(0x456)
  
  Doesn't (b1 - b2) mean difference of the last one 
 interrupt between have
  patch and havenot patch?
  The time of previous 999 interrupts is hidden in the cpu idle time.
  
  
  
  Probably I have not described properly. b1 and b2 are 
 delta, not timestamp. In this case I run this test with patch
  Print on console the total time (in TB tick) for which 
 this test runs. Which includes time of all 1000 interrupts.
  
  Then I exit and rerun the above test case without patch
  Then mannualy calculated difference/percentage etc.
  
  Also if you see timebase delta, it suggest that it is not 
 timebase difference of one decrementer.
 
 So Yu are you ok with this patch? If so, please ack.
 

Acked-by: Liu Yu yu@freescale.com

Thanks,
Yu
--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord

RE: [PATCH v2] Fix DEC truncation for greater than 0xffff_ffff/1000

2011-10-20 Thread Liu Yu-B13201
 

 -Original Message-
 From: Bhushan Bharat-R65777 
 Sent: Thursday, October 20, 2011 2:41 PM
 To: Liu Yu-B13201; ag...@suse.de
 Cc: kvm-ppc@vger.kernel.org; bharatb.ya...@gmail.com
 Subject: RE: [PATCH v2] Fix DEC truncation for greater than 
 0x_/1000
 
 
 
  -Original Message-
  From: Liu Yu-B13201
  Sent: Wednesday, October 19, 2011 4:28 PM
  To: Bhushan Bharat-R65777; ag...@suse.de
  Cc: kvm-ppc@vger.kernel.org; bharatb.ya...@gmail.com; 
 Bhushan Bharat-
  R65777
  Subject: RE: [PATCH v2] Fix DEC truncation for greater than
  0x_/1000
  
  
  
   -Original Message-
   From: kvm-ppc-ow...@vger.kernel.org
   [mailto:kvm-ppc-ow...@vger.kernel.org] On Behalf Of Bharat Bhushan
   Sent: Wednesday, October 19, 2011 12:16 PM
   To: ag...@suse.de
   Cc: kvm-ppc@vger.kernel.org; bharatb.ya...@gmail.com; Bhushan
   Bharat-R65777
   Subject: [PATCH v2] Fix DEC truncation for greater than
   0x_/1000
  
   kvmppc_emulate_dec() uses dec_nsec of type unsigned long and does
   below calculation:
  
   dec_nsec = vcpu-arch.dec;
   dec_nsec *= 1000;
   This will truncate if DEC value vcpu-arch.dec is greater than
   0x_/1000.
   For example : For tb_ticks_per_usec = 4a, we can not set 
 decrementer
   more than ~58ms.
  
   Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
   ---
arch/powerpc/kvm/emulate.c |   12 +++-
1 files changed, 7 insertions(+), 5 deletions(-)
  
   diff --git a/arch/powerpc/kvm/emulate.c 
 b/arch/powerpc/kvm/emulate.c
   index 8af3bad..e7f3da4 100644
   --- a/arch/powerpc/kvm/emulate.c
   +++ b/arch/powerpc/kvm/emulate.c
   @@ -84,6 +84,7 @@ static bool kvmppc_dec_enabled(struct kvm_vcpu
   *vcpu)  void kvmppc_emulate_dec(struct kvm_vcpu *vcpu)  {
 unsigned long dec_nsec;
   + unsigned long long dec_time;
  
 pr_debug(mtDEC: %x\n, vcpu-arch.dec);
#ifdef CONFIG_PPC_BOOK3S
   @@ -103,11 +104,12 @@ void kvmppc_emulate_dec(struct 
 kvm_vcpu *vcpu)
  * host ticks. */
  
 hrtimer_try_to_cancel(vcpu-arch.dec_timer);
   - dec_nsec = vcpu-arch.dec;
   - dec_nsec *= 1000;
   - dec_nsec /= tb_ticks_per_usec;
   - hrtimer_start(vcpu-arch.dec_timer,
   ktime_set(0, dec_nsec),
   -   HRTIMER_MODE_REL);
   + dec_time = vcpu-arch.dec;
   + dec_time *= 1000;
   + do_div(dec_time, tb_ticks_per_usec);
   + dec_nsec = do_div(dec_time, NSEC_PER_SEC);
   + hrtimer_start(vcpu-arch.dec_timer,
   + ktime_set(dec_time, dec_nsec),
   HRTIMER_MODE_REL);
 vcpu-arch.dec_jiffies = get_tb();
 } else {
 hrtimer_try_to_cancel(vcpu-arch.dec_timer);
   --
   1.7.0.4
  
  
  How does this impact performance?
  64bits multiplication and division looks slow.
  
 
 I tried running below test as guest, with and without this 
 patch and tried to find latency added by this patch. Also I 
 run this for a list of timeouts (1, 2 , 4, 8, 16, 32ms) one by one.
 
 - get TB (say a).
 - set decrementer in auto reload mode.
 - wait for 1000 timebase interrupts.
 - Get timebase delta (b = get_tb - a).
 
   (b1 -   b2)  = b1 with this patch and b2 
 without this patch. And roughly I found any impact. For example:
 For 1ms =  ( 48a19d8 -  48a1459)  = 0x57f  = .0018%  
 For 32ms = (90fdfa23 - 90fdfe79)  = -(0x456)

Doesn't (b1 - b2) mean difference of the last one interrupt between have patch 
and havenot patch?
The time of previous 999 interrupts is hidden in the cpu idle time.

Thanks,
Yu

--
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 v2] Fix DEC truncation for greater than 0xffff_ffff/1000

2011-10-19 Thread Liu Yu-B13201
 

 -Original Message-
 From: kvm-ppc-ow...@vger.kernel.org 
 [mailto:kvm-ppc-ow...@vger.kernel.org] On Behalf Of Bharat Bhushan
 Sent: Wednesday, October 19, 2011 12:16 PM
 To: ag...@suse.de
 Cc: kvm-ppc@vger.kernel.org; bharatb.ya...@gmail.com; Bhushan 
 Bharat-R65777
 Subject: [PATCH v2] Fix DEC truncation for greater than 
 0x_/1000
 
 kvmppc_emulate_dec() uses dec_nsec of type unsigned long and 
 does below calculation:
 
 dec_nsec = vcpu-arch.dec;
 dec_nsec *= 1000;
 This will truncate if DEC value vcpu-arch.dec is greater 
 than 0x_/1000.
 For example : For tb_ticks_per_usec = 4a, we can not set 
 decrementer more than ~58ms.
 
 Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
 ---
  arch/powerpc/kvm/emulate.c |   12 +++-
  1 files changed, 7 insertions(+), 5 deletions(-)
 
 diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c
 index 8af3bad..e7f3da4 100644
 --- a/arch/powerpc/kvm/emulate.c
 +++ b/arch/powerpc/kvm/emulate.c
 @@ -84,6 +84,7 @@ static bool kvmppc_dec_enabled(struct 
 kvm_vcpu *vcpu)
  void kvmppc_emulate_dec(struct kvm_vcpu *vcpu)
  {
   unsigned long dec_nsec;
 + unsigned long long dec_time;
  
   pr_debug(mtDEC: %x\n, vcpu-arch.dec);
  #ifdef CONFIG_PPC_BOOK3S
 @@ -103,11 +104,12 @@ void kvmppc_emulate_dec(struct kvm_vcpu *vcpu)
* host ticks. */
  
   hrtimer_try_to_cancel(vcpu-arch.dec_timer);
 - dec_nsec = vcpu-arch.dec;
 - dec_nsec *= 1000;
 - dec_nsec /= tb_ticks_per_usec;
 - hrtimer_start(vcpu-arch.dec_timer, 
 ktime_set(0, dec_nsec),
 -   HRTIMER_MODE_REL);
 + dec_time = vcpu-arch.dec;
 + dec_time *= 1000;
 + do_div(dec_time, tb_ticks_per_usec);
 + dec_nsec = do_div(dec_time, NSEC_PER_SEC);
 + hrtimer_start(vcpu-arch.dec_timer,
 + ktime_set(dec_time, dec_nsec), 
 HRTIMER_MODE_REL);
   vcpu-arch.dec_jiffies = get_tb();
   } else {
   hrtimer_try_to_cancel(vcpu-arch.dec_timer);
 -- 
 1.7.0.4
 

How does this impact performance?
64bits multiplication and division looks slow.

Thanks,
Yu
--
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] KVM: PPC: E500: Support hugetlbfs

2011-09-22 Thread Liu Yu-B13201
 

 -Original Message-
 From: kvm-ppc-ow...@vger.kernel.org 
 [mailto:kvm-ppc-ow...@vger.kernel.org] On Behalf Of Alexander Graf
 Sent: Tuesday, September 20, 2011 7:36 AM
 To: kvm-ppc@vger.kernel.org
 Cc: k...@vger.kernel.org
 Subject: [PATCH] KVM: PPC: E500: Support hugetlbfs
 
 With hugetlbfs support emerging on e500, we should also support KVM
 backing its guest memory by it.
 
 This patch adds support for hugetlbfs into the e500 shadow mmu code.
 
 Signed-off-by: Alexander Graf ag...@suse.de
 ---
  arch/powerpc/kvm/e500_tlb.c |   22 ++
  1 files changed, 22 insertions(+), 0 deletions(-)
 
 diff --git a/arch/powerpc/kvm/e500_tlb.c b/arch/powerpc/kvm/e500_tlb.c
 index ec17148..64f75eb 100644
 --- a/arch/powerpc/kvm/e500_tlb.c
 +++ b/arch/powerpc/kvm/e500_tlb.c
 @@ -24,6 +24,7 @@
  #include linux/sched.h
  #include linux/rwsem.h
  #include linux/vmalloc.h
 +#include linux/hugetlb.h
  #include asm/kvm_ppc.h
  #include asm/kvm_e500.h
  
 @@ -673,13 +674,34 @@ static inline void 
 kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500,
   pfn = ~(tsize_pages - 1);
   break;
   }
 + } else if (vma  hva = vma-vm_start 
 +   (vma-vm_flags  VM_HUGETLB)) {

Why check (vma  hva = vma-vm_start) twice?

Thanks,
Yu

--
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 5/5] KVM: PPC: booke: Improve timer register emulation

2011-09-07 Thread Liu Yu-B13201
 

 -Original Message-
 From: kvm-ppc-ow...@vger.kernel.org 
 [mailto:kvm-ppc-ow...@vger.kernel.org] On Behalf Of Alexander Graf
 Sent: Wednesday, September 07, 2011 3:06 AM
 To: Liu Yu-B13201
 Cc: Wood Scott-B07421; kvm-ppc@vger.kernel.org
 Subject: Re: [PATCH 5/5] KVM: PPC: booke: Improve timer 
 register emulation
 
 
 
 Am 06.09.2011 um 10:04 schrieb Alexander Graf ag...@suse.de:
 
  
  On 06.09.2011, at 05:17, Liu Yu-B13201 wrote:
  
  
  
  -Original Message-
  From: kvm-ppc-ow...@vger.kernel.org 
  [mailto:kvm-ppc-ow...@vger.kernel.org] On Behalf Of Alexander Graf
  Sent: Tuesday, September 06, 2011 6:45 AM
  To: Wood Scott-B07421
  Cc: kvm-ppc@vger.kernel.org
  Subject: Re: [PATCH 5/5] KVM: PPC: booke: Improve timer 
  register emulation
  
  
  On 27.08.2011, at 01:31, Scott Wood wrote:
  
  From: Liu Yu yu@freescale.com
  
  Decrementers are now properly driven by TCR/TSR, and the guest
  has full read/write access to these registers.
  
  The decrementer keeps ticking (and setting the TSR bit) 
  regardless of
  whether the interrupts are enabled with TCR.
  
  The decrementer stops at zero, rather than going negative.
  
  Signed-off-by: Liu Yu yu@freescale.com
  [scott: added dequeue in kvmppc_booke_irqprio_deliver, and 
  dec stop-at-zero]
  Signed-off-by: Scott Wood scottw...@freescale.com
  ---
  arch/powerpc/include/asm/kvm_host.h |2 +-
  arch/powerpc/include/asm/kvm_ppc.h  |   11 +
  arch/powerpc/kvm/book3s.c   |8 
  arch/powerpc/kvm/booke.c|   80 
  +++
  arch/powerpc/kvm/booke.h|4 ++
  arch/powerpc/kvm/booke_emulate.c|   11 -
  arch/powerpc/kvm/emulate.c  |   45 ---
  arch/powerpc/kvm/powerpc.c  |   20 +
  8 files changed, 114 insertions(+), 67 deletions(-)
  
  diff --git a/arch/powerpc/include/asm/kvm_host.h 
  b/arch/powerpc/include/asm/kvm_host.h
  index 3305af4..ea08c79 100644
  --- a/arch/powerpc/include/asm/kvm_host.h
  +++ b/arch/powerpc/include/asm/kvm_host.h
  @@ -334,7 +334,7 @@ struct kvm_vcpu_arch {
 u32 tbl;
 u32 tbu;
 u32 tcr;
  -u32 tsr;
  +ulong tsr; /* we need to perform set/clr_bits() which 
  requires ulong */
 u32 ivor[64];
 ulong ivpr;
 u32 pvr;
  diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
  b/arch/powerpc/include/asm/kvm_ppc.h
  index bdaa6c8..ddaa615 100644
  --- a/arch/powerpc/include/asm/kvm_ppc.h
  +++ b/arch/powerpc/include/asm/kvm_ppc.h
  @@ -66,6 +66,7 @@ extern int 
  kvmppc_emulate_instruction(struct kvm_run *run,
  extern int kvmppc_emulate_mmio(struct kvm_run *run, struct 
  kvm_vcpu *vcpu);
  extern void kvmppc_emulate_dec(struct kvm_vcpu *vcpu);
  extern u32 kvmppc_get_dec(struct kvm_vcpu *vcpu, u64 tb);
  +extern void kvmppc_decrementer_func(unsigned long data);
  
  /* Core-specific hooks */
  
  @@ -197,4 +198,14 @@ int kvm_vcpu_ioctl_config_tlb(struct 
  kvm_vcpu *vcpu,
  int kvm_vcpu_ioctl_dirty_tlb(struct kvm_vcpu *vcpu,
  struct kvm_dirty_tlb *cfg);
  
  +static inline void kvmppc_wakeup_vcpu(struct kvm_vcpu *vcpu)
  +{
  +if (waitqueue_active(vcpu-wq)) {
  +wake_up_interruptible(vcpu-wq);
  +vcpu-stat.halt_wakeup++;
  +} else if (vcpu-cpu != -1) {
  +smp_send_reschedule(vcpu-cpu);
  +}
  +}
  +
  #endif /* __POWERPC_KVM_PPC_H__ */
  diff --git a/arch/powerpc/kvm/book3s.c 
 b/arch/powerpc/kvm/book3s.c
  index f68a34d..b057856 100644
  --- a/arch/powerpc/kvm/book3s.c
  +++ b/arch/powerpc/kvm/book3s.c
  @@ -514,3 +514,11 @@ out:
 mutex_unlock(kvm-slots_lock);
 return r;
  }
  +
  +void kvmppc_decrementer_func(unsigned long data)
  +{
  +struct kvm_vcpu *vcpu = (struct kvm_vcpu *)data;
  +
  +kvmppc_core_queue_dec(vcpu);
  +kvmppc_wakeup_vcpu(vcpu);
  +}
  diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
  index 0ed62c1..502f9ff 100644
  --- a/arch/powerpc/kvm/booke.c
  +++ b/arch/powerpc/kvm/booke.c
  @@ -205,7 +205,8 @@ void 
  kvmppc_core_dequeue_external(struct kvm_vcpu *vcpu,
  static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu,
unsigned int priority)
  {
  -int allowed = 0;
  +int allowed = 1;
  +int dequeue = 0;
 ulong uninitialized_var(msr_mask);
 bool update_esr = false, update_dear = false;
 ulong crit_raw = vcpu-arch.shared-critical;
  @@ -258,10 +259,15 @@ static int 
  kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu,
 allowed = vcpu-arch.shared-msr  MSR_ME;
 msr_mask = 0;
 break;
  -case BOOKE_IRQPRIO_EXTERNAL:
 case BOOKE_IRQPRIO_DECREMENTER:
  +if (!(vcpu-arch.tcr  TCR_DIE)) {
  +allowed = 0;
  +dequeue = 1;
  +}
  +/* fall through */
  +case BOOKE_IRQPRIO_EXTERNAL:
 case BOOKE_IRQPRIO_FIT:
  -allowed = vcpu-arch.shared-msr  MSR_EE;
  +allowed = allowed  vcpu-arch.shared-msr

RE: [PATCH 5/5] KVM: PPC: booke: Improve timer register emulation

2011-09-05 Thread Liu Yu-B13201
 

 -Original Message-
 From: kvm-ppc-ow...@vger.kernel.org 
 [mailto:kvm-ppc-ow...@vger.kernel.org] On Behalf Of Alexander Graf
 Sent: Tuesday, September 06, 2011 6:45 AM
 To: Wood Scott-B07421
 Cc: kvm-ppc@vger.kernel.org
 Subject: Re: [PATCH 5/5] KVM: PPC: booke: Improve timer 
 register emulation
 
 
 On 27.08.2011, at 01:31, Scott Wood wrote:
 
  From: Liu Yu yu@freescale.com
  
  Decrementers are now properly driven by TCR/TSR, and the guest
  has full read/write access to these registers.
  
  The decrementer keeps ticking (and setting the TSR bit) 
 regardless of
  whether the interrupts are enabled with TCR.
  
  The decrementer stops at zero, rather than going negative.
  
  Signed-off-by: Liu Yu yu@freescale.com
  [scott: added dequeue in kvmppc_booke_irqprio_deliver, and 
 dec stop-at-zero]
  Signed-off-by: Scott Wood scottw...@freescale.com
  ---
  arch/powerpc/include/asm/kvm_host.h |2 +-
  arch/powerpc/include/asm/kvm_ppc.h  |   11 +
  arch/powerpc/kvm/book3s.c   |8 
  arch/powerpc/kvm/booke.c|   80 
 +++
  arch/powerpc/kvm/booke.h|4 ++
  arch/powerpc/kvm/booke_emulate.c|   11 -
  arch/powerpc/kvm/emulate.c  |   45 ---
  arch/powerpc/kvm/powerpc.c  |   20 +
  8 files changed, 114 insertions(+), 67 deletions(-)
  
  diff --git a/arch/powerpc/include/asm/kvm_host.h 
 b/arch/powerpc/include/asm/kvm_host.h
  index 3305af4..ea08c79 100644
  --- a/arch/powerpc/include/asm/kvm_host.h
  +++ b/arch/powerpc/include/asm/kvm_host.h
  @@ -334,7 +334,7 @@ struct kvm_vcpu_arch {
  u32 tbl;
  u32 tbu;
  u32 tcr;
  -   u32 tsr;
  +   ulong tsr; /* we need to perform set/clr_bits() which 
 requires ulong */
  u32 ivor[64];
  ulong ivpr;
  u32 pvr;
  diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
 b/arch/powerpc/include/asm/kvm_ppc.h
  index bdaa6c8..ddaa615 100644
  --- a/arch/powerpc/include/asm/kvm_ppc.h
  +++ b/arch/powerpc/include/asm/kvm_ppc.h
  @@ -66,6 +66,7 @@ extern int 
 kvmppc_emulate_instruction(struct kvm_run *run,
  extern int kvmppc_emulate_mmio(struct kvm_run *run, struct 
 kvm_vcpu *vcpu);
  extern void kvmppc_emulate_dec(struct kvm_vcpu *vcpu);
  extern u32 kvmppc_get_dec(struct kvm_vcpu *vcpu, u64 tb);
  +extern void kvmppc_decrementer_func(unsigned long data);
  
  /* Core-specific hooks */
  
  @@ -197,4 +198,14 @@ int kvm_vcpu_ioctl_config_tlb(struct 
 kvm_vcpu *vcpu,
  int kvm_vcpu_ioctl_dirty_tlb(struct kvm_vcpu *vcpu,
   struct kvm_dirty_tlb *cfg);
  
  +static inline void kvmppc_wakeup_vcpu(struct kvm_vcpu *vcpu)
  +{
  +   if (waitqueue_active(vcpu-wq)) {
  +   wake_up_interruptible(vcpu-wq);
  +   vcpu-stat.halt_wakeup++;
  +   } else if (vcpu-cpu != -1) {
  +   smp_send_reschedule(vcpu-cpu);
  +   }
  +}
  +
  #endif /* __POWERPC_KVM_PPC_H__ */
  diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
  index f68a34d..b057856 100644
  --- a/arch/powerpc/kvm/book3s.c
  +++ b/arch/powerpc/kvm/book3s.c
  @@ -514,3 +514,11 @@ out:
  mutex_unlock(kvm-slots_lock);
  return r;
  }
  +
  +void kvmppc_decrementer_func(unsigned long data)
  +{
  +   struct kvm_vcpu *vcpu = (struct kvm_vcpu *)data;
  +
  +   kvmppc_core_queue_dec(vcpu);
  +   kvmppc_wakeup_vcpu(vcpu);
  +}
  diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
  index 0ed62c1..502f9ff 100644
  --- a/arch/powerpc/kvm/booke.c
  +++ b/arch/powerpc/kvm/booke.c
  @@ -205,7 +205,8 @@ void 
 kvmppc_core_dequeue_external(struct kvm_vcpu *vcpu,
  static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu,
  unsigned int priority)
  {
  -   int allowed = 0;
  +   int allowed = 1;
  +   int dequeue = 0;
  ulong uninitialized_var(msr_mask);
  bool update_esr = false, update_dear = false;
  ulong crit_raw = vcpu-arch.shared-critical;
  @@ -258,10 +259,15 @@ static int 
 kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu,
  allowed = vcpu-arch.shared-msr  MSR_ME;
  msr_mask = 0;
  break;
  -   case BOOKE_IRQPRIO_EXTERNAL:
  case BOOKE_IRQPRIO_DECREMENTER:
  +   if (!(vcpu-arch.tcr  TCR_DIE)) {
  +   allowed = 0;
  +   dequeue = 1;
  +   }
  +   /* fall through */
  +   case BOOKE_IRQPRIO_EXTERNAL:
  case BOOKE_IRQPRIO_FIT:
  -   allowed = vcpu-arch.shared-msr  MSR_EE;
  +   allowed = allowed  vcpu-arch.shared-msr  MSR_EE;
  allowed = allowed  !crit;
  msr_mask = MSR_CE|MSR_ME|MSR_DE;
  break;
  @@ -269,6 +275,8 @@ static int 
 kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu,
  allowed = vcpu-arch.shared-msr  MSR_DE;
  msr_mask = MSR_ME;
  break;
  +   default:
  +   allowed = 0;
  }
  
  if (allowed) {
  @@ -283,6 +291,9 @@ static

RE: [PATCH v5 4/4] KVM: PPC: e500: Save/restore SPE state

2011-03-30 Thread Liu Yu-B13201
 

 -Original Message-
 From: kvm-ppc-ow...@vger.kernel.org 
 [mailto:kvm-ppc-ow...@vger.kernel.org] On Behalf Of Scott Wood
 Sent: Thursday, March 31, 2011 7:35 AM
 To: ag...@suse.de
 Cc: kvm-ppc@vger.kernel.org
 Subject: [PATCH v5 4/4] KVM: PPC: e500: Save/restore SPE state
 
 This is done lazily.  The SPE save will be done only if the guest has
 used SPE since the last preemption or heavyweight exit.  
 Restore will be
 done only on demand, when enabling MSR_SPE in the shadow MSR, 
 in response
 to an SPE fault or mtmsr emulation.
 
 For SPEFSCR, Linux already switches it on context switch 
 (non-lazily), so
 the only remaining bit is to save it between qemu and the guest.
 
 Signed-off-by: Liu Yu yu@freescale.com
 Signed-off-by: Scott Wood scottw...@freescale.com
 ---
 v5: disable preemption when restoring SPE state
 
 Saving SPE state is only done from a preempt notifier or vcpu_put(),
 where preemption is already disabled.
 
 The other patches in this series are the same as v4.
 
  arch/powerpc/include/asm/kvm_host.h  |6 +++
  arch/powerpc/include/asm/reg_booke.h |1 +
  arch/powerpc/kernel/asm-offsets.c|6 +++
  arch/powerpc/kvm/booke.c |   72 
 +-
  arch/powerpc/kvm/booke.h |   18 ++---
  arch/powerpc/kvm/booke_interrupts.S  |   40 +++
  arch/powerpc/kvm/e500.c  |   19 -
  7 files changed, 145 insertions(+), 17 deletions(-)
 

I think the patch miss the bit to handle the case that
if guest clear the MSR_SPE.

Thanks,
Yu

--
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


Software breakpoint in kvmppc guest debug

2010-11-08 Thread Liu Yu-B13201

Hello all,

Software breakpoint is a instruction which should make guest exit.
We replace guest code with software breakpoint instruction so that we can stop 
at anywhere we want.

In my previous guest debug patches for e500, I used instruction (sc 64) as 
software breakpoint.
Seem this was not good, since (sc 64) maybe defined in future.
also this instruction has uncertain effective on E.HV platform such as e500mc.

Another choice is to use trap instruction.
In order to distinguish between real guest trap and software breakpoint trap.
It's needed to trace software breakpoint addressed in kernel,
and we need to create ioctls to add/remove software point.

So guys, which way should we choose?
Or is there any other better idea?

Thanks,
Yu


RE: [PATCH] KVM: PPC: e500: Call kvm_vcpu_uninit() before kvmppc_e500_tlb_uninit().

2010-10-07 Thread Liu Yu-B13201
 

 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de] 
 Sent: Wednesday, October 06, 2010 3:42 AM
 To: Wood Scott-B07421
 Cc: kvm-ppc@vger.kernel.org; Liu Yu-B13201
 Subject: Re: [PATCH] KVM: PPC: e500: Call kvm_vcpu_uninit() 
 before kvmppc_e500_tlb_uninit().
 
 
 On 05.10.2010, at 21:22, Scott Wood wrote:
 
  The VCPU uninit calls some TLB functions, and the TLB 
 uninit function
  frees the memory used by them.
 
 Liu, this is your code. Please sign it off if you think the 
 change is correct.
 

Yes. The fix is correct.
Acked-by: Liu Yu yu@freescale.com

Thanks,
Yu

--
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 2/2] kvm/e500v2: mapping guest TLB1 to host TLB0

2010-09-17 Thread Liu Yu-B13201
 

 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de] 
 Sent: Friday, September 17, 2010 7:34 PM
 To: Liu Yu-B13201
 Cc: k...@vger.kernel.org; kvm-ppc@vger.kernel.org
 Subject: Re: [PATCH 2/2] kvm/e500v2: mapping guest TLB1 to host TLB0
 
 
 On 17.09.2010, at 13:28, Liu Yu-B13201 wrote:
 
  
  
  -Original Message-
  From: Alexander Graf [mailto:ag...@suse.de] 
  Sent: Friday, September 17, 2010 6:20 PM
  To: Liu Yu-B13201
  Cc: k...@vger.kernel.org; kvm-ppc@vger.kernel.org
  Subject: Re: [PATCH 2/2] kvm/e500v2: mapping guest TLB1 to 
 host TLB0
  
  
  On 17.09.2010, at 10:47, Liu Yu-B13201 wrote:
  
  
  
  -Original Message-
  From: kvm-ppc-ow...@vger.kernel.org 
  [mailto:kvm-ppc-ow...@vger.kernel.org] On Behalf Of 
 Alexander Graf
  Sent: Thursday, September 16, 2010 7:44 PM
  To: Liu Yu-B13201
  Cc: k...@vger.kernel.org; kvm-ppc@vger.kernel.org
  Subject: Re: [PATCH 2/2] kvm/e500v2: mapping guest TLB1 to 
  host TLB0
  
  
  /*
  * writing shadow tlb entry to host TLB
  */
  -static inline void __write_host_tlbe(struct tlbe *stlbe)
  +static inline void __host_tlbe_write(struct tlbe *stlbe)
  {
mtspr(SPRN_MAS1, stlbe-mas1);
mtspr(SPRN_MAS2, stlbe-mas2);
  @@ -109,25 +110,22 @@ static inline void 
  
  __write_host_tlbe(struct tlbe *stlbe)
  
__asm__ __volatile__ (tlbwe\n : : );
  }
  
  -static inline void write_host_tlbe(struct kvmppc_vcpu_e500 
  
  *vcpu_e500,
  
  - int tlbsel, int esel, struct tlbe *stlbe)
  +static inline u32 host_tlb0_write(struct kvmppc_vcpu_e500 
  
  *vcpu_e500,
  
  +   u32 gvaddr, struct 
  tlbe *stlbe)
  {
  - local_irq_disable();
  - if (tlbsel == 0) {
  - __write_host_tlbe(stlbe);
  - } else {
  - unsigned register mas0;
  + unsigned register mas0;
  
  - mas0 = mfspr(SPRN_MAS0);
  + local_irq_disable();
  
  Do you have to disable interrupts for a tlb write? If you get 
  preempted before the write, the entry you overwrite could be 
  different. But you don't protect against that either way. And 
  if you get preempted afterwards, you could lose the entry. 
  But since you enable interrupts beyond that, that could 
  happen either way too.
  
  So what's the reason for the disable here?
  
  
  
  Hello Alex,
  
  Doesn't local_irq_disable() also disable preempt?
  The reason to disable interrupts is because it's possible 
  to have tlb
  misses in interrupt service route.
  
  
  Yes, local_irq_disable disables preempt. That's exactly 
 what I was
  referring to :).
  I don't understand the statement about the service route. 
  A tlb miss
  still arrives with local_irq_disable.
  
  
  
  Use local_irq_disable here is to make sure we update masN 
 in atomic.
  If get preempted when we update part of masN,
  then we may write wrong TLB entry in hardware.
  
  I see, makes sense. Doing the mfmsr of MAS0 in an irq 
  disabled section doesn't make sense to me though. 
  
  Hardware choose the position and put TLB entry by itself.
  I need to get the position from MAS0.
  So that I know exactly which old entry is overrided.
 
 Huh? But you do the mfmsr before the tlb write? Or does MAS0 
 contain the next tlb pointer?

There's no mfmsr.
The MAS0 contain the position we are going to write the entry in.

 
  
  Also, wouldn't it be better to do the irq disabling inside of 
  __host_tlbe_write using irqsave, not the explicit enable/disable?
  
  
  Oh? What benefit we can get from this?
 
 Cleaner structure. If writing a tlb entry needs to happen 
 atomically, the function you call should be atomic. In your 
 case that's reasonably simple to do. Also, you could return 
 MAS0 in that function. That would make things a lot more 
 obvious. While you're at it, a comment explaining what the 
 function does doesn't hurt either :)
 

Sound reasonable.:)
but why using irqsave?


Yu

--
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 2/2] kvm/e500v2: mapping guest TLB1 to host TLB0

2010-09-16 Thread Liu Yu-B13201
 

 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de] 
 Sent: Friday, September 10, 2010 7:24 AM
 To: Liu Yu-B13201
 Cc: k...@vger.kernel.org; kvm-ppc@vger.kernel.org
 Subject: Re: [PATCH 2/2] kvm/e500v2: mapping guest TLB1 to host TLB0
 
 
 On 08.09.2010, at 11:40, Liu Yu wrote:
 
  Current guest TLB1 is mapped to host TLB1.
  As host kernel only provides 4K uncontinuous pages,
  we have to break guest large mapping into 4K shadow mappings.
  These 4K shadow mappings are then mapped into host TLB1 on fly.
  As host TLB1 only has 13 free entries, there's serious tlb miss.
  
  Since e500v2 has a big number of TLB0 entries,
  it should be help to map those 4K shadow mappings to host TLB0.
  To achieve this, we need to unlink guest tlb and host tlb,
  So that guest TLB1 mappings can route to any host TLB0 
 entries freely.
  
  Pages/mappings are considerred in the same kind as host tlb entry.
  This patch remove the link between pages and guest tlb 
 entry to do the unlink.
  And keep host_tlb0_ref in each vcpu to trace pages.
  Then it's easy to map guest TLB1 to host TLB0.
  
  In guest ramdisk boot test(guest mainly uses TLB1),
  with this patch, the tlb miss number get down 90%.
  
  Signed-off-by: Liu Yu yu@freescale.com
  ---
  arch/powerpc/include/asm/kvm_e500.h |7 +-
  arch/powerpc/kvm/e500.c |4 +
  arch/powerpc/kvm/e500_tlb.c |  280 
 ---
  arch/powerpc/kvm/e500_tlb.h |1 +
  4 files changed, 104 insertions(+), 188 deletions(-)
  

 
  
  -static unsigned int tlb1_entry_num;
  +static inline unsigned int get_tlb0_entry_offset(u32 
 eaddr, u32 esel)
  +{
  +   return ((eaddr  0x7F000)  (12 - host_tlb0_assoc_bit) |
  +   (esel  (host_tlb0_assoc - 1)));
  +}
  
  void kvmppc_dump_tlbs(struct kvm_vcpu *vcpu)
  {
  @@ -62,11 +68,6 @@ static inline unsigned int tlb0_get_next_victim(
  return victim;
  }
  
  -static inline unsigned int tlb1_max_shadow_size(void)
  -{
  -   return tlb1_entry_num - tlbcam_index;
  -}
  -
  static inline int tlbe_is_writable(struct tlbe *tlbe)
  {
  return tlbe-mas3  (MAS3_SW|MAS3_UW);
  @@ -100,7 +101,7 @@ static inline u32 
 e500_shadow_mas2_attrib(u32 mas2, int usermode)
  /*
   * writing shadow tlb entry to host TLB
   */
  -static inline void __write_host_tlbe(struct tlbe *stlbe)
  +static inline void __host_tlbe_write(struct tlbe *stlbe)
  {
  mtspr(SPRN_MAS1, stlbe-mas1);
  mtspr(SPRN_MAS2, stlbe-mas2);
  @@ -109,25 +110,22 @@ static inline void 
 __write_host_tlbe(struct tlbe *stlbe)
  __asm__ __volatile__ (tlbwe\n : : );
  }
  
  -static inline void write_host_tlbe(struct kvmppc_vcpu_e500 
 *vcpu_e500,
  -   int tlbsel, int esel, struct tlbe *stlbe)
  +static inline u32 host_tlb0_write(struct kvmppc_vcpu_e500 
 *vcpu_e500,
  +   u32 gvaddr, struct tlbe *stlbe)
  {
  -   local_irq_disable();
  -   if (tlbsel == 0) {
  -   __write_host_tlbe(stlbe);
  -   } else {
  -   unsigned register mas0;
  +   unsigned register mas0;
  
  -   mas0 = mfspr(SPRN_MAS0);
  +   local_irq_disable();
 
 Do you have to disable interrupts for a tlb write? If you get 
 preempted before the write, the entry you overwrite could be 
 different. But you don't protect against that either way. And 
 if you get preempted afterwards, you could lose the entry. 
 But since you enable interrupts beyond that, that could 
 happen either way too.
 
 So what's the reason for the disable here?
 

Hello Alex,

Doesn't local_irq_disable() also disable preempt?
The reason to disable interrupts is because it's possible to have tlb
misses in interrupt service route.


Thanks,
Yu

--
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 0/2] kvm/e500v2: MMU optimization

2010-09-09 Thread Liu Yu-B13201
 

 -Original Message-
 From: kvm-ppc-ow...@vger.kernel.org 
 [mailto:kvm-ppc-ow...@vger.kernel.org] On Behalf Of Hollis Blanchard
 Sent: Thursday, September 09, 2010 12:07 AM
 To: Liu Yu-B13201
 Cc: k...@vger.kernel.org; kvm-ppc@vger.kernel.org; ag...@suse.de
 Subject: Re: [PATCH 0/2] kvm/e500v2: MMU optimization
 
 On 09/08/2010 02:40 AM, Liu Yu wrote:
  The patchset aims at mapping guest TLB1 to host TLB0.
  And it includes:
  [PATCH 1/2] kvm/e500v2: Remove shadow tlb
  [PATCH 2/2] kvm/e500v2: mapping guest TLB1 to host TLB0
 
  The reason we need patch 1 is because patch 1 make things 
 simple and flexible.
  Only applying patch 1 aslo make kvm work.
 
 I've always thought the best long-term optimization on 
 these cores is 
 to share in the host PID allocation (i.e. __init_new_context()). This 
 way, the TID in guest mappings would not overlap the TID in host 
 mappings, and guest mappings could be demand-faulted rather 
 than swapped 
 wholesale. To do that, you would need to track the host PID 
 in KVM data 
 structures, I guess in the tlbe_ref structure.
 

Hi Hollis,

Guest uses AS=1 and host uses AS=0,
so even guest uses the same TID with host, they're in different space.

Then why guest needs to care about host TID?


Thanks,
Yu

--
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 1/2] kvm/e500v2: Remove shadow tlb

2010-09-09 Thread Liu Yu-B13201
 

 -Original Message-
 From: Hollis Blanchard [mailto:hollis_blanch...@mentor.com] 
 Sent: Thursday, September 09, 2010 12:07 AM
 To: Liu Yu-B13201
 Cc: k...@vger.kernel.org; kvm-ppc@vger.kernel.org; ag...@suse.de
 Subject: Re: [PATCH 1/2] kvm/e500v2: Remove shadow tlb
 
 On 09/08/2010 02:40 AM, Liu Yu wrote:
  It is unnecessary to keep shadow tlb.
  first, shadow tlb keep fixed value in shadow, which make 
 things unflexible.
  second, remove shadow tlb can save a lot memory.
 
  This patch remove shadow tlb and caculate the shadow tlb entry value
  before we write it to hardware.
 
  Also we use new struct tlbe_ref to trace the relation
  between guest tlb entry and page.
 
 Did you look at the performance impact?
 
 Back in the day, we did essentially the same thing on 440. However, 
 rather than discard the whole TLB when context switching away 
 from the 
 host (to be demand-faulted when the guest is resumed), we found a 
 noticeable performance improvement by preserving a shadow TLB across 
 context switches. We only use it in the vcpu_put/vcpu_load path.
 
 Of course, our TLB was much smaller (64 entries), so the use 
 model may 
 not be the same at all (e.g. it takes longer to restore a 
 full guest TLB 
 working set, but maybe it's not really possible to use all 1024 TLB0 
 entries in one timeslice anyways).
 

Yes, it's hard to resume TLB0. We only resume TLB1 in previous code.
But TLB1 is even more smaller (13 free entries) than 440,
So that it still has little possibility to get hit.
thus the resumption is useless.

And we plan to use shadow PID to minimize the TLB invalidation.
Then we don't need to invalidate TLB when guest schedule out.
So that we don't need to resume TLB entries.

But thit method require dynamic TID in shadow TLB,
So we wouldn't like to keep shadow TLB anyway.

Thanks,
Yu

--
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 0/2] kvm/e500v2: MMU optimization

2010-09-09 Thread Liu Yu-B13201
 

 -Original Message-
 From: Hollis Blanchard [mailto:hollis_blanch...@mentor.com] 
 Sent: Friday, September 10, 2010 12:23 AM
 To: Liu Yu-B13201
 Cc: k...@vger.kernel.org; kvm-ppc@vger.kernel.org; ag...@suse.de
 Subject: Re: [PATCH 0/2] kvm/e500v2: MMU optimization
 
 
   
  Hi Hollis,
 
  Guest uses AS=1 and host uses AS=0,
  so even guest uses the same TID with host, they're in 
 different space.
 
  Then why guest needs to care about host TID?
 
 
 You're absolutely right, but this makes a couple key assumptions:
 1. The guest doesn't try to use AS=1. This is already false in Linux, 
 because the udbg code uses an AS=1 mapping for the UART, but 
 this can be 
 configured out (with a small loss in functionality). In 
 non-Linux guests 
 the AS=0 restriction could be onerous.

We could map (guest AS, guest TID) to (shadow TID),
So that we still don't need to bother host.

 2. A Book E MMU. If we participate in the host MMU context 
 allocation, 
 the guest - host address space code could be generalized to include 
 e.g. an e600 guest on an e500 host, or vice versa.
 

Hmm.. Not sure it's a real requirement.


Thanks,
Yu

--
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


[PATCH 1/2] kvm/e500v2: Remove shadow tlb

2010-09-08 Thread Liu Yu
It is unnecessary to keep shadow tlb.
first, shadow tlb keep fixed value in shadow, which make things unflexible.
second, remove shadow tlb can save a lot memory.

This patch remove shadow tlb and caculate the shadow tlb entry value
before we write it to hardware.

Also we use new struct tlbe_ref to trace the relation
between guest tlb entry and page.

Signed-off-by: Liu Yu yu@freescale.com
---
 arch/powerpc/include/asm/kvm_e500.h |7 +-
 arch/powerpc/kvm/e500_tlb.c |  287 +--
 2 files changed, 108 insertions(+), 186 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_e500.h 
b/arch/powerpc/include/asm/kvm_e500.h
index 7fea26f..cb785f9 100644
--- a/arch/powerpc/include/asm/kvm_e500.h
+++ b/arch/powerpc/include/asm/kvm_e500.h
@@ -29,13 +29,18 @@ struct tlbe{
u32 mas7;
 };
 
+struct tlbe_ref {
+   struct page *page;
+   struct tlbe *gtlbe;
+};
+
 struct kvmppc_vcpu_e500 {
/* Unmodified copy of the guest's TLB. */
struct tlbe *guest_tlb[E500_TLB_NUM];
/* TLB that's actually used when the guest is running. */
struct tlbe *shadow_tlb[E500_TLB_NUM];
/* Pages which are referenced in the shadow TLB. */
-   struct page **shadow_pages[E500_TLB_NUM];
+   struct tlbe_ref *shadow_refs[E500_TLB_NUM];
 
unsigned int guest_tlb_size[E500_TLB_NUM];
unsigned int shadow_tlb_size[E500_TLB_NUM];
diff --git a/arch/powerpc/kvm/e500_tlb.c b/arch/powerpc/kvm/e500_tlb.c
index f11ca0f..0b657af 100644
--- a/arch/powerpc/kvm/e500_tlb.c
+++ b/arch/powerpc/kvm/e500_tlb.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 Freescale Semiconductor, Inc. All rights reserved.
+ * Copyright (C) 2008, 2010 Freescale Semiconductor, Inc. All rights reserved.
  *
  * Author: Yu Liu, yu@freescale.com
  *
@@ -48,17 +48,6 @@ void kvmppc_dump_tlbs(struct kvm_vcpu *vcpu)
tlbe-mas3, tlbe-mas7);
}
}
-
-   for (tlbsel = 0; tlbsel  2; tlbsel++) {
-   printk(Shadow TLB%d:\n, tlbsel);
-   for (i = 0; i  vcpu_e500-shadow_tlb_size[tlbsel]; i++) {
-   tlbe = vcpu_e500-shadow_tlb[tlbsel][i];
-   if (tlbe-mas1  MAS1_VALID)
-   printk( S[%d][%3d] |  %08X | %08X | %08X | 
%08X |\n,
-   tlbsel, i, tlbe-mas1, tlbe-mas2,
-   tlbe-mas3, tlbe-mas7);
-   }
-   }
 }
 
 static inline unsigned int tlb0_get_next_victim(
@@ -121,10 +110,8 @@ static inline void __write_host_tlbe(struct tlbe *stlbe)
 }
 
 static inline void write_host_tlbe(struct kvmppc_vcpu_e500 *vcpu_e500,
-   int tlbsel, int esel)
+   int tlbsel, int esel, struct tlbe *stlbe)
 {
-   struct tlbe *stlbe = vcpu_e500-shadow_tlb[tlbsel][esel];
-
local_irq_disable();
if (tlbsel == 0) {
__write_host_tlbe(stlbe);
@@ -139,28 +126,12 @@ static inline void write_host_tlbe(struct 
kvmppc_vcpu_e500 *vcpu_e500,
mtspr(SPRN_MAS0, mas0);
}
local_irq_enable();
+   trace_kvm_stlb_write(index_of(tlbsel, esel), stlbe-mas1, stlbe-mas2,
+   stlbe-mas3, stlbe-mas7);
 }
 
 void kvmppc_e500_tlb_load(struct kvm_vcpu *vcpu, int cpu)
 {
-   struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
-   int i;
-   unsigned register mas0;
-
-   /* Load all valid TLB1 entries to reduce guest tlb miss fault */
-   local_irq_disable();
-   mas0 = mfspr(SPRN_MAS0);
-   for (i = 0; i  tlb1_max_shadow_size(); i++) {
-   struct tlbe *stlbe = vcpu_e500-shadow_tlb[1][i];
-
-   if (get_tlb_v(stlbe)) {
-   mtspr(SPRN_MAS0, MAS0_TLBSEL(1)
-   | MAS0_ESEL(to_htlb1_esel(i)));
-   __write_host_tlbe(stlbe);
-   }
-   }
-   mtspr(SPRN_MAS0, mas0);
-   local_irq_enable();
 }
 
 void kvmppc_e500_tlb_put(struct kvm_vcpu *vcpu)
@@ -202,16 +173,19 @@ static int kvmppc_e500_tlb_index(struct kvmppc_vcpu_e500 
*vcpu_e500,
 }
 
 static void kvmppc_e500_shadow_release(struct kvmppc_vcpu_e500 *vcpu_e500,
-   int tlbsel, int esel)
+   int stlbsel, int sesel)
 {
-   struct tlbe *stlbe = vcpu_e500-shadow_tlb[tlbsel][esel];
-   struct page *page = vcpu_e500-shadow_pages[tlbsel][esel];
+   struct tlbe_ref *ref;
+   struct page *page;
+
+   ref = vcpu_e500-shadow_refs[stlbsel][sesel];
+   page = ref-page;
 
if (page) {
-   vcpu_e500-shadow_pages[tlbsel][esel] = NULL;
+   ref-page = NULL;
 
-   if (get_tlb_v(stlbe)) {
-   if (tlbe_is_writable(stlbe))
+   if (get_tlb_v(ref-gtlbe)) {
+   if (tlbe_is_writable(ref-gtlbe))
kvm_release_page_dirty(page);
else

[PATCH 2/2] kvm/e500v2: mapping guest TLB1 to host TLB0

2010-09-08 Thread Liu Yu
Current guest TLB1 is mapped to host TLB1.
As host kernel only provides 4K uncontinuous pages,
we have to break guest large mapping into 4K shadow mappings.
These 4K shadow mappings are then mapped into host TLB1 on fly.
As host TLB1 only has 13 free entries, there's serious tlb miss.

Since e500v2 has a big number of TLB0 entries,
it should be help to map those 4K shadow mappings to host TLB0.
To achieve this, we need to unlink guest tlb and host tlb,
So that guest TLB1 mappings can route to any host TLB0 entries freely.

Pages/mappings are considerred in the same kind as host tlb entry.
This patch remove the link between pages and guest tlb entry to do the unlink.
And keep host_tlb0_ref in each vcpu to trace pages.
Then it's easy to map guest TLB1 to host TLB0.

In guest ramdisk boot test(guest mainly uses TLB1),
with this patch, the tlb miss number get down 90%.

Signed-off-by: Liu Yu yu@freescale.com
---
 arch/powerpc/include/asm/kvm_e500.h |7 +-
 arch/powerpc/kvm/e500.c |4 +
 arch/powerpc/kvm/e500_tlb.c |  280 ---
 arch/powerpc/kvm/e500_tlb.h |1 +
 4 files changed, 104 insertions(+), 188 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_e500.h 
b/arch/powerpc/include/asm/kvm_e500.h
index cb785f9..16c0ed0 100644
--- a/arch/powerpc/include/asm/kvm_e500.h
+++ b/arch/powerpc/include/asm/kvm_e500.h
@@ -37,13 +37,10 @@ struct tlbe_ref {
 struct kvmppc_vcpu_e500 {
/* Unmodified copy of the guest's TLB. */
struct tlbe *guest_tlb[E500_TLB_NUM];
-   /* TLB that's actually used when the guest is running. */
-   struct tlbe *shadow_tlb[E500_TLB_NUM];
-   /* Pages which are referenced in the shadow TLB. */
-   struct tlbe_ref *shadow_refs[E500_TLB_NUM];
+   /* Pages which are referenced in host TLB. */
+   struct tlbe_ref *host_tlb0_ref;
 
unsigned int guest_tlb_size[E500_TLB_NUM];
-   unsigned int shadow_tlb_size[E500_TLB_NUM];
unsigned int guest_tlb_nv[E500_TLB_NUM];
 
u32 host_pid[E500_PID_NUM];
diff --git a/arch/powerpc/kvm/e500.c b/arch/powerpc/kvm/e500.c
index e8a00b0..14af6d7 100644
--- a/arch/powerpc/kvm/e500.c
+++ b/arch/powerpc/kvm/e500.c
@@ -146,6 +146,10 @@ static int __init kvmppc_e500_init(void)
if (r)
return r;
 
+   r = kvmppc_e500_mmu_init();
+   if (r)
+   return r;
+
/* copy extra E500 exception handlers */
ivor[0] = mfspr(SPRN_IVOR32);
ivor[1] = mfspr(SPRN_IVOR33);
diff --git a/arch/powerpc/kvm/e500_tlb.c b/arch/powerpc/kvm/e500_tlb.c
index 0b657af..a6c2320 100644
--- a/arch/powerpc/kvm/e500_tlb.c
+++ b/arch/powerpc/kvm/e500_tlb.c
@@ -25,9 +25,15 @@
 #include e500_tlb.h
 #include trace.h
 
-#define to_htlb1_esel(esel) (tlb1_entry_num - (esel) - 1)
+static unsigned int host_tlb0_entry_num;
+static unsigned int host_tlb0_assoc;
+static unsigned int host_tlb0_assoc_bit;
 
-static unsigned int tlb1_entry_num;
+static inline unsigned int get_tlb0_entry_offset(u32 eaddr, u32 esel)
+{
+   return ((eaddr  0x7F000)  (12 - host_tlb0_assoc_bit) |
+   (esel  (host_tlb0_assoc - 1)));
+}
 
 void kvmppc_dump_tlbs(struct kvm_vcpu *vcpu)
 {
@@ -62,11 +68,6 @@ static inline unsigned int tlb0_get_next_victim(
return victim;
 }
 
-static inline unsigned int tlb1_max_shadow_size(void)
-{
-   return tlb1_entry_num - tlbcam_index;
-}
-
 static inline int tlbe_is_writable(struct tlbe *tlbe)
 {
return tlbe-mas3  (MAS3_SW|MAS3_UW);
@@ -100,7 +101,7 @@ static inline u32 e500_shadow_mas2_attrib(u32 mas2, int 
usermode)
 /*
  * writing shadow tlb entry to host TLB
  */
-static inline void __write_host_tlbe(struct tlbe *stlbe)
+static inline void __host_tlbe_write(struct tlbe *stlbe)
 {
mtspr(SPRN_MAS1, stlbe-mas1);
mtspr(SPRN_MAS2, stlbe-mas2);
@@ -109,25 +110,22 @@ static inline void __write_host_tlbe(struct tlbe *stlbe)
__asm__ __volatile__ (tlbwe\n : : );
 }
 
-static inline void write_host_tlbe(struct kvmppc_vcpu_e500 *vcpu_e500,
-   int tlbsel, int esel, struct tlbe *stlbe)
+static inline u32 host_tlb0_write(struct kvmppc_vcpu_e500 *vcpu_e500,
+   u32 gvaddr, struct tlbe *stlbe)
 {
-   local_irq_disable();
-   if (tlbsel == 0) {
-   __write_host_tlbe(stlbe);
-   } else {
-   unsigned register mas0;
+   unsigned register mas0;
 
-   mas0 = mfspr(SPRN_MAS0);
+   local_irq_disable();
 
-   mtspr(SPRN_MAS0, MAS0_TLBSEL(1) | 
MAS0_ESEL(to_htlb1_esel(esel)));
-   __write_host_tlbe(stlbe);
+   mas0 = mfspr(SPRN_MAS0);
+   __host_tlbe_write(stlbe);
 
-   mtspr(SPRN_MAS0, mas0);
-   }
local_irq_enable();
-   trace_kvm_stlb_write(index_of(tlbsel, esel), stlbe-mas1, stlbe-mas2,
+
+   trace_kvm_stlb_write(mas0, stlbe-mas1, stlbe-mas2,
stlbe-mas3, stlbe-mas7

[PATCH 0/2] kvm/e500v2: MMU optimization

2010-09-08 Thread Liu Yu
The patchset aims at mapping guest TLB1 to host TLB0.
And it includes:
[PATCH 1/2] kvm/e500v2: Remove shadow tlb
[PATCH 2/2] kvm/e500v2: mapping guest TLB1 to host TLB0

The reason we need patch 1 is because patch 1 make things simple and flexible.
Only applying patch 1 aslo make kvm work.

--
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 14/27] KVM: PPC: Magic Page BookE support

2010-07-12 Thread Liu Yu-B13201
 

 -Original Message-
 From: kvm-ow...@vger.kernel.org 
 [mailto:kvm-ow...@vger.kernel.org] On Behalf Of Alexander Graf
 Sent: Thursday, July 01, 2010 6:43 PM
 To: kvm-ppc@vger.kernel.org
 Cc: KVM list; linuxppc-dev
 Subject: [PATCH 14/27] KVM: PPC: Magic Page BookE support
 
 As we now have Book3s support for the magic page, we also 
 need BookE to
 join in on the party.
 
 This patch implements generic magic page logic for BookE and specific
 TLB logic for e500. I didn't have any 440 around, so I didn't dare to
 blindly try and write up broken code.
 
 Signed-off-by: Alexander Graf ag...@suse.de
 ---
  arch/powerpc/kvm/booke.c|   29 +
  arch/powerpc/kvm/e500_tlb.c |   19 +--
  2 files changed, 46 insertions(+), 2 deletions(-)
 
 diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
 index 0f8ff9d..9609207 100644
 --- a/arch/powerpc/kvm/booke.c
 +++ b/arch/powerpc/kvm/booke.c

 @@ -380,6 +406,9 @@ int kvmppc_handle_exit(struct kvm_run 
 *run, struct kvm_vcpu *vcpu,
   gpa_t gpaddr;
   gfn_t gfn;
  
 + if (kvmppc_dtlb_magic_page(vcpu, eaddr))
 + break;
 +
   /* Check the guest TLB. */
   gtlb_index = kvmppc_mmu_dtlb_index(vcpu, eaddr);
   if (gtlb_index  0) {

How about moving this part into tlb search fail path?

--
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: Status of KVM on e500

2010-05-18 Thread Liu Yu-B13201
 

 -Original Message-
 From: kvm-ppc-ow...@vger.kernel.org 
 [mailto:kvm-ppc-ow...@vger.kernel.org] On Behalf Of Alexander Graf
 Sent: Tuesday, May 18, 2010 5:33 PM
 To: Mu Lin
 Cc: kvm-ppc@vger.kernel.org; Liu Yu-B13201
 Subject: Status of KVM on e500
 
 Hi Mu,
 
  Hi, All,
  
  Is there a status summary somewhere about Linux KVM on powerpc?
 
 Unfortunately no. There are some outdated documents on linux-kvm.org:
 
 http://www.linux-kvm.org/page/PowerPC
 
  I am interested in KVM on MPC8572 with e500 core, and how 
 about e500mc?
 
 The e500 definitely works. I'm not sure about the e500mc. KVM 
 definitely has no code to leverage the new hypervisor 
 capabilities, but I don't see why the e500 code shouldn't 
 work on the e500mc.

Heh. I think the problem is people wouldn't like to run e500 kvm code on
e500mc.

 
  Is there bench mark testing results?
 
 The closest thing I found is this page:
 
 http://www.linux-kvm.org/page/PowerPC_Exittimings
 
 The last time I tried out KVM on an e500, the MMU overhead 
 was a lot bigger though. So I guess there's more room for 
 improvement on that side.
 

Indeed.
Since you have code and board.
Do you have any plan?  :-D

--
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


[PATCH 1/4] kvmppc: guest debug definitions

2010-02-03 Thread Liu Yu
Signed-off-by: Liu Yu yu@freescale.com
---
 arch/powerpc/include/asm/kvm.h  |   20 
 arch/powerpc/include/asm/kvm_host.h |   16 
 2 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm.h b/arch/powerpc/include/asm/kvm.h
index 81f3b0b..b7f7861 100644
--- a/arch/powerpc/include/asm/kvm.h
+++ b/arch/powerpc/include/asm/kvm.h
@@ -22,6 +22,9 @@
 
 #include linux/types.h
 
+/* Select powerpc specific features in linux/kvm.h */
+#define __KVM_HAVE_GUEST_DEBUG
+
 struct kvm_regs {
__u64 pc;
__u64 cr;
@@ -71,10 +74,27 @@ struct kvm_fpu {
 };
 
 struct kvm_debug_exit_arch {
+   __u32 exception;
+   __u32 pc;
+   __u32 status;
 };
 
+#define KVM_INST_GUESTGDB   0x4422
+
+#define KVM_GUESTDBG_USE_SW_BP  0x0001
+#define KVM_GUESTDBG_USE_HW_BP  0x0002
+
+#define KVMPPC_DEBUG_NOTYPE 0x0
+#define KVMPPC_DEBUG_BREAKPOINT (1UL  1)
+#define KVMPPC_DEBUG_WATCH_WRITE(1UL  2)
+#define KVMPPC_DEBUG_WATCH_READ (1UL  3)
+
 /* for KVM_SET_GUEST_DEBUG */
 struct kvm_guest_debug_arch {
+   struct {
+   __u32 addr;
+   __u32 type;
+   } bp[6];
 };
 
 #endif /* __LINUX_KVM_POWERPC_H */
diff --git a/arch/powerpc/include/asm/kvm_host.h 
b/arch/powerpc/include/asm/kvm_host.h
index 5e5bae7..a364832 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -157,6 +157,18 @@ struct hpte_cache {
struct kvmppc_pte pte;
 };
 
+struct kvmppc_debug_reg {
+   u32 dbcr0;
+   u32 iac[0];
+   u32 iac1;
+   u32 iac2;
+   u32 iac3;
+   u32 iac4;
+   u32 dac[0];
+   u32 dac1;
+   u32 dac2;
+};
+
 struct kvm_vcpu_arch {
ulong host_stack;
u32 host_pid;
@@ -240,6 +252,9 @@ struct kvm_vcpu_arch {
u32 dbcr1;
u32 dbsr;
 
+   struct kvmppc_debug_reg shadow_dbg_reg;
+   struct kvmppc_debug_reg host_dbg_reg;
+
 #ifdef CONFIG_KVM_EXIT_TIMING
struct kvmppc_exit_timing timing_exit;
struct kvmppc_exit_timing timing_last_enter;
@@ -274,6 +289,7 @@ struct kvm_vcpu_arch {
struct tasklet_struct tasklet;
u64 dec_jiffies;
unsigned long pending_exceptions;
+   struct kvm_guest_debug_arch dbg;
 
 #ifdef CONFIG_PPC64
struct hpte_cache hpte_cache[HPTEG_CACHE_NUM];
-- 
1.6.4

--
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


[PATCH 2/4] kvmppc/booke: switch shadow/host debug registers on guest enter/exit path

2010-02-03 Thread Liu Yu
This provide a precise way to avoid confounding settings of guest and host.
Also the guest hardware emulation about debug can be implemented based on this.

Signed-off-by: Liu Yu yu@freescale.com
---
 arch/powerpc/kernel/asm-offsets.c   |3 ++
 arch/powerpc/kvm/booke_interrupts.S |   58 +++
 2 files changed, 61 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/kernel/asm-offsets.c 
b/arch/powerpc/kernel/asm-offsets.c
index 957ceb7..67e978d 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -425,6 +425,9 @@ int main(void)
DEFINE(VCPU_LAST_INST, offsetof(struct kvm_vcpu, arch.last_inst));
DEFINE(VCPU_FAULT_DEAR, offsetof(struct kvm_vcpu, arch.fault_dear));
DEFINE(VCPU_FAULT_ESR, offsetof(struct kvm_vcpu, arch.fault_esr));
+   DEFINE(VCPU_SHADOW_DBG, offsetof(struct kvm_vcpu, arch.shadow_dbg_reg));
+   DEFINE(VCPU_HOST_DBG, offsetof(struct kvm_vcpu, arch.host_dbg_reg));
+   DEFINE(VCPU_GUEST_DEBUG, offsetof(struct kvm_vcpu, guest_debug));
 
/* book3s_64 */
 #ifdef CONFIG_PPC64
diff --git a/arch/powerpc/kvm/booke_interrupts.S 
b/arch/powerpc/kvm/booke_interrupts.S
index 380a78c..644ff1d 100644
--- a/arch/powerpc/kvm/booke_interrupts.S
+++ b/arch/powerpc/kvm/booke_interrupts.S
@@ -168,6 +168,26 @@ _GLOBAL(kvmppc_resume_host)
stw r9, VCPU_FAULT_ESR(r4)
 ..skip_esr:
 
+   lwz r6, VCPU_GUEST_DEBUG(r4)
+   or. r6, r6, r6
+   beq ..skip_load_host_debug
+   addir7, r4, VCPU_HOST_DBG - 4
+   lwzur9, 4(r7)
+   mtspr   SPRN_DBCR0, r9
+   lwzur9, 4(r7)
+   mtspr   SPRN_IAC1, r9
+   lwzur9, 4(r7)
+   mtspr   SPRN_IAC2, r9
+   lwzur9, 4(r7)
+   mtspr   SPRN_IAC3, r9
+   lwzur9, 4(r7)
+   mtspr   SPRN_IAC4, r9
+   lwzur9, 4(r7)
+   mtspr   SPRN_DAC1, r9
+   lwzur9, 4(r7)
+   mtspr   SPRN_DAC2, r9
+..skip_load_host_debug:
+
/* Save remaining volatile guest register state to vcpu. */
stw r0, VCPU_GPR(r0)(r4)
stw r1, VCPU_GPR(r1)(r4)
@@ -392,6 +412,44 @@ lightweight_exit:
lwz r3, VCPU_SPRG7(r4)
mtspr   SPRN_SPRG7W, r3
 
+   lwz r6, VCPU_GUEST_DEBUG(r4)
+   or. r6, r6, r6
+   beq ..skip_load_guest_debug
+   mfmsr   r7
+   rlwinm  r7, r7, 0, ~MSR_DE
+   mtmsr   r7
+   addir7, r4, VCPU_HOST_DBG - 4
+   mfspr   r8, SPRN_DBCR0
+   stwur8, 4(r7)
+   mfspr   r8, SPRN_IAC1
+   stwur8, 4(r7)
+   mfspr   r8, SPRN_IAC2
+   stwur8, 4(r7)
+   mfspr   r8, SPRN_IAC3
+   stwur8, 4(r7)
+   mfspr   r8, SPRN_IAC4
+   stwur8, 4(r7)
+   mfspr   r8, SPRN_DAC1
+   stwur8, 4(r7)
+   mfspr   r8, SPRN_DAC2
+   stwur8, 4(r7)
+   addir7, r4, VCPU_SHADOW_DBG - 4
+   lwzur8, 4(r7)
+   mtspr   SPRN_DBCR0, r8
+   lwzur8, 4(r7)
+   mtspr   SPRN_IAC1, r8
+   lwzur8, 4(r7)
+   mtspr   SPRN_IAC2, r8
+   lwzur8, 4(r7)
+   mtspr   SPRN_IAC3, r8
+   lwzur8, 4(r7)
+   mtspr   SPRN_IAC4, r8
+   lwzur8, 4(r7)
+   mtspr   SPRN_DAC1, r8
+   lwzur8, 4(r7)
+   mtspr   SPRN_DAC2, r8
+..skip_load_guest_debug:
+
 #ifdef CONFIG_KVM_EXIT_TIMING
/* save enter time */
 1:
-- 
1.6.4

--
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


[PATCH 4/4] kvmppc/booke: exit_nr fixup for guest debug single step

2010-02-03 Thread Liu Yu
As BOOKE doesn't have hardware support for virtualization,
hardware never know who's guest and host.

When enable hardware single step in guest,
we cannot disabled it at the point we switch back to host.
Thus, we'll see that an single step interrupt happens at
the beginning of guest exit path.

Then we need to recognize this kind of single step interrupt
and fix the exit_nr to the original value.
So that everything looks like normal.

Signed-off-by: Liu Yu yu@freescale.com
---
 arch/powerpc/kvm/booke.c|   82 +++
 arch/powerpc/kvm/booke_interrupts.S |9 ++--
 2 files changed, 87 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index ec2722d..9056708 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -24,6 +24,7 @@
 #include linux/module.h
 #include linux/vmalloc.h
 #include linux/fs.h
+#include linux/highmem.h
 
 #include asm/cputable.h
 #include asm/uaccess.h
@@ -34,6 +35,8 @@
 #include booke.h
 
 unsigned long kvmppc_booke_handlers;
+unsigned long kvmppc_booke_handler_addr[16];
+#define handler_vector_num 
(sizeof(kvmppc_booke_handler_addr)/sizeof(kvmppc_booke_handler_addr[0]))
 
 #define VM_STAT(x) offsetof(struct kvm, stat.x), KVM_STAT_VM
 #define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU
@@ -214,6 +217,80 @@ void kvmppc_core_deliver_interrupts(struct kvm_vcpu *vcpu)
}
 }
 
+int kvmppc_read_guest(struct kvm_vcpu *vcpu, unsigned long geaddr,
+ void *data, int len)
+{
+   int gtlb_index;
+   gpa_t gpa;
+   gfn_t gfn;
+   struct page *page;
+   void *headdr, *from;
+
+   /* Check the guest TLB. */
+   gtlb_index = kvmppc_mmu_itlb_index(vcpu, geaddr);
+   if (gtlb_index  0)
+   return -EFAULT;
+
+   gpa = kvmppc_mmu_xlate(vcpu, gtlb_index, geaddr);
+   gfn = gpa  PAGE_SHIFT;
+
+   page = gfn_to_page(vcpu-kvm, gfn);
+   if (page == bad_page)
+   return -EFAULT;
+
+   headdr = kmap_atomic(page, KM_USER0);
+   if (!headdr)
+   return -EFAULT;
+   from = headdr + (geaddr  (PAGE_SIZE - 1));
+   memcpy(data, from, len);
+   kunmap_atomic(headdr, KM_USER0);
+
+   return 0;
+}
+
+static unsigned int kvmppc_guest_debug_exitnr_fixup(struct kvm_vcpu *vcpu,
+  unsigned int exit_nr)
+{
+   unsigned int ret = exit_nr;
+
+   u32 csrr0 = mfspr(SPRN_CSRR0);
+   u32 dbsr = mfspr(SPRN_DBSR);
+
+   if ((dbsr | DBSR_IC) 
+   csrr0 = kvmppc_booke_handlers 
+   csrr0  kvmppc_booke_handlers + (PAGE_SIZE  VCPU_SIZE_ORDER)) {
+   int i = 0;
+
+   for (i = 0; i  handler_vector_num; i++) {
+   if (kvmppc_booke_handler_addr[i] 
+   csrr0 == kvmppc_booke_handler_addr[i] + 4) {
+   mtspr(SPRN_DBSR, ~0);
+   ret = i;
+   break;
+   }
+   }
+
+   }
+
+   switch (ret) {
+   case BOOKE_INTERRUPT_DEBUG:
+   case BOOKE_INTERRUPT_ITLB_MISS:
+   case BOOKE_INTERRUPT_EXTERNAL:
+   case BOOKE_INTERRUPT_DECREMENTER:
+   break;
+
+   case BOOKE_INTERRUPT_PROGRAM:
+   case BOOKE_INTERRUPT_DTLB_MISS:
+   /* Need to save the last instruction */
+   kvmppc_read_guest(vcpu, vcpu-arch.pc, vcpu-arch.last_inst, 
4);
+   break;
+   default:
+   printk(Unhandled debug after interrupt:%d\n, ret);
+   }
+
+   return ret;
+}
+
 /**
  * kvmppc_handle_exit
  *
@@ -233,6 +310,9 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu 
*vcpu,
run-exit_reason = KVM_EXIT_UNKNOWN;
run-ready_for_interrupt_injection = 1;
 
+   if (unlikely(exit_nr == BOOKE_INTERRUPT_DEBUG))
+   exit_nr = kvmppc_guest_debug_exitnr_fixup(vcpu, exit_nr);
+
switch (exit_nr) {
case BOOKE_INTERRUPT_MACHINE_CHECK:
printk(MACHINE CHECK: %lx\n, mfspr(SPRN_MCSR));
@@ -686,6 +766,8 @@ int __init kvmppc_booke_init(void)
memcpy((void *)kvmppc_booke_handlers + ivor[i],
   kvmppc_handlers_start + i * kvmppc_handler_len,
   kvmppc_handler_len);
+   kvmppc_booke_handler_addr[i] =
+   (unsigned long)kvmppc_booke_handlers + ivor[i];
}
flush_icache_range(kvmppc_booke_handlers,
   kvmppc_booke_handlers + max_ivor + 
kvmppc_handler_len);
diff --git a/arch/powerpc/kvm/booke_interrupts.S 
b/arch/powerpc/kvm/booke_interrupts.S
index 644ff1d..fdc48c1 100644
--- a/arch/powerpc/kvm/booke_interrupts.S
+++ b/arch/powerpc/kvm/booke_interrupts.S
@@ -42,16 +42,17 @@
 #define HOST_STACK_LR   (HOST_STACK_SIZE + 4) /* In caller stack frame. */
 
 #define NEED_INST_MASK ((1BOOKE_INTERRUPT_PROGRAM

RE: [PATCH 1/4] kvmppc: guest debug definitions

2010-02-03 Thread Liu Yu-B13201
 

 -Original Message-
 From: kvm-ppc-ow...@vger.kernel.org 
 [mailto:kvm-ppc-ow...@vger.kernel.org] On Behalf Of Alexander Graf
 Sent: Wednesday, February 03, 2010 4:57 PM
 To: Liu Yu-B13201
 Cc: hol...@penguinppc.org; kvm-ppc@vger.kernel.org; 
 k...@vger.kernel.org; Liu Yu-B13201
 Subject: Re: [PATCH 1/4] kvmppc: guest debug definitions
 
 
 Am 03.02.2010 um 08:53 schrieb Liu Yu yu@freescale.com:
 
  Signed-off-by: Liu Yu yu@freescale.com
  ---
  arch/powerpc/include/asm/kvm.h  |   20 
  arch/powerpc/include/asm/kvm_host.h |   16 
  2 files changed, 36 insertions(+), 0 deletions(-)
 
  diff --git a/arch/powerpc/include/asm/kvm.h b/arch/powerpc/include/ 
  asm/kvm.h
  index 81f3b0b..b7f7861 100644
  --- a/arch/powerpc/include/asm/kvm.h
  +++ b/arch/powerpc/include/asm/kvm.h
  @@ -22,6 +22,9 @@
 
  #include linux/types.h
 
  +/* Select powerpc specific features in linux/kvm.h */
  +#define __KVM_HAVE_GUEST_DEBUG
  +
  struct kvm_regs {
 __u64 pc;
 __u64 cr;
  @@ -71,10 +74,27 @@ struct kvm_fpu {
  };
 
  struct kvm_debug_exit_arch {
  +__u32 exception;
  +__u32 pc;
  +__u32 status;
  };
 
  +#define KVM_INST_GUESTGDB   0x4422
 
 What instruction is this again? :) Is it something reserved for  
 purposes like this?
 

Just an invalid instruction which can generate program interrupt...
I'm open to it's value btw.

 
  +
  +#define KVM_GUESTDBG_USE_SW_BP  0x0001
  +#define KVM_GUESTDBG_USE_HW_BP  0x0002
  +
  +#define KVMPPC_DEBUG_NOTYPE 0x0
  +#define KVMPPC_DEBUG_BREAKPOINT (1UL  1)
  +#define KVMPPC_DEBUG_WATCH_WRITE(1UL  2)
  +#define KVMPPC_DEBUG_WATCH_READ (1UL  3)
  +
  /* for KVM_SET_GUEST_DEBUG */
  struct kvm_guest_debug_arch {
  +struct {
  +__u32 addr;
  +__u32 type;
  +} bp[6];
 
 I can't look up the sources right now. Is this a struct that 
 1:1 maps  
 to an ioctl struct? If so, we should add padding for a 
 possible future  
 extension of debug registers.

Yes it's used by ioctl.
What's the usually pad size?

--
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 4/4] kvmppc/booke: exit_nr fixup for guest debug single step

2010-02-03 Thread Liu Yu-B13201
 

 -Original Message-
 From: kvm-ppc-ow...@vger.kernel.org 
 [mailto:kvm-ppc-ow...@vger.kernel.org] On Behalf Of Alexander Graf
 Sent: Wednesday, February 03, 2010 5:03 PM
 To: Liu Yu-B13201
 Cc: hol...@penguinppc.org; kvm-ppc@vger.kernel.org; 
 k...@vger.kernel.org; Liu Yu-B13201
 Subject: Re: [PATCH 4/4] kvmppc/booke: exit_nr fixup for 
 guest debug single step
 
 
 Am 03.02.2010 um 08:53 schrieb Liu Yu yu@freescale.com:
 
  As BOOKE doesn't have hardware support for virtualization,
  hardware never know who's guest and host.
 
  When enable hardware single step in guest,
  we cannot disabled it at the point we switch back to host.
 
 Why not? We directly arrive in our code. So we can just 
 disable it, no?
 
 Or does that break when you'd try to debug the guest 
 interrupt handlers?

That's the hardware limitition.
Assume received itlb miss interrupt, but it doesn't clear MSR_DE in MSR,
so on the exit path single step still work and then debug interrupt is
triggled.


 
  Thus, we'll see that an single step interrupt happens at
  the beginning of guest exit path.
 
  Then we need to recognize this kind of single step interrupt
  and fix the exit_nr to the original value.
  So that everything looks like normal.
 
  Signed-off-by: Liu Yu yu@freescale.com
  ---
  arch/powerpc/kvm/booke.c|   82 
 ++ 
  +
  arch/powerpc/kvm/booke_interrupts.S |9 ++--
  2 files changed, 87 insertions(+), 4 deletions(-)
 
  diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
  index ec2722d..9056708 100644
  --- a/arch/powerpc/kvm/booke.c
  +++ b/arch/powerpc/kvm/booke.c
  @@ -24,6 +24,7 @@
  #include linux/module.h
  #include linux/vmalloc.h
  #include linux/fs.h
  +#include linux/highmem.h
 
  #include asm/cputable.h
  #include asm/uaccess.h
  @@ -34,6 +35,8 @@
  #include booke.h
 
  unsigned long kvmppc_booke_handlers;
  +unsigned long kvmppc_booke_handler_addr[16];
  +#define handler_vector_num 
 (sizeof(kvmppc_booke_handler_addr)/sizeof 
  (kvmppc_booke_handler_addr[0]))
 
  #define VM_STAT(x) offsetof(struct kvm, stat.x), KVM_STAT_VM
  #define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), 
 KVM_STAT_VCPU
  @@ -214,6 +217,80 @@ void kvmppc_core_deliver_interrupts(struct  
  kvm_vcpu *vcpu)
 }
  }
 
  +int kvmppc_read_guest(struct kvm_vcpu *vcpu, unsigned long geaddr,
  +  void *data, int len)
 
 Ah, nice. I have something similar in book3s.c. IIRC it's called  
 kvmppc_ld.
 
 I think we should make the semantics identical and declare it as  
 common kvmppc_core function.
 
Cool.
--
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 1/4] kvmppc: guest debug definitions

2010-02-03 Thread Liu Yu-B13201
 

 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de] 
 Sent: Wednesday, February 03, 2010 5:51 PM
 To: Liu Yu-B13201
 Cc: hol...@penguinppc.org; kvm-ppc@vger.kernel.org; 
 k...@vger.kernel.org
 Subject: Re: [PATCH 1/4] kvmppc: guest debug definitions
 
 Liu Yu-B13201 wrote:
   
 

  -Original Message-
  From: kvm-ppc-ow...@vger.kernel.org 
  [mailto:kvm-ppc-ow...@vger.kernel.org] On Behalf Of Alexander Graf
  Sent: Wednesday, February 03, 2010 4:57 PM
  To: Liu Yu-B13201
  Cc: hol...@penguinppc.org; kvm-ppc@vger.kernel.org; 
  k...@vger.kernel.org; Liu Yu-B13201
  Subject: Re: [PATCH 1/4] kvmppc: guest debug definitions
 
 
  Am 03.02.2010 um 08:53 schrieb Liu Yu yu@freescale.com:
 
  
  Signed-off-by: Liu Yu yu@freescale.com
  ---
  arch/powerpc/include/asm/kvm.h  |   20 
  arch/powerpc/include/asm/kvm_host.h |   16 
  2 files changed, 36 insertions(+), 0 deletions(-)
 
  diff --git a/arch/powerpc/include/asm/kvm.h 
 b/arch/powerpc/include/ 
  asm/kvm.h
  index 81f3b0b..b7f7861 100644
  --- a/arch/powerpc/include/asm/kvm.h
  +++ b/arch/powerpc/include/asm/kvm.h
  @@ -22,6 +22,9 @@
 
  #include linux/types.h
 
  +/* Select powerpc specific features in linux/kvm.h */
  +#define __KVM_HAVE_GUEST_DEBUG
  +
  struct kvm_regs {
 __u64 pc;
 __u64 cr;
  @@ -71,10 +74,27 @@ struct kvm_fpu {
  };
 
  struct kvm_debug_exit_arch {
  +__u32 exception;
  +__u32 pc;
  +__u32 status;
  };
 
  +#define KVM_INST_GUESTGDB   0x4422

  What instruction is this again? :) Is it something reserved for  
  purposes like this?
 
  
 
  Just an invalid instruction which can generate program interrupt...
  I'm open to it's value btw.

 
 Well this definitely doesn't generate a program interrupt. Or at least
 it shouldn't :-).
 I just remembered where I've seen an opcode like this before. 
 This is a
 part of a dump of arch/powerpc/boot/ps3-hvcall.o
 
  lv1_get_logical_ppe_id:
0:   7c 08 02 a6 mflrr0
4:   90 01 00 04 stw r0,4(r1)
8:   94 21 ff f0 stwur1,-16(r1)
c:   90 61 00 08 stw r3,8(r1)
   10:   39 60 00 45 li  r11,69
   14:   44 00 00 22 sc  1
 
 So as you can see, this is the hypercall instruction for lv1. 
 IIRC beat
 uses the same. I don't think we want to reuse that opcode for 
 ourselves.
 Maybe one day someone figures it's a good idea to implement a 
 beat-style
 ABI in KVM.
 
 But IIRC sc can take a lot of values, so we can just take sc 0x1234 or
 so :-).
 
  +
  +#define KVM_GUESTDBG_USE_SW_BP  0x0001
  +#define KVM_GUESTDBG_USE_HW_BP  0x0002
  +
  +#define KVMPPC_DEBUG_NOTYPE 0x0
  +#define KVMPPC_DEBUG_BREAKPOINT (1UL  1)
  +#define KVMPPC_DEBUG_WATCH_WRITE(1UL  2)
  +#define KVMPPC_DEBUG_WATCH_READ (1UL  3)
  +
  /* for KVM_SET_GUEST_DEBUG */
  struct kvm_guest_debug_arch {
  +struct {
  +__u32 addr;
  +__u32 type;
  +} bp[6];

  I can't look up the sources right now. Is this a struct that 
  1:1 maps  
  to an ioctl struct? If so, we should add padding for a 
  possible future  
  extension of debug registers.
  
 
  Yes it's used by ioctl.
  What's the usually pad size?

 
 I don't think there's a default. I just tend to pad it to something
 reasonable. I guess in this case we can even just extend bp to 128
 entries, add a reasonable amount of churn to the debug info 
 and be good:
 
 struct kvm_guest_debug_arch {
 struct {
 __u64 addr;
 __u32 type;
 __u32 pad1;
 __u64 pad2;
 } bp[128];
 }
 

Software breakpoint is maintained by qemu.
Here it's only used by hardware breakpoint/watchpoint
Is 128 much too large?

--
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


[PATCH v2] kvmppc/booke: Set ESR and DEAR when inject interrupt to guest

2010-02-02 Thread Liu Yu
Old method prematurely sets ESR and DEAR.
Move this part after we decide to inject interrupt,
which is more like hardware behave.

Signed-off-by: Liu Yu yu@freescale.com
---
v2:
use new fields queued_esr queued_dear to queue flags

 arch/powerpc/include/asm/kvm_host.h |2 +
 arch/powerpc/kvm/booke.c|   58 ++-
 arch/powerpc/kvm/emulate.c  |4 +-
 3 files changed, 47 insertions(+), 17 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_host.h 
b/arch/powerpc/include/asm/kvm_host.h
index 715aa6b..5e5bae7 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -259,6 +259,8 @@ struct kvm_vcpu_arch {
 #endif
ulong fault_dear;
ulong fault_esr;
+   ulong queued_dear;
+   ulong queued_esr;
gpa_t paddr_accessed;
 
u8 io_gpr; /* GPR used as IO source/target */
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index e283e44..ba93088 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -82,9 +82,31 @@ static void kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu,
set_bit(priority, vcpu-arch.pending_exceptions);
 }
 
-void kvmppc_core_queue_program(struct kvm_vcpu *vcpu, ulong flags)
+void kvmppc_core_queue_dtlb_miss(struct kvm_vcpu *vcpu,
+ ulong dear_flags, ulong esr_flags)
 {
-   /* BookE does flags in ESR, so ignore those we get here */
+   vcpu-arch.queued_dear = dear_flags;
+   vcpu-arch.queued_esr = esr_flags;
+   kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DTLB_MISS);
+}
+
+void kvmppc_core_queue_data_storage(struct kvm_vcpu *vcpu,
+ulong dear_flags, ulong esr_flags)
+{
+   vcpu-arch.queued_dear = dear_flags;
+   vcpu-arch.queued_esr = esr_flags;
+   kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DATA_STORAGE);
+}
+
+void kvmppc_core_queue_inst_storage(struct kvm_vcpu *vcpu, ulong esr_flags)
+{
+   vcpu-arch.queued_esr = esr_flags;
+   kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_INST_STORAGE);
+}
+
+void kvmppc_core_queue_program(struct kvm_vcpu *vcpu, ulong esr_flags)
+{
+   vcpu-arch.queued_esr = esr_flags;
kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_PROGRAM);
 }
 
@@ -115,14 +137,19 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu 
*vcpu,
 {
int allowed = 0;
ulong msr_mask;
+   bool update_esr = false, update_dear = false;
 
switch (priority) {
-   case BOOKE_IRQPRIO_PROGRAM:
case BOOKE_IRQPRIO_DTLB_MISS:
-   case BOOKE_IRQPRIO_ITLB_MISS:
-   case BOOKE_IRQPRIO_SYSCALL:
case BOOKE_IRQPRIO_DATA_STORAGE:
+   update_dear = true;
+   /* fall through */
case BOOKE_IRQPRIO_INST_STORAGE:
+   case BOOKE_IRQPRIO_PROGRAM:
+   update_esr = true;
+   /* fall through */
+   case BOOKE_IRQPRIO_ITLB_MISS:
+   case BOOKE_IRQPRIO_SYSCALL:
case BOOKE_IRQPRIO_FP_UNAVAIL:
case BOOKE_IRQPRIO_SPE_UNAVAIL:
case BOOKE_IRQPRIO_SPE_FP_DATA:
@@ -157,6 +184,10 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu 
*vcpu,
vcpu-arch.srr0 = vcpu-arch.pc;
vcpu-arch.srr1 = vcpu-arch.msr;
vcpu-arch.pc = vcpu-arch.ivpr | vcpu-arch.ivor[priority];
+   if (update_esr == true)
+   vcpu-arch.esr = vcpu-arch.queued_esr;
+   if (update_dear == true)
+   vcpu-arch.dear = vcpu-arch.queued_dear;
kvmppc_set_msr(vcpu, vcpu-arch.msr  msr_mask);
 
clear_bit(priority, vcpu-arch.pending_exceptions);
@@ -229,8 +260,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu 
*vcpu,
if (vcpu-arch.msr  MSR_PR) {
/* Program traps generated by user-level software must 
be handled
 * by the guest kernel. */
-   vcpu-arch.esr = vcpu-arch.fault_esr;
-   kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_PROGRAM);
+   kvmppc_core_queue_program(vcpu, vcpu-arch.fault_esr);
r = RESUME_GUEST;
kvmppc_account_exit(vcpu, USR_PR_INST);
break;
@@ -286,16 +316,14 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
break;
 
case BOOKE_INTERRUPT_DATA_STORAGE:
-   vcpu-arch.dear = vcpu-arch.fault_dear;
-   vcpu-arch.esr = vcpu-arch.fault_esr;
-   kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DATA_STORAGE);
+   kvmppc_core_queue_data_storage(vcpu, vcpu-arch.fault_dear,
+  vcpu-arch.fault_esr);
kvmppc_account_exit(vcpu, DSI_EXITS);
r = RESUME_GUEST;
break;
 
case BOOKE_INTERRUPT_INST_STORAGE

[PATCH v3] kvmppc/booke: Set ESR and DEAR when inject interrupt to guest

2010-02-02 Thread Liu Yu
Old method prematurely sets ESR and DEAR.
Move this part after we decide to inject interrupt,
which is more like hardware behave.

Signed-off-by: Liu Yu yu@freescale.com
---
v3:
change some functions to static

 arch/powerpc/include/asm/kvm_host.h |2 +
 arch/powerpc/kvm/booke.c|   59 ++-
 arch/powerpc/kvm/emulate.c  |4 +-
 3 files changed, 48 insertions(+), 17 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_host.h 
b/arch/powerpc/include/asm/kvm_host.h
index 715aa6b..5e5bae7 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -259,6 +259,8 @@ struct kvm_vcpu_arch {
 #endif
ulong fault_dear;
ulong fault_esr;
+   ulong queued_dear;
+   ulong queued_esr;
gpa_t paddr_accessed;
 
u8 io_gpr; /* GPR used as IO source/target */
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index e283e44..4d686cc 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -82,9 +82,32 @@ static void kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu,
set_bit(priority, vcpu-arch.pending_exceptions);
 }
 
-void kvmppc_core_queue_program(struct kvm_vcpu *vcpu, ulong flags)
+static void kvmppc_core_queue_dtlb_miss(struct kvm_vcpu *vcpu,
+ulong dear_flags, ulong esr_flags)
 {
-   /* BookE does flags in ESR, so ignore those we get here */
+   vcpu-arch.queued_dear = dear_flags;
+   vcpu-arch.queued_esr = esr_flags;
+   kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DTLB_MISS);
+}
+
+static void kvmppc_core_queue_data_storage(struct kvm_vcpu *vcpu,
+   ulong dear_flags, ulong esr_flags)
+{
+   vcpu-arch.queued_dear = dear_flags;
+   vcpu-arch.queued_esr = esr_flags;
+   kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DATA_STORAGE);
+}
+
+static void kvmppc_core_queue_inst_storage(struct kvm_vcpu *vcpu,
+   ulong esr_flags)
+{
+   vcpu-arch.queued_esr = esr_flags;
+   kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_INST_STORAGE);
+}
+
+void kvmppc_core_queue_program(struct kvm_vcpu *vcpu, ulong esr_flags)
+{
+   vcpu-arch.queued_esr = esr_flags;
kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_PROGRAM);
 }
 
@@ -115,14 +138,19 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu 
*vcpu,
 {
int allowed = 0;
ulong msr_mask;
+   bool update_esr = false, update_dear = false;
 
switch (priority) {
-   case BOOKE_IRQPRIO_PROGRAM:
case BOOKE_IRQPRIO_DTLB_MISS:
-   case BOOKE_IRQPRIO_ITLB_MISS:
-   case BOOKE_IRQPRIO_SYSCALL:
case BOOKE_IRQPRIO_DATA_STORAGE:
+   update_dear = true;
+   /* fall through */
case BOOKE_IRQPRIO_INST_STORAGE:
+   case BOOKE_IRQPRIO_PROGRAM:
+   update_esr = true;
+   /* fall through */
+   case BOOKE_IRQPRIO_ITLB_MISS:
+   case BOOKE_IRQPRIO_SYSCALL:
case BOOKE_IRQPRIO_FP_UNAVAIL:
case BOOKE_IRQPRIO_SPE_UNAVAIL:
case BOOKE_IRQPRIO_SPE_FP_DATA:
@@ -157,6 +185,10 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu 
*vcpu,
vcpu-arch.srr0 = vcpu-arch.pc;
vcpu-arch.srr1 = vcpu-arch.msr;
vcpu-arch.pc = vcpu-arch.ivpr | vcpu-arch.ivor[priority];
+   if (update_esr == true)
+   vcpu-arch.esr = vcpu-arch.queued_esr;
+   if (update_dear == true)
+   vcpu-arch.dear = vcpu-arch.queued_dear;
kvmppc_set_msr(vcpu, vcpu-arch.msr  msr_mask);
 
clear_bit(priority, vcpu-arch.pending_exceptions);
@@ -229,8 +261,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu 
*vcpu,
if (vcpu-arch.msr  MSR_PR) {
/* Program traps generated by user-level software must 
be handled
 * by the guest kernel. */
-   vcpu-arch.esr = vcpu-arch.fault_esr;
-   kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_PROGRAM);
+   kvmppc_core_queue_program(vcpu, vcpu-arch.fault_esr);
r = RESUME_GUEST;
kvmppc_account_exit(vcpu, USR_PR_INST);
break;
@@ -286,16 +317,14 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
break;
 
case BOOKE_INTERRUPT_DATA_STORAGE:
-   vcpu-arch.dear = vcpu-arch.fault_dear;
-   vcpu-arch.esr = vcpu-arch.fault_esr;
-   kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DATA_STORAGE);
+   kvmppc_core_queue_data_storage(vcpu, vcpu-arch.fault_dear,
+  vcpu-arch.fault_esr);
kvmppc_account_exit(vcpu, DSI_EXITS);
r = RESUME_GUEST

RE: [PATCH] kvmppc/booke: Set ESR and DEAR when inject interrupt to guest

2010-01-25 Thread Liu Yu-B13201
 

 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de] 
 Sent: Friday, January 22, 2010 7:33 PM
 To: Liu Yu-B13201
 Cc: hol...@penguinppc.org; kvm-ppc@vger.kernel.org; 
 k...@vger.kernel.org
 Subject: Re: [PATCH] kvmppc/booke: Set ESR and DEAR when 
 inject interrupt to guest
 
 
 On 22.01.2010, at 12:27, Liu Yu-B13201 wrote:
 
  
  
  -Original Message-
  From: kvm-ppc-ow...@vger.kernel.org 
  [mailto:kvm-ppc-ow...@vger.kernel.org] On Behalf Of Alexander Graf
  Sent: Friday, January 22, 2010 7:13 PM
  To: Liu Yu-B13201
  Cc: hol...@penguinppc.org; kvm-ppc@vger.kernel.org; 
  k...@vger.kernel.org
  Subject: Re: [PATCH] kvmppc/booke: Set ESR and DEAR when 
  inject interrupt to guest
  
  
  On 22.01.2010, at 11:54, Liu Yu wrote:
  
  Old method prematurely sets ESR and DEAR.
  Move this part after we decide to inject interrupt,
  and make it more like hardware behave.
  
  Signed-off-by: Liu Yu yu@freescale.com
  ---
  arch/powerpc/kvm/booke.c   |   24 ++--
  arch/powerpc/kvm/emulate.c |2 --
  2 files changed, 14 insertions(+), 12 deletions(-)
  
  @@ -286,15 +295,12 @@ int kvmppc_handle_exit(struct kvm_run 
  *run, struct kvm_vcpu *vcpu,
break;
  
case BOOKE_INTERRUPT_DATA_STORAGE:
  - vcpu-arch.dear = vcpu-arch.fault_dear;
  - vcpu-arch.esr = vcpu-arch.fault_esr;
kvmppc_booke_queue_irqprio(vcpu, 
  BOOKE_IRQPRIO_DATA_STORAGE);
  
  kvmppc_booke_queue_data_storage(vcpu, vcpu-arch.fault_esr, 
  vcpu-arch.fault_dear);
  
kvmppc_account_exit(vcpu, DSI_EXITS);
r = RESUME_GUEST;
break;
  
case BOOKE_INTERRUPT_INST_STORAGE:
  - vcpu-arch.esr = vcpu-arch.fault_esr;
kvmppc_booke_queue_irqprio(vcpu, 
  BOOKE_IRQPRIO_INST_STORAGE);
  
  kvmppc_booke_queue_inst_storage(vcpu, vcpu-arch.fault_esr);
  
  
  Not sure if this is redundant, as we already have fault_esr.
  Or should we ignore what hareware is and create a new esr to guest?
 
 On Book3S I take the SRR1 we get from the host as 
 inspiration of what to pass to the guest as SRR1. I think 
 we should definitely be able to inject a fault that we didn't 
 get in that exact form from the exit path.
 
 I'm also not sure if something could clobber fault_esr if 
 another interrupt takes precedence. Say a #MC.

No as far as I know.
And if yes, the clobber could as well happen before we copy it.
Hollis, what do you think we should do here?


--
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


[PATCH v2 2/3] kvmppc/e500: Add PVR/PIR init for E500

2010-01-22 Thread Liu Yu
commit 513579e3a391a3874c478a8493080822069976e8 change the way
we emulate PVR/PIR,
which left PVR/PIR uninitialized on E500, and make guest puzzled.

Signed-off-by: Liu Yu yu@freescale.com
---
 arch/powerpc/kvm/e500.c |6 ++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/kvm/e500.c b/arch/powerpc/kvm/e500.c
index 64949ee..efa1198 100644
--- a/arch/powerpc/kvm/e500.c
+++ b/arch/powerpc/kvm/e500.c
@@ -60,6 +60,12 @@ int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu)
 
kvmppc_e500_tlb_setup(vcpu_e500);
 
+   /* Registers init */
+   vcpu-arch.pvr = mfspr(SPRN_PVR);
+
+   /* Since booke kvm only support one core, update all vcpus' PIR to 0 */
+   vcpu-vcpu_id = 0;
+
return 0;
 }
 
-- 
1.6.4

--
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


[PATCH v2 0/3] kvmppc/e500: fix breaks

2010-01-22 Thread Liu Yu
These patches fix current e500 break.

v2:
patch 2: add comment about PIR
patch 3: move tlbcfg code to init

--
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


[PATCH v2 3/3] kvmppc/e500: fix tlbcfg emulation

2010-01-22 Thread Liu Yu
commit 55fb1027c1cf9797dbdeab48180da530e81b1c39 doesn't update tlbcfg correctly.
Fix it and move this part to init code.

Signed-off-by: Liu Yu yu@freescale.com
---
 arch/powerpc/include/asm/kvm_e500.h |2 ++
 arch/powerpc/kvm/e500_emulate.c |   20 ++--
 arch/powerpc/kvm/e500_tlb.c |6 ++
 3 files changed, 10 insertions(+), 18 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_e500.h 
b/arch/powerpc/include/asm/kvm_e500.h
index 569dfd3..7fea26f 100644
--- a/arch/powerpc/include/asm/kvm_e500.h
+++ b/arch/powerpc/include/asm/kvm_e500.h
@@ -56,6 +56,8 @@ struct kvmppc_vcpu_e500 {
u32 l1csr1;
u32 hid0;
u32 hid1;
+   u32 tlb0cfg;
+   u32 tlb1cfg;
 
struct kvm_vcpu vcpu;
 };
diff --git a/arch/powerpc/kvm/e500_emulate.c b/arch/powerpc/kvm/e500_emulate.c
index 95f8ec8..8e3edfb 100644
--- a/arch/powerpc/kvm/e500_emulate.c
+++ b/arch/powerpc/kvm/e500_emulate.c
@@ -164,25 +164,9 @@ int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int 
sprn, int rt)
kvmppc_set_gpr(vcpu, rt, vcpu_e500-mas7); break;
 
case SPRN_TLB0CFG:
-   {
-   ulong tmp = SPRN_TLB0CFG;
-
-   tmp = ~0xfffUL;
-   tmp |= vcpu_e500-guest_tlb_size[0];
-   kvmppc_set_gpr(vcpu, rt, tmp);
-   break;
-   }
-
+   kvmppc_set_gpr(vcpu, rt, vcpu_e500-tlb0cfg); break;
case SPRN_TLB1CFG:
-   {
-   ulong tmp = SPRN_TLB1CFG;
-
-   tmp = ~0xfffUL;
-   tmp |= vcpu_e500-guest_tlb_size[1];
-   kvmppc_set_gpr(vcpu, rt, tmp);
-   break;
-   }
-
+   kvmppc_set_gpr(vcpu, rt, vcpu_e500-tlb1cfg); break;
case SPRN_L1CSR0:
kvmppc_set_gpr(vcpu, rt, vcpu_e500-l1csr0); break;
case SPRN_L1CSR1:
diff --git a/arch/powerpc/kvm/e500_tlb.c b/arch/powerpc/kvm/e500_tlb.c
index 99a830b..7db158e 100644
--- a/arch/powerpc/kvm/e500_tlb.c
+++ b/arch/powerpc/kvm/e500_tlb.c
@@ -731,6 +731,12 @@ int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 
*vcpu_e500)
if (vcpu_e500-shadow_pages[1] == NULL)
goto err_out_page0;
 
+   /* Init TLB configuration register */
+   vcpu_e500-tlb0cfg = mfspr(SPRN_TLB0CFG)  ~0xfffUL;
+   vcpu_e500-tlb0cfg |= vcpu_e500-guest_tlb_size[0];
+   vcpu_e500-tlb1cfg = mfspr(SPRN_TLB1CFG)  ~0xfffUL;
+   vcpu_e500-tlb1cfg |= vcpu_e500-guest_tlb_size[1];
+
return 0;
 
 err_out_page0:
-- 
1.6.4

--
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


[PATCH v2 1/3] kvmppc/e500: Add register l1csr0 emulation

2010-01-22 Thread Liu Yu
Latest kernel start to access l1csr0 to contron L1.
We just tell guest no operation is on going.

Signed-off-by: Liu Yu yu@freescale.com
---
 arch/powerpc/include/asm/kvm_e500.h |1 +
 arch/powerpc/kvm/e500_emulate.c |6 ++
 2 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_e500.h 
b/arch/powerpc/include/asm/kvm_e500.h
index 9d497ce..569dfd3 100644
--- a/arch/powerpc/include/asm/kvm_e500.h
+++ b/arch/powerpc/include/asm/kvm_e500.h
@@ -52,6 +52,7 @@ struct kvmppc_vcpu_e500 {
u32 mas5;
u32 mas6;
u32 mas7;
+   u32 l1csr0;
u32 l1csr1;
u32 hid0;
u32 hid1;
diff --git a/arch/powerpc/kvm/e500_emulate.c b/arch/powerpc/kvm/e500_emulate.c
index 7644f7a..95f8ec8 100644
--- a/arch/powerpc/kvm/e500_emulate.c
+++ b/arch/powerpc/kvm/e500_emulate.c
@@ -99,6 +99,10 @@ int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int 
sprn, int rs)
vcpu_e500-mas6 = spr_val; break;
case SPRN_MAS7:
vcpu_e500-mas7 = spr_val; break;
+   case SPRN_L1CSR0:
+   vcpu_e500-l1csr0 = spr_val;
+   vcpu_e500-l1csr0 = ~(L1CSR0_DCFI | L1CSR0_CLFC);
+   break;
case SPRN_L1CSR1:
vcpu_e500-l1csr1 = spr_val; break;
case SPRN_HID0:
@@ -179,6 +183,8 @@ int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int 
sprn, int rt)
break;
}
 
+   case SPRN_L1CSR0:
+   kvmppc_set_gpr(vcpu, rt, vcpu_e500-l1csr0); break;
case SPRN_L1CSR1:
kvmppc_set_gpr(vcpu, rt, vcpu_e500-l1csr1); break;
case SPRN_HID0:
-- 
1.6.4

--
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


[PATCH] kvmppc/booke: Set ESR and DEAR when inject interrupt to guest

2010-01-22 Thread Liu Yu
Old method prematurely sets ESR and DEAR.
Move this part after we decide to inject interrupt,
and make it more like hardware behave.

Signed-off-by: Liu Yu yu@freescale.com
---
 arch/powerpc/kvm/booke.c   |   24 ++--
 arch/powerpc/kvm/emulate.c |2 --
 2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index e283e44..a8ee148 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -84,7 +84,8 @@ static void kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu,
 
 void kvmppc_core_queue_program(struct kvm_vcpu *vcpu, ulong flags)
 {
-   /* BookE does flags in ESR, so ignore those we get here */
+   if (flags == SRR1_PROGTRAP)
+   vcpu-arch.fault_esr = ESR_PTR;
kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_PROGRAM);
 }
 
@@ -115,14 +116,19 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu 
*vcpu,
 {
int allowed = 0;
ulong msr_mask;
+   bool update_esr = false, update_dear = false;
 
switch (priority) {
-   case BOOKE_IRQPRIO_PROGRAM:
case BOOKE_IRQPRIO_DTLB_MISS:
-   case BOOKE_IRQPRIO_ITLB_MISS:
-   case BOOKE_IRQPRIO_SYSCALL:
case BOOKE_IRQPRIO_DATA_STORAGE:
+   update_dear = true;
+   /* fall through */
case BOOKE_IRQPRIO_INST_STORAGE:
+   case BOOKE_IRQPRIO_PROGRAM:
+   update_esr = true;
+   /* fall through */
+   case BOOKE_IRQPRIO_ITLB_MISS:
+   case BOOKE_IRQPRIO_SYSCALL:
case BOOKE_IRQPRIO_FP_UNAVAIL:
case BOOKE_IRQPRIO_SPE_UNAVAIL:
case BOOKE_IRQPRIO_SPE_FP_DATA:
@@ -157,6 +163,10 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu 
*vcpu,
vcpu-arch.srr0 = vcpu-arch.pc;
vcpu-arch.srr1 = vcpu-arch.msr;
vcpu-arch.pc = vcpu-arch.ivpr | vcpu-arch.ivor[priority];
+   if (update_esr == true)
+   vcpu-arch.esr = vcpu-arch.fault_esr;
+   if (update_dear == true)
+   vcpu-arch.dear = vcpu-arch.fault_dear;
kvmppc_set_msr(vcpu, vcpu-arch.msr  msr_mask);
 
clear_bit(priority, vcpu-arch.pending_exceptions);
@@ -229,7 +239,6 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu 
*vcpu,
if (vcpu-arch.msr  MSR_PR) {
/* Program traps generated by user-level software must 
be handled
 * by the guest kernel. */
-   vcpu-arch.esr = vcpu-arch.fault_esr;
kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_PROGRAM);
r = RESUME_GUEST;
kvmppc_account_exit(vcpu, USR_PR_INST);
@@ -286,15 +295,12 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
break;
 
case BOOKE_INTERRUPT_DATA_STORAGE:
-   vcpu-arch.dear = vcpu-arch.fault_dear;
-   vcpu-arch.esr = vcpu-arch.fault_esr;
kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DATA_STORAGE);
kvmppc_account_exit(vcpu, DSI_EXITS);
r = RESUME_GUEST;
break;
 
case BOOKE_INTERRUPT_INST_STORAGE:
-   vcpu-arch.esr = vcpu-arch.fault_esr;
kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_INST_STORAGE);
kvmppc_account_exit(vcpu, ISI_EXITS);
r = RESUME_GUEST;
@@ -317,8 +323,6 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu 
*vcpu,
if (gtlb_index  0) {
/* The guest didn't have a mapping for it. */
kvmppc_booke_queue_irqprio(vcpu, 
BOOKE_IRQPRIO_DTLB_MISS);
-   vcpu-arch.dear = vcpu-arch.fault_dear;
-   vcpu-arch.esr = vcpu-arch.fault_esr;
kvmppc_mmu_dtlb_miss(vcpu);
kvmppc_account_exit(vcpu, DTLB_REAL_MISS_EXITS);
r = RESUME_GUEST;
diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c
index b905623..4f6b9df 100644
--- a/arch/powerpc/kvm/emulate.c
+++ b/arch/powerpc/kvm/emulate.c
@@ -151,8 +151,6 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct 
kvm_vcpu *vcpu)
case OP_TRAP:
 #ifdef CONFIG_PPC64
case OP_TRAP_64:
-#else
-   vcpu-arch.esr |= ESR_PTR;
 #endif
kvmppc_core_queue_program(vcpu, SRR1_PROGTRAP);
advance = 0;
-- 
1.6.4

--
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 v2 3/3] kvmppc/e500: fix tlbcfg emulation

2010-01-22 Thread Liu Yu-B13201
 

 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de] 
 Sent: Friday, January 22, 2010 7:05 PM
 To: Liu Yu-B13201
 Cc: kvm-ppc@vger.kernel.org; k...@vger.kernel.org
 Subject: Re: [PATCH v2 3/3] kvmppc/e500: fix tlbcfg emulation
 
 
 On 22.01.2010, at 11:50, Liu Yu wrote:
 
  commit 55fb1027c1cf9797dbdeab48180da530e81b1c39 doesn't 
 update tlbcfg correctly.
  Fix it and move this part to init code.
  
  Signed-off-by: Liu Yu yu@freescale.com
  ---
  arch/powerpc/include/asm/kvm_e500.h |2 ++
  arch/powerpc/kvm/e500_emulate.c |   20 ++--
  arch/powerpc/kvm/e500_tlb.c |6 ++
  3 files changed, 10 insertions(+), 18 deletions(-)
  
  diff --git a/arch/powerpc/include/asm/kvm_e500.h 
 b/arch/powerpc/include/asm/kvm_e500.h
  index 569dfd3..7fea26f 100644
  --- a/arch/powerpc/include/asm/kvm_e500.h
  +++ b/arch/powerpc/include/asm/kvm_e500.h
  @@ -56,6 +56,8 @@ struct kvmppc_vcpu_e500 {
  u32 l1csr1;
  u32 hid0;
  u32 hid1;
  +   u32 tlb0cfg;
  +   u32 tlb1cfg;
  
  struct kvm_vcpu vcpu;
  };
  diff --git a/arch/powerpc/kvm/e500_emulate.c 
 b/arch/powerpc/kvm/e500_emulate.c
  index 95f8ec8..8e3edfb 100644
  --- a/arch/powerpc/kvm/e500_emulate.c
  +++ b/arch/powerpc/kvm/e500_emulate.c
  @@ -164,25 +164,9 @@ int kvmppc_core_emulate_mfspr(struct 
 kvm_vcpu *vcpu, int sprn, int rt)
  kvmppc_set_gpr(vcpu, rt, vcpu_e500-mas7); break;
  
  case SPRN_TLB0CFG:
  -   {
  -   ulong tmp = SPRN_TLB0CFG;
  -
  -   tmp = ~0xfffUL;
  -   tmp |= vcpu_e500-guest_tlb_size[0];
  -   kvmppc_set_gpr(vcpu, rt, tmp);
  -   break;
  -   }
  -
  +   kvmppc_set_gpr(vcpu, rt, vcpu_e500-tlb0cfg); break;
 
 So before the guest couldn't change the guest TLB size and 
 now it can? Is that on purpose? Mind to explain why the old 
 code was there?
 

What? The register is readonly.
I was thinking we could change guest TLB size online.
But I don't think guest kernel would like that.



--
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] kvmppc/booke: Set ESR and DEAR when inject interrupt to guest

2010-01-22 Thread Liu Yu-B13201
 

 -Original Message-
 From: kvm-ppc-ow...@vger.kernel.org 
 [mailto:kvm-ppc-ow...@vger.kernel.org] On Behalf Of Alexander Graf
 Sent: Friday, January 22, 2010 7:13 PM
 To: Liu Yu-B13201
 Cc: hol...@penguinppc.org; kvm-ppc@vger.kernel.org; 
 k...@vger.kernel.org
 Subject: Re: [PATCH] kvmppc/booke: Set ESR and DEAR when 
 inject interrupt to guest
 
 
 On 22.01.2010, at 11:54, Liu Yu wrote:
 
  Old method prematurely sets ESR and DEAR.
  Move this part after we decide to inject interrupt,
  and make it more like hardware behave.
  
  Signed-off-by: Liu Yu yu@freescale.com
  ---
  arch/powerpc/kvm/booke.c   |   24 ++--
  arch/powerpc/kvm/emulate.c |2 --
  2 files changed, 14 insertions(+), 12 deletions(-)
  
  diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
  index e283e44..a8ee148 100644
  --- a/arch/powerpc/kvm/booke.c
  +++ b/arch/powerpc/kvm/booke.c
  @@ -84,7 +84,8 @@ static void 
 kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu,
  
  void kvmppc_core_queue_program(struct kvm_vcpu *vcpu, ulong flags)
  {
  -   /* BookE does flags in ESR, so ignore those we get here */
  +   if (flags == SRR1_PROGTRAP)
  +   vcpu-arch.fault_esr = ESR_PTR;
 
 This looks odd. I was more thinking of flags being ESR in 
 this context. So you'd save off flags to a field in the vcpu 
 here and restore it later when the fault actually gets injected.

See the end.

 
  kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_PROGRAM);
  }
  
  @@ -115,14 +116,19 @@ static int 
 kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu,
  {
  int allowed = 0;
  ulong msr_mask;
  +   bool update_esr = false, update_dear = false;
  
  switch (priority) {
  -   case BOOKE_IRQPRIO_PROGRAM:
  case BOOKE_IRQPRIO_DTLB_MISS:
  -   case BOOKE_IRQPRIO_ITLB_MISS:
  -   case BOOKE_IRQPRIO_SYSCALL:
 
 Is this correct? Was the previous order wrong according to the spec?

what order? just make switch items share the code.

 
  case BOOKE_IRQPRIO_DATA_STORAGE:
  +   update_dear = true;
  +   /* fall through */
  case BOOKE_IRQPRIO_INST_STORAGE:
  +   case BOOKE_IRQPRIO_PROGRAM:
  +   update_esr = true;
  +   /* fall through */
  +   case BOOKE_IRQPRIO_ITLB_MISS:
  +   case BOOKE_IRQPRIO_SYSCALL:
  case BOOKE_IRQPRIO_FP_UNAVAIL:
  case BOOKE_IRQPRIO_SPE_UNAVAIL:
  case BOOKE_IRQPRIO_SPE_FP_DATA:
  @@ -157,6 +163,10 @@ static int 
 kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu,
  vcpu-arch.srr0 = vcpu-arch.pc;
  vcpu-arch.srr1 = vcpu-arch.msr;
  vcpu-arch.pc = vcpu-arch.ivpr | 
 vcpu-arch.ivor[priority];
  +   if (update_esr == true)
  +   vcpu-arch.esr = vcpu-arch.fault_esr;
 
 I'd rather like to see new fields used for that.
  @@ -286,15 +295,12 @@ int kvmppc_handle_exit(struct kvm_run 
 *run, struct kvm_vcpu *vcpu,
  break;
  
  case BOOKE_INTERRUPT_DATA_STORAGE:
  -   vcpu-arch.dear = vcpu-arch.fault_dear;
  -   vcpu-arch.esr = vcpu-arch.fault_esr;
  kvmppc_booke_queue_irqprio(vcpu, 
 BOOKE_IRQPRIO_DATA_STORAGE);
 
 kvmppc_booke_queue_data_storage(vcpu, vcpu-arch.fault_esr, 
 vcpu-arch.fault_dear);
 
  kvmppc_account_exit(vcpu, DSI_EXITS);
  r = RESUME_GUEST;
  break;
  
  case BOOKE_INTERRUPT_INST_STORAGE:
  -   vcpu-arch.esr = vcpu-arch.fault_esr;
  kvmppc_booke_queue_irqprio(vcpu, 
 BOOKE_IRQPRIO_INST_STORAGE);
 
 kvmppc_booke_queue_inst_storage(vcpu, vcpu-arch.fault_esr);
 

Not sure if this is redundant, as we already have fault_esr.
Or should we ignore what hareware is and create a new esr to guest?

 
  -   vcpu-arch.dear = vcpu-arch.fault_dear;
  -   vcpu-arch.esr = vcpu-arch.fault_esr;
  kvmppc_mmu_dtlb_miss(vcpu);
  kvmppc_account_exit(vcpu, DTLB_REAL_MISS_EXITS);
  r = RESUME_GUEST;
  diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c
  index b905623..4f6b9df 100644
  --- a/arch/powerpc/kvm/emulate.c
  +++ b/arch/powerpc/kvm/emulate.c
  @@ -151,8 +151,6 @@ int kvmppc_emulate_instruction(struct 
 kvm_run *run, struct kvm_vcpu *vcpu)
  case OP_TRAP:
  #ifdef CONFIG_PPC64
  case OP_TRAP_64:
  -#else
  -   vcpu-arch.esr |= ESR_PTR;
  #endif
  kvmppc_core_queue_program(vcpu, SRR1_PROGTRAP);
 
 kvmppc_core_queue_program(vcpu, vcpu-arch.esr | ESR_PTR);
 

This breaks book3s code.
--
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


[PATCH v3 3/3] kvmppc/e500: fix tlbcfg emulation

2010-01-22 Thread Liu Yu
commit 55fb1027c1cf9797dbdeab48180da530e81b1c39 doesn't update tlbcfg correctly.
Fix it.

And since guest OS likes 'fixed' hardware,
initialize tlbcfg everytime when guest access is useless.
So move this part to init code.

Signed-off-by: Liu Yu yu@freescale.com
---
v3:
   change the commit message.

 arch/powerpc/include/asm/kvm_e500.h |2 ++
 arch/powerpc/kvm/e500_emulate.c |   20 ++--
 arch/powerpc/kvm/e500_tlb.c |6 ++
 3 files changed, 10 insertions(+), 18 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_e500.h 
b/arch/powerpc/include/asm/kvm_e500.h
index 569dfd3..7fea26f 100644
--- a/arch/powerpc/include/asm/kvm_e500.h
+++ b/arch/powerpc/include/asm/kvm_e500.h
@@ -56,6 +56,8 @@ struct kvmppc_vcpu_e500 {
u32 l1csr1;
u32 hid0;
u32 hid1;
+   u32 tlb0cfg;
+   u32 tlb1cfg;
 
struct kvm_vcpu vcpu;
 };
diff --git a/arch/powerpc/kvm/e500_emulate.c b/arch/powerpc/kvm/e500_emulate.c
index 95f8ec8..8e3edfb 100644
--- a/arch/powerpc/kvm/e500_emulate.c
+++ b/arch/powerpc/kvm/e500_emulate.c
@@ -164,25 +164,9 @@ int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int 
sprn, int rt)
kvmppc_set_gpr(vcpu, rt, vcpu_e500-mas7); break;
 
case SPRN_TLB0CFG:
-   {
-   ulong tmp = SPRN_TLB0CFG;
-
-   tmp = ~0xfffUL;
-   tmp |= vcpu_e500-guest_tlb_size[0];
-   kvmppc_set_gpr(vcpu, rt, tmp);
-   break;
-   }
-
+   kvmppc_set_gpr(vcpu, rt, vcpu_e500-tlb0cfg); break;
case SPRN_TLB1CFG:
-   {
-   ulong tmp = SPRN_TLB1CFG;
-
-   tmp = ~0xfffUL;
-   tmp |= vcpu_e500-guest_tlb_size[1];
-   kvmppc_set_gpr(vcpu, rt, tmp);
-   break;
-   }
-
+   kvmppc_set_gpr(vcpu, rt, vcpu_e500-tlb1cfg); break;
case SPRN_L1CSR0:
kvmppc_set_gpr(vcpu, rt, vcpu_e500-l1csr0); break;
case SPRN_L1CSR1:
diff --git a/arch/powerpc/kvm/e500_tlb.c b/arch/powerpc/kvm/e500_tlb.c
index 99a830b..7db158e 100644
--- a/arch/powerpc/kvm/e500_tlb.c
+++ b/arch/powerpc/kvm/e500_tlb.c
@@ -731,6 +731,12 @@ int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 
*vcpu_e500)
if (vcpu_e500-shadow_pages[1] == NULL)
goto err_out_page0;
 
+   /* Init TLB configuration register */
+   vcpu_e500-tlb0cfg = mfspr(SPRN_TLB0CFG)  ~0xfffUL;
+   vcpu_e500-tlb0cfg |= vcpu_e500-guest_tlb_size[0];
+   vcpu_e500-tlb1cfg = mfspr(SPRN_TLB1CFG)  ~0xfffUL;
+   vcpu_e500-tlb1cfg |= vcpu_e500-guest_tlb_size[1];
+
return 0;
 
 err_out_page0:
-- 
1.6.4

--
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 7/9] KVM: PPC: Emulate trap SRR1 flags properly

2010-01-21 Thread Liu Yu-B13201
 

 -Original Message-
 From: kvm-ppc-ow...@vger.kernel.org 
 [mailto:kvm-ppc-ow...@vger.kernel.org] On Behalf Of Hollis Blanchard
 Sent: Saturday, January 09, 2010 3:30 AM
 To: Alexander Graf
 Cc: k...@vger.kernel.org; kvm-ppc; Benjamin Herrenschmidt; Liu Yu
 Subject: Re: [PATCH 7/9] KVM: PPC: Emulate trap SRR1 flags properly
 
  diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
  index 338baf9..e283e44 100644
  --- a/arch/powerpc/kvm/booke.c
  +++ b/arch/powerpc/kvm/booke.c
  @@ -82,8 +82,9 @@ static void 
 kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu,
         set_bit(priority, vcpu-arch.pending_exceptions);
   }
 
  -void kvmppc_core_queue_program(struct kvm_vcpu *vcpu)
  +void kvmppc_core_queue_program(struct kvm_vcpu *vcpu, ulong flags)
   {
  +       /* BookE does flags in ESR, so ignore those we get here */
         kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_PROGRAM);
   }
 
 Actually, I think Book E prematurely sets ESR, since it's done before
 the program interrupt is actually delivered. Architecturally, I'm not
 sure if it's a problem, but philosophically I've always wanted it to
 work the way you've just implemented for Book S.
 

ESR is updated not only by program but by data_tlb, data_storage, etc.
Should we rearrange them all? 
Also DEAR has the same situation as ESR.
Should it be updated when we decide to inject interrupt to guest?


--
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


[PATCH 1/3] kvmppc/e500: Add register l1csr0 emulation

2010-01-20 Thread Liu Yu
Latest kernel start to access l1csr0 to contron L1.
We just tell guest no operation is on going.

Signed-off-by: Liu Yu yu@freescale.com
---
 arch/powerpc/include/asm/kvm_e500.h |1 +
 arch/powerpc/kvm/e500_emulate.c |6 ++
 2 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_e500.h 
b/arch/powerpc/include/asm/kvm_e500.h
index 9d497ce..569dfd3 100644
--- a/arch/powerpc/include/asm/kvm_e500.h
+++ b/arch/powerpc/include/asm/kvm_e500.h
@@ -52,6 +52,7 @@ struct kvmppc_vcpu_e500 {
u32 mas5;
u32 mas6;
u32 mas7;
+   u32 l1csr0;
u32 l1csr1;
u32 hid0;
u32 hid1;
diff --git a/arch/powerpc/kvm/e500_emulate.c b/arch/powerpc/kvm/e500_emulate.c
index 7644f7a..95f8ec8 100644
--- a/arch/powerpc/kvm/e500_emulate.c
+++ b/arch/powerpc/kvm/e500_emulate.c
@@ -99,6 +99,10 @@ int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int 
sprn, int rs)
vcpu_e500-mas6 = spr_val; break;
case SPRN_MAS7:
vcpu_e500-mas7 = spr_val; break;
+   case SPRN_L1CSR0:
+   vcpu_e500-l1csr0 = spr_val;
+   vcpu_e500-l1csr0 = ~(L1CSR0_DCFI | L1CSR0_CLFC);
+   break;
case SPRN_L1CSR1:
vcpu_e500-l1csr1 = spr_val; break;
case SPRN_HID0:
@@ -179,6 +183,8 @@ int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int 
sprn, int rt)
break;
}
 
+   case SPRN_L1CSR0:
+   kvmppc_set_gpr(vcpu, rt, vcpu_e500-l1csr0); break;
case SPRN_L1CSR1:
kvmppc_set_gpr(vcpu, rt, vcpu_e500-l1csr1); break;
case SPRN_HID0:
-- 
1.6.4

--
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


[PATCH 0/3] kvmppc/e500:

2010-01-20 Thread Liu Yu
These patches fix current e500 break.

--
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


[PATCH 3/3] kvmppc/e500: fix tlbcfg emulation

2010-01-20 Thread Liu Yu
Signed-off-by: Liu Yu yu@freescale.com
---
 arch/powerpc/kvm/e500_emulate.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kvm/e500_emulate.c b/arch/powerpc/kvm/e500_emulate.c
index 95f8ec8..97337dd 100644
--- a/arch/powerpc/kvm/e500_emulate.c
+++ b/arch/powerpc/kvm/e500_emulate.c
@@ -165,7 +165,7 @@ int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int 
sprn, int rt)
 
case SPRN_TLB0CFG:
{
-   ulong tmp = SPRN_TLB0CFG;
+   ulong tmp = mfspr(SPRN_TLB0CFG);
 
tmp = ~0xfffUL;
tmp |= vcpu_e500-guest_tlb_size[0];
@@ -175,7 +175,7 @@ int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int 
sprn, int rt)
 
case SPRN_TLB1CFG:
{
-   ulong tmp = SPRN_TLB1CFG;
+   ulong tmp = mfspr(SPRN_TLB1CFG);
 
tmp = ~0xfffUL;
tmp |= vcpu_e500-guest_tlb_size[1];
-- 
1.6.4

--
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 3/3] kvmppc/e500: fix tlbcfg emulation

2010-01-20 Thread Liu Yu-B13201
 

 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de] 
 Sent: Wednesday, January 20, 2010 6:47 PM
 To: Liu Yu-B13201
 Cc: kvm-ppc@vger.kernel.org; a...@redhat.com; hol...@penguinppc.org
 Subject: Re: [PATCH 3/3] kvmppc/e500: fix tlbcfg emulation
 Importance: High
 
 
 On 20.01.2010, at 09:03, Liu Yu wrote:
 
  Signed-off-by: Liu Yu yu@freescale.com
  ---
  arch/powerpc/kvm/e500_emulate.c |4 ++--
  1 files changed, 2 insertions(+), 2 deletions(-)
  
  diff --git a/arch/powerpc/kvm/e500_emulate.c 
 b/arch/powerpc/kvm/e500_emulate.c
  index 95f8ec8..97337dd 100644
  --- a/arch/powerpc/kvm/e500_emulate.c
  +++ b/arch/powerpc/kvm/e500_emulate.c
  @@ -165,7 +165,7 @@ int kvmppc_core_emulate_mfspr(struct 
 kvm_vcpu *vcpu, int sprn, int rt)
  
  case SPRN_TLB0CFG:
  {
  -   ulong tmp = SPRN_TLB0CFG;
  +   ulong tmp = mfspr(SPRN_TLB0CFG);
 
 Does this SPR value change? I hope not :-). If not, better 
 read it once on init and then use it from there.
 

Out of curiousity. Does read it once in order to get better performance?
If yes, I think read from register is faster than read from mem.

--
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 2/3] kvmppc/e500: Add PVR/PIR init for E500

2010-01-20 Thread Liu Yu-B13201
 

 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de] 
 Sent: Wednesday, January 20, 2010 6:45 PM
 To: Liu Yu-B13201
 Cc: kvm-ppc@vger.kernel.org; a...@redhat.com; hol...@penguinppc.org
 Subject: Re: [PATCH 2/3] kvmppc/e500: Add PVR/PIR init for E500
 Importance: High
 
 
 On 20.01.2010, at 09:03, Liu Yu wrote:
 
  Signed-off-by: Liu Yu yu@freescale.com
  ---
  arch/powerpc/kvm/e500.c |4 
  1 files changed, 4 insertions(+), 0 deletions(-)
  
  diff --git a/arch/powerpc/kvm/e500.c b/arch/powerpc/kvm/e500.c
  index 64949ee..fd3683d 100644
  --- a/arch/powerpc/kvm/e500.c
  +++ b/arch/powerpc/kvm/e500.c
  @@ -60,6 +60,10 @@ int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu)
  
  kvmppc_e500_tlb_setup(vcpu_e500);
  
  +   /* Registers init */
  +   vcpu-arch.pvr = mfspr(SPRN_PVR);
  +   vcpu-vcpu_id = mfspr(SPRN_PIR);
 
 Is this correct? IIUC this should be the number of the vcpu. 
 So if you virtualize a 2-core system, but both vcpu init 
 functions run on core 1, this will break, right?
 

Since kvm booke doesn't support more than 1 core virtualization.
Can we put a comment here for now?

--
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 7/9] KVM: PPC: Emulate trap SRR1 flags properly

2010-01-12 Thread Liu Yu-B13201
 

 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de] 
 Sent: Tuesday, January 12, 2010 8:08 AM
 To: Liu Yu-B13201
 Cc: Hollis Blanchard; k...@vger.kernel.org; kvm-ppc; Benjamin 
 Herrenschmidt; Liu Yu
 Subject: Re: [PATCH 7/9] KVM: PPC: Emulate trap SRR1 flags properly
 
  
  Anyways, since we can't test changes at the moment (Yu, 
 can you?), I'd
  settle for a comment to the effect that Book E code 
 *should* do this,
  but doesn't (rather than the comment above that says it's ok).
  
  
  Sure.
  You mean set the ESR at the moment we inject trap to guest?
  If it is not urgent, I'll do it later.
 
 It's definitely not urgent. In fact, If you could just test 
 patches I send to you I can write it and have you test it :-).
 

That would be nice.:-)
But last time I try the top tree, it seemed not work.
Maybe I need to find out the reason and fix it first...
--
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 7/9] KVM: PPC: Emulate trap SRR1 flags properly

2010-01-10 Thread Liu Yu-B13201
 

 -Original Message-
 From: kvm-ppc-ow...@vger.kernel.org 
 [mailto:kvm-ppc-ow...@vger.kernel.org] On Behalf Of Hollis Blanchard
 Sent: Saturday, January 09, 2010 3:30 AM
 To: Alexander Graf
 Cc: k...@vger.kernel.org; kvm-ppc; Benjamin Herrenschmidt; Liu Yu
 Subject: Re: [PATCH 7/9] KVM: PPC: Emulate trap SRR1 flags properly
 
 On Thu, Jan 7, 2010 at 5:58 PM, Alexander Graf ag...@suse.de wrote:
  Book3S needs some flags in SRR1 to get to know details 
 about an interrupt.
 
  One such example is the trap instruction. It tells the 
 guest kernel that
  a program interrupt is due to a trap using a bit in SRR1.
 
  This patch implements above behavior, making WARN_ON behave 
 like WARN_ON.
 
 ... for Book S. It already works properly for Book E, 
 thankyouverymuch. ;)
 
  diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
  index 338baf9..e283e44 100644
  --- a/arch/powerpc/kvm/booke.c
  +++ b/arch/powerpc/kvm/booke.c
  @@ -82,8 +82,9 @@ static void 
 kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu,
         set_bit(priority, vcpu-arch.pending_exceptions);
   }
 
  -void kvmppc_core_queue_program(struct kvm_vcpu *vcpu)
  +void kvmppc_core_queue_program(struct kvm_vcpu *vcpu, ulong flags)
   {
  +       /* BookE does flags in ESR, so ignore those we get here */
         kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_PROGRAM);
   }
 
 Actually, I think Book E prematurely sets ESR, since it's done before
 the program interrupt is actually delivered. Architecturally, I'm not
 sure if it's a problem, but philosophically I've always wanted it to
 work the way you've just implemented for Book S.
 
 Anyways, since we can't test changes at the moment (Yu, can you?), I'd
 settle for a comment to the effect that Book E code *should* do this,
 but doesn't (rather than the comment above that says it's ok).
 

Sure.
You mean set the ESR at the moment we inject trap to guest?
If it is not urgent, I'll do it later.
--
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] KVM: PPC: E500 compile fix

2010-01-10 Thread Liu Yu-B13201
 

 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de] 
 Sent: Monday, January 11, 2010 1:02 AM
 To: k...@vger.kernel.org
 Cc: kvm-ppc; Liu Yu-B13201
 Subject: [PATCH] KVM: PPC: E500 compile fix
 
 While trying to compile an E500 vmlinux, I stumbled across a 
 compilation bug
 that was obviously there before I touched any of the code. A 
 trace point
 doesn't get the correct arguments.
 
 Since that shouldn't be any critical to the functionality of 
 the code, my quick
 workaround is to #if 0 it out. I would very much appreciate 
 someone fixing it
 properly though.
 
 Liu, it would be nice if you could be the one doing that.
 

Hrr...
I sent it before, but the whole series is blocked.
http://marc.info/?l=kvm-ppcm=124929800623835w=2

Anyway the series needs to be resent, since there's a lot changes.

Thanks for doing this for me!

--
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: Error trying to build qemu with --enable-kvm

2009-11-06 Thread Liu Yu-B13201
 

 -Original Message-
 From: kvm-ppc-ow...@vger.kernel.org 
 [mailto:kvm-ppc-ow...@vger.kernel.org] On Behalf Of Benjamin 
 Herrenschmidt
 Sent: Thursday, November 05, 2009 2:41 PM
 To: kvmppc
 Cc: Alexander Graf
 Subject: Error trying to build qemu with --enable-kvm
 
 Hoy !
 
 I wanted to try out all that new shiny stuff and got:
 
   CCppc-softmmu/kvm-all.o
 /home/benh/kernels/qemu/kvm-all.c: In function ‘kvm_put_mp_state’:
 /home/benh/kernels/qemu/kvm-all.c:212: error: ‘struct 
 CPUPPCState’ has no member named ‘mp_state’
 /home/benh/kernels/qemu/kvm-all.c: In function ‘kvm_get_mp_state’:
 /home/benh/kernels/qemu/kvm-all.c:226: error: ‘struct 
 CPUPPCState’ has no member named ‘mp_state’
 
 (qemu top of git tree)
 

Seems need this patch

Index: qemu.git/target-ppc/cpu.h
===
--- qemu.git.orig/target-ppc/cpu.h  2009-07-24 13:52:14.0 +0800
+++ qemu.git/target-ppc/cpu.h   2009-07-24 13:52:58.0 +0800
@@ -677,6 +677,9 @@
 
 /* temporary hack to handle OSI calls (only used if non NULL) */
 int (*osi_call)(struct CPUPPCState *env);
+
+/* For KVM */
+uint32_t mp_state;
 };
 
 /* Context used internally during MMU translations */
@@ -802,7 +805,7 @@
 #define cpu_signal_handler cpu_ppc_signal_handler
 #define cpu_list ppc_cpu_list
 
-#define CPU_SAVE_VERSION 4
+#define CPU_SAVE_VERSION 5
 
 /* MMU modes definitions */
 #define MMU_MODE0_SUFFIX _user


RE: [PATCH 4/5] kvmppc: Translate eaddr for fsl_booke mmu

2009-08-23 Thread Liu Yu-B13201
 

 -Original Message-
 From: Alexander Graf [mailto:a...@csgraf.de] 
 Sent: Friday, August 21, 2009 8:39 PM
 To: Liu Yu-B13201
 Cc: Hollis Blanchard; qemu-de...@nongnu.org; 
 kvm-ppc@vger.kernel.org; jan.kis...@siemens.com; 
 froy...@codesourcery.com
 Subject: Re: [PATCH 4/5] kvmppc: Translate eaddr for fsl_booke mmu
 
 
 Am 20.08.2009 um 12:21 schrieb Liu Yu-B13201 yu@freescale.com:
 
 
 
  -Original Message-
  From: Hollis Blanchard [mailto:holl...@us.ibm.com]
  Sent: Thursday, August 20, 2009 6:51 AM
  To: Liu Yu-B13201
  Cc: qemu-de...@nongnu.org; kvm-ppc@vger.kernel.org;
  jan.kis...@siemens.com; froy...@codesourcery.com; Alexander Graf
  Subject: Re: [PATCH 4/5] kvmppc: Translate eaddr for fsl_booke mmu
 
  On Tue, 2009-08-04 at 17:36 +0800, Liu Yu wrote:
  Signed-off-by: Liu Yu yu@freescale.com
  ---
  target-ppc/helper.c |   17 +++--
  1 files changed, 15 insertions(+), 2 deletions(-)
 
  diff --git a/target-ppc/helper.c b/target-ppc/helper.c
  index 6eca2e5..07e56a4 100644
  --- a/target-ppc/helper.c
  +++ b/target-ppc/helper.c
  @@ -22,6 +22,7 @@
  #include string.h
  #include inttypes.h
  #include signal.h
  +#include linux/kvm.h
 
  #include cpu.h
  #include exec-all.h
  @@ -1325,8 +1326,20 @@ static always_inline int
  check_physical (CPUState *env, mmu_ctx_t *ctx,
  cpu_abort(env, MPC8xx MMU model is not implemented\n);
  break;
  case POWERPC_MMU_BOOKE_FSL:
  -/* XXX: TODO */
  -cpu_abort(env, BookE FSL MMU model not implemented\n);
  +if (kvm_enabled()) {
  +struct kvm_translation tr;
  +
  +/* For now we only debug guest kernel */
  +tr.linear_address = eaddr;
  +ret = kvm_vcpu_ioctl(env, KVM_TRANSLATE, tr);
  +if (ret  0)
  +return ret;
  +
  +ctx-raddr = tr.physical_address;
  +} else {
  +/* XXX: TODO */
  +cpu_abort(env, BookE FSL MMU model not
  implemented\n);
  +}
  break;
  default:
  cpu_abort(env, Unknown or invalid MMU model\n);
 
  One objection: the comment is a little obscure. I think what you're
  really saying is in Linux guests, kernel addresses should 
 always be
  covered by TLB1, which means for those addresses we can expect this
  ioctl to succeed. However, since you need to handle failures
  anyways, I
  think you should remove the comment entirely.
 
  As BOOKE mmu translation needs AS + PID + address,
  The infomations we pass to kvmppc here only count in address and set
  AS=0, PID=0.
  Which indicates that it's a kernel address.
 
  If want to translate user space address, one way is read registers  
  from
  kvmppc at first
  and then pass the correct AS and PID to translator.
  As we don't need to debug guest userspace, for simplicity, 
 I didn't do
  that.
 
 
  Second, (and this isn't an objection but rather a question)
  do you have
  any better ideas for struct kvm_translation? It only really
  makes sense
  for x86. We don't need to stick with it.
 
 
  Hrr.. We need to combine AS, PID and 32-bit addr into 64-bit linear
  address. it's not that convenient.
  But except that, I am not sure if there is strong requirement to  
  change
  it...
 
  BOOK3S KVM has more work in qemu (openbios, vga etc.),
  Maybe Alex has some suggestion?
 
 
 What does that do again? Enable userspace to do EA to PA translation?
 
 IMHO userspace should do the translation and do an ioctl to 
 fetch the  
 required information (soft TLB cache / SLB / SDR1) so we can 
 reuse the  
 existing qemu infrastructure.
 

BOOK3S has mmu implement in qemu, but BOOKE doesn't.

--
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


[PATCH v2 0/5] kvmppc: Add guest debug support

2009-08-04 Thread Liu Yu
The whole patchset add guest debug support for kvmppc.
patch 1: fix kvmppc build error
patch 2: fix kvmppc init error
patch 3: add guest debug support
patch 4: translate eaddr for fsl_booke mmu
patch 5: guest debug init

[v2]:
1. use cpu_synchronize_state() instead of kvm_arch_put_registers()
2. move guest debug init work into kvm_arch_init_vcpu()
3. add GDB_WATCHPOINT_READ support
4. some cleanup


--
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


[PATCH 3/5] kvmppc: Guest debug support

2009-08-04 Thread Liu Yu
Signed-off-by: Liu Yu yu@freescale.com
---
 target-ppc/kvm.c |  203 ++
 1 files changed, 203 insertions(+), 0 deletions(-)

diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
index b53d6e9..97a0737 100644
--- a/target-ppc/kvm.c
+++ b/target-ppc/kvm.c
@@ -8,6 +8,9 @@
  *  Christian Ehrhardt ehrha...@linux.vnet.ibm.com
  *  Hollis Blanchard holl...@us.ibm.com
  *
+ * Copyright (C) 2009 Freescale Semiconductor, Inc. All rights reserved.
+ *  Yu Liu yu@freescale.com
+ *
  * This work is licensed under the terms of the GNU GPL, version 2 or later.
  * See the COPYING file in the top-level directory.
  *
@@ -18,6 +21,7 @@
 #include sys/mman.h
 
 #include linux/kvm.h
+#include asm/kvm_asm.h
 
 #include qemu-common.h
 #include qemu-timer.h
@@ -26,6 +30,7 @@
 #include kvm_ppc.h
 #include cpu.h
 #include device_tree.h
+#include gdbstub.h
 
 //#define DEBUG_KVM
 
@@ -216,3 +221,201 @@ int kvm_arch_handle_exit(CPUState *env, struct kvm_run 
*run)
 return ret;
 }
 
+#ifdef KVM_CAP_SET_GUEST_DEBUG
+int kvm_arch_insert_sw_breakpoint(CPUState *env, struct kvm_sw_breakpoint *bp)
+{
+uint32_t sc = tswap32(KVM_INST_GUESTGDB);
+uint32_t tmp;
+
+if (cpu_memory_rw_debug(env, bp-pc, (uint8_t *)bp-saved_insn, 4, 0) ||
+cpu_memory_rw_debug(env, bp-pc, (uint8_t *)sc, 4, 1))
+return -EINVAL;
+cpu_memory_rw_debug(env, bp-pc, (uint8_t *)tmp, 4, 0);
+return 0;
+}
+
+int kvm_arch_remove_sw_breakpoint(CPUState *env, struct kvm_sw_breakpoint *bp)
+{
+uint32_t sc;
+
+if (cpu_memory_rw_debug(env, bp-pc, (uint8_t *)sc, 4, 0) ||
+sc != tswap32(KVM_INST_GUESTGDB) ||
+cpu_memory_rw_debug(env, bp-pc, (uint8_t *)bp-saved_insn, 4, 1))
+return -EINVAL;
+return 0;
+}
+
+static struct {
+target_ulong addr;
+int type;
+} hw_breakpoint[6];
+
+static int nb_hw_breakpoint;
+static int nb_hw_watchpoint;
+static int max_hw_breakpoint;
+static int max_hw_watchpoint;
+
+static void kvmppc_debug_init(int max_hw_bp, int max_hw_wp)
+{
+max_hw_breakpoint = max_hw_bp  4? 4 : max_hw_bp;
+max_hw_watchpoint = max_hw_wp  2? 2 : max_hw_wp;
+}
+
+static int find_hw_breakpoint(target_ulong addr, int type)
+{
+int n;
+
+for (n = 0; n  nb_hw_breakpoint + nb_hw_watchpoint; n++)
+if (hw_breakpoint[n].addr == addr  hw_breakpoint[n].type == type)
+return n;
+return -1;
+}
+
+int kvm_arch_insert_hw_breakpoint(target_ulong addr,
+  target_ulong len, int type)
+{
+hw_breakpoint[nb_hw_breakpoint + nb_hw_watchpoint].addr = addr;
+hw_breakpoint[nb_hw_breakpoint + nb_hw_watchpoint].type = type;
+
+switch (type) {
+case GDB_BREAKPOINT_HW:
+if (nb_hw_breakpoint = max_hw_breakpoint)
+return -ENOBUFS;
+
+if (find_hw_breakpoint(addr, type) = 0)
+return -EEXIST;
+
+nb_hw_breakpoint++;
+break;
+
+case GDB_WATCHPOINT_WRITE:
+case GDB_WATCHPOINT_READ:
+case GDB_WATCHPOINT_ACCESS:
+if (nb_hw_watchpoint = max_hw_watchpoint)
+return -ENOBUFS;
+
+if (find_hw_breakpoint(addr, type) = 0)
+return -EEXIST;
+
+nb_hw_watchpoint++;
+break;
+
+default:
+return -ENOSYS;
+}
+
+return 0;
+}
+
+int kvm_arch_remove_hw_breakpoint(target_ulong addr,
+  target_ulong len, int type)
+{
+int n;
+
+n = find_hw_breakpoint(addr, type);
+if (n  0)
+return -ENOENT;
+
+switch (type) {
+case GDB_BREAKPOINT_HW:
+nb_hw_breakpoint--;
+break;
+
+case GDB_WATCHPOINT_WRITE:
+case GDB_WATCHPOINT_READ:
+case GDB_WATCHPOINT_ACCESS:
+nb_hw_watchpoint--;
+break;
+
+default:
+return -ENOSYS;
+}
+hw_breakpoint[n] = hw_breakpoint[nb_hw_breakpoint + nb_hw_watchpoint];
+
+return 0;
+}
+
+void kvm_arch_remove_all_hw_breakpoints(void)
+{
+nb_hw_breakpoint = nb_hw_watchpoint = 0;
+}
+
+static CPUWatchpoint hw_watchpoint;
+
+int kvm_arch_debug(struct kvm_debug_exit_arch *arch_info)
+{
+int handle = 0;
+int n;
+
+if (cpu_single_env-singlestep_enabled) {
+handle = 1;
+
+} else if (arch_info-status) {
+if (arch_info-status  KVMPPC_DEBUG_BREAKPOINT) {
+n = find_hw_breakpoint(arch_info-pc, GDB_BREAKPOINT_HW);
+if (n = 0)
+handle = 1;
+
+} else if (arch_info-status  (KVMPPC_DEBUG_WATCH_READ |
+KVMPPC_DEBUG_WATCH_WRITE)) {
+if ((n = find_hw_breakpoint(arch_info-pc, GDB_WATCHPOINT_ACCESS)) 
= 0) {
+handle = 1;
+cpu_single_env-watchpoint_hit = hw_watchpoint;
+hw_watchpoint.vaddr = hw_breakpoint[n].addr;
+hw_watchpoint.flags = BP_MEM_ACCESS;
+} else if ((n = find_hw_breakpoint(arch_info-pc, 
GDB_WATCHPOINT_WRITE) = 0)) {
+handle = 1

[PATCH 4/5] kvmppc: Translate eaddr for fsl_booke mmu

2009-08-04 Thread Liu Yu
Signed-off-by: Liu Yu yu@freescale.com
---
 target-ppc/helper.c |   17 +++--
 1 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/target-ppc/helper.c b/target-ppc/helper.c
index 6eca2e5..07e56a4 100644
--- a/target-ppc/helper.c
+++ b/target-ppc/helper.c
@@ -22,6 +22,7 @@
 #include string.h
 #include inttypes.h
 #include signal.h
+#include linux/kvm.h
 
 #include cpu.h
 #include exec-all.h
@@ -1325,8 +1326,20 @@ static always_inline int check_physical (CPUState *env, 
mmu_ctx_t *ctx,
 cpu_abort(env, MPC8xx MMU model is not implemented\n);
 break;
 case POWERPC_MMU_BOOKE_FSL:
-/* XXX: TODO */
-cpu_abort(env, BookE FSL MMU model not implemented\n);
+if (kvm_enabled()) {
+struct kvm_translation tr;
+
+/* For now we only debug guest kernel */
+tr.linear_address = eaddr;
+ret = kvm_vcpu_ioctl(env, KVM_TRANSLATE, tr);
+if (ret  0)
+return ret;
+
+ctx-raddr = tr.physical_address;
+} else {
+/* XXX: TODO */
+cpu_abort(env, BookE FSL MMU model not implemented\n);
+}
 break;
 default:
 cpu_abort(env, Unknown or invalid MMU model\n);
-- 
1.5.4

--
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


[PATCH 5/5] kvmppc: guest debug init

2009-08-04 Thread Liu Yu
440(BOOKE) supports 4 hardware breakpoints,
while e500 supports 2.

Signed-off-by: Liu Yu yu@freescale.com
---
 target-ppc/kvm.c |   10 ++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
index 97a0737..82e7897 100644
--- a/target-ppc/kvm.c
+++ b/target-ppc/kvm.c
@@ -42,6 +42,10 @@
 do { } while (0)
 #endif
 
+#ifdef KVM_CAP_SET_GUEST_DEBUG
+static void kvmppc_debug_init(int, int);
+#endif
+
 int kvm_arch_init(KVMState *s, int smp_cpus)
 {
 return 0;
@@ -55,6 +59,12 @@ int kvm_arch_init_vcpu(CPUState *cenv)
 sregs.pvr = cenv-spr[SPR_PVR];
 ret = kvm_vcpu_ioctl(cenv, KVM_SET_SREGS, sregs);
 
+#ifdef KVM_CAP_SET_GUEST_DEBUG
+if (strcmp(cenv-cpu_model_str, 405))
+kvmppc_debug_init(4, 2);
+if (strcmp(cenv-cpu_model_str, e500v2_v30))
+kvmppc_debug_init(2, 2);   /* E500v2 doesn't support IAC3,IAC4 */
+#endif
 return ret;
 }
 
-- 
1.5.4

--
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


[PATCH v2 0/5] kvmppc: Add guest debug support

2009-08-03 Thread Liu Yu
This patchset add guest debug support for BOOKE.

patch 1: fix current e500 broken
patch 2: guest debug definitions
patch 3: switch shadow/host debug register on guest enter/exit path
patch 4: guest debug support
patch 5: exitnr fixup in single step mode

[v2]
1. move code from 2.6.30 to current head
2. move the debug registers updating code to guest enter/exit path
3. some cleanup.


--
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


[PATCH 1/5] Fix the trace broken for e500 kvm

2009-08-03 Thread Liu Yu
Remove the broken trace.
Will get them cleanup in future.

Signed-off-by: Liu Yu yu@freescale.com
---
 arch/powerpc/kvm/e500_tlb.c |2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kvm/e500_tlb.c b/arch/powerpc/kvm/e500_tlb.c
index fb1e1dc..a344be6 100644
--- a/arch/powerpc/kvm/e500_tlb.c
+++ b/arch/powerpc/kvm/e500_tlb.c
@@ -225,8 +225,6 @@ static void kvmppc_e500_stlbe_invalidate(struct 
kvmppc_vcpu_e500 *vcpu_e500,
 
kvmppc_e500_shadow_release(vcpu_e500, tlbsel, esel);
stlbe-mas1 = 0;
-   trace_kvm_stlb_inval(index_of(tlbsel, esel), stlbe-mas1, stlbe-mas2,
-stlbe-mas3, stlbe-mas7);
 }
 
 static void kvmppc_e500_tlb1_invalidate(struct kvmppc_vcpu_e500 *vcpu_e500,
-- 
1.5.4

--
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


[PATCH 2/5] kvmppc guest debug definitions

2009-08-03 Thread Liu Yu
Signed-off-by: Liu Yu yu@freescale.com
---
 arch/powerpc/include/asm/kvm.h  |   20 
 arch/powerpc/include/asm/kvm_host.h |   18 ++
 2 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm.h b/arch/powerpc/include/asm/kvm.h
index bb2de6a..804df17 100644
--- a/arch/powerpc/include/asm/kvm.h
+++ b/arch/powerpc/include/asm/kvm.h
@@ -22,6 +22,9 @@
 
 #include linux/types.h
 
+/* Select powerpc specific features in linux/kvm.h */
+#define __KVM_HAVE_GUEST_DEBUG
+
 struct kvm_regs {
__u64 pc;
__u64 cr;
@@ -53,10 +56,27 @@ struct kvm_fpu {
 };
 
 struct kvm_debug_exit_arch {
+   __u32 exception;
+   __u32 pc;
+   __u32 status;
 };
 
+#define KVM_INST_GUESTGDB   0x4422
+
+#define KVM_GUESTDBG_USE_SW_BP  0x0001
+#define KVM_GUESTDBG_USE_HW_BP  0x0002
+
+#define KVMPPC_DEBUG_NOTYPE 0x0
+#define KVMPPC_DEBUG_BREAKPOINT (1UL  1)
+#define KVMPPC_DEBUG_WATCH_WRITE(1UL  2)
+#define KVMPPC_DEBUG_WATCH_READ (1UL  3)
+
 /* for KVM_SET_GUEST_DEBUG */
 struct kvm_guest_debug_arch {
+   struct {
+   __u32 addr;
+   __u32 type;
+   } bp[6];
 };
 
 #endif /* __LINUX_KVM_POWERPC_H */
diff --git a/arch/powerpc/include/asm/kvm_host.h 
b/arch/powerpc/include/asm/kvm_host.h
index c9c930e..6caabfc 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -109,9 +109,22 @@ struct kvmppc_exit_timing {
 struct kvm_arch {
 };
 
+struct kvmppc_debug_reg {
+   u32 dbcr0;
+   u32 iac[0];
+   u32 iac1;
+   u32 iac2;
+   u32 iac3;
+   u32 iac4;
+   u32 dac[0];
+   u32 dac1;
+   u32 dac2;
+};
+
 struct kvm_vcpu_arch {
u32 host_stack;
u32 host_pid;
+   u32 host_msr;
 
u64 fpr[32];
ulong gpr[32];
@@ -160,6 +173,10 @@ struct kvm_vcpu_arch {
u32 dbcr1;
u32 dbsr;
 
+   struct kvmppc_debug_reg shadow_dbg_reg;
+   struct kvmppc_debug_reg host_dbg_reg;
+   bool has_load_host_dbg;
+
 #ifdef CONFIG_KVM_EXIT_TIMING
struct kvmppc_exit_timing timing_exit;
struct kvmppc_exit_timing timing_last_enter;
@@ -187,6 +204,7 @@ struct kvm_vcpu_arch {
 
struct timer_list dec_timer;
unsigned long pending_exceptions;
+   struct kvm_guest_debug_arch dbg;
 };
 
 #endif /* __POWERPC_KVM_HOST_H__ */
-- 
1.5.4

--
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


[PATCH 3/5] Switch shadow/host debug registers on guest enter/exit path

2009-08-03 Thread Liu Yu
So that we don't give any chance for host to trigger the debug event.
Also the debug ability in guest can be implemented based on this.

Signed-off-by: Liu Yu yu@freescale.com
---
 arch/powerpc/kernel/asm-offsets.c   |3 ++
 arch/powerpc/kvm/booke_interrupts.S |   58 +++
 2 files changed, 61 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/kernel/asm-offsets.c 
b/arch/powerpc/kernel/asm-offsets.c
index 561b646..643ee15 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -379,6 +379,9 @@ int main(void)
DEFINE(VCPU_LAST_INST, offsetof(struct kvm_vcpu, arch.last_inst));
DEFINE(VCPU_FAULT_DEAR, offsetof(struct kvm_vcpu, arch.fault_dear));
DEFINE(VCPU_FAULT_ESR, offsetof(struct kvm_vcpu, arch.fault_esr));
+   DEFINE(VCPU_SHADOW_DBG, offsetof(struct kvm_vcpu, arch.shadow_dbg_reg));
+   DEFINE(VCPU_HOST_DBG, offsetof(struct kvm_vcpu, arch.host_dbg_reg));
+   DEFINE(VCPU_GUEST_DEBUG, offsetof(struct kvm_vcpu, guest_debug));
 #endif
 #ifdef CONFIG_44x
DEFINE(PGD_T_LOG2, PGD_T_LOG2);
diff --git a/arch/powerpc/kvm/booke_interrupts.S 
b/arch/powerpc/kvm/booke_interrupts.S
index d0c6f84..52592fe 100644
--- a/arch/powerpc/kvm/booke_interrupts.S
+++ b/arch/powerpc/kvm/booke_interrupts.S
@@ -168,6 +168,26 @@ _GLOBAL(kvmppc_resume_host)
stw r9, VCPU_FAULT_ESR(r4)
 ..skip_esr:
 
+   lwz r6, VCPU_GUEST_DEBUG(r4)
+   or. r6, r6, r6
+   beq ..skip_host_debug
+   addir7, r4, VCPU_HOST_DBG - 4
+   lwzur9, 4(r7)
+   mtspr   SPRN_DBCR0, r9
+   lwzur9, 4(r7)
+   mtspr   SPRN_IAC1, r9
+   lwzur9, 4(r7)
+   mtspr   SPRN_IAC2, r9
+   lwzur9, 4(r7)
+   mtspr   SPRN_IAC3, r9
+   lwzur9, 4(r7)
+   mtspr   SPRN_IAC4, r9
+   lwzur9, 4(r7)
+   mtspr   SPRN_DAC1, r9
+   lwzur9, 4(r7)
+   mtspr   SPRN_DAC2, r9
+..skip_host_debug:
+
/* Save remaining volatile guest register state to vcpu. */
stw r0, VCPU_GPR(r0)(r4)
stw r1, VCPU_GPR(r1)(r4)
@@ -392,6 +412,44 @@ lightweight_exit:
lwz r3, VCPU_SPRG7(r4)
mtspr   SPRN_SPRG7, r3
 
+   lwz r6, VCPU_GUEST_DEBUG(r4)
+   or. r6, r6, r6
+   beq ..skip_guest_debug
+   mfmsr   r7
+   rlwinm  r7, r7, 0, ~MSR_DE
+   mtmsr   r7
+   addir7, r4, VCPU_HOST_DBG - 4
+   mfspr   r8, SPRN_DBCR0
+   stwur8, 4(r7)
+   mfspr   r8, SPRN_IAC1
+   stwur8, 4(r7)
+   mfspr   r8, SPRN_IAC2
+   stwur8, 4(r7)
+   mfspr   r8, SPRN_IAC3
+   stwur8, 4(r7)
+   mfspr   r8, SPRN_IAC4
+   stwur8, 4(r7)
+   mfspr   r8, SPRN_DAC1
+   stwur8, 4(r7)
+   mfspr   r8, SPRN_DAC2
+   stwur8, 4(r7)
+   addir7, r4, VCPU_SHADOW_DBG - 4
+   lwzur8, 4(r7)
+   mtspr   SPRN_DBCR0, r8
+   lwzur8, 4(r7)
+   mtspr   SPRN_IAC1, r8
+   lwzur8, 4(r7)
+   mtspr   SPRN_IAC2, r8
+   lwzur8, 4(r7)
+   mtspr   SPRN_IAC3, r8
+   lwzur8, 4(r7)
+   mtspr   SPRN_IAC4, r8
+   lwzur8, 4(r7)
+   mtspr   SPRN_DAC1, r8
+   lwzur8, 4(r7)
+   mtspr   SPRN_DAC2, r8
+..skip_guest_debug:
+
 #ifdef CONFIG_KVM_EXIT_TIMING
/* save enter time */
 1:
-- 
1.5.4

--
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


[PATCH 4/5] kvmppc guest debug support

2009-08-03 Thread Liu Yu
Signed-off-by: Liu Yu yu@freescale.com
---
 arch/powerpc/include/asm/kvm_ppc.h |5 ++
 arch/powerpc/kvm/booke.c   |   97 ++--
 arch/powerpc/kvm/e500.c|8 ---
 arch/powerpc/kvm/powerpc.c |2 +-
 4 files changed, 99 insertions(+), 13 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
b/arch/powerpc/include/asm/kvm_ppc.h
index 2c6ee34..4f3656b 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -89,6 +89,11 @@ extern int kvmppc_core_emulate_op(struct kvm_run *run, 
struct kvm_vcpu *vcpu,
 extern int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs);
 extern int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt);
 
+extern void kvmppc_core_load_host_debugstate(struct kvm_vcpu *vcpu);
+extern void kvmppc_core_load_guest_debugstate(struct kvm_vcpu *vcpu);
+extern int kvmppc_core_set_guest_debug(struct kvm_vcpu *vcpu,
+   struct kvm_guest_debug *dbg);
+
 extern int kvmppc_booke_init(void);
 extern void kvmppc_booke_exit(void);
 
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index e7bf4d0..4e7954f 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -16,6 +16,9 @@
  *
  * Authors: Hollis Blanchard holl...@us.ibm.com
  *  Christian Ehrhardt ehrha...@linux.vnet.ibm.com
+ *
+ * Copyright (C) 2009 Freescale Semiconductor, Inc. All rights reserved.
+ *  Yu Liu yu@freescale.com
  */
 
 #include linux/errno.h
@@ -230,6 +233,16 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
break;
}
 
+   if (unlikely(vcpu-guest_debug  KVM_GUESTDBG_ENABLE) 
+(vcpu-arch.last_inst == KVM_INST_GUESTGDB)) {
+   run-exit_reason = KVM_EXIT_DEBUG;
+   run-debug.arch.pc = vcpu-arch.pc;
+   run-debug.arch.exception = exit_nr;
+   kvmppc_account_exit(vcpu, DEBUG_EXITS);
+   r = RESUME_HOST;
+   break;
+   }
+
er = kvmppc_emulate_instruction(run, vcpu);
switch (er) {
case EMULATE_DONE:
@@ -256,6 +269,12 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
default:
BUG();
}
+
+   if (unlikely(vcpu-guest_debug  KVM_GUESTDBG_ENABLE) 
+   (vcpu-guest_debug  KVM_GUESTDBG_SINGLESTEP)) {
+   run-exit_reason = KVM_EXIT_DEBUG;
+   r = RESUME_HOST;
+   }
break;
 
case BOOKE_INTERRUPT_FP_UNAVAIL:
@@ -386,12 +405,27 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
u32 dbsr;
 
vcpu-arch.pc = mfspr(SPRN_CSRR0);
-
-   /* clear IAC events in DBSR register */
dbsr = mfspr(SPRN_DBSR);
-   dbsr = DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4;
-   mtspr(SPRN_DBSR, dbsr);
+   run-debug.arch.pc = vcpu-arch.pc;
+   run-debug.arch.status = 0;
+
+   if (dbsr  (DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4)) {
+   run-debug.arch.status |= KVMPPC_DEBUG_BREAKPOINT;
+   } else {
+   if (dbsr  (DBSR_DAC1W | DBSR_DAC2W))
+   run-debug.arch.status |= 
KVMPPC_DEBUG_WATCH_WRITE;
+   else if (dbsr  (DBSR_DAC1R | DBSR_DAC2R))
+   run-debug.arch.status |= 
KVMPPC_DEBUG_WATCH_READ;
+   if (dbsr  (DBSR_DAC1R | DBSR_DAC1W))
+   run-debug.arch.pc = 
vcpu-arch.shadow_dbg_reg.dac1;
+   else if (dbsr  (DBSR_DAC2R | DBSR_DAC2W))
+   run-debug.arch.pc = 
vcpu-arch.shadow_dbg_reg.dac2;
+   }
 
+   /* clear events in DBSR register */
+   mtspr(SPRN_DBSR, ~0);
+
+   run-debug.arch.exception = exit_nr;
run-exit_reason = KVM_EXIT_DEBUG;
kvmppc_account_exit(vcpu, DEBUG_EXITS);
r = RESUME_HOST;
@@ -463,6 +497,7 @@ int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, 
struct kvm_regs *regs)
for (i = 0; i  ARRAY_SIZE(regs-gpr); i++)
regs-gpr[i] = vcpu-arch.gpr[i];
 
+
return 0;
 }
 
@@ -520,6 +555,60 @@ int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
return kvmppc_core_vcpu_translate(vcpu, tr);
 }
 
+int kvmppc_core_set_guest_debug(struct kvm_vcpu *vcpu,
+struct kvm_guest_debug *dbg)
+{
+   if (!(dbg-control  KVM_GUESTDBG_ENABLE)) {
+   vcpu-guest_debug = 0;
+   return 0;
+   }
+
+   vcpu-guest_debug = dbg-control;
+   vcpu

[PATCH 5/5] kvmppc: exit_nr fixup for guest debug single step

2009-08-03 Thread Liu Yu
As BOOKE doesn't have hardware support for virtualization,
hardware never know guest and host.
So when enable hardware single step for guest,
it cannot be disabled timely if guest want to exit.

Thus, we'll see that an single step interrupt happens at
the beginning of guest exit path.
Then we need to recognize this kind of single step interrupt
and fix the exit_nr to the corret value.

Signed-off-by: Liu Yu yu@freescale.com
---
 arch/powerpc/kvm/booke.c|   82 +++
 arch/powerpc/kvm/booke_interrupts.S |9 ++--
 2 files changed, 87 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 4e7954f..d3cfd85 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -27,6 +27,7 @@
 #include linux/module.h
 #include linux/vmalloc.h
 #include linux/fs.h
+#include linux/highmem.h
 
 #include asm/cputable.h
 #include asm/uaccess.h
@@ -37,6 +38,8 @@
 #include booke.h
 
 unsigned long kvmppc_booke_handlers;
+unsigned long kvmppc_booke_handler_addr[16];
+#define handler_vector_num 
(sizeof(kvmppc_booke_handler_addr)/sizeof(kvmppc_booke_handler_addr[0]))
 
 #define VM_STAT(x) offsetof(struct kvm, stat.x), KVM_STAT_VM
 #define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU
@@ -179,6 +182,80 @@ void kvmppc_core_deliver_interrupts(struct kvm_vcpu *vcpu)
}
 }
 
+int kvmppc_read_guest(struct kvm_vcpu *vcpu, unsigned long geaddr,
+ void *data, int len)
+{
+   int gtlb_index;
+   gpa_t gpa;
+   gfn_t gfn;
+   struct page *page;
+   void *headdr, *from;
+
+   /* Check the guest TLB. */
+   gtlb_index = kvmppc_mmu_itlb_index(vcpu, geaddr);
+   if (gtlb_index  0)
+   return -EFAULT;
+
+   gpa = kvmppc_mmu_xlate(vcpu, gtlb_index, geaddr);
+   gfn = gpa  PAGE_SHIFT;
+
+   page = gfn_to_page(vcpu-kvm, gfn);
+   if (page == bad_page)
+   return -EFAULT;
+
+   headdr = kmap_atomic(page, KM_USER0);
+   if (!headdr)
+   return -EFAULT;
+   from = headdr + (geaddr  (PAGE_SIZE - 1));
+   memcpy(data, from, len);
+   kunmap_atomic(headdr, KM_USER0);
+
+   return 0;
+}
+
+static unsigned int kvmppc_guest_debug_exit_fixup(struct kvm_vcpu *vcpu,
+  unsigned int exit_nr)
+{
+   unsigned int ret = exit_nr;
+
+   u32 csrr0 = mfspr(SPRN_CSRR0);
+   u32 dbsr = mfspr(SPRN_DBSR);
+
+   if ((dbsr | DBSR_IC) 
+   csrr0 = kvmppc_booke_handlers 
+   csrr0  kvmppc_booke_handlers + (PAGE_SIZE  VCPU_SIZE_ORDER)) {
+   int i = 0;
+
+   for (i = 0; i  handler_vector_num; i++) {
+   if (kvmppc_booke_handler_addr[i] 
+   csrr0 == kvmppc_booke_handler_addr[i] + 4) {
+   mtspr(SPRN_DBSR, ~0);
+   ret = i;
+   break;
+   }
+   }
+
+   }
+
+   switch (ret) {
+   case BOOKE_INTERRUPT_DEBUG:
+   case BOOKE_INTERRUPT_ITLB_MISS:
+   case BOOKE_INTERRUPT_EXTERNAL:
+   case BOOKE_INTERRUPT_DECREMENTER:
+   break;
+
+   case BOOKE_INTERRUPT_PROGRAM:
+   case BOOKE_INTERRUPT_DTLB_MISS:
+   /* Need to save the last instruction */
+   kvmppc_read_guest(vcpu, vcpu-arch.pc, vcpu-arch.last_inst, 
4);
+   break;
+   default:
+   printk(Unhandled debug after interrupt:%d\n, ret);
+   }
+
+   return ret;
+}
+
 /**
  * kvmppc_handle_exit
  *
@@ -198,6 +275,9 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu 
*vcpu,
run-exit_reason = KVM_EXIT_UNKNOWN;
run-ready_for_interrupt_injection = 1;
 
+   if (exit_nr == BOOKE_INTERRUPT_DEBUG)
+   exit_nr = kvmppc_guest_debug_exit_fixup(vcpu, exit_nr);
+
switch (exit_nr) {
case BOOKE_INTERRUPT_MACHINE_CHECK:
printk(MACHINE CHECK: %lx\n, mfspr(SPRN_MCSR));
@@ -650,6 +730,8 @@ int __init kvmppc_booke_init(void)
memcpy((void *)kvmppc_booke_handlers + ivor[i],
   kvmppc_handlers_start + i * kvmppc_handler_len,
   kvmppc_handler_len);
+   kvmppc_booke_handler_addr[i] =
+   (unsigned long)kvmppc_booke_handlers + ivor[i];
}
flush_icache_range(kvmppc_booke_handlers,
   kvmppc_booke_handlers + max_ivor + 
kvmppc_handler_len);
diff --git a/arch/powerpc/kvm/booke_interrupts.S 
b/arch/powerpc/kvm/booke_interrupts.S
index 52592fe..d7cd37e 100644
--- a/arch/powerpc/kvm/booke_interrupts.S
+++ b/arch/powerpc/kvm/booke_interrupts.S
@@ -42,16 +42,17 @@
 #define HOST_STACK_LR   (HOST_STACK_SIZE + 4) /* In caller stack frame. */
 
 #define NEED_INST_MASK ((1BOOKE_INTERRUPT_PROGRAM) | \
-(1BOOKE_INTERRUPT_DTLB_MISS

RE: [PATCH 2/5] kvmppc guest debug definitions

2009-08-03 Thread Liu Yu-B13201
 

 -Original Message-
 From: Liu Yu-B13201 
 Sent: Monday, August 03, 2009 7:08 PM
 To: kvm-ppc@vger.kernel.org
 Cc: holl...@us.ibm.com; a...@redhat.com; Liu Yu-B13201
 Subject: [PATCH 2/5] kvmppc guest debug definitions
 
 Signed-off-by: Liu Yu yu@freescale.com
 ---
  arch/powerpc/include/asm/kvm.h  |   20 
  arch/powerpc/include/asm/kvm_host.h |   18 ++
  2 files changed, 38 insertions(+), 0 deletions(-)
 
 diff --git a/arch/powerpc/include/asm/kvm_host.h 
 b/arch/powerpc/include/asm/kvm_host.h
 index c9c930e..6caabfc 100644
 --- a/arch/powerpc/include/asm/kvm_host.h
 +++ b/arch/powerpc/include/asm/kvm_host.h
 @@ -160,6 +173,10 @@ struct kvm_vcpu_arch {
   u32 dbcr1;
   u32 dbsr;
  
 + struct kvmppc_debug_reg shadow_dbg_reg;
 + struct kvmppc_debug_reg host_dbg_reg;
 + bool has_load_host_dbg;

Forgot to remove this variable for debug
--
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 0/5]

2009-07-27 Thread Liu Yu-B13201
 

 -Original Message-
 From: jan.kis...@web.de [mailto:jan.kis...@web.de] 
 Sent: Saturday, July 25, 2009 6:44 PM
 To: Liu Yu-B13201
 Cc: qemu-devel; Hollis Blanchard; kvm-ppc; Nathan Froyd
 Subject: Re: [PATCH 0/5]
 
 Liu Yu wrote:
  2. gdb 'watch' command
  Jan told me gdb6.8 can issue hardware watchpoint request 
 via command 'watch',
  my gdb is 6.8.50.20080821-cvs and our toolchain provider 
 confirm that it supports hardware watch
  However when I use 'watch', I can only see single step from 
 gdbstub side.
  Did I miss anything?
 
 Did you install a watchpoint on a symbol? If yes, try if 
 placing one on
 an absolute address changes the picture.

Cool, it did use hardware watch when I used absolute address.
Seems I need to test more. :)
--
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 3/5] Add guest debug support for kvmppc

2009-07-27 Thread Liu Yu-B13201
 

 -Original Message-
 From: jan.kis...@web.de [mailto:jan.kis...@web.de] 
 Sent: Saturday, July 25, 2009 6:19 PM
 To: Liu Yu-B13201
 Cc: qemu-devel; Hollis Blanchard; kvm-ppc; Nathan Froyd
 Subject: Re: [PATCH 3/5] Add guest debug support for kvmppc
 
 Liu Yu wrote:
  Signed-off-by: Liu Yu 
 yu.liu-kzfg59tc24xl57midrc...@public.gmane.org
  ---
   target-ppc/kvm.c |  197 
 ++
   1 files changed, 197 insertions(+), 0 deletions(-)
  
  diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
  index b53d6e9..d8dbdb4 100644
  --- a/target-ppc/kvm.c
  +++ b/target-ppc/kvm.c
  +
  +int kvm_arch_debug(struct kvm_debug_exit_arch *arch_info)
  +{
  +int handle = 0;
  +int n;
  +
  +if (cpu_single_env-singlestep_enabled) {
  +handle = 1;
  +
  +} else if (arch_info-status) {
  +if (arch_info-status == KVMPPC_DEBUG_BREAKPOINT) {
  +n = find_hw_breakpoint(arch_info-pc, 
 GDB_BREAKPOINT_HW);
  +if (n = 0)
  +handle = 1;
  +
  +} else if (arch_info-status == 
 KVMPPC_DEBUG_WATCH_ACCESS) {
  +n = find_hw_breakpoint(arch_info-pc, 
 GDB_WATCHPOINT_ACCESS);
  +if (n = 0) {
  +handle = 1;
  +cpu_single_env-watchpoint_hit = hw_watchpoint;
  +hw_watchpoint.vaddr = hw_breakpoint[n].addr;
  +hw_watchpoint.flags = BP_MEM_ACCESS;
  +}
  +
  +} else if (arch_info-status == KVMPPC_DEBUG_WATCH_WRITE) {
  +n = find_hw_breakpoint(arch_info-pc, 
 GDB_WATCHPOINT_WRITE);
  +if (n = 0) {
  +handle = 1;
  +cpu_single_env-watchpoint_hit = hw_watchpoint;
  +hw_watchpoint.vaddr = hw_breakpoint[n].addr;
  +hw_watchpoint.flags = BP_MEM_WRITE;
  +}
  +}
  +
  +} else if (kvm_find_sw_breakpoint(cpu_single_env, 
 arch_info-pc))
  +handle = 1;
  +
  +/* XXX inject guest debug exception */
  +if (!handle)
  +printf(Unhandled debug exception!\n);
 
 Out of curiosity: Not yet implemented here, or is PPC also 
 lacking some
 kernel bits to support it?

Yes, guest has no hardware debug support in booke kvm so far.
It's now useless for a guest to set debug register.

--
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


[PATCH 1/5] Fix kvmppc build error

2009-07-25 Thread Liu Yu
like this:
/home/liuyu/git/qemu.git/target-ppc/kvm_ppc.c: In function 
'kvmppc_read_host_property':
/home/liuyu/git/qemu.git/target-ppc/kvm_ppc.c:55: error: label 'out' defined 
but not used

Signed-off-by: Liu Yu yu@freescale.com
---
 target-ppc/kvm_ppc.c |1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/target-ppc/kvm_ppc.c b/target-ppc/kvm_ppc.c
index 10cfdb3..be47469 100644
--- a/target-ppc/kvm_ppc.c
+++ b/target-ppc/kvm_ppc.c
@@ -52,7 +52,6 @@ close:
 fclose(f);
 free:
 free(path);
-out:
 return ret;
 }
 
-- 
1.5.4

--
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


[PATCH 0/5]

2009-07-25 Thread Liu Yu

The whole patchset includes:
patch 1: fix kvmppc build error
patch 2: fix kvmppc init error
patch 3~5: add kvmppc guest debug support

The guest debug still have some problems I haven't solved.

1. gdb 'next' command uses software breakpoint
software breakpoint is implemented via modify guest's code.
In most case it works well,
but when used by 'next' it's easy to make trouble on powerpc booke.

For example booke has a code template for
jumping to and returning from interrupt handlers:

bl transfer
.long handler_addr
.long ret_addr

when call transfer, it never return but
in transfer assembly code it will read the handler_addr
and ultimately call the handler.
Gdb doesn't know that and treat it as a normal function call.
so gdb put a software breakpoint instruction at handler_addr,
in order to get trap there when return from transfer.

Then guest will read software breakpoint as handler_addr and jump to there..

I'm not sure if x86 suffer this kind of issue.
Is there any way to avoid this?


2. gdb 'watch' command
Jan told me gdb6.8 can issue hardware watchpoint request via command 'watch',
my gdb is 6.8.50.20080821-cvs and our toolchain provider confirm that it 
supports hardware watch
However when I use 'watch', I can only see single step from gdbstub side.
Did I miss anything?



--
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


[PATCH 4/5] Add eaddr translator for fsl_booke mmu

2009-07-25 Thread Liu Yu
Signed-off-by: Liu Yu yu@freescale.com
---
 target-ppc/helper.c |   17 +++--
 1 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/target-ppc/helper.c b/target-ppc/helper.c
index b7162df..f4af124 100644
--- a/target-ppc/helper.c
+++ b/target-ppc/helper.c
@@ -22,6 +22,7 @@
 #include string.h
 #include inttypes.h
 #include signal.h
+#include linux/kvm.h
 
 #include cpu.h
 #include exec-all.h
@@ -1325,8 +1326,20 @@ static always_inline int check_physical (CPUState *env, 
mmu_ctx_t *ctx,
 cpu_abort(env, MPC8xx MMU model is not implemented\n);
 break;
 case POWERPC_MMU_BOOKE_FSL:
-/* XXX: TODO */
-cpu_abort(env, BookE FSL MMU model not implemented\n);
+if (kvm_enabled()) {
+struct kvm_translation tr;
+
+/* For now we only debug guest kernel */
+tr.linear_address = eaddr;
+ret = kvm_vcpu_ioctl(env, KVM_TRANSLATE, tr);
+if (ret  0)
+return ret;
+
+ctx-raddr = tr.physical_address;
+} else {
+/* XXX: TODO */
+cpu_abort(env, BookE FSL MMU model not implemented\n);
+}
 break;
 default:
 cpu_abort(env, Unknown or invalid MMU model\n);
-- 
1.5.4

--
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


[PATCH 5/5] guest debug init for 440 and e500 core

2009-07-25 Thread Liu Yu
e500 only support 2 hardware breakpoints,
440(BOOKE) supports 4.

Signed-off-by: Liu Yu yu@freescale.com
---
 hw/ppc440_bamboo.c |1 +
 hw/ppce500_mpc8544ds.c |1 +
 target-ppc/kvm_ppc.h   |1 +
 3 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/hw/ppc440_bamboo.c b/hw/ppc440_bamboo.c
index f1ba130..8c9c3b6 100644
--- a/hw/ppc440_bamboo.c
+++ b/hw/ppc440_bamboo.c
@@ -185,6 +185,7 @@ static void bamboo_init(ram_addr_t ram_size,
 if (kvm_enabled()) {
 kvm_arch_put_registers(env);
 kvmppc_init();
+kvmppc_debug_init(4, 2);
 }
 }
 
diff --git a/hw/ppce500_mpc8544ds.c b/hw/ppce500_mpc8544ds.c
index f1b3c1a..6c2aa61 100644
--- a/hw/ppce500_mpc8544ds.c
+++ b/hw/ppce500_mpc8544ds.c
@@ -279,6 +279,7 @@ static void mpc8544ds_init(ram_addr_t ram_size,
 if (kvm_enabled()) {
 kvm_arch_put_registers(env);
 kvmppc_init();
+kvmppc_debug_init(2, 2); /* E500v2 doesn't support IAC3,IAC4 */
 }
 
 return;
diff --git a/target-ppc/kvm_ppc.h b/target-ppc/kvm_ppc.h
index 3792ef7..8b4edca 100644
--- a/target-ppc/kvm_ppc.h
+++ b/target-ppc/kvm_ppc.h
@@ -13,5 +13,6 @@ void kvmppc_init(void);
 void kvmppc_fdt_update(void *fdt);
 int kvmppc_read_host_property(const char *node_path, const char *prop,
  void *val, size_t len);
+void kvmppc_debug_init(int max_hw_bp, int max_hw_wp);
 
 #endif /* __KVM_PPC_H__ */
-- 
1.5.4

--
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


[PATCH] Single step hack for guest debug

2009-07-25 Thread Liu Yu
As booke doesn't have hardware support for virtualization,
hardware never know guest and host.

So when enable hardware single step for guest, it cannot disable it timely
if guest failed on certain instruction and then exit.

Thus, we'll see that an single step interrupt happens at
the very beginning of guest exit path.
Then we need to recognize this kind of single step interrupt
and fix the exit_nr to the corret value.

Signed-off-by: Liu Yu yu@freescale.com
---
 arch/powerpc/kvm/booke.c|   82 +++
 arch/powerpc/kvm/booke_interrupts.S |9 ++--
 2 files changed, 87 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 7f47003..b042265 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -24,6 +24,7 @@
 #include linux/module.h
 #include linux/vmalloc.h
 #include linux/fs.h
+#include linux/highmem.h
 
 #include asm/cputable.h
 #include asm/uaccess.h
@@ -34,6 +35,8 @@
 #include booke.h
 
 unsigned long kvmppc_booke_handlers;
+unsigned long kvmppc_booke_handler_addr[16];
+#define handler_vector_num 
(sizeof(kvmppc_booke_handler_addr)/sizeof(kvmppc_booke_handler_addr[0]))
 
 #define VM_STAT(x) offsetof(struct kvm, stat.x), KVM_STAT_VM
 #define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU
@@ -176,6 +179,80 @@ void kvmppc_core_deliver_interrupts(struct kvm_vcpu *vcpu)
}
 }
 
+int kvmppc_read_guest(struct kvm_vcpu *vcpu, unsigned long geaddr,
+ void *data, int len)
+{
+   int gtlb_index;
+   gpa_t gpa;
+   gfn_t gfn;
+   struct page *page;
+   void *headdr, *from;
+
+   /* Check the guest TLB. */
+   gtlb_index = kvmppc_mmu_itlb_index(vcpu, geaddr);
+   if (gtlb_index  0)
+   return -EFAULT;
+
+   gpa = kvmppc_mmu_xlate(vcpu, gtlb_index, geaddr);
+   gfn = gpa  PAGE_SHIFT;
+
+   page = gfn_to_page(vcpu-kvm, gfn);
+   if (page == bad_page)
+   return -EFAULT;
+
+   headdr = kmap_atomic(page, KM_USER0);
+   if (!headdr)
+   return -EFAULT;
+   from = headdr + (geaddr  (PAGE_SIZE - 1));
+   memcpy(data, from, len);
+   kunmap_atomic(headdr, KM_USER0);
+
+   return 0;
+}
+
+static unsigned int kvmppc_guest_debug_exit_fixup(struct kvm_vcpu *vcpu,
+  unsigned int exit_nr)
+{
+   unsigned int ret = exit_nr;
+
+   u32 csrr0 = mfspr(SPRN_CSRR0);
+   u32 dbsr = mfspr(SPRN_DBSR);
+
+   if ((dbsr | DBSR_IC) 
+   csrr0 = kvmppc_booke_handlers 
+   csrr0  kvmppc_booke_handlers + (PAGE_SIZE  VCPU_SIZE_ORDER)) {
+   int i = 0;
+
+   for (i = 0; i  handler_vector_num; i++) {
+   if (kvmppc_booke_handler_addr[i] 
+   csrr0 == kvmppc_booke_handler_addr[i] + 4) {
+   mtspr(SPRN_DBSR, ~0);
+   ret = i;
+   break;
+   }
+   }
+
+   }
+
+   switch (ret) {
+   case BOOKE_INTERRUPT_DEBUG:
+   case BOOKE_INTERRUPT_ITLB_MISS:
+   case BOOKE_INTERRUPT_EXTERNAL:
+   case BOOKE_INTERRUPT_DECREMENTER:
+   break;
+
+   case BOOKE_INTERRUPT_PROGRAM:
+   case BOOKE_INTERRUPT_DTLB_MISS:
+   /* Need to save the last instruction */
+   kvmppc_read_guest(vcpu, vcpu-arch.pc, vcpu-arch.last_inst, 
4);
+   break;
+   default:
+   printk(Unhandled debug after interrupt:%d\n, ret);
+   }
+
+   return ret;
+}
+
 /**
  * kvmppc_handle_exit
  *
@@ -195,6 +272,9 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu 
*vcpu,
run-exit_reason = KVM_EXIT_UNKNOWN;
run-ready_for_interrupt_injection = 1;
 
+   if (exit_nr == BOOKE_INTERRUPT_DEBUG)
+   exit_nr = kvmppc_guest_debug_exit_fixup(vcpu, exit_nr);
+
switch (exit_nr) {
case BOOKE_INTERRUPT_MACHINE_CHECK:
printk(MACHINE CHECK: %lx\n, mfspr(SPRN_MCSR));
@@ -693,6 +773,8 @@ int kvmppc_booke_init(void)
memcpy((void *)kvmppc_booke_handlers + ivor[i],
   kvmppc_handlers_start + i * kvmppc_handler_len,
   kvmppc_handler_len);
+   kvmppc_booke_handler_addr[i] =
+   (void *)kvmppc_booke_handlers + ivor[i];
}
flush_icache_range(kvmppc_booke_handlers,
   kvmppc_booke_handlers + max_ivor + 
kvmppc_handler_len);
diff --git a/arch/powerpc/kvm/booke_interrupts.S 
b/arch/powerpc/kvm/booke_interrupts.S
index d0c6f84..45ff93f 100644
--- a/arch/powerpc/kvm/booke_interrupts.S
+++ b/arch/powerpc/kvm/booke_interrupts.S
@@ -42,16 +42,17 @@
 #define HOST_STACK_LR   (HOST_STACK_SIZE + 4) /* In caller stack frame. */
 
 #define NEED_INST_MASK ((1BOOKE_INTERRUPT_PROGRAM

RE: [PATCH 1/2] KVM/PPC: Fix PPC KVM e500_tlb.c build error

2009-07-01 Thread Liu Yu-B13201

This fix is already accepted in kvm.git 

 -Original Message-
 From: Yang Shi [mailto:yang@windriver.com] 
 Sent: Thursday, July 02, 2009 10:55 AM
 To: Liu Yu-B13201; holl...@us.ibm.com; a...@redhat.com
 Cc: kvm-ppc@vger.kernel.org; k...@vger.kernel.org; 
 linuxppc-...@ozlabs.org
 Subject: [PATCH 1/2] KVM/PPC: Fix PPC KVM e500_tlb.c build error
 
 Since include/asm/mmu-fsl-booke.h was replaced by 
 include/asm/mmu-book3e.h,
 fix e500_tlb.h to reflect the change and fix e500_tlb.c to 
 align with the
 new page size macro definition in include/asm/mmu-book3e.h.
 
 Signed-off-by: Yang Shi yang@windriver.com
 ---
  arch/powerpc/kvm/e500_tlb.c |8 
  arch/powerpc/kvm/e500_tlb.h |2 +-
  2 files changed, 5 insertions(+), 5 deletions(-)
 
 diff --git a/arch/powerpc/kvm/e500_tlb.c b/arch/powerpc/kvm/e500_tlb.c
 index 0e773fc..616762b 100644
 --- a/arch/powerpc/kvm/e500_tlb.c
 +++ b/arch/powerpc/kvm/e500_tlb.c
 @@ -309,7 +309,7 @@ static inline void 
 kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500,
   vcpu_e500-shadow_pages[tlbsel][esel] = new_page;
  
   /* Force TS=1 IPROT=0 TSIZE=4KB for all guest mappings. */
 - stlbe-mas1 = MAS1_TSIZE(BOOKE_PAGESZ_4K)
 + stlbe-mas1 = MAS1_TSIZE(BOOK3E_PAGESZ_4K)
   | MAS1_TID(get_tlb_tid(gtlbe)) | MAS1_TS | MAS1_VALID;
   stlbe-mas2 = (gvaddr  MAS2_EPN)
   | e500_shadow_mas2_attrib(gtlbe-mas2,
 @@ -545,7 +545,7 @@ int kvmppc_e500_emul_tlbwe(struct kvm_vcpu *vcpu)
   case 0:
   /* TLB0 */
   gtlbe-mas1 = ~MAS1_TSIZE(~0);
 - gtlbe-mas1 |= MAS1_TSIZE(BOOKE_PAGESZ_4K);
 + gtlbe-mas1 |= MAS1_TSIZE(BOOK3E_PAGESZ_4K);
  
   stlbsel = 0;
   sesel = 
 kvmppc_e500_stlbe_map(vcpu_e500, 0, esel);
 @@ -679,14 +679,14 @@ void kvmppc_e500_tlb_setup(struct 
 kvmppc_vcpu_e500 *vcpu_e500)
  
   /* Insert large initial mapping for guest. */
   tlbe = vcpu_e500-guest_tlb[1][0];
 - tlbe-mas1 = MAS1_VALID | MAS1_TSIZE(BOOKE_PAGESZ_256M);
 + tlbe-mas1 = MAS1_VALID | MAS1_TSIZE(BOOK3E_PAGESZ_256M);
   tlbe-mas2 = 0;
   tlbe-mas3 = E500_TLB_SUPER_PERM_MASK;
   tlbe-mas7 = 0;
  
   /* 4K map for serial output. Used by kernel wrapper. */
   tlbe = vcpu_e500-guest_tlb[1][1];
 - tlbe-mas1 = MAS1_VALID | MAS1_TSIZE(BOOKE_PAGESZ_4K);
 + tlbe-mas1 = MAS1_VALID | MAS1_TSIZE(BOOK3E_PAGESZ_4K);
   tlbe-mas2 = (0xe0004500  0xF000) | MAS2_I | MAS2_G;
   tlbe-mas3 = (0xe0004500  0xF000) | 
 E500_TLB_SUPER_PERM_MASK;
   tlbe-mas7 = 0;
 diff --git a/arch/powerpc/kvm/e500_tlb.h b/arch/powerpc/kvm/e500_tlb.h
 index 45b064b..abb1bf8 100644
 --- a/arch/powerpc/kvm/e500_tlb.h
 +++ b/arch/powerpc/kvm/e500_tlb.h
 @@ -16,7 +16,7 @@
  #define __KVM_E500_TLB_H__
  
  #include linux/kvm_host.h
 -#include asm/mmu-fsl-booke.h
 +#include asm/mmu-book3e.h
  #include asm/tlb.h
  #include asm/kvm_e500.h
  
 -- 
 1.6.0.4
 
 
--
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


[PATCH 0/3] some fix for kvm/e500

2009-06-05 Thread Liu Yu
Avi,

This patchset fix the recent damages of e500.
Hope it's not late for them to go into 2.6.30.


--
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


[PATCH 3/3] kvm/e500: Add MMUCFG and PVR emulation

2009-06-05 Thread Liu Yu
Latest kernel start to use these two register.

Signed-off-by: Liu Yu yu@freescale.com
---
 arch/powerpc/kvm/e500_emulate.c |3 +++
 arch/powerpc/kvm/emulate.c  |2 ++
 2 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/kvm/e500_emulate.c b/arch/powerpc/kvm/e500_emulate.c
index 3f76041..be95b8d 100644
--- a/arch/powerpc/kvm/e500_emulate.c
+++ b/arch/powerpc/kvm/e500_emulate.c
@@ -180,6 +180,9 @@ int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int 
sprn, int rt)
case SPRN_MMUCSR0:
vcpu-arch.gpr[rt] = 0; break;
 
+   case SPRN_MMUCFG:
+   vcpu-arch.gpr[rt] = mfspr(SPRN_MMUCFG); break;
+
/* extra exceptions */
case SPRN_IVOR32:
vcpu-arch.gpr[rt] = vcpu-arch.ivor[BOOKE_IRQPRIO_SPE_UNAVAIL];
diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c
index f8b8248..28a8237 100644
--- a/arch/powerpc/kvm/emulate.c
+++ b/arch/powerpc/kvm/emulate.c
@@ -188,6 +188,8 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct 
kvm_vcpu *vcpu)
vcpu-arch.gpr[rt] = vcpu-arch.srr1; break;
case SPRN_PVR:
vcpu-arch.gpr[rt] = mfspr(SPRN_PVR); break;
+   case SPRN_PIR:
+   vcpu-arch.gpr[rt] = mfspr(SPRN_PIR); break;
 
/* Note: mftb and TBRL/TBWL are user-accessible, so
 * the guest can always access the real TB anyways.
-- 
1.5.4

--
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] powerpc/kvm: is MAS6_SAS a mask or boolean?

2009-05-18 Thread Liu Yu-B13201
 

 -Original Message-
 From: Hollis Blanchard [mailto:holl...@us.ibm.com] 
 Sent: Saturday, May 16, 2009 2:59 AM
 To: Roel Kluin
 Cc: kvm-ppc@vger.kernel.org; Andrew Morton; Liu Yu-B13201
 Subject: Re: [PATCH] powerpc/kvm: is MAS6_SAS a mask or boolean?
 
 On Fri, 2009-05-15 at 20:48 +0200, Roel Kluin wrote:
  MAS6_SAS is not a boolean.
  
  Signed-off-by: Roel Kluin roel.kl...@gmail.com
  ---
  MAS6_SAS is defined at arch/powerpc/include/asm/mmu-book3e.h:89:
  #define MAS6_SAS0x0001
  
  This looks like it's a mask rather than a boolean.
  
  Is my patch below correct? please review.
  
  diff --git a/arch/powerpc/kvm/e500_tlb.c 
 b/arch/powerpc/kvm/e500_tlb.c
  index 0e773fc..5b0b198 100644
  --- a/arch/powerpc/kvm/e500_tlb.c
  +++ b/arch/powerpc/kvm/e500_tlb.c
  @@ -498,7 +498,7 @@ int kvmppc_e500_emul_tlbsx(struct 
 kvm_vcpu *vcpu, int rb)
  vcpu_e500-mas0 = MAS0_TLBSEL(tlbsel) | 
 MAS0_ESEL(victim)
  | MAS0_NV(vcpu_e500-guest_tlb_nv[tlbsel]);
  vcpu_e500-mas1 = (vcpu_e500-mas6  MAS6_SPID0)
  -   | (vcpu_e500-mas6  (MAS6_SAS ? MAS1_TS : 0))
  +   | (vcpu_e500-mas6  MAS6_SAS ? MAS1_TS : 0)
  | (vcpu_e500-mas4  MAS4_TSIZED(~0));
  vcpu_e500-mas2 = MAS2_EPN;
  vcpu_e500-mas2 |= vcpu_e500-mas4  MAS2_ATTRIB_MASK;
 
 This patch looks correct to me. I'll let Liu Yu (CCed) approve it
 though; it's his code and he has other outstanding patches in 
 this area.
 

Yes. It's correct.
Looks like this won't conflict with my current work.
Thanks.

Acked-by: Liu Yu yu@freescale.com

--
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


[PATCH 2/5] kvm/e500: Add shadow ID mapping support

2009-05-15 Thread Liu Yu
Based on Hollis's idea,
this patch map (vcpu, as, pid) to individual shadow id.

Every vcpu has a mapping table,
which keep the mapping from guest (as, id) to shadow id.

Every hardware core has a shadow id reference table,
which keep the mapping from shadow id to (vcpu, as, pid).

When mapping is created, both vcpu and core need to update their tables.
But they can destroy the mapping one-sided.

When shadow id get exhausted,
a flush is needed for shadow id reference table.

Signed-off-by: Liu Yu yu@freescale.com
---
 arch/powerpc/include/asm/kvm_e500.h |3 +
 arch/powerpc/kvm/e500_tlb.c |   96 +++
 arch/powerpc/kvm/e500_tlb.h |4 +-
 3 files changed, 102 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_e500.h 
b/arch/powerpc/include/asm/kvm_e500.h
index b248f31..bc73abe 100644
--- a/arch/powerpc/include/asm/kvm_e500.h
+++ b/arch/powerpc/include/asm/kvm_e500.h
@@ -42,6 +42,9 @@ struct kvmppc_vcpu_e500 {
/* Pages which are referenced in the shadow TLB. */
struct kvmppc_e500_shadow_ref *shadow_refs[E500_TLB_NUM];
 
+   /* MMU id mapping */
+   void *id_mapping;
+
unsigned int guest_tlb_size[E500_TLB_NUM];
unsigned int shadow_tlb_size[E500_TLB_NUM];
unsigned int guest_tlb_nv[E500_TLB_NUM];
diff --git a/arch/powerpc/kvm/e500_tlb.c b/arch/powerpc/kvm/e500_tlb.c
index 4952dba..e5c9211 100644
--- a/arch/powerpc/kvm/e500_tlb.c
+++ b/arch/powerpc/kvm/e500_tlb.c
@@ -27,6 +27,96 @@
 
 static unsigned int tlb1_entry_num;
 
+struct id_mapping {
+   unsigned char id[2][256];
+};
+
+struct shadow_id_ref {
+   void *entry[256];
+};
+
+static DEFINE_PER_CPU(struct shadow_id_ref, host_sid);
+
+static inline int e500_id_create_mapping(unsigned char *entry)
+{
+   unsigned long sid;
+   int ret = -1;
+
+   preempt_disable();
+   sid = (unsigned long)++(__get_cpu_var(host_sid).entry[0]);
+   if (sid  256) {
+   *entry = (unsigned char)sid;
+   __get_cpu_var(host_sid).entry[sid] = entry;
+   ret = sid;
+   }
+   preempt_enable();
+
+   return ret;
+}
+
+static inline void e500_id_destroy_all(void)
+{
+   preempt_disable();
+   memset(__get_cpu_var(host_sid), 0, sizeof(__get_cpu_var(host_sid)));
+   preempt_enable();
+}
+
+static inline int e500_id_find_mapping(unsigned char *entry)
+{
+   if (*entry  __get_cpu_var(host_sid).entry[*entry] == entry)
+   return *entry;
+   return -1;
+}
+
+static void *kvmppc_e500_alloc_idm(void)
+{
+   return kzalloc(sizeof(struct id_mapping), GFP_KERNEL);
+}
+
+static void kvmppc_e500_free_idm(void *idm)
+{
+   kfree(idm);
+   return;
+}
+
+static inline void kvmppc_e500_reset_idm(void *idm)
+{
+   memset(idm, 0, sizeof(struct id_mapping));
+}
+
+static void inline kvmppc_e500_update_spid(struct kvmppc_vcpu_e500 *vcpu_e500)
+{
+   unsigned int as = !!(vcpu_e500-vcpu.arch.msr  (MSR_IS | MSR_DS));
+
+   vcpu_e500-vcpu.arch.shadow_pid = kvmppc_e500_get_sid(vcpu_e500, as,
+   get_cur_pid(vcpu_e500-vcpu));
+   vcpu_e500-vcpu.arch.swap_pid = kvmppc_e500_get_sid(vcpu_e500, as, 0);
+}
+
+/*
+ * Map guest (vcpu,as,id) to individual shadow id.
+ */
+unsigned int kvmppc_e500_get_sid(struct kvmppc_vcpu_e500 *vcpu_e500,
+ int as, int gid)
+{
+   struct id_mapping *idm = vcpu_e500-id_mapping;
+   int sid;
+
+   sid = e500_id_find_mapping(idm-id[as][gid]);
+
+   while (sid = 0) {
+   /* None mapping yet */
+   sid = e500_id_create_mapping(idm-id[as][gid]);
+   if(sid = 0) {
+   BUG_ON(sid == 0);
+   e500_id_destroy_all();
+   kvmppc_e500_update_spid(vcpu_e500);
+   }
+   }
+
+   return sid;
+}
+
 void kvmppc_dump_tlbs(struct kvm_vcpu *vcpu)
 {
struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
@@ -653,8 +743,13 @@ int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 
*vcpu_e500)
if (vcpu_e500-shadow_refs[1] == NULL)
goto err_out_ref0;
 
+   if((vcpu_e500-id_mapping = kvmppc_e500_alloc_idm()) == NULL)
+   goto err_out_ref1;
+
return 0;
 
+err_out_ref1:
+   kfree(vcpu_e500-shadow_refs[1]);
 err_out_ref0:
kfree(vcpu_e500-shadow_refs[0]);
 err_out_guest1:
@@ -667,6 +762,7 @@ err_out:
 
 void kvmppc_e500_tlb_uninit(struct kvmppc_vcpu_e500 *vcpu_e500)
 {
+   kvmppc_e500_free_idm(vcpu_e500-id_mapping);
kfree(vcpu_e500-shadow_refs[1]);
kfree(vcpu_e500-shadow_refs[0]);
kfree(vcpu_e500-guest_tlb[1]);
diff --git a/arch/powerpc/kvm/e500_tlb.h b/arch/powerpc/kvm/e500_tlb.h
index 45b064b..eb36514 100644
--- a/arch/powerpc/kvm/e500_tlb.h
+++ b/arch/powerpc/kvm/e500_tlb.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 Freescale Semiconductor, Inc. All rights reserved.
+ * Copyright (C) 2008

[PATCH 1/5] kvm/e500: Discard shadow TLB

2009-05-15 Thread Liu Yu
There are several reasons to discard shadow TLB.

1. After implement shadow ID support for E500,
keep shadow TLB may incur potential coherence problem.
(if shadow ID mappings change, shadow TLB cannot be updated intime)

2. We use shadow TLB restore hardware TLB in vcpu_load().
However, since after implement shadow ID there is no tlbia() in vcpu_put(),
it's no need to restore hardware TLB any more.

3. Discard shadow TLB saves a lot memory.

Signed-off-by: Liu Yu yu@freescale.com
---
 arch/powerpc/include/asm/kvm_e500.h |9 +-
 arch/powerpc/kvm/e500_tlb.c |  275 ---
 2 files changed, 103 insertions(+), 181 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_e500.h 
b/arch/powerpc/include/asm/kvm_e500.h
index 9d497ce..b248f31 100644
--- a/arch/powerpc/include/asm/kvm_e500.h
+++ b/arch/powerpc/include/asm/kvm_e500.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 Freescale Semiconductor, Inc. All rights reserved.
+ * Copyright (C) 2008 - 2009 Freescale Semiconductor, Inc. All rights reserved.
  *
  * Author: Yu Liu, yu@freescale.com
  *
@@ -29,13 +29,18 @@ struct tlbe{
u32 mas7;
 };
 
+struct kvmppc_e500_shadow_ref {
+   struct page *page;
+   struct tlbe *gtlbe;
+};
+
 struct kvmppc_vcpu_e500 {
/* Unmodified copy of the guest's TLB. */
struct tlbe *guest_tlb[E500_TLB_NUM];
/* TLB that's actually used when the guest is running. */
struct tlbe *shadow_tlb[E500_TLB_NUM];
/* Pages which are referenced in the shadow TLB. */
-   struct page **shadow_pages[E500_TLB_NUM];
+   struct kvmppc_e500_shadow_ref *shadow_refs[E500_TLB_NUM];
 
unsigned int guest_tlb_size[E500_TLB_NUM];
unsigned int shadow_tlb_size[E500_TLB_NUM];
diff --git a/arch/powerpc/kvm/e500_tlb.c b/arch/powerpc/kvm/e500_tlb.c
index 0e773fc..4952dba 100644
--- a/arch/powerpc/kvm/e500_tlb.c
+++ b/arch/powerpc/kvm/e500_tlb.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 Freescale Semiconductor, Inc. All rights reserved.
+ * Copyright (C) 2008 - 2009 Freescale Semiconductor, Inc. All rights reserved.
  *
  * Author: Yu Liu, yu@freescale.com
  *
@@ -46,17 +46,6 @@ void kvmppc_dump_tlbs(struct kvm_vcpu *vcpu)
tlbe-mas3, tlbe-mas7);
}
}
-
-   for (tlbsel = 0; tlbsel  2; tlbsel++) {
-   printk(Shadow TLB%d:\n, tlbsel);
-   for (i = 0; i  vcpu_e500-shadow_tlb_size[tlbsel]; i++) {
-   tlbe = vcpu_e500-shadow_tlb[tlbsel][i];
-   if (tlbe-mas1  MAS1_VALID)
-   printk( S[%d][%3d] |  %08X | %08X | %08X | 
%08X |\n,
-   tlbsel, i, tlbe-mas1, tlbe-mas2,
-   tlbe-mas3, tlbe-mas7);
-   }
-   }
 }
 
 static inline unsigned int tlb0_get_next_victim(
@@ -119,10 +108,8 @@ static inline void __write_host_tlbe(struct tlbe *stlbe)
 }
 
 static inline void write_host_tlbe(struct kvmppc_vcpu_e500 *vcpu_e500,
-   int tlbsel, int esel)
+   int tlbsel, int esel, struct tlbe *stlbe)
 {
-   struct tlbe *stlbe = vcpu_e500-shadow_tlb[tlbsel][esel];
-
local_irq_disable();
if (tlbsel == 0) {
__write_host_tlbe(stlbe);
@@ -137,28 +124,13 @@ static inline void write_host_tlbe(struct 
kvmppc_vcpu_e500 *vcpu_e500,
mtspr(SPRN_MAS0, mas0);
}
local_irq_enable();
+   KVMTRACE_5D(STLB_WRITE, vcpu_e500-vcpu, index_of(tlbsel, esel),
+   stlbe-mas1, stlbe-mas2, stlbe-mas3, stlbe-mas7,
+   handler);
 }
 
 void kvmppc_e500_tlb_load(struct kvm_vcpu *vcpu, int cpu)
 {
-   struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
-   int i;
-   unsigned register mas0;
-
-   /* Load all valid TLB1 entries to reduce guest tlb miss fault */
-   local_irq_disable();
-   mas0 = mfspr(SPRN_MAS0);
-   for (i = 0; i  tlb1_max_shadow_size(); i++) {
-   struct tlbe *stlbe = vcpu_e500-shadow_tlb[1][i];
-
-   if (get_tlb_v(stlbe)) {
-   mtspr(SPRN_MAS0, MAS0_TLBSEL(1)
-   | MAS0_ESEL(to_htlb1_esel(i)));
-   __write_host_tlbe(stlbe);
-   }
-   }
-   mtspr(SPRN_MAS0, mas0);
-   local_irq_enable();
 }
 
 void kvmppc_e500_tlb_put(struct kvm_vcpu *vcpu)
@@ -200,16 +172,19 @@ static int kvmppc_e500_tlb_index(struct kvmppc_vcpu_e500 
*vcpu_e500,
 }
 
 static void kvmppc_e500_shadow_release(struct kvmppc_vcpu_e500 *vcpu_e500,
-   int tlbsel, int esel)
+   int stlbsel, int sesel)
 {
-   struct tlbe *stlbe = vcpu_e500-shadow_tlb[tlbsel][esel];
-   struct page *page = vcpu_e500-shadow_pages[tlbsel][esel];
+   struct kvmppc_e500_shadow_ref *ref;
+   struct page *page;
+
+   ref = vcpu_e500-shadow_refs[stlbsel][sesel];
+   page

[PATCH 4/5] kvm/e500: minmize the TLB flush

2009-05-15 Thread Liu Yu
Only flush TLB when a reset to the shadow mappings is needed.

For guest tlbia, we can reset vcpu's mappings instead of a real flush.
And because different vcpu maps to different IDs,
no flush is needed at vcpu_put() and mmu_destroy().

Signed-off-by: Liu Yu yu@freescale.com
---
 arch/powerpc/kvm/e500_tlb.c |   14 +++---
 1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/kvm/e500_tlb.c b/arch/powerpc/kvm/e500_tlb.c
index d090d97..570185c 100644
--- a/arch/powerpc/kvm/e500_tlb.c
+++ b/arch/powerpc/kvm/e500_tlb.c
@@ -109,6 +109,7 @@ unsigned int kvmppc_e500_get_sid(struct kvmppc_vcpu_e500 
*vcpu_e500,
sid = e500_id_create_mapping(idm-id[as][gid]);
if(sid = 0) {
BUG_ON(sid == 0);
+   _tlbil_all();
e500_id_destroy_all();
kvmppc_e500_update_spid(vcpu_e500);
}
@@ -229,7 +230,6 @@ void kvmppc_e500_tlb_load(struct kvm_vcpu *vcpu, int cpu)
 
 void kvmppc_e500_tlb_put(struct kvm_vcpu *vcpu)
 {
-   _tlbil_all();
 }
 
 /* Search the guest TLB for a matching entry. */
@@ -412,7 +412,6 @@ void kvmppc_mmu_priv_switch(struct kvm_vcpu *vcpu, int 
usermode)
struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
 
if (usermode) {
-   _tlbil_all();
/* clear PID for guest kernel mapping */
vcpu-arch.swap_pid = 0;
} else {
@@ -458,7 +457,9 @@ int kvmppc_e500_emul_mt_mmucsr0(struct kvmppc_vcpu_e500 
*vcpu_e500, ulong value)
for (esel = 0; esel  vcpu_e500-guest_tlb_size[1]; esel++)
kvmppc_e500_gtlbe_invalidate(vcpu_e500, 1, esel);
 
-   _tlbil_all();
+   /* Reset vcpu shadow id mapping */
+   kvmppc_e500_reset_idm(vcpu_e500-id_mapping);
+   kvmppc_e500_update_spid(vcpu_e500);
 
return EMULATE_DONE;
 }
@@ -489,7 +490,9 @@ int kvmppc_e500_emul_tlbivax(struct kvm_vcpu *vcpu, int ra, 
int rb)
kvmppc_e500_gtlbe_invalidate(vcpu_e500, tlbsel, esel);
}
 
-   _tlbil_all();
+   /* Reset vcpu shadow id mapping */
+   kvmppc_e500_reset_idm(vcpu_e500-id_mapping);
+   kvmppc_e500_update_spid(vcpu_e500);
 
return EMULATE_DONE;
 }
@@ -668,9 +671,6 @@ void kvmppc_mmu_destroy(struct kvm_vcpu *vcpu)
for (stlbsel = 0; stlbsel  2; stlbsel++)
for (i = 0; i  vcpu_e500-guest_tlb_size[stlbsel]; i++)
kvmppc_e500_shadow_release(vcpu_e500, stlbsel, i);
-
-   /* discard all guest mapping */
-   _tlbil_all();
 }
 
 void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 eaddr, gpa_t gpaddr,
-- 
1.5.4

--
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


[PATCH 5/5] kvm/e500: Add tlb0 entry invalidate

2009-05-15 Thread Liu Yu
Invalidate TLB0 hardware entry when
the related guest TLB entry is invalidated.

It's a bug we didn't do this before.

It didn't make problem is because that
we flushed TLB every time when we enterred to guest's userspace.

Signed-off-by: Liu Yu yu@freescale.com
---
 arch/powerpc/kvm/e500_tlb.c |   32 ++--
 1 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kvm/e500_tlb.c b/arch/powerpc/kvm/e500_tlb.c
index 570185c..ce4a379 100644
--- a/arch/powerpc/kvm/e500_tlb.c
+++ b/arch/powerpc/kvm/e500_tlb.c
@@ -286,6 +286,30 @@ static void kvmppc_e500_shadow_release(struct 
kvmppc_vcpu_e500 *vcpu_e500,
}
 }
 
+static void kvmppc_e500_tlb0_invalidate(struct kvmppc_vcpu_e500 *vcpu_e500,
+   int esel)
+{
+   struct tlbe *gtlbe = vcpu_e500-guest_tlb[0][esel];
+   u32 eaddr, pid, val;
+
+   eaddr = get_tlb_eaddr(gtlbe);
+   pid = kvmppc_e500_get_sid(vcpu_e500, get_tlb_ts(gtlbe),
+   get_tlb_tid(gtlbe));
+   val = (pid  16) | MAS6_SAS;
+
+   local_irq_disable();
+
+   mtspr(SPRN_MAS6, val);
+   asm volatile ( tlbsx 0, %[eaddr]\n : : [eaddr] a(eaddr));
+   val = mfspr(SPRN_MAS1);
+   if (val  MAS1_VALID) {
+   mtspr(SPRN_MAS1, val  ~MAS1_VALID);
+   asm volatile (tlbwe\n : : );
+   }
+
+   local_irq_enable();
+}
+
 static void kvmppc_e500_tlb1_invalidate(struct kvmppc_vcpu_e500 *vcpu_e500,
int esel)
 {
@@ -575,8 +599,12 @@ int kvmppc_e500_emul_tlbwe(struct kvm_vcpu *vcpu)
 
gtlbe = vcpu_e500-guest_tlb[tlbsel][esel];
 
-   if (get_tlb_v(gtlbe)  tlbsel == 1)
-   kvmppc_e500_tlb1_invalidate(vcpu_e500, esel);
+   if (get_tlb_v(gtlbe)) {
+   if (tlbsel == 0)
+   kvmppc_e500_tlb0_invalidate(vcpu_e500, esel);
+   else
+   kvmppc_e500_tlb1_invalidate(vcpu_e500, esel);
+   }
 
gtlbe-mas1 = vcpu_e500-mas1;
gtlbe-mas2 = vcpu_e500-mas2;
-- 
1.5.4

--
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


e500 shadow_ref

2009-04-28 Thread Liu Yu-B13201

Hi guys,

As you know kvmppc uses shadow_ref to record connections between gtlbes and 
pages.
44x implement it as kvmppc_44x_shadow_ref, and e500 implement it as 
kvmppc_e500_shadow_ref in recent patches.

The problem for e500 now is that, the shadow_ref for TLB0 doesn't reflect the 
hardware situation
but has one-one mappings to guest TLB0 entries.
This doesn't sounds logic, and make me hard to try new things, such as redirect 
guest TLB1 to host TLB0, large guest TLB,
44x is fine for kvmppc_44x_shadow_ref reflects the hardware.

So I'm thinking about seperating kvmppc_e500_shadow_ref from guest TLB0 and 
connect it with hardware.

Then I notice both 44x and e500 implement shadow_ref as per-vcpu data.
Can shadow_ref be per-core data?
This looks like could save some memory.

I don't want to do the wrong thing at the first step, so any suggestion?

Best Regards.
 
Yu
N�r��yb�X��ǧv�^�)޺{.n�+jir)w*jg����ݢj/���z�ޖ��2�ޙ�)ߡ�a�����G���h��j:+v���w��٥

RE: [PATCH 1/3] kvm/e500: Do not keep shadow tlb array

2009-04-28 Thread Liu Yu-B13201


 -Original Message-
 From: Hollis Blanchard [mailto:holl...@us.ibm.com] 
 Sent: Wednesday, April 29, 2009 3:34 AM
 To: Liu Yu-B13201
 Cc: kvm-ppc@vger.kernel.org; rkulk...@force10networks.com
 Subject: Re: [PATCH 1/3] kvm/e500: Do not keep shadow tlb array
 
 On Mon, 2009-04-27 at 14:58 +0800, Liu Yu wrote:
  Shadow tlb array costs a lot memory
  and incurs potential coherence problem.
  
  Remove it and we now translate to shadow mappings directly
  from guest TLB entries.
  
  Signed-off-by: Liu Yu yu@freescale.com
 
 Well, funny story... pretty much as soon as we removed the 
 shadow TLB on
 440, we put it back. But we use it differently now. Our experience on
 440 was that it was a performance win to *also* keep a shadow 
 TLB array,
 but use that *only* in the vcpu_put/vcpu_load() path instead 
 of tlbia().
 In other words, instead of just clearing all that guest TLB state you
 worked so hard to build up, preserve it across host context switches.
 
 We don't use that array for anything other than host context switches.
 For normal exits (handled in kernel or handled in qemu) we take a less
 precise shadowy approach, where host and guest TLB entries 
 can compete
 without KVM's knowledge, and we indiscriminately invalidate them.
 
 (Yes, http://www.linux-kvm.org/page/PowerPC_Book_E_MMU is no longer
 completely accurate.)
 
 I'm not sure what the coherence problems are that you allude 
 to, but we
 never did SMP host support for 440.

It's not a SMP coherence problem.
But that after we apply shadow id trick, the shadow tlb entry may be
expired due to the change of id mapping.
As we always update PID0, PID1 to the latest shadow id, write expired
shadow entry back is useless and may incur other problem.

Moreover after applying shadow id trick, there is no tlbia() in the
vcpu_load()/vcpu_put().
So I think it doesn't affect the performance of e500.


--
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


[PATCH 1/3] kvm/e500: Do not keep shadow tlb array

2009-04-27 Thread Liu Yu
Shadow tlb array costs a lot memory
and incurs potential coherence problem.

Remove it and we now translate to shadow mappings directly
from guest TLB entries.

Signed-off-by: Liu Yu yu@freescale.com
---
 arch/powerpc/include/asm/kvm_e500.h |8 +-
 arch/powerpc/kvm/e500_tlb.c |  277 +--
 2 files changed, 106 insertions(+), 179 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_e500.h 
b/arch/powerpc/include/asm/kvm_e500.h
index 9d497ce..ffa111b 100644
--- a/arch/powerpc/include/asm/kvm_e500.h
+++ b/arch/powerpc/include/asm/kvm_e500.h
@@ -29,13 +29,19 @@ struct tlbe{
u32 mas7;
 };
 
+struct kvmppc_e500_shadow_ref {
+   struct page *page;
+   u16 gtlb_index;
+   u16 pad;
+};
+
 struct kvmppc_vcpu_e500 {
/* Unmodified copy of the guest's TLB. */
struct tlbe *guest_tlb[E500_TLB_NUM];
/* TLB that's actually used when the guest is running. */
struct tlbe *shadow_tlb[E500_TLB_NUM];
/* Pages which are referenced in the shadow TLB. */
-   struct page **shadow_pages[E500_TLB_NUM];
+   struct kvmppc_e500_shadow_ref *shadow_refs[E500_TLB_NUM];
 
unsigned int guest_tlb_size[E500_TLB_NUM];
unsigned int shadow_tlb_size[E500_TLB_NUM];
diff --git a/arch/powerpc/kvm/e500_tlb.c b/arch/powerpc/kvm/e500_tlb.c
index 0e773fc..847dfec 100644
--- a/arch/powerpc/kvm/e500_tlb.c
+++ b/arch/powerpc/kvm/e500_tlb.c
@@ -46,17 +46,6 @@ void kvmppc_dump_tlbs(struct kvm_vcpu *vcpu)
tlbe-mas3, tlbe-mas7);
}
}
-
-   for (tlbsel = 0; tlbsel  2; tlbsel++) {
-   printk(Shadow TLB%d:\n, tlbsel);
-   for (i = 0; i  vcpu_e500-shadow_tlb_size[tlbsel]; i++) {
-   tlbe = vcpu_e500-shadow_tlb[tlbsel][i];
-   if (tlbe-mas1  MAS1_VALID)
-   printk( S[%d][%3d] |  %08X | %08X | %08X | 
%08X |\n,
-   tlbsel, i, tlbe-mas1, tlbe-mas2,
-   tlbe-mas3, tlbe-mas7);
-   }
-   }
 }
 
 static inline unsigned int tlb0_get_next_victim(
@@ -119,10 +108,8 @@ static inline void __write_host_tlbe(struct tlbe *stlbe)
 }
 
 static inline void write_host_tlbe(struct kvmppc_vcpu_e500 *vcpu_e500,
-   int tlbsel, int esel)
+   int tlbsel, int esel, struct tlbe *stlbe)
 {
-   struct tlbe *stlbe = vcpu_e500-shadow_tlb[tlbsel][esel];
-
local_irq_disable();
if (tlbsel == 0) {
__write_host_tlbe(stlbe);
@@ -137,28 +124,13 @@ static inline void write_host_tlbe(struct 
kvmppc_vcpu_e500 *vcpu_e500,
mtspr(SPRN_MAS0, mas0);
}
local_irq_enable();
+   KVMTRACE_5D(STLB_WRITE, vcpu_e500-vcpu, index_of(tlbsel, esel),
+   stlbe-mas1, stlbe-mas2, stlbe-mas3, stlbe-mas7,
+   handler);
 }
 
 void kvmppc_e500_tlb_load(struct kvm_vcpu *vcpu, int cpu)
 {
-   struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
-   int i;
-   unsigned register mas0;
-
-   /* Load all valid TLB1 entries to reduce guest tlb miss fault */
-   local_irq_disable();
-   mas0 = mfspr(SPRN_MAS0);
-   for (i = 0; i  tlb1_max_shadow_size(); i++) {
-   struct tlbe *stlbe = vcpu_e500-shadow_tlb[1][i];
-
-   if (get_tlb_v(stlbe)) {
-   mtspr(SPRN_MAS0, MAS0_TLBSEL(1)
-   | MAS0_ESEL(to_htlb1_esel(i)));
-   __write_host_tlbe(stlbe);
-   }
-   }
-   mtspr(SPRN_MAS0, mas0);
-   local_irq_enable();
 }
 
 void kvmppc_e500_tlb_put(struct kvm_vcpu *vcpu)
@@ -200,16 +172,24 @@ static int kvmppc_e500_tlb_index(struct kvmppc_vcpu_e500 
*vcpu_e500,
 }
 
 static void kvmppc_e500_shadow_release(struct kvmppc_vcpu_e500 *vcpu_e500,
-   int tlbsel, int esel)
+   int stlbsel, int sesel)
 {
-   struct tlbe *stlbe = vcpu_e500-shadow_tlb[tlbsel][esel];
-   struct page *page = vcpu_e500-shadow_pages[tlbsel][esel];
+   struct tlbe *gtlbe;
+   struct kvmppc_e500_shadow_ref *ref;
+   struct page *page;
+   int index;
+
+   ref = vcpu_e500-shadow_refs[stlbsel][sesel];
+   page = ref-page;
 
if (page) {
-   vcpu_e500-shadow_pages[tlbsel][esel] = NULL;
+   index = ref-gtlb_index;
+   gtlbe = vcpu_e500-guest_tlb[tlbsel_of(index)][esel_of(index)];
 
-   if (get_tlb_v(stlbe)) {
-   if (tlbe_is_writable(stlbe))
+   ref-page = NULL;
+
+   if (get_tlb_v(gtlbe)) {
+   if (tlbe_is_writable(gtlbe))
kvm_release_page_dirty(page);
else
kvm_release_page_clean(page);
@@ -217,44 +197,19 @@ static void kvmppc_e500_shadow_release(struct 
kvmppc_vcpu_e500

[PATCH 2/3] kvm/e500: Map (vcpu,as,id) to core's shadow id.

2009-04-27 Thread Liu Yu
The shadow id mappings is based on Hollis's idea.

We can benifit a lot from this trick:

1. Support AS=1 in guest.
So that OSes other than Linux can be expected to run in the guest.

2. Minimize the frequency of TLB flushes.

Signed-off-by: Liu Yu yu@freescale.com
---
 arch/powerpc/include/asm/kvm_e500.h |3 +
 arch/powerpc/include/asm/kvm_ppc.h  |1 +
 arch/powerpc/kernel/asm-offsets.c   |1 +
 arch/powerpc/kvm/booke.h|4 +
 arch/powerpc/kvm/booke_interrupts.S |   11 +++
 arch/powerpc/kvm/e500_emulate.c |   10 ++-
 arch/powerpc/kvm/e500_tlb.c |  146 +--
 arch/powerpc/kvm/e500_tlb.h |2 +
 8 files changed, 167 insertions(+), 11 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_e500.h 
b/arch/powerpc/include/asm/kvm_e500.h
index ffa111b..e5ca811 100644
--- a/arch/powerpc/include/asm/kvm_e500.h
+++ b/arch/powerpc/include/asm/kvm_e500.h
@@ -43,6 +43,9 @@ struct kvmppc_vcpu_e500 {
/* Pages which are referenced in the shadow TLB. */
struct kvmppc_e500_shadow_ref *shadow_refs[E500_TLB_NUM];
 
+   /* MMU id mapping */
+   void *id_mapping;
+
unsigned int guest_tlb_size[E500_TLB_NUM];
unsigned int shadow_tlb_size[E500_TLB_NUM];
unsigned int guest_tlb_nv[E500_TLB_NUM];
diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
b/arch/powerpc/include/asm/kvm_ppc.h
index 2c6ee34..40823c4 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -57,6 +57,7 @@ extern void kvmppc_emulate_dec(struct kvm_vcpu *vcpu);
 extern void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 gvaddr, gpa_t gpaddr,
unsigned int gtlb_idx);
 extern void kvmppc_mmu_priv_switch(struct kvm_vcpu *vcpu, int usermode);
+extern void kvmppc_mmu_as_switch(struct kvm_vcpu *vcpu, unsigned int as);
 extern void kvmppc_mmu_switch_pid(struct kvm_vcpu *vcpu, u32 pid);
 extern void kvmppc_mmu_destroy(struct kvm_vcpu *vcpu);
 extern int kvmppc_mmu_dtlb_index(struct kvm_vcpu *vcpu, gva_t eaddr);
diff --git a/arch/powerpc/kernel/asm-offsets.c 
b/arch/powerpc/kernel/asm-offsets.c
index 42fe4da..89d28df 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -379,6 +379,7 @@ int main(void)
DEFINE(VCPU_LAST_INST, offsetof(struct kvm_vcpu, arch.last_inst));
DEFINE(VCPU_FAULT_DEAR, offsetof(struct kvm_vcpu, arch.fault_dear));
DEFINE(VCPU_FAULT_ESR, offsetof(struct kvm_vcpu, arch.fault_esr));
+   DEFINE(VCPU_SWAP_PID, offsetof(struct kvm_vcpu, arch.swap_pid));
 #endif
 #ifdef CONFIG_44x
DEFINE(PGD_T_LOG2, PGD_T_LOG2);
diff --git a/arch/powerpc/kvm/booke.h b/arch/powerpc/kvm/booke.h
index d59bcca..96e6cc0 100644
--- a/arch/powerpc/kvm/booke.h
+++ b/arch/powerpc/kvm/booke.h
@@ -57,6 +57,10 @@ static inline void kvmppc_set_msr(struct kvm_vcpu *vcpu, u32 
new_msr)
if ((new_msr  MSR_PR) != (vcpu-arch.msr  MSR_PR))
kvmppc_mmu_priv_switch(vcpu, new_msr  MSR_PR);
 
+   if ((new_msr  (MSR_IS | MSR_DS)) !=
+   (vcpu-arch.msr  (MSR_IS | MSR_DS)))
+   kvmppc_mmu_as_switch(vcpu, new_msr  (MSR_IS | MSR_DS));
+
vcpu-arch.msr = new_msr;
 
if (vcpu-arch.msr  MSR_WE) {
diff --git a/arch/powerpc/kvm/booke_interrupts.S 
b/arch/powerpc/kvm/booke_interrupts.S
index d0c6f84..12383fe 100644
--- a/arch/powerpc/kvm/booke_interrupts.S
+++ b/arch/powerpc/kvm/booke_interrupts.S
@@ -192,6 +192,12 @@ _GLOBAL(kvmppc_resume_host)
lwz r3, VCPU_HOST_PID(r4)
mtspr   SPRN_PID, r3
 
+#ifdef CONFIG_E500
+   /* we cheat and know Linux doesn't use PID1 which is always 0 */
+   lis r3, 0
+   mtspr   SPRN_PID1, r3
+#endif
+
/* Restore host IVPR before re-enabling interrupts. We cheat and know
 * that Linux IVPR is always 0xc000. */
lis r3, 0xc000
@@ -350,6 +356,11 @@ lightweight_exit:
lwz r3, VCPU_SHADOW_PID(r4)
mtspr   SPRN_PID, r3
 
+#ifdef CONFIG_E500
+   lwz r3, VCPU_SWAP_PID(r4)
+   mtspr   SPRN_PID1, r3
+#endif
+
 #ifdef CONFIG_44x
iccci   0, 0 /* XXX hack */
 #endif
diff --git a/arch/powerpc/kvm/e500_emulate.c b/arch/powerpc/kvm/e500_emulate.c
index 3f76041..8d85655 100644
--- a/arch/powerpc/kvm/e500_emulate.c
+++ b/arch/powerpc/kvm/e500_emulate.c
@@ -76,10 +76,14 @@ int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int 
sprn, int rs)
int emulated = EMULATE_DONE;
 
switch (sprn) {
-   case SPRN_PID:
-   vcpu_e500-pid[0] = vcpu-arch.shadow_pid =
-   vcpu-arch.pid = vcpu-arch.gpr[rs];
+   case SPRN_PID: {
+   unsigned int as = !!(vcpu-arch.msr  (MSR_IS | MSR_DS));
+
+   vcpu_e500-pid[0] = vcpu-arch.pid = vcpu-arch.gpr[rs];
+   vcpu-arch.shadow_pid = kvmppc_e500_get_sid(vcpu_e500, as,
+   get_cur_pid(vcpu));
break

[PATCH 3/3] kvm/e500: Add tlb0 entry invalidate

2009-04-27 Thread Liu Yu
It's always needed to invalidate the tlb0 entry
which is overwritten by new one.

It was OK not to do this before is because that
we flushed TLB every time when we entered guest's userspace.

Signed-off-by: Liu Yu yu@freescale.com
---
 arch/powerpc/kvm/e500_tlb.c |   31 +--
 1 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kvm/e500_tlb.c b/arch/powerpc/kvm/e500_tlb.c
index 7b614a9..2c0d58f 100644
--- a/arch/powerpc/kvm/e500_tlb.c
+++ b/arch/powerpc/kvm/e500_tlb.c
@@ -295,6 +295,30 @@ static void kvmppc_e500_shadow_release(struct 
kvmppc_vcpu_e500 *vcpu_e500,
}
 }
 
+static void kvmppc_e500_tlb0_invalidate(struct kvmppc_vcpu_e500 *vcpu_e500,
+   int esel)
+{
+   struct tlbe *gtlbe = vcpu_e500-guest_tlb[0][esel];
+   u32 eaddr, pid, val;
+
+   eaddr = get_tlb_eaddr(gtlbe);
+   pid = kvmppc_e500_get_sid(vcpu_e500, get_tlb_ts(gtlbe),
+   get_tlb_tid(gtlbe));
+   val = (pid  16) | MAS6_SAS;
+
+   local_irq_disable();
+   mtspr(SPRN_MAS6, val);
+   __asm__ __volatile__ (
+   tlbsx 0, %[eaddr]\n
+   : : [eaddr] a(eaddr));
+   val = mfspr(SPRN_MAS1);
+   if (val  MAS1_VALID) {
+   mtspr(SPRN_MAS1, val  ~MAS1_VALID);
+   __asm__ __volatile__ (tlbwe\n : : );
+   }
+   local_irq_enable();
+}
+
 static void kvmppc_e500_tlb1_invalidate(struct kvmppc_vcpu_e500 *vcpu_e500,
int esel)
 {
@@ -583,8 +607,11 @@ int kvmppc_e500_emul_tlbwe(struct kvm_vcpu *vcpu)
 
gtlbe = vcpu_e500-guest_tlb[tlbsel][esel];
 
-   if (get_tlb_v(gtlbe)  tlbsel == 1)
-   kvmppc_e500_tlb1_invalidate(vcpu_e500, esel);
+   if (get_tlb_v(gtlbe))
+   if (tlbsel == 0)
+   kvmppc_e500_tlb0_invalidate(vcpu_e500, esel);
+   else
+   kvmppc_e500_tlb1_invalidate(vcpu_e500, esel);
 
gtlbe-mas1 = vcpu_e500-mas1;
gtlbe-mas2 = vcpu_e500-mas2;
-- 
1.5.4

--
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


  1   2   >