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

Subsystems: kernel virtual machine for powerpc (kvm/powerpc), linux for powerpc (32-bit and 64-bit), the rest

STALE5286d

18 messages, 4 authors, 2012-02-17 · open the first message on its own page

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

From: Liu Yu <hidden>
Date: 2012-02-16 09:31:35

from the kvm guest paravirt init code.

Signed-off-by: Liu Yu <redacted>
---
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
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 1919634..1262b43 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -202,6 +202,10 @@ config EPAPR_BOOT
 	  Used to allow a board to specify it wants an ePAPR compliant wrapper.
 	default n
 
+config EPAPR_PARAVIRT
+	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..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..9e807f3 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_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 0000000..697b390
--- /dev/null
+++ b/arch/powerpc/kernel/epapr.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_para.c b/arch/powerpc/kernel/epapr_para.c
new file mode 100644
index 0000000..ea13cac
--- /dev/null
+++ b/arch/powerpc/kernel/epapr_para.c
@@ -0,0 +1,49 @@
+/*
+ * 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>
+
+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)
+		return -ENODEV;
+
+	insts = of_get_property(hyper_node, "hcall-instructions", &len);
+	if (!(len % 4) && (len >= (4 * 4))) {
+		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);
+
+		epapr_para_enabled = true;
+	}
+
+	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) 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_para_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/kvm/Kconfig b/arch/powerpc/kvm/Kconfig
index 8f64709..9bb9d18 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_PARAVIRT
 
 config KVM_BOOK3S_HANDLER
 	bool
-- 
1.7.0.4

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

From: Liu Yu <hidden>
Date: 2012-02-16 09:31:06

If the guest hypervisor node contains "has-idle" property.

Signed-off-by: Liu Yu <redacted>
---
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

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

From: Liu Yu <hidden>
Date: 2012-02-16 09:31:36

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

Signed-off-by: Liu Yu <redacted>
---
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_R0		0x4b564d21 /* "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_UNIMPLEMENTED	12
+#define HC_EV_UNIMPLEMENTED	EV_UNIMPLEMENTED
 
 #define KVM_FEATURE_MAGIC_PAGE	1
 
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;
 }
 
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   (1<<0)
+
 #define KVMIO 0xAE
 
 /* machine type bits, to be used as argument to KVM_CREATE_VM */
-- 
1.7.0.4

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

From: Alexander Graf <hidden>
Date: 2012-02-16 10:16:29


On 16.02.2012, at 10:26, Liu Yu [off-list ref] wrote:
from the kvm guest paravirt init code.
=20
Signed-off-by: Liu Yu <redacted>
---
v4:
1. code cleanup
2. move kvm_hypercall_start() to epapr_hypercall_start()
=20
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 +++++++++++++++++++++++++++=
++++
quoted hunk
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
=20
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 1919634..1262b43 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -202,6 +202,10 @@ config EPAPR_BOOT
     Used to allow a board to specify it wants an ePAPR compliant wrapper.=
quoted hunk
   default n
=20
+config EPAPR_PARAVIRT
+    bool
+    default n
+
config DEFAULT_UIMAGE
   bool
   help
