public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v10 0/5] KVM: PPC: Add ePAPR idle hcall support
@ 2012-03-15 20:52 Stuart Yoder
  2012-03-15 20:52 ` [PATCH v10 1/5] KVM: PPC: Factor out guest epapr initialization Stuart Yoder
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Stuart Yoder @ 2012-03-15 20:52 UTC (permalink / raw)
  To: agraf, kvm-ppc, kvm

From: Stuart Yoder <stuart.yoder@freescale.com>

v10:
   -patchset is now 5 patches, using the epapr header 
    definitions is split out into a separate patch
   -patch titles and descriptions are also updated
   -cleanup as per review comments addressed

Liu Yu-B13201 (4):
  KVM: PPC: Factor out guest epapr initialization
  KVM: PPC: Add support for ePAPR idle hcall in host kernel
  KVM: PPC: ev_idle hcall support for e500 guests
  PPC: Don't use hardcoded opcode for ePAPR hcall invocation

Stuart Yoder (1):
  KVM: PPC: use definitions in epapr header for hcalls

 arch/powerpc/include/asm/Kbuild         |    1 +
 arch/powerpc/include/asm/epapr_hcalls.h |   35 ++++++++++--------
 arch/powerpc/include/asm/fsl_hcalls.h   |   36 +++++++++---------
 arch/powerpc/include/asm/kvm_para.h     |   19 +++++-----
 arch/powerpc/kernel/Makefile            |    1 +
 arch/powerpc/kernel/epapr_hcalls.S      |   53 +++++++++++++++++++++++++++
 arch/powerpc/kernel/epapr_paravirt.c    |   61 +++++++++++++++++++++++++++++++
 arch/powerpc/kernel/kvm.c               |   30 ++-------------
 arch/powerpc/kernel/kvm_emul.S          |   10 -----
 arch/powerpc/kvm/powerpc.c              |   30 +++++++++++----
 arch/powerpc/platforms/Kconfig          |   10 +++++
 drivers/tty/Kconfig                     |    1 +
 drivers/virt/Kconfig                    |    1 +
 include/linux/kvm.h                     |    2 +
 14 files changed, 202 insertions(+), 88 deletions(-)
 create mode 100644 arch/powerpc/kernel/epapr_hcalls.S
 create mode 100644 arch/powerpc/kernel/epapr_paravirt.c

-- 
1.7.3.4



^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v10 1/5] KVM: PPC: Factor out guest epapr initialization
  2012-03-15 20:52 [PATCH v10 0/5] KVM: PPC: Add ePAPR idle hcall support Stuart Yoder
@ 2012-03-15 20:52 ` Stuart Yoder
  2012-05-08 10:25   ` Alexander Graf
  2012-03-15 20:52 ` [PATCH v10 2/5] KVM: PPC: use definitions in epapr header for hcalls Stuart Yoder
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Stuart Yoder @ 2012-03-15 20:52 UTC (permalink / raw)
  To: agraf, kvm-ppc, kvm

From: Liu Yu-B13201 <Yu.Liu@freescale.com>

epapr paravirtualization support is now a Kconfig
selectable option

Signed-off-by: Liu Yu <yu.liu@freescale.com>
[stuart.yoder@freescale.com: misc minor fixes, description update]
Signed-off-by: Stuart Yoder <stuart.yoder@freescale.com>
---
-v10
   -update patch subject/description

 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    |   52 +++++++++++++++++++++++++++++++
 arch/powerpc/kernel/kvm.c               |   28 ++---------------
 arch/powerpc/kernel/kvm_emul.S          |   10 ------
 arch/powerpc/platforms/Kconfig          |    9 +++++
 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..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 0000000..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 0000000..028aeae
--- /dev/null
+++ b/arch/powerpc/kernel/epapr_paravirt.c
@@ -0,0 +1,52 @@
+/*
+ * 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 -ENODEV;
+
+	if (len % 4 || len > (4 * 4))
+		return -ENODEV;
+
+	for (i = 0; i < (len / 4); i++)
+		patch_instruction(epapr_hypercall_start + i, insts[i]);
+
+	epapr_paravirt_enabled = true;
+
+	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 kvm_hypercall(unsigned long *in,
 	unsigned long register r11 asm("r11") = nr;
 	unsigned long register r12 asm("r12");
 
-	asm volatile("bl	kvm_hypercall_start"
+	asm volatile("bl	epapr_hypercall_start"
 		     : "=r"(r0), "=r"(r3), "=r"(r4), "=r"(r5), "=r"(r6),
 		       "=r"(r7), "=r"(r8), "=r"(r9), "=r"(r10), "=r"(r11),
 		       "=r"(r12)
@@ -747,29 +748,6 @@ unsigned long kvm_hypercall(unsigned long *in,
 }
 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))
-		return -1;
-
-	for (i = 0; i < (len / 4); i++)
-		kvm_patch_ins(&(&kvm_hypercall_start)[i], insts[i]);
-
-	return 0;
-}
-
 static __init void kvm_free_tmp(void)
 {
 	unsigned long start, end;
@@ -791,7 +769,7 @@ static int __init kvm_guest_init(void)
 	if (!kvm_para_available())
 		goto free_tmp;
 
-	if (kvm_para_setup())
+	if (!epapr_paravirt_enabled)
 		goto free_tmp;
 
 	if (kvm_para_has_feature(KVM_FEATURE_MAGIC_PAGE))
diff --git a/arch/powerpc/kernel/kvm_emul.S b/arch/powerpc/kernel/kvm_emul.S
index e291cf3..62ceb2a 100644
--- a/arch/powerpc/kernel/kvm_emul.S
+++ b/arch/powerpc/kernel/kvm_emul.S
@@ -24,16 +24,6 @@
 #include <asm/page.h>
 #include <asm/asm-offsets.h>
 
-/* Hypercall entry point. Will be patched with device tree instructions. */
-
-.global kvm_hypercall_start
-kvm_hypercall_start:
-	li	r3, -1
-	nop
-	nop
-	nop
-	blr
-
 #define KVM_MAGIC_PAGE		(-4096)
 
 #ifdef CONFIG_64BIT
diff --git a/arch/powerpc/platforms/Kconfig b/arch/powerpc/platforms/Kconfig
index 0cfb46d..09348e7 100644
--- a/arch/powerpc/platforms/Kconfig
+++ b/arch/powerpc/platforms/Kconfig
@@ -26,6 +26,7 @@ source "arch/powerpc/platforms/wsp/Kconfig"
 config KVM_GUEST
 	bool "KVM Guest support"
 	default n
