diff mbox series

[for-next,v3,8/9] x86: be more verbose when running on a hypervisor

Message ID 20191021155718.28653-9-liuwe@microsoft.com (mailing list archive)
State Superseded
Headers show
Series Port Xen to Hyper-V | expand

Commit Message

Wei Liu Oct. 21, 2019, 3:57 p.m. UTC
Signed-off-by: Wei Liu <liuwe@microsoft.com>
---
V3: Address Roger's comment, add ASSERTs
---
 xen/arch/x86/guest/hypervisor.c        | 6 ++++++
 xen/arch/x86/setup.c                   | 6 +++++-
 xen/include/asm-x86/guest/hypervisor.h | 3 +++
 3 files changed, 14 insertions(+), 1 deletion(-)

Comments

Paul Durrant Oct. 23, 2019, 9:03 a.m. UTC | #1
On Mon, 21 Oct 2019 at 17:00, Wei Liu <wl@xen.org> wrote:
>
> Signed-off-by: Wei Liu <liuwe@microsoft.com>

Reviewed-by: Paul Durrant <paul@xen.org>

> ---
> V3: Address Roger's comment, add ASSERTs
> ---
>  xen/arch/x86/guest/hypervisor.c        | 6 ++++++
>  xen/arch/x86/setup.c                   | 6 +++++-
>  xen/include/asm-x86/guest/hypervisor.h | 3 +++
>  3 files changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c
> index 33bf1a769d..a666ad9526 100644
> --- a/xen/arch/x86/guest/hypervisor.c
> +++ b/xen/arch/x86/guest/hypervisor.c
> @@ -46,6 +46,12 @@ bool hypervisor_probe(void)
>      return false;
>  }
>
> +const char *hypervisor_name(void)
> +{
> +    ASSERT(hops);
> +    return hops->name;
> +}
> +
>  void hypervisor_setup(void)
>  {
>      if ( hops && hops->setup )
> diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
> index 0ee11b15a6..cf5a7b8e1e 100644
> --- a/xen/arch/x86/setup.c
> +++ b/xen/arch/x86/setup.c
> @@ -689,6 +689,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
>      int i, j, e820_warn = 0, bytes = 0;
>      bool acpi_boot_table_init_done = false, relocated = false;
>      int ret;
> +    bool running_on_hypervisor;
>      struct ns16550_defaults ns16550 = {
>          .data_bits = 8,
>          .parity    = 'n',
> @@ -763,7 +764,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
>       * allocing any xenheap structures wanted in lower memory. */
>      kexec_early_calculations();
>
> -    hypervisor_probe();
> +    running_on_hypervisor = hypervisor_probe();
>
>      parse_video_info();
>
> @@ -789,6 +790,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)
>
>      printk("Xen image load base address: %#lx\n", xen_phys_start);
>
> +    if ( running_on_hypervisor )
> +        printk("Running on %s\n", hypervisor_name());
> +
>  #ifdef CONFIG_VIDEO
>      printk("Video information:\n");
>
> diff --git a/xen/include/asm-x86/guest/hypervisor.h b/xen/include/asm-x86/guest/hypervisor.h
> index 38344e2e89..b583722f5d 100644
> --- a/xen/include/asm-x86/guest/hypervisor.h
> +++ b/xen/include/asm-x86/guest/hypervisor.h
> @@ -36,15 +36,18 @@ bool hypervisor_probe(void);
>  void hypervisor_setup(void);
>  void hypervisor_ap_setup(void);
>  void hypervisor_resume(void);
> +const char *hypervisor_name(void);
>
>  #else
>
> +#include <xen/lib.h>
>  #include <xen/types.h>
>
>  static inline bool hypervisor_probe(void) { return false; }
>  static inline void hypervisor_setup(void) {}
>  static inline void hypervisor_ap_setup(void) {}
>  static inline void hypervisor_resume(void) {}
> +static inline char *hypervisor_name(void) { ASSERT_UNREACHABLE(); return NULL; }
>
>  #endif  /* CONFIG_GUEST */
>
> --
> 2.20.1
>
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xenproject.org
> https://lists.xenproject.org/mailman/listinfo/xen-devel
Jan Beulich Nov. 15, 2019, 1:59 p.m. UTC | #2
On 21.10.2019 17:57, Wei Liu wrote:
> --- a/xen/arch/x86/setup.c
> +++ b/xen/arch/x86/setup.c
> @@ -689,6 +689,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
>      int i, j, e820_warn = 0, bytes = 0;
>      bool acpi_boot_table_init_done = false, relocated = false;
>      int ret;
> +    bool running_on_hypervisor;
>      struct ns16550_defaults ns16550 = {
>          .data_bits = 8,
>          .parity    = 'n',
> @@ -763,7 +764,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
>       * allocing any xenheap structures wanted in lower memory. */
>      kexec_early_calculations();
>  
> -    hypervisor_probe();
> +    running_on_hypervisor = hypervisor_probe();
>  
>      parse_video_info();
>  
> @@ -789,6 +790,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)
>  
>      printk("Xen image load base address: %#lx\n", xen_phys_start);
>  
> +    if ( running_on_hypervisor )
> +        printk("Running on %s\n", hypervisor_name());

Instead of a bool, why don't you make hypervisor_probe() return the
name (or NULL), avoiding the separate hypervisor_name() (and making
it moot for me to ask for it to become __init)?

Jan
diff mbox series

Patch

diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c
index 33bf1a769d..a666ad9526 100644
--- a/xen/arch/x86/guest/hypervisor.c
+++ b/xen/arch/x86/guest/hypervisor.c
@@ -46,6 +46,12 @@  bool hypervisor_probe(void)
     return false;
 }
 