diff --git a/arch/powerpc/include/asm/epapr_hcalls.h b/arch/powerpc/includ=
e/asm/epapr_hcalls.h
quoted hunk
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"
=20
+extern bool epapr_para_enabled;
+extern u32 epapr_hypercall_start[];
=20
/*
 * We use "uintptr_t" to define a register because it's guaranteed to be a=
quoted hunk
diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index ee728e4..9e807f3 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -136,6 +136,7 @@ ifneq ($(CONFIG_XMON)$(CONFIG_KEXEC),)
obj-y                +=3D ppc_save_regs.o
endif
=20
+obj-$(CONFIG_EPAPR_PARAVIRT)    +=3D epapr_para.o epapr.o
obj-$(CONFIG_KVM_GUEST)        +=3D kvm.o kvm_emul.o
=20
# 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 0000000..697b390
--- /dev/null
+++ b/arch/powerpc/kernel/epapr.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. *=
/
quoted hunk
+.global epapr_hypercall_start
+epapr_hypercall_start:
+    li    r3, -1
+    nop
+    nop
+    nop
+    blr
diff --git a/arch/powerpc/kernel/epapr_para.c b/arch/powerpc/kernel/epapr_=
para.c
quoted hunk
new file mode 100644
index 0000000..ea13cac
--- /dev/null
+++ b/arch/powerpc/kernel/epapr_para.c
@@ -0,0 +1,49 @@
+/*
+ * 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, U=
SA.
+ *
+ * Copyright (C) 2012 Freescale Semiconductor, Inc.
+ */
+
+#include <linux/of.h>
+#include <asm/epapr_hcalls.h>
+#include <asm/cacheflush.h>
+
+bool epapr_para_enabled =3D false;
+
+static int __init epapr_para_init(void)
+{
+    struct device_node *hyper_node;
+    const u32 *insts;
+    int len, i;
+
+    hyper_node =3D of_find_node_by_path("/hypervisor");
+    if (!hyper_node)
+        return -ENODEV;
+
+    insts =3D of_get_property(hyper_node, "hcall-instructions", &len);
+    if (!(len % 4) && (len >=3D (4 * 4))) {
+        for (i =3D 0; i < (len / 4); i++)
So if the dt passes in less than 4 ops, you bail out, and for more you overw=
rite the buffer? Not good :)
quoted hunk
+            epapr_hypercall_start[i] =3D insts[i];
+        flush_icache_range((ulong)epapr_hypercall_start,
+                           (ulong)epapr_hypercall_start + len);
+
+        epapr_para_enabled =3D true;
+    }
+
+    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>
=20
#define KVM_MAGIC_PAGE        (-4096L)
#define magic_var(x) KVM_MAGIC_PAGE + offsetof(struct kvm_vcpu_arch_shared=
, x)
quoted hunk
@@ -726,7 +727,7 @@ unsigned long kvm_hypercall(unsigned long *in,
   unsigned long register r11 asm("r11") =3D nr;
   unsigned long register r12 asm("r12");
=20
-    asm volatile("bl    kvm_hypercall_start"
+    asm volatile("bl    epapr_hypercall_start"
            : "=3Dr"(r0), "=3Dr"(r3), "=3Dr"(r4), "=3Dr"(r5), "=3Dr"(r6),
              "=3Dr"(r7), "=3Dr"(r8), "=3Dr"(r9), "=3Dr"(r10), "=3Dr"(r11)=
,
quoted hunk
              "=3Dr"(r12)
@@ -747,29 +748,6 @@ unsigned long kvm_hypercall(unsigned long *in,
}
EXPORT_SYMBOL_GPL(kvm_hypercall);
=20
-static int kvm_para_setup(void)
-{
-    extern u32 kvm_hypercall_start;
-    struct device_node *hyper_node;
-    u32 *insts;
-    int len, i;
-
-    hyper_node =3D of_find_node_by_path("/hypervisor");
-    if (!hyper_node)
-        return -1;
-
-    insts =3D (u32*)of_get_property(hyper_node, "hcall-instructions", &le=
n);
-    if (len % 4)
-        return -1;
-    if (len > (4 * 4))
As you can see, the previous code allowed for less than 4 instructions, but n=
ot more.

Alex
quoted hunk
-        return -1;
-
-    for (i =3D 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;
=20
-    if (kvm_para_setup())
+    if (!epapr_para_enabled)
       goto free_tmp;
=20
   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
quoted hunk
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>
=20
-/* Hypercall entry point. Will be patched with device tree instructions. *=
/
quoted hunk
-
-.global kvm_hypercall_start
-kvm_hypercall_start:
-    li    r3, -1
-    nop
-    nop
-    nop
-    blr
-
#define KVM_MAGIC_PAGE        (-4096)
=20
#ifdef CONFIG_64BIT
diff --git a/arch/powerpc/kvm/Kconfig b/arch/powerpc/kvm/Kconfig
index 8f64709..9bb9d18 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_PARAVIRT
=20
config KVM_BOOK3S_HANDLER
   bool
--=20
1.7.0.4
=20
=20
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@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

From: Alexander Graf <hidden>
Date: 2012-02-16 10:19:28


On 16.02.2012, at 10:26, Liu Yu [off-list ref] wrote:
quoted hunk
And add a new flag definition in kvm_ppc_pvinfo to indicate
whether host support EV_IDLE hcall.
=20
Signed-off-by: Liu Yu <redacted>
---
v4:
no change
=20
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(-)
=20
diff --git a/arch/powerpc/include/asm/kvm_para.h b/arch/powerpc/include/as=
m/kvm_para.h
quoted hunk
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 {
};
=20
#define KVM_SC_MAGIC_R0        0x4b564d21 /* "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_UNIMPLEMENTED    12
+#define HC_EV_UNIMPLEMENTED    EV_UNIMPLEMENTED
=20
#define KVM_FEATURE_MAGIC_PAGE    1
=20
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)
=20
       /* Second return value is in r4 */
       break;
+    case HC_VENDOR_EPAPR | HC_EV_IDLE:
+        r =3D HC_EV_SUCCESS;
+        kvm_vcpu_block(vcpu);
+        break;
   default:
       r =3D HC_EV_UNIMPLEMENTED;
       break;
@@ -746,6 +750,10 @@ static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvi=
nfo *pvinfo)
   pvinfo->hcall[2] =3D inst_sc;
   pvinfo->hcall[3] =3D inst_nop;
=20
+#ifdef CONFIG_BOOKE
Why limit it to booke? The less ifdefs our code has, the better :)

Alex
quoted hunk
+    pvinfo->flags |=3D KVM_PPC_PVINFO_FLAGS_EV_IDLE;
+#endif
+
   return 0;
}
=20
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];
};
=20
+#define KVM_PPC_PVINFO_FLAGS_EV_IDLE   (1<<0)
+
#define KVMIO 0xAE
=20
/* machine type bits, to be used as argument to KVM_CREATE_VM */
--=20
1.7.0.4
=20
=20
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