+	select EPAPR_PARAVIRT
 	---help---
 	  This option enables various optimizations for running under the KVM
 	  hypervisor. Overhead for the kernel when not running inside KVM should
@@ -33,6 +34,14 @@ config KVM_GUEST
 
 	  In case of doubt, say Y
 
+config EPAPR_PARAVIRT
+	bool "ePAPR para-virtualization support"
+	default n
+	help
+	  Enables ePAPR para-virtualization support for guests.
+
+	  In case of doubt, say Y
+
 config PPC_NATIVE
 	bool
 	depends on 6xx || PPC64
-- 
1.7.3.4



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v10 2/5] KVM: PPC: use definitions in epapr header for hcalls
  2012-03-15 20:52 [PATCH v10 0/5] KVM: PPC: Add ePAPR idle hcall support Stuart Yoder
  2012-03-15 20:52 ` [PATCH v10 1/5] KVM: PPC: Factor out guest epapr initialization Stuart Yoder
@ 2012-03-15 20:52 ` Stuart Yoder
  2012-05-08 10:29   ` Alexander Graf
  2012-03-15 20:52 ` [PATCH v10 3/5] KVM: PPC: Add support for ePAPR idle hcall in host kernel Stuart Yoder
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Stuart Yoder @ 2012-03-15 20:52 UTC (permalink / raw)
  To: agraf, kvm-ppc, kvm

From: Stuart Yoder <stuart.yoder@freescale.com>

Signed-off-by: Stuart Yoder <stuart.yoder@freescale.com>
---
 arch/powerpc/include/asm/kvm_para.h |   19 +++++++++----------
 arch/powerpc/kernel/kvm.c           |    2 +-
 arch/powerpc/kvm/powerpc.c          |   10 +++++-----
 3 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_para.h b/arch/powerpc/include/asm/kvm_para.h
index c18916b..7d4a870 100644
--- a/arch/powerpc/include/asm/kvm_para.h
+++ b/arch/powerpc/include/asm/kvm_para.h
@@ -75,9 +75,8 @@ struct kvm_vcpu_arch_shared {
 };
 
 #define KVM_SC_MAGIC_R0		0x4b564d21 /* "KVM!" */
-#define HC_VENDOR_KVM		(42 << 16)
-#define HC_EV_SUCCESS		0
-#define HC_EV_UNIMPLEMENTED	12
+
+#include <asm/epapr_hcalls.h>
 
 #define KVM_FEATURE_MAGIC_PAGE	1
 
@@ -121,7 +120,7 @@ static unsigned long kvm_hypercall(unsigned long *in,
 				   unsigned long *out,
 				   unsigned long nr)
 {
-	return HC_EV_UNIMPLEMENTED;
+	return EV_UNIMPLEMENTED;
 }
 
 #endif
@@ -132,7 +131,7 @@ static inline long kvm_hypercall0_1(unsigned int nr, unsigned long *r2)
 	unsigned long out[8];
 	unsigned long r;
 
-	r = kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+	r = kvm_hypercall(in, out, nr | EV_KVM_VENDOR_ID);
 	*r2 = out[0];
 
 	return r;
@@ -143,7 +142,7 @@ static inline long kvm_hypercall0(unsigned int nr)
 	unsigned long in[8];
 	unsigned long out[8];
 
-	return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+	return kvm_hypercall(in, out, nr | EV_KVM_VENDOR_ID);
 }
 
 static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
@@ -152,7 +151,7 @@ static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
 	unsigned long out[8];
 
 	in[0] = p1;
-	return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+	return kvm_hypercall(in, out, nr | EV_KVM_VENDOR_ID);
 }
 
 static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
@@ -163,7 +162,7 @@ static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
 
 	in[0] = p1;
 	in[1] = p2;
-	return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+	return kvm_hypercall(in, out, nr | EV_KVM_VENDOR_ID);
 }
 
 static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
@@ -175,7 +174,7 @@ static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
 	in[0] = p1;
 	in[1] = p2;
 	in[2] = p3;
-	return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+	return kvm_hypercall(in, out, nr | EV_KVM_VENDOR_ID);
 }
 
 static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
@@ -189,7 +188,7 @@ static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
 	in[1] = p2;
 	in[2] = p3;
 	in[3] = p4;
-	return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+	return kvm_hypercall(in, out, nr | EV_KVM_VENDOR_ID);
 }
 
 
diff --git a/arch/powerpc/kernel/kvm.c b/arch/powerpc/kernel/kvm.c
index 1c13307..b5ba561 100644
--- a/arch/powerpc/kernel/kvm.c
+++ b/arch/powerpc/kernel/kvm.c
@@ -419,7 +419,7 @@ static void kvm_map_magic_page(void *data)
 	in[0] = KVM_MAGIC_PAGE;
 	in[1] = KVM_MAGIC_PAGE;
 
-	kvm_hypercall(in, out, HC_VENDOR_KVM | KVM_HC_PPC_MAP_MAGIC_PAGE);
+	kvm_hypercall(in, out, _EV_HCALL_TOKEN(EV_KVM_VENDOR_ID, KVM_HC_PPC_MAP_MAGIC_PAGE));
 
 	*features = out[0];
 }
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 58ad860..d738626 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -67,18 +67,18 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
 	}
 
 	switch (nr) {
-	case HC_VENDOR_KVM | KVM_HC_PPC_MAP_MAGIC_PAGE:
+	case _EV_HCALL_TOKEN(EV_KVM_VENDOR_ID, KVM_HC_PPC_MAP_MAGIC_PAGE):
 	{
 		vcpu->arch.magic_page_pa = param1;
 		vcpu->arch.magic_page_ea = param2;
 
 		r2 = KVM_MAGIC_FEAT_SR | KVM_MAGIC_FEAT_MAS0_TO_SPRG7;
 
-		r = HC_EV_SUCCESS;
+		r = 0;  /* success */
 		break;
 	}
-	case HC_VENDOR_KVM | KVM_HC_FEATURES:
-		r = HC_EV_SUCCESS;
+	case _EV_HCALL_TOKEN(EV_KVM_VENDOR_ID, KVM_HC_FEATURES):
+		r = 0;  /* success */
 #if defined(CONFIG_PPC_BOOK3S) || defined(CONFIG_KVM_E500V2)
 		/* XXX Missing magic page on 44x */
 		r2 |= (1 << KVM_FEATURE_MAGIC_PAGE);
@@ -87,7 +87,7 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
 		/* Second return value is in r4 */
 		break;
 	default:
-		r = HC_EV_UNIMPLEMENTED;
+		r = EV_UNIMPLEMENTED;
 		break;
 	}
 
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v10 3/5] KVM: PPC: Add support for ePAPR idle hcall in host kernel
  2012-03-15 20:52 [PATCH v10 0/5] KVM: PPC: Add ePAPR idle hcall support Stuart Yoder
  2012-03-15 20:52 ` [PATCH v10 1/5] KVM: PPC: Factor out guest epapr initialization Stuart Yoder
  2012-03-15 20:52 ` [PATCH v10 2/5] KVM: PPC: use definitions in epapr header for hcalls Stuart Yoder
