diff mbox series

[v6,11/11] x86/hyperv: setup VP assist page

Message ID 20200131174930.31045-12-liuwe@microsoft.com (mailing list archive)
State Superseded
Headers show
Series More Hyper-V infrastructures | expand

Commit Message

Wei Liu Jan. 31, 2020, 5:49 p.m. UTC
VP assist page is rather important as we need to toggle some bits in it
for efficient nested virtualisation.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
---
v6:
1. Use hv_vp_assist_page_msr
2. Make code shorter
3. Preserve rsvdP fields

v5:
1. Deal with error properly instead of always panicking
2. Swap percpu variables declarations' location

v4:
1. Use private.h
2. Prevent leak

v3:
1. Use xenheap page
2. Drop set_vp_assist

v2:
1. Use HV_HYP_PAGE_SHIFT instead
---
 xen/arch/x86/guest/hyperv/hyperv.c  | 37 ++++++++++++++++++++++++++++-
 xen/arch/x86/guest/hyperv/private.h |  1 +
 2 files changed, 37 insertions(+), 1 deletion(-)

Comments

Durrant, Paul Feb. 3, 2020, 11:25 a.m. UTC | #1
> -----Original Message-----
> From: Wei Liu <wei.liu.xen@gmail.com> On Behalf Of Wei Liu
> Sent: 31 January 2020 17:50
> To: Xen Development List <xen-devel@lists.xenproject.org>
> Cc: Durrant, Paul <pdurrant@amazon.co.uk>; Michael Kelley
> <mikelley@microsoft.com>; Wei Liu <liuwe@microsoft.com>; Wei Liu
> <wl@xen.org>; Jan Beulich <jbeulich@suse.com>; Andrew Cooper
> <andrew.cooper3@citrix.com>; Roger Pau Monné <roger.pau@citrix.com>
> Subject: [PATCH v6 11/11] x86/hyperv: setup VP assist page
> 
> VP assist page is rather important as we need to toggle some bits in it
> for efficient nested virtualisation.
> 
> Signed-off-by: Wei Liu <liuwe@microsoft.com>

Reviewed-by: Paul Durrant <pdurrant@amazon.com>

> ---
> v6:
> 1. Use hv_vp_assist_page_msr
> 2. Make code shorter
> 3. Preserve rsvdP fields
> 
> v5:
> 1. Deal with error properly instead of always panicking
> 2. Swap percpu variables declarations' location
> 
> v4:
> 1. Use private.h
> 2. Prevent leak
> 
> v3:
> 1. Use xenheap page
> 2. Drop set_vp_assist
> 
> v2:
> 1. Use HV_HYP_PAGE_SHIFT instead
> ---
>  xen/arch/x86/guest/hyperv/hyperv.c  | 37 ++++++++++++++++++++++++++++-
>  xen/arch/x86/guest/hyperv/private.h |  1 +
>  2 files changed, 37 insertions(+), 1 deletion(-)
> 
> diff --git a/xen/arch/x86/guest/hyperv/hyperv.c
> b/xen/arch/x86/guest/hyperv/hyperv.c
> index 6dac3bfceb..75fb329d4d 100644
> --- a/xen/arch/x86/guest/hyperv/hyperv.c
> +++ b/xen/arch/x86/guest/hyperv/hyperv.c
> @@ -31,6 +31,7 @@
> 
>  struct ms_hyperv_info __read_mostly ms_hyperv;
>  DEFINE_PER_CPU_READ_MOSTLY(void *, hv_input_page);
> +DEFINE_PER_CPU_READ_MOSTLY(void *, hv_vp_assist);
>  DEFINE_PER_CPU_READ_MOSTLY(unsigned int, hv_vp_index);
> 
>  static uint64_t generate_guest_id(void)
> @@ -155,17 +156,51 @@ static int setup_hypercall_pcpu_arg(void)
>      return 0;
>  }
> 
> +static int setup_vp_assist(void)
> +{
> +    union hv_vp_assist_page_msr msr;
> +
> +    if ( !this_cpu(hv_vp_assist) )
> +    {
> +        this_cpu(hv_vp_assist) = alloc_xenheap_page();
> +        if ( !this_cpu(hv_vp_assist) )
> +        {
> +            printk("CPU%u: Failed to allocate vp_assist page\n",
> +                   smp_processor_id());
> +            return -ENOMEM;
> +        }
> +
> +        clear_page(this_cpu(hv_vp_assist));
> +    }
> +
> +    rdmsrl(HV_X64_MSR_VP_ASSIST_PAGE, msr.raw);
> +    msr.pfn = virt_to_mfn(this_cpu(hv_vp_assist));
> +    msr.enabled = 1;
> +    wrmsrl(HV_X64_MSR_VP_ASSIST_PAGE, msr.raw);
> +
> +    return 0;
> +}
> +
>  static void __init setup(void)
>  {
>      setup_hypercall_page();
> 
>      if ( setup_hypercall_pcpu_arg() )
>          panic("Hyper-V hypercall percpu arg setup failed\n");
> +
> +    if ( setup_vp_assist() )
> +        panic("VP assist page setup failed\n");
>  }
> 
>  static int ap_setup(void)
>  {
> -    return setup_hypercall_pcpu_arg();
> +    int rc;
> +
> +    rc = setup_hypercall_pcpu_arg();
> +    if ( rc )
> +        return rc;
> +
> +    return setup_vp_assist();
>  }
> 
>  static void __init e820_fixup(struct e820map *e820)
> diff --git a/xen/arch/x86/guest/hyperv/private.h
> b/xen/arch/x86/guest/hyperv/private.h
> index d1765d4f23..956eff831f 100644
> --- a/xen/arch/x86/guest/hyperv/private.h
> +++ b/xen/arch/x86/guest/hyperv/private.h
> @@ -25,6 +25,7 @@
>  #include <xen/percpu.h>
> 
>  DECLARE_PER_CPU(void *, hv_input_page);
> +DECLARE_PER_CPU(void *, hv_vp_assist);
>  DECLARE_PER_CPU(unsigned int, hv_vp_index);
> 
>  #endif /* __XEN_HYPERV_PRIVIATE_H__  */
> --
> 2.20.1
Roger Pau Monné Feb. 3, 2020, 2:25 p.m. UTC | #2
On Fri, Jan 31, 2020 at 05:49:30PM +0000, Wei Liu wrote:
> VP assist page is rather important as we need to toggle some bits in it
> for efficient nested virtualisation.
> 
> Signed-off-by: Wei Liu <liuwe@microsoft.com>

Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>