From: Alexander Graf <hidden>
Date: 2012-02-16 10:23:48


On 16.02.2012, at 10:26, Liu Yu [off-list ref] wrote:
quoted hunk
If the guest hypervisor node contains "has-idle" property.
=20
Signed-off-by: Liu Yu <redacted>
---
v4:
1. discard the CONFIG_E500 to make code for all powerpc platform
2. code cleanup
=20
arch/powerpc/kernel/epapr.S      |   29 +++++++++++++++++++++++++++++
arch/powerpc/kernel/epapr_para.c |   13 ++++++++++++-
2 files changed, 41 insertions(+), 1 deletions(-)
=20
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>
=20
+#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
Can't you just bl into epapr_hypercall_start? You don't even have to save th=
e old lr. because we never return anyways :)

Alex
+
+    /*
+     * 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. *=
/
quoted hunk
.global epapr_hypercall_start
epapr_hypercall_start:
diff --git a/arch/powerpc/kernel/epapr_para.c b/arch/powerpc/kernel/epapr_=
para.c
quoted hunk
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[];
=20
bool epapr_para_enabled =3D false;
=20
@@ -35,10 +39,17 @@ static int __init epapr_para_init(void)
=20
   insts =3D of_get_property(hyper_node, "hcall-instructions", &len);
   if (!(len % 4) && (len >=3D (4 * 4))) {
-        for (i =3D 0; i < (len / 4); i++)
+        for (i =3D 0; i < (len / 4); i++) {
           epapr_hypercall_start[i] =3D insts[i];
+            epapr_ev_idle_start[i] =3D 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 =3D epapr_ev_idle;
=20
       epapr_para_enabled =3D true;
   }
--=20
1.7.0.4
=20
=20
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

From: Scott Wood <hidden>
Date: 2012-02-16 16:58:13

On 02/16/2012 04:24 AM, Alexander Graf wrote:
On 16.02.2012, at 10:26, Liu Yu [off-list ref] wrote:
quoted
+_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
Can't you just bl into epapr_hypercall_start? You don't even have to save the old lr. because we never return anyways :)
The interrupt will branch to LR, so no, we can't trash it or put it
anywhere else.

-scott

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

From: Scott Wood <hidden>
Date: 2012-02-16 17:13:33

On 02/16/2012 03:26 AM, Liu Yu wrote:
from the kvm guest paravirt init code.

Signed-off-by: Liu Yu <redacted>
---
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.
quoted hunk
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 1919634..1262b43 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -202,6 +202,10 @@ config EPAPR_BOOT
 	  Used to allow a board to specify it wants an ePAPR compliant wrapper.
 	default n
 
+config EPAPR_PARAVIRT
+	bool
+	default n
Why isn't this user-selectable?  It's useful on its own.
quoted hunk
diff --git a/arch/powerpc/kernel/epapr.S b/arch/powerpc/kernel/epapr.S
new file mode 100644
index 0000000..697b390
--- /dev/null
+++ b/arch/powerpc/kernel/epapr.S
epapr-hcall.S
+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)
+		return -ENODEV;
+
+	insts = of_get_property(hyper_node, "hcall-instructions", &len);
+	if (!(len % 4) && (len >= (4 * 4))) {
+		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);
+
+		epapr_para_enabled = true;
+	}
Use patch_instruction(), fix the if test, and remove unnecessary
parentheses.  Print an error if the if test fails, but return silently
if the property is absent.

Please make asm/epapr_hcalls.h and asm/fsl_hcalls.h work with this as well.

-Scott

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

From: Scott Wood <hidden>
Date: 2012-02-16 17:14:36

On 02/16/2012 03:26 AM, Liu Yu wrote:
If the guest hypervisor node contains "has-idle" property.

Signed-off-by: Liu Yu <redacted>
---
v4:
1. discard the CONFIG_E500 to make code for all powerpc platform
2. code cleanup
Is the TLF_NAPPING stuff supported on all powerpc platforms?

-Scott

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

From: Alexander Graf <hidden>
Date: 2012-02-16 17:18:56

On 16.02.2012, at 17:58, Scott Wood wrote:
On 02/16/2012 04:24 AM, Alexander Graf wrote:
quoted
On 16.02.2012, at 10:26, Liu Yu [off-list ref] wrote:
quoted
+_GLOBAL(epapr_ev_idle)
+epapr_ev_idle:
+    rlwinm    r3,r1,0,0,31-THREAD_SHIFT    /* current thread_info =
*/
quoted
quoted
+    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 =
*/
quoted
quoted
+
+    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
=20
Can't you just bl into epapr_hypercall_start? You don't even have to =
save the old lr. because we never return anyways :)
=20
The interrupt will branch to LR, so no, we can't trash it or put it
anywhere else.
Hrm. But we can clobber ctr, right? So how about we make the generic =
version do a bctr and then just do a small C wrapper that takes lr, =
moves it to ctr and branches to the generic one?

