[v5,6/8] x86: switch xen guest implementation to use hypervisor framework
diff mbox series

Message ID 20191130115737.15752-7-liuwe@microsoft.com
State New
Headers show
Series
  • Port Xen to Hyper-V
Related show

Commit Message

Wei Liu Nov. 30, 2019, 11:57 a.m. UTC
Signed-off-by: Wei Liu <liuwe@microsoft.com>
---
Changes in v5:
1. xen_probe -> xg_probe
2. Drop xen_ prefix for private functions
---
 xen/arch/x86/guest/hypervisor.c   | 27 +++++++++++++++++-
 xen/arch/x86/guest/xen/pvh-boot.c |  2 +-
 xen/arch/x86/guest/xen/xen.c      | 47 ++++++++++++++++++-------------
 xen/arch/x86/setup.c              |  2 +-
 xen/include/asm-x86/guest/xen.h   |  5 ++--
 5 files changed, 59 insertions(+), 24 deletions(-)

Comments

Jan Beulich Dec. 3, 2019, 2:52 p.m. UTC | #1
On 30.11.2019 12:57, Wei Liu wrote:
> Signed-off-by: Wei Liu <liuwe@microsoft.com>

Acked-by: Jan Beulich <jbeulich@suse.com>
again with one more remark:

> @@ -326,6 +310,31 @@ void hypervisor_resume(void)
>          pv_console_init();
>  }
>  
> +static const struct hypervisor_ops xg_ops = {

Along with other static variable not having an xg_ prefix,
this one could lose its one, too. But I'm not going to make
this a requirement.

Jan
Wei Liu Dec. 3, 2019, 4:29 p.m. UTC | #2
On Tue, Dec 03, 2019 at 03:52:47PM +0100, Jan Beulich wrote:
> On 30.11.2019 12:57, Wei Liu wrote:
> > Signed-off-by: Wei Liu <liuwe@microsoft.com>
> 
> Acked-by: Jan Beulich <jbeulich@suse.com>
> again with one more remark:
> 
> > @@ -326,6 +310,31 @@ void hypervisor_resume(void)
> >          pv_console_init();
> >  }
> >  
> > +static const struct hypervisor_ops xg_ops = {
> 
> Along with other static variable not having an xg_ prefix,
> this one could lose its one, too. But I'm not going to make
> this a requirement.

I will drop the xg_ prefix locally per your comment here.

Wei.

> 
> Jan

Patch
diff mbox series

diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c
index c35c610d01..6cd86d0c02 100644
--- a/xen/arch/x86/guest/hypervisor.c
+++ b/xen/arch/x86/guest/hypervisor.c
@@ -22,18 +22,43 @@ 
 #include <xen/types.h>
 
 #include <asm/cache.h>
-#include <asm/guest/hypervisor.h>
+#include <asm/guest.h>
 
 static const struct hypervisor_ops __read_mostly *ops;
 
 const char *__init hypervisor_probe(void)
 {
+    if ( !cpu_has_hypervisor )
+        return NULL;
+
+    if ( ops )
+        return ops->name;
+
+    ops = xg_probe();
     if ( ops )
         return ops->name;
 
     return NULL;
 }
 
+void __init hypervisor_setup(void)
+{
+    if ( ops && ops->setup )
+        ops->setup();
+}
+
+void hypervisor_ap_setup(void)
+{
+    if ( ops && ops->ap_setup )
+        ops->ap_setup();
+}
+
+void hypervisor_resume(void)
+{
+    if ( ops && ops->resume )
+        ops->resume();
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/xen/arch/x86/guest/xen/pvh-boot.c b/xen/arch/x86/guest/xen/pvh-boot.c
index ca8e156f7d..498625eae0 100644
--- a/xen/arch/x86/guest/xen/pvh-boot.c
+++ b/xen/arch/x86/guest/xen/pvh-boot.c
@@ -103,7 +103,7 @@  void __init pvh_init(multiboot_info_t **mbi, module_t **mod)
 {
     convert_pvh_info(mbi, mod);
 
-    probe_hypervisor();
+    hypervisor_probe();
     ASSERT(xen_guest);
 
     get_memory_map();
diff --git a/xen/arch/x86/guest/xen/xen.c b/xen/arch/x86/guest/xen/xen.c
index 0f5b5267c5..10daa043e4 100644
--- a/xen/arch/x86/guest/xen/xen.c
+++ b/xen/arch/x86/guest/xen/xen.c
@@ -67,22 +67,6 @@  static void __init find_xen_leaves(void)
     }
 }
 
-void __init probe_hypervisor(void)
-{
-    if ( xen_guest || !cpu_has_hypervisor )
-        return;
-
-    find_xen_leaves();
-
-    if ( !xen_cpuid_base )
-        return;
-
-    /* Fill the hypercall page. */
-    wrmsrl(cpuid_ebx(xen_cpuid_base + 2), __pa(hypercall_page));
-
-    xen_guest = true;
-}
-
 static void map_shared_info(void)
 {
     mfn_t mfn;
@@ -245,7 +229,7 @@  static void init_evtchn(void)
     }
 }
 
