diff mbox series

[v6,04/11] x86/hypervisor: provide hypervisor_fixup_e820

Message ID 20200131174930.31045-5-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
And implement the hook for Xen guest.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
---
 xen/arch/x86/e820.c                    | 4 ++--
 xen/arch/x86/guest/hypervisor.c        | 6 ++++++
 xen/arch/x86/guest/xen/xen.c           | 7 +++++++
 xen/include/asm-x86/guest/hypervisor.h | 6 ++++++
 4 files changed, 21 insertions(+), 2 deletions(-)

Comments

Jan Beulich Feb. 3, 2020, 1:19 p.m. UTC | #1
On 31.01.2020 18:49, Wei Liu wrote:
> And implement the hook for Xen guest.
> 
> Signed-off-by: Wei Liu <liuwe@microsoft.com>

Reviewed-by: Jan Beulich <jbeulich@suse.com>
Roger Pau Monné Feb. 3, 2020, 2:32 p.m. UTC | #2
On Fri, Jan 31, 2020 at 05:49:23PM +0000, Wei Liu wrote:
> And implement the hook for Xen guest.
> 
> Signed-off-by: Wei Liu <liuwe@microsoft.com>
> ---
>  xen/arch/x86/e820.c                    | 4 ++--
>  xen/arch/x86/guest/hypervisor.c        | 6 ++++++
>  xen/arch/x86/guest/xen/xen.c           | 7 +++++++
>  xen/include/asm-x86/guest/hypervisor.h | 6 ++++++
>  4 files changed, 21 insertions(+), 2 deletions(-)
> 
> diff --git a/xen/arch/x86/e820.c b/xen/arch/x86/e820.c
> index 3892c9cfb7..2219c63861 100644
> --- a/xen/arch/x86/e820.c
> +++ b/xen/arch/x86/e820.c
> @@ -690,8 +690,8 @@ unsigned long __init init_e820(const char *str, struct e820map *raw)
>  
>      machine_specific_memory_setup(raw);
>  
> -    if ( pv_shim )
> -        pv_shim_fixup_e820(&e820);
> +    if ( cpu_has_hypervisor )
> +        hypervisor_e820_fixup(&e820);
>  
>      printk("%s RAM map:\n", str);
>      print_e820_memory_map(e820.map, e820.nr_map);
> diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c
> index e72c92ffdf..5fd433c8d4 100644
> --- a/xen/arch/x86/guest/hypervisor.c
> +++ b/xen/arch/x86/guest/hypervisor.c
> @@ -66,6 +66,12 @@ void hypervisor_resume(void)
>          ops->resume();
>  }
>  
> +void __init hypervisor_e820_fixup(struct e820map *e820)
> +{
> +    if ( ops && ops->e820_fixup )
> +        ops->e820_fixup(e820);
> +}
> +
>  /*
>   * Local variables:
>   * mode: C
> diff --git a/xen/arch/x86/guest/xen/xen.c b/xen/arch/x86/guest/xen/xen.c
> index d50f86bae7..45e54dfbba 100644
> --- a/xen/arch/x86/guest/xen/xen.c
> +++ b/xen/arch/x86/guest/xen/xen.c
> @@ -316,11 +316,18 @@ static void resume(void)
>          pv_console_init();
>  }
>  
> +static void __init e820_fixup(struct e820map *e820)
> +{
> +    if ( pv_shim )
> +        pv_shim_fixup_e820(e820);
> +}
> +
>  static const struct hypervisor_ops ops = {
>      .name = "Xen",
>      .setup = setup,
>      .ap_setup = ap_setup,
>      .resume = resume,
> +    .e820_fixup = e820_fixup,
>  };
>  
>  const struct hypervisor_ops *__init xg_probe(void)
> diff --git a/xen/include/asm-x86/guest/hypervisor.h b/xen/include/asm-x86/guest/hypervisor.h
> index b503854c5b..b66cb28333 100644
> --- a/xen/include/asm-x86/guest/hypervisor.h
> +++ b/xen/include/asm-x86/guest/hypervisor.h
> @@ -19,6 +19,8 @@
>  #ifndef __X86_HYPERVISOR_H__
>  #define __X86_HYPERVISOR_H__
>  
> +#include <asm/e820.h>
> +
>  struct hypervisor_ops {
>      /* Name of the hypervisor */
>      const char *name;
> @@ -28,6 +30,8 @@ struct hypervisor_ops {
>      int (*ap_setup)(void);
>      /* Resume from suspension */
>      void (*resume)(void);
> +    /* Fix up e820 map */
> +    void (*e820_fixup)(struct e820map *e820);
>  };
>  
>  #ifdef CONFIG_GUEST
> @@ -36,6 +40,7 @@ const char *hypervisor_probe(void);
>  void hypervisor_setup(void);
>  int hypervisor_ap_setup(void);
>  void hypervisor_resume(void);
> +void hypervisor_e820_fixup(struct e820map *e820);
>  
>  #else
>  
> @@ -46,6 +51,7 @@ static inline const char *hypervisor_probe(void) { return NULL; }
>  static inline void hypervisor_setup(void) { ASSERT_UNREACHABLE(); }
>  static inline int hypervisor_ap_setup(void) { ASSERT_UNREACHABLE(); return 0; }
>  static inline void hypervisor_resume(void) { ASSERT_UNREACHABLE(); }
> +static inline void hypervisor_e820_fixup(struct e820map *e820) { ASSERT_UNREACHABLE(); }