Then we don't have to replicate the hypercall code all over again for =
every invocation.

Alex

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

From: Scott Wood <hidden>
Date: 2012-02-16 17:28:50

On 02/16/2012 11:18 AM, Alexander Graf wrote:
On 16.02.2012, at 17:58, Scott Wood wrote:
quoted
On 02/16/2012 04:24 AM, Alexander Graf wrote:
quoted
On 16.02.2012, at 10:26, Liu Yu [off-list ref] wrote:
quoted
+_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
Can't you just bl into epapr_hypercall_start? You don't even have to save the old lr. because we never return anyways :)
The interrupt will branch to LR, so no, we can't trash it or put it
anywhere else.
Hrm. But we can clobber ctr, right? So how about we make the generic version do a bctr and then just do a small C wrapper that takes lr, moves it to ctr and branches to the generic one?
If it's just for this, I would say don't mess with the normal hcall path
for the sake of idle.  If using CTR would let us get away without
creating a stack frame in call sites, maybe that would be worthwhile,
depending on what sort of hcalls we end up having.
Then we don't have to replicate the hypercall code all over again for every invocation.
We shouldn't need to do it for every invocation.  Idle is special due to
the TLF_NAPPING hack.

-Scott

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

From: Alexander Graf <hidden>
Date: 2012-02-16 17:30:45

On 16.02.2012, at 18:28, Scott Wood wrote:
On 02/16/2012 11:18 AM, Alexander Graf wrote:
quoted
=20
On 16.02.2012, at 17:58, Scott Wood wrote:
=20
quoted
On 02/16/2012 04:24 AM, Alexander Graf wrote:
quoted
On 16.02.2012, at 10:26, Liu Yu [off-list ref] wrote:
quoted
+_GLOBAL(epapr_ev_idle)
+epapr_ev_idle:
+    rlwinm    r3,r1,0,0,31-THREAD_SHIFT    /* current thread_info =
*/
quoted
quoted
quoted
quoted
+    lwz    r4,TI_LOCAL_FLAGS(r3)    /* set napping bit */
+    ori    r4,r4,_TLF_NAPPING    /* so when we take an exception =
*/
quoted
quoted
quoted
quoted
+    stw    r4,TI_LOCAL_FLAGS(r3)    /* it will return to our =
caller */
quoted
quoted
quoted
quoted
+
+    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
=20
Can't you just bl into epapr_hypercall_start? You don't even have =
to save the old lr. because we never return anyways :)
quoted
quoted
=20
The interrupt will branch to LR, so no, we can't trash it or put it
anywhere else.
=20
Hrm. But we can clobber ctr, right? So how about we make the generic =
version do a bctr and then just do a small C wrapper that takes lr, =
moves it to ctr and branches to the generic one?
=20
If it's just for this, I would say don't mess with the normal hcall =
path
for the sake of idle.  If using CTR would let us get away without
creating a stack frame in call sites, maybe that would be worthwhile,
depending on what sort of hcalls we end up having.
=20
quoted
Then we don't have to replicate the hypercall code all over again for =
every invocation.
=20
We shouldn't need to do it for every invocation.  Idle is special due =
to
the TLF_NAPPING hack.
Famous last words. If it's the only case, duplication should be ok. =
Let's hope there are no others.