+const char *hypervisor_name(void)
+{
+    ASSERT(hops);
+    return hops->name;
+}
+
 void hypervisor_setup(void)
 {
     if ( hops && hops->setup )
diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
index 0ee11b15a6..cf5a7b8e1e 100644
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -689,6 +689,7 @@  void __init noreturn __start_xen(unsigned long mbi_p)
     int i, j, e820_warn = 0, bytes = 0;
     bool acpi_boot_table_init_done = false, relocated = false;
     int ret;
+    bool running_on_hypervisor;
     struct ns16550_defaults ns16550 = {
         .data_bits = 8,
         .parity    = 'n',
@@ -763,7 +764,7 @@  void __init noreturn __start_xen(unsigned long mbi_p)
      * allocing any xenheap structures wanted in lower memory. */
     kexec_early_calculations();
 
-    hypervisor_probe();
+    running_on_hypervisor = hypervisor_probe();
 
     parse_video_info();
 
@@ -789,6 +790,9 @@  void __init noreturn __start_xen(unsigned long mbi_p)
 
     printk("Xen image load base address: %#lx\n", xen_phys_start);
 
+    if ( running_on_hypervisor )
+        printk("Running on %s\n", hypervisor_name());
+
 #ifdef CONFIG_VIDEO
     printk("Video information:\n");
 
diff --git a/xen/include/asm-x86/guest/hypervisor.h b/xen/include/asm-x86/guest/hypervisor.h
index 38344e2e89..b583722f5d 100644
--- a/xen/include/asm-x86/guest/hypervisor.h
+++ b/xen/include/asm-x86/guest/hypervisor.h
@@ -36,15 +36,18 @@  bool hypervisor_probe(void);
 void hypervisor_setup(void);
 void hypervisor_ap_setup(void);
 void hypervisor_resume(void);
+const char *hypervisor_name(void);
 
 #else
 
+#include <xen/lib.h>
 #include <xen/types.h>
 
 static inline bool hypervisor_probe(void) { return false; }
 static inline void hypervisor_setup(void) {}
 static inline void hypervisor_ap_setup(void) {}
 static inline void hypervisor_resume(void) {}
+static inline char *hypervisor_name(void) { ASSERT_UNREACHABLE(); return NULL; }
 
 #endif  /* CONFIG_GUEST */