Are you sure the assert here is fine?

Consider Xen running nested on another hypervisor, and built without
CONFIG_GUEST enabled, I think the above assert would trigger.

Thanks, Roger.
Wei Liu Feb. 3, 2020, 2:39 p.m. UTC | #3
On Mon, Feb 03, 2020 at 03:32:01PM +0100, Roger Pau Monné wrote:
[...]
> >  
> >  #else
> >  
> > @@ -46,6 +51,7 @@ static inline const char *hypervisor_probe(void) { return NULL; }
> >  static inline void hypervisor_setup(void) { ASSERT_UNREACHABLE(); }
> >  static inline int hypervisor_ap_setup(void) { ASSERT_UNREACHABLE(); return 0; }
> >  static inline void hypervisor_resume(void) { ASSERT_UNREACHABLE(); }
> > +static inline void hypervisor_e820_fixup(struct e820map *e820) { ASSERT_UNREACHABLE(); }
> 
> Are you sure the assert here is fine?
> 
> Consider Xen running nested on another hypervisor, and built without
> CONFIG_GUEST enabled, I think the above assert would trigger.

Hmm... yes, this assertion should be dropped. Thanks.

Wei.

> 
> Thanks, Roger.
diff mbox series

Patch

diff --git a/xen/arch/x86/e820.c b/xen/arch/x86/e820.c
index 3892c9cfb7..2219c63861 100644
--- a/xen/arch/x86/e820.c
+++ b/xen/arch/x86/e820.c
@@ -690,8 +690,8 @@  unsigned long __init init_e820(const char *str, struct e820map *raw)
 
     machine_specific_memory_setup(raw);
 
-    if ( pv_shim )
-        pv_shim_fixup_e820(&e820);
+    if ( cpu_has_hypervisor )
+        hypervisor_e820_fixup(&e820);
 
     printk("%s RAM map:\n", str);
     print_e820_memory_map(e820.map, e820.nr_map);
diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c
index e72c92ffdf..5fd433c8d4 100644
--- a/xen/arch/x86/guest/hypervisor.c
+++ b/xen/arch/x86/guest/hypervisor.c
@@ -66,6 +66,12 @@  void hypervisor_resume(void)
         ops->resume();
 }
 
+void __init hypervisor_e820_fixup(struct e820map *e820)
+{
+    if ( ops && ops->e820_fixup )
+        ops->e820_fixup(e820);
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/xen/arch/x86/guest/xen/xen.c b/xen/arch/x86/guest/xen/xen.c
index d50f86bae7..45e54dfbba 100644
--- a/xen/arch/x86/guest/xen/xen.c
+++ b/xen/arch/x86/guest/xen/xen.c
@@ -316,11 +316,18 @@  static void resume(void)
         pv_console_init();
 }
 
+static void __init e820_fixup(struct e820map *e820)
+{
+    if ( pv_shim )
+        pv_shim_fixup_e820(e820);
+}
+
 static const struct hypervisor_ops ops = {
     .name = "Xen",
     .setup = setup,
     .ap_setup = ap_setup,
     .resume = resume,
+    .e820_fixup = e820_fixup,
 };
 
 const struct hypervisor_ops *__init xg_probe(void)
diff --git a/xen/include/asm-x86/guest/hypervisor.h b/xen/include/asm-x86/guest/hypervisor.h
index b503854c5b..b66cb28333 100644
--- a/xen/include/asm-x86/guest/hypervisor.h
+++ b/xen/include/asm-x86/guest/hypervisor.h
@@ -19,6 +19,8 @@ 
 #ifndef __X86_HYPERVISOR_H__
 #define __X86_HYPERVISOR_H__
 
+#include <asm/e820.h>
+
 struct hypervisor_ops {
     /* Name of the hypervisor */
     const char *name;
@@ -28,6 +30,8 @@  struct hypervisor_ops {
     int (*ap_setup)(void);
     /* Resume from suspension */
     void (*resume)(void);
+    /* Fix up e820 map */
+    void (*e820_fixup)(struct e820map *e820);
 };
 
 #ifdef CONFIG_GUEST
@@ -36,6 +40,7 @@  const char *hypervisor_probe(void);
 void hypervisor_setup(void);
 int hypervisor_ap_setup(void);
 void hypervisor_resume(void);
+void hypervisor_e820_fixup(struct e820map *e820);
 
 #else
 
@@ -46,6 +51,7 @@  static inline const char *hypervisor_probe(void) { return NULL; }
 static inline void hypervisor_setup(void) { ASSERT_UNREACHABLE(); }
 static inline int hypervisor_ap_setup(void) { ASSERT_UNREACHABLE(); return 0; }
 static inline void hypervisor_resume(void) { ASSERT_UNREACHABLE(); }
+static inline void hypervisor_e820_fixup(struct e820map *e820) { ASSERT_UNREACHABLE(); }
 
 #endif  /* CONFIG_GUEST */