Alex

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

From: Scott Wood <hidden>
Date: 2012-02-16 17:36:23

On 02/16/2012 11:30 AM, Alexander Graf wrote:
On 16.02.2012, at 18:28, Scott Wood wrote:
quoted
On 02/16/2012 11:18 AM, Alexander Graf wrote:
quoted
Hrm. But we can clobber ctr, right? So how about we make the generic version do a bctr and then just do a small C wrapper that takes lr, moves it to ctr and branches to the generic one?
If it's just for this, I would say don't mess with the normal hcall path
for the sake of idle.  If using CTR would let us get away without
creating a stack frame in call sites, maybe that would be worthwhile,
depending on what sort of hcalls we end up having.
quoted
Then we don't have to replicate the hypercall code all over again for every invocation.
We shouldn't need to do it for every invocation.  Idle is special due to
the TLF_NAPPING hack.
Famous last words. If it's the only case, duplication should be ok. Let's hope there are no others.
Actually, we can't use CTR -- it's volatile in the ePAPR hypercall ABI.

-Scott

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

From: Alexander Graf <hidden>
Date: 2012-02-16 17:39:15

On 16.02.2012, at 18:36, Scott Wood wrote:
On 02/16/2012 11:30 AM, Alexander Graf wrote:
quoted
=20
On 16.02.2012, at 18:28, Scott Wood wrote:
=20
quoted
On 02/16/2012 11:18 AM, Alexander Graf wrote:
quoted
Hrm. But we can clobber ctr, right? So how about we make the =
generic version do a bctr and then just do a small C wrapper that takes =
lr, moves it to ctr and branches to the generic one?
quoted
quoted
=20
If it's just for this, I would say don't mess with the normal hcall =
path
quoted
quoted
for the sake of idle.  If using CTR would let us get away without
creating a stack frame in call sites, maybe that would be =
worthwhile,
quoted
quoted
depending on what sort of hcalls we end up having.
=20
quoted
Then we don't have to replicate the hypercall code all over again =
for every invocation.
quoted
quoted
=20
We shouldn't need to do it for every invocation.  Idle is special =
due to
quoted
quoted
the TLF_NAPPING hack.
=20
Famous last words. If it's the only case, duplication should be ok. =
Let's hope there are no others.
=20
Actually, we can't use CTR -- it's volatile in the ePAPR hypercall =
ABI.

Ugh. Alrighty, let's duplicate the hc code then.


Alex

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

From: Liu Yu-B13201 <hidden>
Date: 2012-02-17 02:14:26

-----Original Message-----
From: Alexander Graf [mailto:agraf@suse.de]
Sent: Thursday, February 16, 2012 6:20 PM
To: Liu Yu-B13201
Cc: <redacted>; <redacted>; <linuxppc-
dev@ozlabs.org>; Wood Scott-B07421; Liu Yu-B13201
Subject: Re: [PATCH v4 2/3] KVM: PPC: epapr: Add idle hcall support for
host
=20
=20
=20
On 16.02.2012, at 10:26, Liu Yu [off-list ref] wrote:
=20
quoted
And add a new flag definition in kvm_ppc_pvinfo to indicate whether
host support EV_IDLE hcall.

