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

login
register
mail settings
Submitter Liu Yu-B13201
Date Feb. 16, 2012, 9:26 a.m.
Message ID <1329384365-4028-1-git-send-email-yu.liu@freescale.com>
Download mbox | patch
Permalink /patch/141541/
State New
Headers show

Comments

Liu Yu-B13201 - Feb. 16, 2012, 9:26 a.m.
from the kvm guest paravirt init code.

Signed-off-by: Liu Yu <yu.liu@freescale.com>
---
v4:
1. code cleanup
2. move kvm_hypercall_start() to epapr_hypercall_start()

 arch/powerpc/Kconfig                    |    4 ++
 arch/powerpc/include/asm/epapr_hcalls.h |    2 +
 arch/powerpc/kernel/Makefile            |    1 +
 arch/powerpc/kernel/epapr.S             |   25 ++++++++++++++++
 arch/powerpc/kernel/epapr_para.c        |   49 +++++++++++++++++++++++++++++++
 arch/powerpc/kernel/kvm.c               |   28 ++----------------
 arch/powerpc/kernel/kvm_emul.S          |   10 ------
 arch/powerpc/kvm/Kconfig                |    1 +
 8 files changed, 85 insertions(+), 35 deletions(-)
 create mode 100644 arch/powerpc/kernel/epapr.S
 create mode 100644 arch/powerpc/kernel/epapr_para.c
Alexander Graf - Feb. 16, 2012, 10:17 a.m.
On 16.02.2012, at 10:26, Liu Yu <yu.liu@freescale.com> wrote:

> from the kvm guest paravirt init code.
> 
> Signed-off-by: Liu Yu <yu.liu@freescale.com>
> ---
> v4:
> 1. code cleanup
> 2. move kvm_hypercall_start() to epapr_hypercall_start()
> 
> arch/powerpc/Kconfig                    |    4 ++
> arch/powerpc/include/asm/epapr_hcalls.h |    2 +
> arch/powerpc/kernel/Makefile            |    1 +
> arch/powerpc/kernel/epapr.S             |   25 ++++++++++++++++
> arch/powerpc/kernel/epapr_para.c        |   49 +++++++++++++++++++++++++++++++
> arch/powerpc/kernel/kvm.c               |   28 ++----------------
> arch/powerpc/kernel/kvm_emul.S          |   10 ------
> arch/powerpc/kvm/Kconfig                |    1 +
> 8 files changed, 85 insertions(+), 35 deletions(-)
> create mode 100644 arch/powerpc/kernel/epapr.S
> create mode 100644 arch/powerpc/kernel/epapr_para.c
> 
> 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++)

So if the dt passes in less than 4 ops, you bail out, and for more you overwrite the buffer? Not good :)

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

As you can see, the previous code allowed for less than 4 instructions, but not more.

Alex

> -        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
> 
> 
> --
> 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
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Scott Wood - Feb. 16, 2012, 5:13 p.m.
On 02/16/2012 03:26 AM, Liu Yu wrote:
> from the kvm guest paravirt init code.
> 
> Signed-off-by: Liu Yu <yu.liu@freescale.com>
> ---
> v4:
> 1. code cleanup
> 2. move kvm_hypercall_start() to epapr_hypercall_start()
> 
>  arch/powerpc/Kconfig                    |    4 ++
>  arch/powerpc/include/asm/epapr_hcalls.h |    2 +
>  arch/powerpc/kernel/Makefile            |    1 +
>  arch/powerpc/kernel/epapr.S             |   25 ++++++++++++++++
>  arch/powerpc/kernel/epapr_para.c        |   49 +++++++++++++++++++++++++++++++
>  arch/powerpc/kernel/kvm.c               |   28 ++----------------
>  arch/powerpc/kernel/kvm_emul.S          |   10 ------
>  arch/powerpc/kvm/Kconfig                |    1 +
>  8 files changed, 85 insertions(+), 35 deletions(-)
>  create mode 100644 arch/powerpc/kernel/epapr.S
>  create mode 100644 arch/powerpc/kernel/epapr_para.c

The comment about spelling out "paravirt" wasnn't meant to be restricted
to the kconfig symbol.  There are lots of words that begin with "para",
and ePAPR isn't just about virtualization.

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

> 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

--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Liu Yu-B13201 - Feb. 17, 2012, 10:03 a.m.
> -----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:

> > from the kvm guest paravirt init code.

> >

> > Signed-off-by: Liu Yu <yu.liu@freescale.com>

> > ---

> > v4:

> > 1. code cleanup

> > 2. move kvm_hypercall_start() to epapr_hypercall_start()

> >

> >  arch/powerpc/Kconfig                    |    4 ++

> >  arch/powerpc/include/asm/epapr_hcalls.h |    2 +

> >  arch/powerpc/kernel/Makefile            |    1 +

> >  arch/powerpc/kernel/epapr.S             |   25 ++++++++++++++++

> >  arch/powerpc/kernel/epapr_para.c        |   49

> +++++++++++++++++++++++++++++++

> >  arch/powerpc/kernel/kvm.c               |   28 ++----------------

> >  arch/powerpc/kernel/kvm_emul.S          |   10 ------

> >  arch/powerpc/kvm/Kconfig                |    1 +

> >  8 files changed, 85 insertions(+), 35 deletions(-)  create mode

> > 100644 arch/powerpc/kernel/epapr.S  create mode 100644

> > arch/powerpc/kernel/epapr_para.c

> 

> The comment about spelling out "paravirt" wasnn't meant to be restricted

> to the kconfig symbol.  There are lots of words that begin with "para",

> and ePAPR isn't just about virtualization.


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

Thanks,
Yu
Scott Wood - Feb. 17, 2012, 6:58 p.m.
On 02/17/2012 04:03 AM, Liu Yu-B13201 wrote:
> 
> 
>> -----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:
>>> from the kvm guest paravirt init code.
>>>
>>> Signed-off-by: Liu Yu <yu.liu@freescale.com>
>>> ---
>>> v4:
>>> 1. code cleanup
>>> 2. move kvm_hypercall_start() to epapr_hypercall_start()
>>>
>>>  arch/powerpc/Kconfig                    |    4 ++
>>>  arch/powerpc/include/asm/epapr_hcalls.h |    2 +
>>>  arch/powerpc/kernel/Makefile            |    1 +
>>>  arch/powerpc/kernel/epapr.S             |   25 ++++++++++++++++
>>>  arch/powerpc/kernel/epapr_para.c        |   49
>> +++++++++++++++++++++++++++++++
>>>  arch/powerpc/kernel/kvm.c               |   28 ++----------------
>>>  arch/powerpc/kernel/kvm_emul.S          |   10 ------
>>>  arch/powerpc/kvm/Kconfig                |    1 +
>>>  8 files changed, 85 insertions(+), 35 deletions(-)  create mode
>>> 100644 arch/powerpc/kernel/epapr.S  create mode 100644
>>> arch/powerpc/kernel/epapr_para.c
>>
>> The comment about spelling out "paravirt" wasnn't meant to be restricted
>> to the kconfig symbol.  There are lots of words that begin with "para",
>> and ePAPR isn't just about virtualization.
> 
> What do you mean? Do you suggest that we should name it epapr_paravirt.c?

Yes, and likewise with variables and functions and such (at least
anything that is exposed outside a single file).

-Scott

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

Patch

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