Thanks, Roger.
diff mbox series

Patch

diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c
index 6dac3bfceb..75fb329d4d 100644
--- a/xen/arch/x86/guest/hyperv/hyperv.c
+++ b/xen/arch/x86/guest/hyperv/hyperv.c
@@ -31,6 +31,7 @@ 
 
 struct ms_hyperv_info __read_mostly ms_hyperv;
 DEFINE_PER_CPU_READ_MOSTLY(void *, hv_input_page);
+DEFINE_PER_CPU_READ_MOSTLY(void *, hv_vp_assist);
 DEFINE_PER_CPU_READ_MOSTLY(unsigned int, hv_vp_index);
 
 static uint64_t generate_guest_id(void)
@@ -155,17 +156,51 @@  static int setup_hypercall_pcpu_arg(void)
     return 0;
 }
 
+static int setup_vp_assist(void)
+{
+    union hv_vp_assist_page_msr msr;
+
+    if ( !this_cpu(hv_vp_assist) )
+    {
+        this_cpu(hv_vp_assist) = alloc_xenheap_page();
+        if ( !this_cpu(hv_vp_assist) )
+        {
+            printk("CPU%u: Failed to allocate vp_assist page\n",
+                   smp_processor_id());
+            return -ENOMEM;
+        }
+
+        clear_page(this_cpu(hv_vp_assist));
+    }
+
+    rdmsrl(HV_X64_MSR_VP_ASSIST_PAGE, msr.raw);
+    msr.pfn = virt_to_mfn(this_cpu(hv_vp_assist));
+    msr.enabled = 1;
+    wrmsrl(HV_X64_MSR_VP_ASSIST_PAGE, msr.raw);
+
+    return 0;
+}
+
 static void __init setup(void)
 {
     setup_hypercall_page();
 
     if ( setup_hypercall_pcpu_arg() )
         panic("Hyper-V hypercall percpu arg setup failed\n");
+
+    if ( setup_vp_assist() )
+        panic("VP assist page setup failed\n");
 }
 
 static int ap_setup(void)
 {
-    return setup_hypercall_pcpu_arg();
+    int rc;
+
+    rc = setup_hypercall_pcpu_arg();
+    if ( rc )
+        return rc;
+
+    return setup_vp_assist();
 }
 
 static void __init e820_fixup(struct e820map *e820)
diff --git a/xen/arch/x86/guest/hyperv/private.h b/xen/arch/x86/guest/hyperv/private.h
index d1765d4f23..956eff831f 100644
--- a/xen/arch/x86/guest/hyperv/private.h
+++ b/xen/arch/x86/guest/hyperv/private.h
@@ -25,6 +25,7 @@ 
 #include <xen/percpu.h>
 
 DECLARE_PER_CPU(void *, hv_input_page);
+DECLARE_PER_CPU(void *, hv_vp_assist);
 DECLARE_PER_CPU(unsigned int, hv_vp_index);
 
 #endif /* __XEN_HYPERV_PRIVIATE_H__  */