Signed-off-by: Liu Yu <redacted>
---
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_R0        0x4b564d21 /* "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_UNIMPLEMENTED    12
+#define HC_EV_UNIMPLEMENTED    EV_UNIMPLEMENTED

#define KVM_FEATURE_MAGIC_PAGE    1
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 =3D HC_EV_SUCCESS;
+        kvm_vcpu_block(vcpu);
+        break;
   default:
       r =3D HC_EV_UNIMPLEMENTED;
       break;
@@ -746,6 +750,10 @@ static int kvm_vm_ioctl_get_pvinfo(struct
kvm_ppc_pvinfo *pvinfo)
quoted
   pvinfo->hcall[2] =3D inst_sc;
   pvinfo->hcall[3] =3D inst_nop;

+#ifdef CONFIG_BOOKE
+    pvinfo->flags |=3D KVM_PPC_PVINFO_FLAGS_EV_IDLE; #endif
+
   return 0;
}>=20
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

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

From: Alexander Graf <hidden>
Date: 2012-02-17 02:20:24

On 17.02.2012, at 03:13, Liu Yu-B13201 wrote:
=20
=20
quoted
-----Original Message-----
From: Alexander Graf [mailto:agraf@suse.de]
Sent: Thursday, February 16, 2012 6:20 PM
To: Liu Yu-B13201
Cc: <redacted>; <redacted>; <linuxppc-
dev@ozlabs.org>; Wood Scott-B07421; Liu Yu-B13201
Subject: Re: [PATCH v4 2/3] KVM: PPC: epapr: Add idle hcall support =
for
quoted
host
=20
=20
=20
On 16.02.2012, at 10:26, Liu Yu [off-list ref] wrote:
=20
quoted
And add a new flag definition in kvm_ppc_pvinfo to indicate whether
host support EV_IDLE hcall.
=20
Signed-off-by: Liu Yu <redacted>
---
v4:
no change
=20
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(-)
=20
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 { };
=20
#define KVM_SC_MAGIC_R0        0x4b564d21 /* "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_UNIMPLEMENTED    12
+#define HC_EV_UNIMPLEMENTED    EV_UNIMPLEMENTED
=20
#define KVM_FEATURE_MAGIC_PAGE    1
=20
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)
=20
      /* Second return value is in r4 */
      break;
+    case HC_VENDOR_EPAPR | HC_EV_IDLE:
+        r =3D HC_EV_SUCCESS;
+        kvm_vcpu_block(vcpu);
+        break;
  default:
      r =3D HC_EV_UNIMPLEMENTED;
      break;
@@ -746,6 +750,10 @@ static int kvm_vm_ioctl_get_pvinfo(struct
kvm_ppc_pvinfo *pvinfo)
quoted
  pvinfo->hcall[2] =3D inst_sc;
  pvinfo->hcall[3] =3D inst_nop;
=20
+#ifdef CONFIG_BOOKE
+    pvinfo->flags |=3D KVM_PPC_PVINFO_FLAGS_EV_IDLE; #endif
+
  return 0;
}>=20
=20
Why limit it to booke? The less ifdefs our code has, the better :)
=20
The code here tells userspace that kvm support ev_idle.
But I'm not sure if the ev_idle code works for other platforms.
=20
So I think we should keep the ifdef until other platform test the code =
:)

But the implementation is in generic code and is not #ifdef'ed, so a =
guest could still call it just fine. It looks simple enough to work =
without major testing on different platforms, so I'd say just expose it =
and be done :)


Alex

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

From: Liu Yu-B13201 <hidden>
Date: 2012-02-17 10:03:32