@ 2012-03-15 20:52 ` Stuart Yoder
  2012-05-08 10:40   ` Alexander Graf
  2012-03-15 20:52 ` [PATCH v10 4/5] KVM: PPC: ev_idle hcall support for e500 guests Stuart Yoder
  2012-03-15 20:52 ` [PATCH v10 5/5] PPC: Don't use hardcoded opcode for ePAPR hcall invocation Stuart Yoder
  4 siblings, 1 reply; 11+ messages in thread
From: Stuart Yoder @ 2012-03-15 20:52 UTC (permalink / raw)
  To: agraf, kvm-ppc, kvm

From: Liu Yu-B13201 <Yu.Liu@freescale.com>

And add a new flag definition in kvm_ppc_pvinfo to indicate
whether the host supports the EV_IDLE hcall.

Signed-off-by: Liu Yu <yu.liu@freescale.com>
[stuart.yoder@freescale.com: cleanup,fixes for conditions allowing idle]
Signed-off-by: Stuart Yoder <stuart.yoder@freescale.com>
---
-v10:
   -ePAPR definitions now addressed in separate patch
   -move clearing of KVM_REQ_UNHALT after kvm_vcpu_block() call 

 arch/powerpc/include/asm/Kbuild |    1 +
 arch/powerpc/kvm/powerpc.c      |   20 +++++++++++++++++---
 include/linux/kvm.h             |    2 ++
 3 files changed, 20 insertions(+), 3 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/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index d738626..7c4e5cc 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -38,8 +38,7 @@
 
 int kvm_arch_vcpu_runnable(struct kvm_vcpu *v)
 {
-	return !(v->arch.shared->msr & MSR_WE) ||
-	       !!(v->arch.pending_exceptions) ||
+	return !!(v->arch.pending_exceptions) ||
 	       v->requests;
 }
 
@@ -86,6 +85,11 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
 
 		/* Second return value is in r4 */
 		break;
+	case _EV_HCALL_TOKEN(EV_EPAPR_VENDOR_ID, EV_IDLE):
+		r = 0;  /* success */
+		kvm_vcpu_block(vcpu);
+		clear_bit(KVM_REQ_UNHALT, &vcpu->requests);
+		break;
 	default:
 		r = EV_UNIMPLEMENTED;
 		break;
@@ -732,9 +736,16 @@ int kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct vm_fault *vmf)
 
 static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo *pvinfo)
 {
+	u32 inst_nop = 0x60000000;
+#ifdef CONFIG_KVM_BOOKE_HV
+	u32 inst_sc1 = 0x44000022;
+	pvinfo->hcall[0] = inst_sc1;
+	pvinfo->hcall[1] = inst_nop;
+	pvinfo->hcall[2] = inst_nop;
+	pvinfo->hcall[3] = inst_nop;
+#else
 	u32 inst_lis = 0x3c000000;
 	u32 inst_ori = 0x60000000;
-	u32 inst_nop = 0x60000000;
 	u32 inst_sc = 0x44000002;
 	u32 inst_imm_mask = 0xffff;
 
@@ -751,6 +762,9 @@ static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo *pvinfo)
 	pvinfo->hcall[1] = inst_ori | (KVM_SC_MAGIC_R0 & inst_imm_mask);
 	pvinfo->hcall[2] = inst_sc;
 	pvinfo->hcall[3] = inst_nop;
+#endif
+
+	pvinfo->flags = KVM_PPC_PVINFO_FLAGS_EV_IDLE;
 
 	return 0;
 }
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 7a9dd4b..640ec5a 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   (1<<0)
+
 #define KVMIO 0xAE
 
 /* machine type bits, to be used as argument to KVM_CREATE_VM */
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v10 4/5] KVM: PPC: ev_idle hcall support for e500 guests
  2012-03-15 20:52 [PATCH v10 0/5] KVM: PPC: Add ePAPR idle hcall support Stuart Yoder
                   ` (2 preceding siblings ...)
  2012-03-15 20:52 ` [PATCH v10 3/5] KVM: PPC: Add support for ePAPR idle hcall in host kernel Stuart Yoder