-void __init hypervisor_setup(void)
+static void __init setup(void)
 {
     init_memmap();
 
@@ -273,7 +257,7 @@  void __init hypervisor_setup(void)
     init_evtchn();
 }
 
-void hypervisor_ap_setup(void)
+static void ap_setup(void)
 {
     set_vcpu_id();
     map_vcpuinfo();
@@ -303,7 +287,7 @@  static void ap_resume(void *unused)
     init_evtchn();
 }
 
-void hypervisor_resume(void)
+static void resume(void)
 {
     /* Reset shared info page. */
     map_shared_info();
@@ -326,6 +310,31 @@  void hypervisor_resume(void)
         pv_console_init();
 }
 
+static const struct hypervisor_ops xg_ops = {
+    .name = "Xen",
+    .setup = setup,
+    .ap_setup = ap_setup,
+    .resume = resume,
+};
+
+const struct hypervisor_ops *__init xg_probe(void)
+{
+    if ( xen_guest )
+        return &xg_ops;
+
+    find_xen_leaves();
+
+    if ( !xen_cpuid_base )
+        return NULL;
+
+    /* Fill the hypercall page. */
+    wrmsrl(cpuid_ebx(xen_cpuid_base + 2), __pa(hypercall_page));
+
+    xen_guest = true;
+
+    return &xg_ops;
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
index 7d27f36053..a6b354c29f 100644
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -763,7 +763,7 @@  void __init noreturn __start_xen(unsigned long mbi_p)
      * allocing any xenheap structures wanted in lower memory. */
     kexec_early_calculations();
 
-    probe_hypervisor();
+    hypervisor_probe();
 
     parse_video_info();
 
diff --git a/xen/include/asm-x86/guest/xen.h b/xen/include/asm-x86/guest/xen.h
index 01dc3ee6f6..2042a9a0c2 100644
--- a/xen/include/asm-x86/guest/xen.h
+++ b/xen/include/asm-x86/guest/xen.h
@@ -23,6 +23,7 @@ 
 
 #include <asm/e820.h>
 #include <asm/fixmap.h>
+#include <asm/guest/hypervisor.h>
 
 #define XEN_shared_info ((struct shared_info *)fix_to_virt(FIX_XEN_SHARED_INFO))
 
@@ -32,7 +33,7 @@  extern bool xen_guest;
 extern bool pv_console;
 extern uint32_t xen_cpuid_base;
 
-void probe_hypervisor(void);
+const struct hypervisor_ops *xg_probe(void);
 int xg_alloc_unused_page(mfn_t *mfn);
 int xg_free_unused_page(mfn_t mfn);
 
@@ -44,7 +45,7 @@  DECLARE_PER_CPU(struct vcpu_info *, vcpu_info);
 #define xen_guest 0
 #define pv_console 0
 
-static inline void probe_hypervisor(void) {}
+static inline const struct hypervisor_ops *xg_probe(void) { return NULL; }
 
 #endif /* CONFIG_XEN_GUEST */
 #endif /* __X86_GUEST_XEN_H__ */