DQoNCj4gLS0tLS1PcmlnaW5hbCBNZXNzYWdlLS0tLS0NCj4gRnJvbTogV29vZCBTY290dC1CMDc0
MjENCj4gU2VudDogRnJpZGF5LCBGZWJydWFyeSAxNywgMjAxMiAxOjEzIEFNDQo+IFRvOiBMaXUg
WXUtQjEzMjAxDQo+IENjOiBhZ3JhZkBzdXNlLmRlOyBrdm0tcHBjQHZnZXIua2VybmVsLm9yZzsg
a3ZtQHZnZXIua2VybmVsLm9yZzsNCj4gbGludXhwcGMtZGV2QG96bGFicy5vcmc7IFdvb2QgU2Nv
dHQtQjA3NDIxDQo+IFN1YmplY3Q6IFJlOiBbUEFUQ0ggdjQgMS8zXSBLVk06IFBQQzogZXBhcHI6
IEZhY3RvciBvdXQgdGhlIGVwYXByIGluaXQNCj4gDQo+IE9uIDAyLzE2LzIwMTIgMDM6MjYgQU0s
IExpdSBZdSB3cm90ZToNCj4gPiBmcm9tIHRoZSBrdm0gZ3Vlc3QgcGFyYXZpcnQgaW5pdCBjb2Rl
Lg0KPiA+DQo+ID4gU2lnbmVkLW9mZi1ieTogTGl1IFl1IDx5dS5saXVAZnJlZXNjYWxlLmNvbT4N
Cj4gPiAtLS0NCj4gPiB2NDoNCj4gPiAxLiBjb2RlIGNsZWFudXANCj4gPiAyLiBtb3ZlIGt2bV9o
eXBlcmNhbGxfc3RhcnQoKSB0byBlcGFwcl9oeXBlcmNhbGxfc3RhcnQoKQ0KPiA+DQo+ID4gIGFy
Y2gvcG93ZXJwYy9LY29uZmlnICAgICAgICAgICAgICAgICAgICB8ICAgIDQgKysNCj4gPiAgYXJj
aC9wb3dlcnBjL2luY2x1ZGUvYXNtL2VwYXByX2hjYWxscy5oIHwgICAgMiArDQo+ID4gIGFyY2gv
cG93ZXJwYy9rZXJuZWwvTWFrZWZpbGUgICAgICAgICAgICB8ICAgIDEgKw0KPiA+ICBhcmNoL3Bv
d2VycGMva2VybmVsL2VwYXByLlMgICAgICAgICAgICAgfCAgIDI1ICsrKysrKysrKysrKysrKysN
Cj4gPiAgYXJjaC9wb3dlcnBjL2tlcm5lbC9lcGFwcl9wYXJhLmMgICAgICAgIHwgICA0OQ0KPiAr
KysrKysrKysrKysrKysrKysrKysrKysrKysrKysrDQo+ID4gIGFyY2gvcG93ZXJwYy9rZXJuZWwv
a3ZtLmMgICAgICAgICAgICAgICB8ICAgMjggKystLS0tLS0tLS0tLS0tLS0tDQo+ID4gIGFyY2gv
cG93ZXJwYy9rZXJuZWwva3ZtX2VtdWwuUyAgICAgICAgICB8ICAgMTAgLS0tLS0tDQo+ID4gIGFy
Y2gvcG93ZXJwYy9rdm0vS2NvbmZpZyAgICAgICAgICAgICAgICB8ICAgIDEgKw0KPiA+ICA4IGZp
bGVzIGNoYW5nZWQsIDg1IGluc2VydGlvbnMoKyksIDM1IGRlbGV0aW9ucygtKSAgY3JlYXRlIG1v
ZGUNCj4gPiAxMDA2NDQgYXJjaC9wb3dlcnBjL2tlcm5lbC9lcGFwci5TICBjcmVhdGUgbW9kZSAx
MDA2NDQNCj4gPiBhcmNoL3Bvd2VycGMva2VybmVsL2VwYXByX3BhcmEuYw0KPiANCj4gVGhlIGNv
bW1lbnQgYWJvdXQgc3BlbGxpbmcgb3V0ICJwYXJhdmlydCIgd2Fzbm4ndCBtZWFudCB0byBiZSBy
ZXN0cmljdGVkDQo+IHRvIHRoZSBrY29uZmlnIHN5bWJvbC4gIFRoZXJlIGFyZSBsb3RzIG9mIHdv
cmRzIHRoYXQgYmVnaW4gd2l0aCAicGFyYSIsDQo+IGFuZCBlUEFQUiBpc24ndCBqdXN0IGFib3V0
IHZpcnR1YWxpemF0aW9uLg0KDQpXaGF0IGRvIHlvdSBtZWFuPyBEbyB5b3Ugc3VnZ2VzdCB0aGF0
IHdlIHNob3VsZCBuYW1lIGl0IGVwYXByX3BhcmF2aXJ0LmM/DQoNClRoYW5rcywNCll1DQo=

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

From: Scott Wood <hidden>
Date: 2012-02-17 18:59:09

On 02/17/2012 04:03 AM, Liu Yu-B13201 wrote:
quoted
-----Original Message-----
From: Wood Scott-B07421
Sent: Friday, February 17, 2012 1:13 AM
To: Liu Yu-B13201
Cc: agraf@suse.de; kvm-ppc@vger.kernel.org; kvm@vger.kernel.org;
linuxppc-dev@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:
quoted
from the kvm guest paravirt init code.

Signed-off-by: Liu Yu <redacted>
---
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
+++++++++++++++++++++++++++++++
quoted
 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?
Yes, and likewise with variables and functions and such (at least
anything that is exposed outside a single file).

-Scott
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help