@ 2012-03-15 20:52 ` Stuart Yoder
  2012-05-08 10:45   ` Alexander Graf
  2012-03-15 20:52 ` [PATCH v10 5/5] PPC: Don't use hardcoded opcode for ePAPR hcall invocation Stuart Yoder
  4 siblings, 1 reply; 11+ messages in thread
From: Stuart Yoder @ 2012-03-15 20:52 UTC (permalink / raw)
  To: agraf, kvm-ppc, kvm

From: Liu Yu-B13201 <Yu.Liu@freescale.com>

Signed-off-by: Liu Yu <yu.liu@freescale.com>
[stuart: update patch description]
Signed-off-by: Stuart Yoder <stuart.yoder@freescale.com>
---
v10:
   -add spaces as per comments
   -use PPC_LL/PPC_STL for long accesses

 arch/powerpc/include/asm/epapr_hcalls.h |   11 ++++++-----
 arch/powerpc/kernel/epapr_hcalls.S      |   28 ++++++++++++++++++++++++++++
 arch/powerpc/kernel/epapr_paravirt.c    |   11 ++++++++++-
 3 files changed, 44 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h b/arch/powerpc/include/asm/epapr_hcalls.h
index 2173d4c..78460ac 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -50,10 +50,6 @@
 #ifndef _EPAPR_HCALLS_H
 #define _EPAPR_HCALLS_H
 
-#include <linux/types.h>
-#include <linux/errno.h>
-#include <asm/byteorder.h>
-
 #define EV_BYTE_CHANNEL_SEND		1
 #define EV_BYTE_CHANNEL_RECEIVE		2
 #define EV_BYTE_CHANNEL_POLL		3
@@ -108,6 +104,11 @@
 #define EV_UNIMPLEMENTED	12	/* Unimplemented hypercall */
 #define EV_BUFFER_OVERFLOW	13	/* Caller-supplied buffer too small */
 
+#ifndef __ASSEMBLY__
+#include <linux/types.h>
+#include <linux/errno.h>
+#include <asm/byteorder.h>
+
 /*
  * Hypercall register clobber list
  *
@@ -500,5 +501,5 @@ static inline unsigned int ev_idle(void)
 
 	return r3;
 }
-
+#endif /* !__ASSEMBLY__ */
 #endif
diff --git a/arch/powerpc/kernel/epapr_hcalls.S b/arch/powerpc/kernel/epapr_hcalls.S
index 697b390..698e7d9 100644
--- a/arch/powerpc/kernel/epapr_hcalls.S
+++ b/arch/powerpc/kernel/epapr_hcalls.S
@@ -8,13 +8,41 @@
  */
 
 #include <linux/threads.h>
+#include <asm/epapr_hcalls.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-compat.h>
 #include <asm/asm-offsets.h>
 
+_GLOBAL(epapr_ev_idle)
+epapr_ev_idle:
+	rlwinm	r3, r1, 0, 0, 31-THREAD_SHIFT	/* current thread_info */
+	PPC_LL	r4, TI_LOCAL_FLAGS(r3)	/* set napping bit */
+	ori	r4, r4,_TLF_NAPPING	/* so when we take an exception */
+	PPC_STL	r4, TI_LOCAL_FLAGS(r3)	/* it will return to our caller */
+
+	wrteei	1
+
+idle_loop:
+	LOAD_REG_IMMEDIATE(r11, EV_HCALL_TOKEN(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 028aeae..f3eab85 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_paravirt_enabled;
 
@@ -41,8 +45,13 @@ static int __init epapr_paravirt_init(void)
 	if (len % 4 || len > (4 * 4))
 		return -ENODEV;
 
-	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_paravirt_enabled = true;
 
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v10 5/5] PPC: Don't use hardcoded opcode for ePAPR hcall invocation
  2012-03-15 20:52 [PATCH v10 0/5] KVM: PPC: Add ePAPR idle hcall support Stuart Yoder
                   ` (3 preceding siblings ...)
  2012-03-15 20:52 ` [PATCH v10 4/5] KVM: PPC: ev_idle hcall support for e500 guests Stuart Yoder
@ 2012-03-15 20:52 ` Stuart Yoder
  4 siblings, 0 replies; 11+ messages in thread
From: Stuart Yoder @ 2012-03-15 20:52 UTC (permalink / raw)
  To: agraf, kvm-ppc, kvm

From: Liu Yu-B13201 <Yu.Liu@freescale.com>

Also, select ePAPR kconfig option for all users of  ePAPR hcalls.

Signed-off-by: Liu Yu <yu.liu@freescale.com>
[stuart.yoder@freescale.com: kconfig fixes]
Signed-off-by: Stuart Yoder <stuart.yoder@freescale.com>
---
v10: update patch subject/description

 arch/powerpc/include/asm/epapr_hcalls.h |   22 +++++++++---------
 arch/powerpc/include/asm/fsl_hcalls.h   |   36 +++++++++++++++---------------
 arch/powerpc/platforms/Kconfig          |    1 +
 drivers/tty/Kconfig                     |    1 +
 drivers/virt/Kconfig                    |    1 +
 5 files changed, 32 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("bl	epapr_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("bl	epapr_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("bl	epapr_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("bl	epapr_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("bl	epapr_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("bl	epapr_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("bl	epapr_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("bl	epapr_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("bl	epapr_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("bl	epapr_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("bl	epapr_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("bl	epapr_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__ __volatile__ ("sc 1"
+	asm volatile("bl	epapr_hypercall_start"
 		: "+r" (r11),
 		  "+r" (r3), "+r" (r4), "+r" (r5), "+r" (r6), "+r" (r7),
 		  "+r" (r8), "+r" (r9), "+r" (r10)
@@ -205,7 +205,7 @@ static inline unsigned int fh_partition_set_dtprop(int handle,
 	r9 = (uint32_t)propvalue_addr;
 	r10 = propvalue_len;
 
-	__asm__ __volatile__ ("sc 1"
+	asm volatile("bl	epapr_hypercall_start"
 		: "+r" (r11),
 		  "+r" (r3), "+r" (r4), "+r" (r5), "+r" (r6), "+r" (r7),
 		  "+r" (r8), "+r" (r9), "+r" (r10)
@@ -229,7 +229,7 @@ static inline unsigned int fh_partition_restart(unsigned int partition)
 	r11 = FH_HCALL_TOKEN(FH_PARTITION_RESTART);
 	r3 = partition;
 
-	__asm__ __volatile__ ("sc 1"
+	asm volatile("bl	epapr_hypercall_start"
 		: "+r" (r11), "+r" (r3)
 		: : EV_HCALL_CLOBBERS1
 	);
@@ -262,7 +262,7 @@ static inline unsigned int fh_partition_get_status(unsigned int partition,
 	r11 = FH_HCALL_TOKEN(FH_PARTITION_GET_STATUS);
 	r3 = partition;
 
-	__asm__ __volatile__ ("sc 1"
+	asm volatile("bl	epapr_hypercall_start"
 		: "+r" (r11), "+r" (r3), "=r" (r4)
 		: : EV_HCALL_CLOBBERS2
 	);
@@ -295,7 +295,7 @@ static inline unsigned int fh_partition_start(unsigned int partition,
 	r4 = entry_point;
 	r5 = load;
 
-	__asm__ __volatile__ ("sc 1"
+	asm volatile("bl	epapr_hypercall_start"
 		: "+r" (r11), "+r" (r3), "+r" (r4), "+r" (r5)
 		: : EV_HCALL_CLOBBERS3
 	);
@@ -317,7 +317,7 @@ static inline unsigned int fh_partition_stop(unsigned int partition)
 	r11 = FH_HCALL_TOKEN(FH_PARTITION_STOP);
 	r3 = partition;
 
-	__asm__ __volatile__ ("sc 1"
+	asm volatile("bl	epapr_hypercall_start"
 		: "+r" (r11), "+r" (r3)
 		: : EV_HCALL_CLOBBERS1
 	);
@@ -376,7 +376,7 @@ static inline unsigned int fh_partition_memcpy(unsigned int source,
 #endif
 	r7 = count;
 
-	__asm__ __volatile__ ("sc 1"
+	asm volatile("bl	epapr_hypercall_start"
 		: "+r" (r11),
 		  "+r" (r3), "+r" (r4), "+r" (r5), "+r" (r6), "+r" (r7)
 		: : EV_HCALL_CLOBBERS5
@@ -399,7 +399,7 @@ static inline unsigned int fh_dma_enable(unsigned int liodn)
 	r11 = FH_HCALL_TOKEN(FH_DMA_ENABLE);
 	r3 = liodn;
 
-	__asm__ __volatile__ ("sc 1"
+	asm volatile("bl	epapr_hypercall_start"
 		: "+r" (r11), "+r" (r3)
 		: : EV_HCALL_CLOBBERS1
 	);
@@ -421,7 +421,7 @@ static inline unsigned int fh_dma_disable(unsigned int liodn)
 	r11 = FH_HCALL_TOKEN(FH_DMA_DISABLE);
 	r3 = liodn;
 
-	__asm__ __volatile__ ("sc 1"
+	asm volatile("bl	epapr_hypercall_start"
 		: "+r" (r11), "+r" (r3)
 		: : EV_HCALL_CLOBBERS1
 	);
@@ -447,7 +447,7 @@ static inline unsigned int fh_vmpic_get_msir(unsigned int interrupt,
 	r11 = FH_HCALL_TOKEN(FH_VMPIC_GET_MSIR);
 	r3 = interrupt;
 
-	__asm__ __volatile__ ("sc 1"
+	asm volatile("bl	epapr_hypercall_start"
 		: "+r" (r11), "+r" (r3), "=r" (r4)
 		: : EV_HCALL_CLOBBERS2
 	);
@@ -469,7 +469,7 @@ static inline unsigned int fh_system_reset(void)
 
 	r11 = FH_HCALL_TOKEN(FH_SYSTEM_RESET);
 
-	__asm__ __volatile__ ("sc 1"
+	asm volatile("bl	epapr_hypercall_start"
 		: "+r" (r11), "=r" (r3)
 		: : EV_HCALL_CLOBBERS1
 	);
@@ -506,7 +506,7 @@ static inline unsigned int fh_err_get_info(int queue, uint32_t *bufsize,
 	r6 = addr_lo;
 	r7 = peek;
 
-	__asm__ __volatile__ ("sc 1"
+	asm volatile("bl	epapr_hypercall_start"
 		: "+r" (r11), "+r" (r3), "+r" (r4), "+r" (r5), "+r" (r6),
 		  "+r" (r7)
 		: : EV_HCALL_CLOBBERS5
@@ -542,7 +542,7 @@ static inline unsigned int fh_get_core_state(unsigned int handle,
 	r3 = handle;
 	r4 = vcpu;
 
-	__asm__ __volatile__ ("sc 1"
+	asm volatile("bl	epapr_hypercall_start"
 		: "+r" (r11), "+r" (r3), "+r" (r4)
 		: : EV_HCALL_CLOBBERS2
 	);
@@ -572,7 +572,7 @@ static inline unsigned int fh_enter_nap(unsigned int handle, unsigned int vcpu)
 	r3 = handle;
 	r4 = vcpu;
 
-	__asm__ __volatile__ ("sc 1"
+	asm volatile("bl	epapr_hypercall_start"
 		: "+r" (r11), "+r" (r3), "+r" (r4)
 		: : EV_HCALL_CLOBBERS2
 	);
@@ -597,7 +597,7 @@ static inline unsigned int fh_exit_nap(unsigned int handle, unsigned int vcpu)
 	r3 = handle;
 	r4 = vcpu;
 
-	__asm__ __volatile__ ("sc 1"
+	asm volatile("bl	epapr_hypercall_start"
 		: "+r" (r11), "+r" (r3), "+r" (r4)
 		: : EV_HCALL_CLOBBERS2
 	);
@@ -618,7 +618,7 @@ static inline unsigned int fh_claim_device(unsigned int handle)
 	r11 = FH_HCALL_TOKEN(FH_CLAIM_DEVICE);
 	r3 = handle;
 
-	__asm__ __volatile__ ("sc 1"
+	asm volatile("bl	epapr_hypercall_start"
 		: "+r" (r11), "+r" (r3)
 		: : EV_HCALL_CLOBBERS1
 	);
@@ -645,7 +645,7 @@ static inline unsigned int fh_partition_stop_dma(unsigned int handle)
 	r11 = FH_HCALL_TOKEN(FH_PARTITION_STOP_DMA);
 	r3 = handle;
 
-	__asm__ __volatile__ ("sc 1"
+	asm volatile("bl	epapr_hypercall_start"
 		: "+r" (r11), "+r" (r3)
 		: : EV_HCALL_CLOBBERS1
 	);
diff --git a/arch/powerpc/platforms/Kconfig b/arch/powerpc/platforms/Kconfig
index 09348e7..e91c91f 100644
--- a/arch/powerpc/platforms/Kconfig
+++ b/arch/powerpc/platforms/Kconfig
@@ -91,6 +91,7 @@ config MPIC
 config PPC_EPAPR_HV_PIC
 	bool
 	default n
+	select EPAPR_PARAVIRT
 
 config MPIC_WEIRD
 	bool
diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig
index b3d1741..06427b4 100644
--- a/drivers/tty/Kconfig
+++ b/drivers/tty/Kconfig
@@ -358,6 +358,7 @@ config TRACE_SINK
 config PPC_EPAPR_HV_BYTECHAN
 	tristate "ePAPR hypervisor byte channel driver"
 	depends on PPC
+	select EPAPR_PARAVIRT
 	help
 	  This driver creates /dev entries for each ePAPR hypervisor byte
 	  channel, thereby allowing applications to communicate with byte
diff --git a/drivers/virt/Kconfig b/drivers/virt/Kconfig
index 2dcdbc9..99ebdde 100644
--- a/drivers/virt/Kconfig
+++ b/drivers/virt/Kconfig
@@ -15,6 +15,7 @@ if VIRT_DRIVERS
 config FSL_HV_MANAGER
 	tristate "Freescale hypervisor management driver"
 	depends on FSL_SOC
+	select EPAPR_PARAVIRT
 	help
           The Freescale hypervisor management driver provides several services
 	  to drivers and applications related to the Freescale hypervisor:
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v10 1/5] KVM: PPC: Factor out guest epapr initialization
  2012-03-15 20:52 ` [PATCH v10 1/5] KVM: PPC: Factor out guest epapr initialization Stuart Yoder
@ 2012-05-08 10:25   ` Alexander Graf
  0 siblings, 0 replies; 11+ messages in thread
From: Alexander Graf @ 2012-05-08 10:25 UTC (permalink / raw)
  To: Stuart Yoder; +Cc: kvm-ppc, kvm


On 15.03.2012, at 21:52, Stuart Yoder wrote:

> From: Liu Yu-B13201 <Yu.Liu@freescale.com>
> 
> epapr paravirtualization support is now a Kconfig
> selectable option
> 
> Signed-off-by: Liu Yu <yu.liu@freescale.com>
> [stuart.yoder@freescale.com: misc minor fixes, description update]
> Signed-off-by: Stuart Yoder <stuart.yoder@freescale.com>

Thanks, applied to kvm-ppc-next.


Alex

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v10 2/5] KVM: PPC: use definitions in epapr header for hcalls
  2012-03-15 20:52 ` [PATCH v10 2/5] KVM: PPC: use definitions in epapr header for hcalls Stuart Yoder
@ 2012-05-08 10:29   ` Alexander Graf
  0 siblings, 0 replies; 11+ messages in thread
From: Alexander Graf @ 2012-05-08 10:29 UTC (permalink / raw)
  To: Stuart Yoder; +Cc: kvm-ppc, kvm


On 15.03.2012, at 21:52, Stuart Yoder wrote:

> From: Stuart Yoder <stuart.yoder@freescale.com>
> 
> Signed-off-by: Stuart Yoder <stuart.yoder@freescale.com>
> ---
> arch/powerpc/include/asm/kvm_para.h |   19 +++++++++----------
> arch/powerpc/kernel/kvm.c           |    2 +-
> arch/powerpc/kvm/powerpc.c          |   10 +++++-----
> 3 files changed, 15 insertions(+), 16 deletions(-)
> 
> diff --git a/arch/powerpc/include/asm/kvm_para.h b/arch/powerpc/include/asm/kvm_para.h
> index c18916b..7d4a870 100644
> --- a/arch/powerpc/include/asm/kvm_para.h
> +++ b/arch/powerpc/include/asm/kvm_para.h
> @@ -75,9 +75,8 @@ struct kvm_vcpu_arch_shared {
> };
> 
> #define KVM_SC_MAGIC_R0		0x4b564d21 /* "KVM!" */
> -#define HC_VENDOR_KVM		(42 << 16)
> -#define HC_EV_SUCCESS		0
> -#define HC_EV_UNIMPLEMENTED	12
> +
> +#include <asm/epapr_hcalls.h>
> 
> #define KVM_FEATURE_MAGIC_PAGE	1
> 
> @@ -121,7 +120,7 @@ static unsigned long kvm_hypercall(unsigned long *in,
> 				   unsigned long *out,
> 				   unsigned long nr)
> {
> -	return HC_EV_UNIMPLEMENTED;
> +	return EV_UNIMPLEMENTED;
> }
> 
> #endif
> @@ -132,7 +131,7 @@ static inline long kvm_hypercall0_1(unsigned int nr, unsigned long *r2)
> 	unsigned long out[8];
> 	unsigned long r;
> 
> -	r = kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
> +	r = kvm_hypercall(in, out, nr | EV_KVM_VENDOR_ID);

#define EV_KVM_VENDOR_ID                42      /* KVM */

This is different from (42 << 16). We need to shift the value again :). I guess that one needs _EV_HCALL_TOKEN?


> 	*r2 = out[0];
> 
> 	return r;
> @@ -143,7 +142,7 @@ static inline long kvm_hypercall0(unsigned int nr)
> 	unsigned long in[8];
> 	unsigned long out[8];
> 
> -	return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
> +	return kvm_hypercall(in, out, nr | EV_KVM_VENDOR_ID);
> }
> 
> static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
> @@ -152,7 +151,7 @@ static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
> 	unsigned long out[8];
> 
> 	in[0] = p1;
> -	return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
> +	return kvm_hypercall(in, out, nr | EV_KVM_VENDOR_ID);
> }
> 
> static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
> @@ -163,7 +162,7 @@ static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
> 
> 	in[0] = p1;
> 	in[1] = p2;
> -	return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
> +	return kvm_hypercall(in, out, nr | EV_KVM_VENDOR_ID);
> }
> 
> static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
> @@ -175,7 +174,7 @@ static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
> 	in[0] = p1;
> 	in[1] = p2;
> 	in[2] = p3;
> -	return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
> +	return kvm_hypercall(in, out, nr | EV_KVM_VENDOR_ID);
> }
> 
> static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
> @@ -189,7 +188,7 @@ static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
> 	in[1] = p2;
> 	in[2] = p3;
> 	in[3] = p4;
> -	return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
> +	return kvm_hypercall(in, out, nr | EV_KVM_VENDOR_ID);
> }
> 
> 
> diff --git a/arch/powerpc/kernel/kvm.c b/arch/powerpc/kernel/kvm.c
> index 1c13307..b5ba561 100644
> --- a/arch/powerpc/kernel/kvm.c
> +++ b/arch/powerpc/kernel/kvm.c
> @@ -419,7 +419,7 @@ static void kvm_map_magic_page(void *data)
> 	in[0] = KVM_MAGIC_PAGE;
> 	in[1] = KVM_MAGIC_PAGE;
> 
> -	kvm_hypercall(in, out, HC_VENDOR_KVM | KVM_HC_PPC_MAP_MAGIC_PAGE);
> +	kvm_hypercall(in, out, _EV_HCALL_TOKEN(EV_KVM_VENDOR_ID, KVM_HC_PPC_MAP_MAGIC_PAGE));

Ah, here you're using the macro :). Please also make sure to not exceed 80 chars per line :).

> 
> 	*features = out[0];
> }
> diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
> index 58ad860..d738626 100644
> --- a/arch/powerpc/kvm/powerpc.c
> +++ b/arch/powerpc/kvm/powerpc.c
> @@ -67,18 +67,18 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
> 	}
> 
> 	switch (nr) {
> -	case HC_VENDOR_KVM | KVM_HC_PPC_MAP_MAGIC_PAGE:
> +	case _EV_HCALL_TOKEN(EV_KVM_VENDOR_ID, KVM_HC_PPC_MAP_MAGIC_PAGE):
> 	{
> 		vcpu->arch.magic_page_pa = param1;
> 		vcpu->arch.magic_page_ea = param2;
> 
> 		r2 = KVM_MAGIC_FEAT_SR | KVM_MAGIC_FEAT_MAS0_TO_SPRG7;
> 
> -		r = HC_EV_SUCCESS;
> +		r = 0;  /* success */
> 		break;
> 	}
> -	case HC_VENDOR_KVM | KVM_HC_FEATURES:
> -		r = HC_EV_SUCCESS;
> +	case _EV_HCALL_TOKEN(EV_KVM_VENDOR_ID, KVM_HC_FEATURES):
> +		r = 0;  /* success */

There's no define for success? Wouldn't it be better to just add one?


Alex

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v10 3/5] KVM: PPC: Add support for ePAPR idle hcall in host kernel
  2012-03-15 20:52 ` [PATCH v10 3/5] KVM: PPC: Add support for ePAPR idle hcall in host kernel Stuart Yoder
@ 2012-05-08 10:40   ` Alexander Graf
  2012-05-16 22:46     ` Scott Wood
  0 siblings, 1 reply; 11+ messages in thread
From: Alexander Graf @ 2012-05-08 10:40 UTC (permalink / raw)
  To: Stuart Yoder; +Cc: kvm-ppc, kvm


On 15.03.2012, at 21:52, Stuart Yoder wrote:

> From: Liu Yu-B13201 <Yu.Liu@freescale.com>
> 
> And add a new flag definition in kvm_ppc_pvinfo to indicate
> whether the host supports the EV_IDLE hcall.
> 
> Signed-off-by: Liu Yu <yu.liu@freescale.com>
> [stuart.yoder@freescale.com: cleanup,fixes for conditions allowing idle]
> Signed-off-by: Stuart Yoder <stuart.yoder@freescale.com>
> ---
> -v10:
>   -ePAPR definitions now addressed in separate patch
>   -move clearing of KVM_REQ_UNHALT after kvm_vcpu_block() call 
> 
> arch/powerpc/include/asm/Kbuild |    1 +
> arch/powerpc/kvm/powerpc.c      |   20 +++++++++++++++++---
> include/linux/kvm.h             |    2 ++
> 3 files changed, 20 insertions(+), 3 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/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
> index d738626..7c4e5cc 100644
> --- a/arch/powerpc/kvm/powerpc.c
> +++ b/arch/powerpc/kvm/powerpc.c
> @@ -38,8 +38,7 @@
> 
> int kvm_arch_vcpu_runnable(struct kvm_vcpu *v)
> {
> -	return !(v->arch.shared->msr & MSR_WE) ||
> -	       !!(v->arch.pending_exceptions) ||
> +	return !!(v->arch.pending_exceptions) ||

Are you sure this doesn't break book3s or e500v2?

> 	       v->requests;
> }
> 
> @@ -86,6 +85,11 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
> 
> 		/* Second return value is in r4 */
> 		break;
> +	case _EV_HCALL_TOKEN(EV_EPAPR_VENDOR_ID, EV_IDLE):
> +		r = 0;  /* success */
> +		kvm_vcpu_block(vcpu);
> +		clear_bit(KVM_REQ_UNHALT, &vcpu->requests);
> +		break;
> 	default:
> 		r = EV_UNIMPLEMENTED;
> 		break;
> @@ -732,9 +736,16 @@ int kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct vm_fault *vmf)
> 
> static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo *pvinfo)
> {
> +	u32 inst_nop = 0x60000000;
> +#ifdef CONFIG_KVM_BOOKE_HV
> +	u32 inst_sc1 = 0x44000022;
> +	pvinfo->hcall[0] = inst_sc1;
> +	pvinfo->hcall[1] = inst_nop;
> +	pvinfo->hcall[2] = inst_nop;
> +	pvinfo->hcall[3] = inst_nop;
> +#else

This hunk is unrelated to the rest of the patch. Please factor it out into its own patch :).

> 	u32 inst_lis = 0x3c000000;
> 	u32 inst_ori = 0x60000000;
> -	u32 inst_nop = 0x60000000;
> 	u32 inst_sc = 0x44000002;
> 	u32 inst_imm_mask = 0xffff;
> 
> @@ -751,6 +762,9 @@ static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo *pvinfo)
> 	pvinfo->hcall[1] = inst_ori | (KVM_SC_MAGIC_R0 & inst_imm_mask);
> 	pvinfo->hcall[2] = inst_sc;
> 	pvinfo->hcall[3] = inst_nop;
> +#endif
> +
> +	pvinfo->flags = KVM_PPC_PVINFO_FLAGS_EV_IDLE;
> 
> 	return 0;
> }
> diff --git a/include/linux/kvm.h b/include/linux/kvm.h
> index 7a9dd4b..640ec5a 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   (1<<0)

This needs an update to the documentation in Documentation/virtual/kvm/api.txt. Please also update Documentation/virtual/kvm/ppc-pv.txt with the new hypercall.


Alex


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v10 4/5] KVM: PPC: ev_idle hcall support for e500 guests
  2012-03-15 20:52 ` [PATCH v10 4/5] KVM: PPC: ev_idle hcall support for e500 guests Stuart Yoder
@ 2012-05-08 10:45   ` Alexander Graf
  0 siblings, 0 replies; 11+ messages in thread
From: Alexander Graf @ 2012-05-08 10:45 UTC (permalink / raw)
  To: Stuart Yoder; +Cc: kvm-ppc, kvm


On 15.03.2012, at 21:52, Stuart Yoder wrote:

> From: Liu Yu-B13201 <Yu.Liu@freescale.com>
> 
> Signed-off-by: Liu Yu <yu.liu@freescale.com>
> [stuart: update patch description]
> Signed-off-by: Stuart Yoder <stuart.yoder@freescale.com>
> ---
> v10:
>   -add spaces as per comments
>   -use PPC_LL/PPC_STL for long accesses
> 
> arch/powerpc/include/asm/epapr_hcalls.h |   11 ++++++-----
> arch/powerpc/kernel/epapr_hcalls.S      |   28 ++++++++++++++++++++++++++++
> arch/powerpc/kernel/epapr_paravirt.c    |   11 ++++++++++-
> 3 files changed, 44 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/powerpc/include/asm/epapr_hcalls.h b/arch/powerpc/include/asm/epapr_hcalls.h
> index 2173d4c..78460ac 100644
> --- a/arch/powerpc/include/asm/epapr_hcalls.h
> +++ b/arch/powerpc/include/asm/epapr_hcalls.h
> @@ -50,10 +50,6 @@
> #ifndef _EPAPR_HCALLS_H
> #define _EPAPR_HCALLS_H
> 
> -#include <linux/types.h>
> -#include <linux/errno.h>
> -#include <asm/byteorder.h>
> -
> #define EV_BYTE_CHANNEL_SEND		1
> #define EV_BYTE_CHANNEL_RECEIVE		2
> #define EV_BYTE_CHANNEL_POLL		3
> @@ -108,6 +104,11 @@
> #define EV_UNIMPLEMENTED	12	/* Unimplemented hypercall */
> #define EV_BUFFER_OVERFLOW	13	/* Caller-supplied buffer too small */
> 
> +#ifndef __ASSEMBLY__
> +#include <linux/types.h>
> +#include <linux/errno.h>
> +#include <asm/byteorder.h>
> +
> /*
>  * Hypercall register clobber list
>  *
> @@ -500,5 +501,5 @@ static inline unsigned int ev_idle(void)
> 
> 	return r3;
> }
> -
> +#endif /* !__ASSEMBLY__ */
> #endif
> diff --git a/arch/powerpc/kernel/epapr_hcalls.S b/arch/powerpc/kernel/epapr_hcalls.S
> index 697b390..698e7d9 100644
> --- a/arch/powerpc/kernel/epapr_hcalls.S
> +++ b/arch/powerpc/kernel/epapr_hcalls.S
> @@ -8,13 +8,41 @@
>  */
> 
> #include <linux/threads.h>
> +#include <asm/epapr_hcalls.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-compat.h>
> #include <asm/asm-offsets.h>
> 
> +_GLOBAL(epapr_ev_idle)
> +epapr_ev_idle:

Please document here that this is a copy from the original idle code.

> +	rlwinm	r3, r1, 0, 0, 31-THREAD_SHIFT	/* current thread_info */
> +	PPC_LL	r4, TI_LOCAL_FLAGS(r3)	/* set napping bit */
> +	ori	r4, r4,_TLF_NAPPING	/* so when we take an exception */
> +	PPC_STL	r4, TI_LOCAL_FLAGS(r3)	/* it will return to our caller */
> +
> +	wrteei	1
> +
> +idle_loop:
> +	LOAD_REG_IMMEDIATE(r11, EV_HCALL_TOKEN(EV_IDLE))

Ah, nice. So why not use EV_HCALL_TOKEN instead of the clumsy _EV_HCALL_TOKEN(EV_EPAPR_VENDOR_ID, EV_IDLE)? We could also add a KVM_HCALL_TOKEN() similar to the fsl one:

  arch/powerpc/include/asm/fsl_hcalls.h:#define FH_HCALL_TOKEN(num)		_EV_HCALL_TOKEN(EV_FSL_VENDOR_ID, num)

which would help us keep our lines short :).


Alex


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v10 3/5] KVM: PPC: Add support for ePAPR idle hcall in host kernel
  2012-05-08 10:40   ` Alexander Graf
@ 2012-05-16 22:46     ` Scott Wood
  0 siblings, 0 replies; 11+ messages in thread
From: Scott Wood @ 2012-05-16 22:46 UTC (permalink / raw)
  To: Alexander Graf; +Cc: Stuart Yoder, kvm-ppc, kvm

On 05/08/2012 05:40 AM, Alexander Graf wrote:
> 
> On 15.03.2012, at 21:52, Stuart Yoder wrote:
> 
>> From: Liu Yu-B13201 <Yu.Liu@freescale.com>
>>
>> And add a new flag definition in kvm_ppc_pvinfo to indicate
>> whether the host supports the EV_IDLE hcall.
>>
>> Signed-off-by: Liu Yu <yu.liu@freescale.com>
>> [stuart.yoder@freescale.com: cleanup,fixes for conditions allowing idle]
>> Signed-off-by: Stuart Yoder <stuart.yoder@freescale.com>
>> ---
>> -v10:
>>   -ePAPR definitions now addressed in separate patch
>>   -move clearing of KVM_REQ_UNHALT after kvm_vcpu_block() call 
>>
>> arch/powerpc/include/asm/Kbuild |    1 +
>> arch/powerpc/kvm/powerpc.c      |   20 +++++++++++++++++---
>> include/linux/kvm.h             |    2 ++
>> 3 files changed, 20 insertions(+), 3 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/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
>> index d738626..7c4e5cc 100644
>> --- a/arch/powerpc/kvm/powerpc.c
>> +++ b/arch/powerpc/kvm/powerpc.c
>> @@ -38,8 +38,7 @@
>>
>> int kvm_arch_vcpu_runnable(struct kvm_vcpu *v)
>> {
>> -	return !(v->arch.shared->msr & MSR_WE) ||
>> -	       !!(v->arch.pending_exceptions) ||
>> +	return !!(v->arch.pending_exceptions) ||
> 
> Are you sure this doesn't break book3s or e500v2?

It's only used inside kvm_vcpu_block().  We only call kvm_vcpu_block()
if there's a request to go idle (MSR[WE], hcall, etc), and MSR[WE] can't
be cleared except via exception or userspace.  Exceptions are already
checked for in runnable(), and an exit to userspace would exit
kvm_vcpu_block().

-Scott

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2012-05-16 22:46 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-15 20:52 [PATCH v10 0/5] KVM: PPC: Add ePAPR idle hcall support Stuart Yoder
2012-03-15 20:52 ` [PATCH v10 1/5] KVM: PPC: Factor out guest epapr initialization Stuart Yoder
2012-05-08 10:25   ` Alexander Graf
2012-03-15 20:52 ` [PATCH v10 2/5] KVM: PPC: use definitions in epapr header for hcalls Stuart Yoder
2012-05-08 10:29   ` Alexander Graf
2012-03-15 20:52 ` [PATCH v10 3/5] KVM: PPC: Add support for ePAPR idle hcall in host kernel Stuart Yoder
2012-05-08 10:40   ` Alexander Graf
2012-05-16 22:46     ` Scott Wood
2012-03-15 20:52 ` [PATCH v10 4/5] KVM: PPC: ev_idle hcall support for e500 guests Stuart Yoder
2012-05-08 10:45   ` Alexander Graf
2012-03-15 20:52 ` [PATCH v10 5/5] PPC: Don't use hardcoded opcode for ePAPR hcall invocation Stuart Yoder

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox