Skip to contentSkip to conversation

Port Xen to Hyper-V

PATCH In review Wei Liu 2 participants 19 messages Nov 30, 2019 – Dec 3, 2019

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

v5 cover Port Xen to Hyper-V

Please see individual patches for changes

Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
Cc Wei Liu <[email protected]>
Cc Roger Pau Monné <[email protected]>
Cc Paul Durrant <[email protected]>

Wei Liu (8):
x86: introduce CONFIG_GUEST and move code
x86: add missing headers in hypercall.h
x86: drop hypervisor_cpuid_base
x86: introduce hypervisor framework
x86: rename hypervisor_{alloc,free}_unused_page
x86: switch xen guest implementation to use hypervisor framework
x86: be more verbose when running on a hypervisor
x86: introduce CONFIG_HYPERV and detection code

 xen/arch/x86/Kconfig                          | 15 +++-
 xen/arch/x86/Makefile                         |  2 +-
 xen/arch/x86/guest/Makefile                   |  6 +-
 xen/arch/x86/guest/hyperv/Makefile            |  1 +
 xen/arch/x86/guest/hyperv/hyperv.c            | 54 +++++++++++++
 xen/arch/x86/guest/hypervisor.c               | 78 +++++++++++++++++++
 xen/arch/x86/guest/xen/Makefile               |  4 +
 xen/arch/x86/guest/{ => xen}/hypercall_page.S |  0
 xen/arch/x86/guest/{ => xen}/pvh-boot.c       |  2 +-
 xen/arch/x86/guest/{ => xen}/xen.c            | 60 +++++++-------
 xen/arch/x86/pv/shim.c                        |  6 +-
 xen/arch/x86/setup.c                          |  7 +-
 xen/include/asm-x86/guest.h                   |  2 +
 xen/include/asm-x86/guest/hypercall.h         |  4 +
 xen/include/asm-x86/guest/hyperv.h            | 43 ++++++++++
 xen/include/asm-x86/guest/hypervisor.h        | 62 +++++++++++++++
 xen/include/asm-x86/guest/xen.h               | 23 ++----
 17 files changed, 312 insertions(+), 57 deletions(-)
 create mode 100644 xen/arch/x86/guest/hyperv/Makefile
 create mode 100644 xen/arch/x86/guest/hyperv/hyperv.c
 create mode 100644 xen/arch/x86/guest/hypervisor.c
 create mode 100644 xen/arch/x86/guest/xen/Makefile
 rename xen/arch/x86/guest/{ => xen}/hypercall_page.S (100%)
 rename xen/arch/x86/guest/{ => xen}/pvh-boot.c (99%)
 rename xen/arch/x86/guest/{ => xen}/xen.c (94%)
 create mode 100644 xen/include/asm-x86/guest/hyperv.h
 create mode 100644 xen/include/asm-x86/guest/hypervisor.h
Signature · 7 lines
2.20.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
author
#1 lore raw

PATCH v5 1/8 x86: introduce CONFIG_GUEST and move code

Xen is able to run as a guest on Xen. We plan to make it able to run on Hyper-V as well.

Introduce CONFIG_GUEST which is set to true if either running on Xen or Hyper-V is desired. Restructure code hierarchy for new code to come.

No functional change intended.

---
 xen/arch/x86/Kconfig                          | 7 +++++--
 xen/arch/x86/Makefile                         | 2 +-
 xen/arch/x86/guest/Makefile                   | 5 +----
 xen/arch/x86/guest/xen/Makefile               | 4 ++++
 xen/arch/x86/guest/{ => xen}/hypercall_page.S | 0
 xen/arch/x86/guest/{ => xen}/pvh-boot.c       | 0
 xen/arch/x86/guest/{ => xen}/xen.c            | 0
 7 files changed, 11 insertions(+), 7 deletions(-)
 create mode 100644 xen/arch/x86/guest/xen/Makefile
 rename xen/arch/x86/guest/{ => xen}/hypercall_page.S (100%)
 rename xen/arch/x86/guest/{ => xen}/pvh-boot.c (100%)
 rename xen/arch/x86/guest/{ => xen}/xen.c (100%)
xen/arch/x86/Kconfig +5 -2
index 28b3b4692a..18c8f6fd26 100644
@@ -161,9 +161,12 @@ config XEN_ALIGN_2M
 
 endchoice
 
+config GUEST
+	bool
+
 config XEN_GUEST
-	def_bool n
-	prompt "Xen Guest"
+	bool "Xen Guest"
+	select GUEST
 	---help---
 	  Support for Xen detecting when it is running under Xen.
 
xen/arch/x86/Makefile +1 -1
index a0b2f4ab15..7da5a2631e 100644
@@ -1,7 +1,7 @@
 subdir-y += acpi
 subdir-y += cpu
 subdir-y += genapic
-subdir-$(CONFIG_XEN_GUEST) += guest
+subdir-$(CONFIG_GUEST) += guest
 subdir-$(CONFIG_HVM) += hvm
 subdir-y += mm
 subdir-$(CONFIG_XENOPROF) += oprofile
xen/arch/x86/guest/Makefile +1 -4
index 26fb4b1007..6806f04947 100644
@@ -1,4 +1 @@
-obj-y += hypercall_page.o
-obj-y += xen.o
-
-obj-bin-$(CONFIG_PVH_GUEST) += pvh-boot.init.o
+subdir-$(CONFIG_XEN_GUEST) += xen
xen/arch/x86/guest/xen/Makefile new file +4 -0
new file mode 100644
index 0000000000..26fb4b1007
@@ -0,0 +1,4 @@
+obj-y += hypercall_page.o
+obj-y += xen.o
+
+obj-bin-$(CONFIG_PVH_GUEST) += pvh-boot.init.o
xen/arch/x86/guest/xen/hypercall_page.S renamed from xen/arch/x86/guest/hypercall_page.S +0 -0
similarity index 100%
rename from xen/arch/x86/guest/hypercall_page.S
rename to xen/arch/x86/guest/xen/hypercall_page.S
xen/arch/x86/guest/xen/pvh-boot.c renamed from xen/arch/x86/guest/pvh-boot.c +0 -0
similarity index 100%
rename from xen/arch/x86/guest/pvh-boot.c
rename to xen/arch/x86/guest/xen/pvh-boot.c
xen/arch/x86/guest/xen/xen.c renamed from xen/arch/x86/guest/xen.c +0 -0
similarity index 100%
rename from xen/arch/x86/guest/xen.c
rename to xen/arch/x86/guest/xen/xen.c
Signature · 7 lines
2.20.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
author
#2 lore raw

PATCH v5 2/8 x86: add missing headers in hypercall.h

In reply to Wei Liu

Include asm_defns.h because ASM_CALL_CONSTRAINT is defined there.

Include xen/lib.h because we need ASSERT_UNREACHABLE.

No functional change.

---
 xen/include/asm-x86/guest/hypercall.h | 4 ++++
 1 file changed, 4 insertions(+)
xen/include/asm-x86/guest/hypercall.h +4 -0
index d548816b30..d0d2f5022d 100644
@@ -23,6 +23,8 @@
 
 #include <xen/types.h>
 
+#include <asm/asm_defns.h>
+
 #include <public/xen.h>
 #include <public/sched.h>
 #include <public/hvm/hvm_op.h>
@@ -180,6 +182,8 @@ static inline long xen_hypercall_set_evtchn_upcall_vector(
 
 #else /* CONFIG_XEN_GUEST */
 
+#include <xen/lib.h>
+
 #include <public/sched.h>
 
 static inline void xen_hypercall_console_write(
Signature · 7 lines
2.20.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
author
#3 lore raw

PATCH v5 3/8 x86: drop hypervisor_cpuid_base

In reply to Wei Liu

The only user is Xen specific code in PV shim. We can therefore export the variable directly.

Move __read_mostly to its standard place while at it.

---
 xen/arch/x86/guest/xen/xen.c    | 7 +------
 xen/arch/x86/pv/shim.c          | 2 +-
 xen/include/asm-x86/guest/xen.h | 2 +-
 3 files changed, 3 insertions(+), 8 deletions(-)
xen/arch/x86/guest/xen/xen.c +1 -6
index a329e7c886..1e37086518 100644
@@ -37,7 +37,7 @@
 
 bool __read_mostly xen_guest;
 
-static __read_mostly uint32_t xen_cpuid_base;
+uint32_t __read_mostly xen_cpuid_base;
 extern char hypercall_page[];
 static struct rangeset *mem;
 
@@ -297,11 +297,6 @@ int hypervisor_free_unused_page(mfn_t mfn)
     return rangeset_remove_range(mem, mfn_x(mfn), mfn_x(mfn));
 }
 
-uint32_t hypervisor_cpuid_base(void)
-{
-    return xen_cpuid_base;
-}
-
 static void ap_resume(void *unused)
 {
     map_vcpuinfo();
xen/arch/x86/pv/shim.c +1 -1
index 35bf3945ac..351da970ef 100644
@@ -995,7 +995,7 @@ domid_t get_initial_domain_id(void)
     if ( !pv_shim )
         return 0;
 
-    cpuid(hypervisor_cpuid_base() + 4, &eax, &ebx, &ecx, &edx);
+    cpuid(xen_cpuid_base + 4, &eax, &ebx, &ecx, &edx);
 
     return (eax & XEN_HVM_CPUID_DOMID_PRESENT) ? ecx : 1;
 }
xen/include/asm-x86/guest/xen.h +1 -1
index 7e04e4a7ab..b015ed1883 100644
@@ -30,13 +30,13 @@
 
 extern bool xen_guest;
 extern bool pv_console;
+extern uint32_t xen_cpuid_base;
 
 void probe_hypervisor(void);
 void hypervisor_setup(void);
 void hypervisor_ap_setup(void);
 int hypervisor_alloc_unused_page(mfn_t *mfn);
 int hypervisor_free_unused_page(mfn_t mfn);
-uint32_t hypervisor_cpuid_base(void);
 void hypervisor_resume(void);
 
 DECLARE_PER_CPU(unsigned int, vcpu_id);
Signature · 7 lines
2.20.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
author
#4 lore raw

PATCH v5 4/8 x86: introduce hypervisor framework

In reply to Wei Liu

We will soon implement Hyper-V support for Xen. Add a framework for that.

This requires moving some of the hypervisor_* functions from xen.h to hypervisor.h.

---
Changes in v5:
1. Make hypervisor_probe return const char *.

Changes in v4:
1. Add ASSERT_UNREACHABLE to stubs.
2. Move __read_mostly.
3. Return hops directly.
4. Drop Paul's review tag.

---
 xen/arch/x86/guest/Makefile            |  2 +
 xen/arch/x86/guest/hypervisor.c        | 45 +++++++++++++++++++
 xen/include/asm-x86/guest.h            |  1 +
 xen/include/asm-x86/guest/hypervisor.h | 62 ++++++++++++++++++++++++++
 xen/include/asm-x86/guest/xen.h        | 12 -----
 5 files changed, 110 insertions(+), 12 deletions(-)
 create mode 100644 xen/arch/x86/guest/hypervisor.c
 create mode 100644 xen/include/asm-x86/guest/hypervisor.h
xen/arch/x86/guest/Makefile +2 -0
index 6806f04947..f63d64bbee 100644
@@ -1 +1,3 @@
+obj-y += hypervisor.o
+
 subdir-$(CONFIG_XEN_GUEST) += xen
xen/arch/x86/guest/hypervisor.c new file +45 -0

45 lines not on this page · raw message

xen/include/asm-x86/guest.h +1 -0
index a38c6b5b3f..8e167165ae 100644
@@ -20,6 +20,7 @@
 #define __X86_GUEST_H__
 
 #include <asm/guest/hypercall.h>
+#include <asm/guest/hypervisor.h>
 #include <asm/guest/pvh-boot.h>
 #include <asm/guest/xen.h>
 #include <asm/pv/shim.h>
xen/include/asm-x86/guest/hypervisor.h new file +62 -0

62 lines not on this page · raw message

xen/include/asm-x86/guest/xen.h +0 -12
index b015ed1883..3145f75361 100644
@@ -33,11 +33,8 @@ extern bool pv_console;
 extern uint32_t xen_cpuid_base;
 
 void probe_hypervisor(void);
-void hypervisor_setup(void);
-void hypervisor_ap_setup(void);
 int hypervisor_alloc_unused_page(mfn_t *mfn);
 int hypervisor_free_unused_page(mfn_t mfn);
-void hypervisor_resume(void);
 
 DECLARE_PER_CPU(unsigned int, vcpu_id);
 DECLARE_PER_CPU(struct vcpu_info *, vcpu_info);
@@ -49,15 +46,6 @@ DECLARE_PER_CPU(struct vcpu_info *, vcpu_info);
 
 static inline void probe_hypervisor(void) {}
 
-static inline void hypervisor_setup(void)
-{
-    ASSERT_UNREACHABLE();
-}
-static inline void hypervisor_ap_setup(void)
-{
-    ASSERT_UNREACHABLE();
-}
-
 #endif /* CONFIG_XEN_GUEST */
 #endif /* __X86_GUEST_XEN_H__ */
 
Signature · 7 lines
2.20.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v5 4/8
#5 lore raw

Re: [Xen-devel] [PATCH v5 4/8] x86: introduce hypervisor framework

Quoted 7 lines · Wei Liu

We will soon implement Hyper-V support for Xen. Add a framework for that.

This requires moving some of the hypervisor_* functions from xen.h to hypervisor.h.

with one more adjustment (sorry for noticing only now):

Quoted 20 lines
xen/arch/x86/guest/hypervisor.c new file +17 -0
@@ -0,0 +1,45 @@
+/******************************************************************************
+ * arch/x86/guest/hypervisor.c
+ *
+ * Support for detecting and running under a hypervisor.
+ *
+ * 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.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.

xen/arch/x86/guest/hypervisor.c line 27

Quoted 10 lines
xen/arch/x86/guest/hypervisor.c new file +10 -0
+ *
+ * Copyright (c) 2019 Microsoft.
+ */
+#include <xen/init.h>
+#include <xen/types.h>
+
+#include <asm/cache.h>
+#include <asm/guest/hypervisor.h>
+
+static const struct hypervisor_ops __read_mostly *ops;

The __read_mostly is misplaced - it's an attribute of the variable, not its type, and hence belongs after the * . It just so happens that the compiler is (still) relatively relaxed in what it accepts, but I think at least the gcc manual has a warning towards future more strict behavior.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#6 lore raw

Re: [Xen-devel] [PATCH v5 4/8] x86: introduce hypervisor framework

Quoted 10 lines · Jan Beulich
Quoted 7 lines · Wei Liu

We will soon implement Hyper-V support for Xen. Add a framework for that.

This requires moving some of the hypervisor_* functions from xen.h to hypervisor.h.

[...]

Quoted 9 lines

xen/arch/x86/guest/hypervisor.c line 27

Quoted 3 lines
xen/arch/x86/guest/hypervisor.c new file +3 -0
+#include <asm/guest/hypervisor.h>
+
+static const struct hypervisor_ops __read_mostly *ops;

The __read_mostly is misplaced - it's an attribute of the variable, not its type, and hence belongs after the * . It just so happens that the compiler is (still) relatively relaxed in what it accepts, but I think at least the gcc manual has a warning towards future more strict behavior.

Fixed.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#7 lore raw

PATCH v5 5/8 x86: rename hypervisor_{alloc, free}_unused_page

In reply to Wei Liu

They are used in Xen code only.

No functional change.

---
 xen/arch/x86/guest/xen/xen.c    | 6 +++---
 xen/arch/x86/pv/shim.c          | 4 ++--
 xen/include/asm-x86/guest/xen.h | 4 ++--
 3 files changed, 7 insertions(+), 7 deletions(-)
xen/arch/x86/guest/xen/xen.c +3 -3
index 1e37086518..0f5b5267c5 100644
@@ -93,7 +93,7 @@ static void map_shared_info(void)
     unsigned int i;
     unsigned long rc;
 
-    if ( hypervisor_alloc_unused_page(&mfn) )
+    if ( xg_alloc_unused_page(&mfn) )
         panic("unable to reserve shared info memory page\n");
 
     xatp.gpfn = mfn_x(mfn);
@@ -280,7 +280,7 @@ void hypervisor_ap_setup(void)
     init_evtchn();
 }
 
-int hypervisor_alloc_unused_page(mfn_t *mfn)
+int xg_alloc_unused_page(mfn_t *mfn)
 {
     unsigned long m;
     int rc;
@@ -292,7 +292,7 @@ int hypervisor_alloc_unused_page(mfn_t *mfn)
     return rc;
 }
 
-int hypervisor_free_unused_page(mfn_t mfn)
+int xg_free_unused_page(mfn_t mfn)
 {
     return rangeset_remove_range(mem, mfn_x(mfn), mfn_x(mfn));
 }
xen/arch/x86/pv/shim.c +2 -2
index 351da970ef..7a898fdbe5 100644
@@ -742,7 +742,7 @@ static long pv_shim_grant_table_op(unsigned int cmd,
                 };
                 mfn_t mfn;
 
-                rc = hypervisor_alloc_unused_page(&mfn);
+                rc = xg_alloc_unused_page(&mfn);
                 if ( rc )
                 {
                     gprintk(XENLOG_ERR,
@@ -754,7 +754,7 @@ static long pv_shim_grant_table_op(unsigned int cmd,
                 rc = xen_hypercall_memory_op(XENMEM_add_to_physmap, &xatp);
                 if ( rc )
                 {
-                    hypervisor_free_unused_page(mfn);
+                    xg_free_unused_page(mfn);
                     break;
                 }
 
xen/include/asm-x86/guest/xen.h +2 -2
index 3145f75361..01dc3ee6f6 100644
@@ -33,8 +33,8 @@ extern bool pv_console;
 extern uint32_t xen_cpuid_base;
 
 void probe_hypervisor(void);
-int hypervisor_alloc_unused_page(mfn_t *mfn);
-int hypervisor_free_unused_page(mfn_t mfn);
+int xg_alloc_unused_page(mfn_t *mfn);
+int xg_free_unused_page(mfn_t mfn);
 
 DECLARE_PER_CPU(unsigned int, vcpu_id);
 DECLARE_PER_CPU(struct vcpu_info *, vcpu_info);
Signature · 7 lines
2.20.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
author
#8 lore raw

PATCH v5 6/8 x86: switch xen guest implementation to use hypervisor framework

In reply to Wei Liu

---
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(-)
xen/arch/x86/guest/hypervisor.c +26 -1
index c35c610d01..6cd86d0c02 100644
@@ -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
xen/arch/x86/guest/xen/pvh-boot.c +1 -1
index ca8e156f7d..498625eae0 100644
@@ -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();
xen/arch/x86/guest/xen/xen.c +28 -19

77 lines not on this page · raw message

xen/arch/x86/setup.c +1 -1
index 7d27f36053..a6b354c29f 100644
@@ -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();
 
xen/include/asm-x86/guest/xen.h +3 -2
index 01dc3ee6f6..2042a9a0c2 100644
@@ -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__ */
Signature · 7 lines
2.20.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v5 6/8
#9 lore raw

Re: [Xen-devel] [PATCH v5 6/8] x86: switch xen guest implementation to use hypervisor framework

Quoted 1 line · Wei Liu

again with one more remark:

xen/arch/x86/guest/xen/xen.c void hypervisor_resume(void) · line 313

Quoted 5 lines
xen/arch/x86/guest/xen/xen.c +1 -0
@@ -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

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#10 lore raw

Re: [Xen-devel] [PATCH v5 6/8] x86: switch xen guest implementation to use hypervisor framework

Quoted 10 lines · Jan Beulich
Quoted 1 line · Wei Liu

again with one more remark:

Quoted 4 lines
xen/arch/x86/guest/xen/xen.c +0 -0
@@ -326,6 +310,31 @@ void hypervisor_resume(void)
         pv_console_init();
 }
 
Quoted 5 lines

xen/arch/x86/guest/xen/xen.c void hypervisor_resume(void) · line 313

Quoted 1 line
xen/arch/x86/guest/xen/xen.c +1 -0
+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.

Quoted 2 lines

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#11 lore raw

PATCH v5 7/8 x86: be more verbose when running on a hypervisor

In reply to Wei Liu

Also replace reference to xen_guest.

---
Changes in v5:
1. Cache and use hypervisor name instead

---
 xen/arch/x86/setup.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
xen/arch/x86/setup.c +5 -2
index a6b354c29f..fc049eaac8 100644
@@ -700,6 +700,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
         .max_grant_frames = -1,
         .max_maptrack_frames = -1,
     };
+    const char *hypervisor_name;
 
     /* Critical region without IDT or TSS.  Any fault is deadly! */
 
@@ -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();
+    hypervisor_name = hypervisor_probe();
 
     parse_video_info();
 
@@ -788,6 +789,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)
     printk("Command line: %s\n", cmdline);
 
     printk("Xen image load base address: %#lx\n", xen_phys_start);
+    if ( hypervisor_name )
+        printk("Running on %s\n", hypervisor_name);
 
 #ifdef CONFIG_VIDEO
     printk("Video information:\n");
@@ -1569,7 +1572,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
             max_cpus = nr_cpu_ids;
     }
 
-    if ( xen_guest )
+    if ( hypervisor_name )
         hypervisor_setup();
 
     /* Low mappings were only needed for some BIOS table parsing. */
Signature · 7 lines
2.20.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v5 7/8
#12 lore raw

Re: [Xen-devel] [PATCH v5 7/8] x86: be more verbose when running on a hypervisor

Quoted 3 lines · Wei Liu

Also replace reference to xen_guest.

However, ...

Quoted 11 lines
xen/arch/x86/setup.c +1 -0
@@ -700,6 +700,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
         .max_grant_frames = -1,
         .max_maptrack_frames = -1,
     };
+    const char *hypervisor_name;
 
     /* Critical region without IDT or TSS.  Any fault is deadly! */
 

xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p) · line 767

Quoted 5 lines
xen/arch/x86/setup.c +1 -1
@@ -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();
+    hypervisor_name = hypervisor_probe();

... you no longer calling this function multiple time, why does patch 4 still put in a respective guard?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#13 lore raw

Re: [Xen-devel] [PATCH v5 7/8] x86: be more verbose when running on a hypervisor

Quoted 6 lines · Jan Beulich
Quoted 3 lines · Wei Liu

Also replace reference to xen_guest.

Thanks.

Quoted 17 lines

However, ...

Quoted 14 lines
xen/arch/x86/setup.c +1 -0
@@ -700,6 +700,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
         .max_grant_frames = -1,
         .max_maptrack_frames = -1,
     };
+    const char *hypervisor_name;
 
     /* Critical region without IDT or TSS.  Any fault is deadly! */
 
@@ -763,7 +764,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
      * allocing any xenheap structures wanted in lower memory. */
     kexec_early_calculations();
 
Quoted 5 lines

xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p) · line 767

Quoted 2 lines
xen/arch/x86/setup.c +1 -1
-    hypervisor_probe();
+    hypervisor_name = hypervisor_probe();

... you no longer calling this function multiple time, why does patch 4 still put in a respective guard?

Remnant from previous iterations.

I can submit a follow-up patch to drop that -- do really want to invalidate all the reviews and acks I got so far.

Wei.

Quoted 2 lines

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#14 lore raw

Re: [Xen-devel] [PATCH v5 7/8] x86: be more verbose when running on a hypervisor

Quoted 33 lines · Wei Liu
Quoted 6 lines · Jan Beulich
Quoted 3 lines · Wei Liu

Also replace reference to xen_guest.

Thanks.

Quoted 17 lines

However, ...

Quoted 14 lines
xen/arch/x86/setup.c +1 -0
@@ -700,6 +700,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
         .max_grant_frames = -1,
         .max_maptrack_frames = -1,
     };
+    const char *hypervisor_name;
 
     /* Critical region without IDT or TSS.  Any fault is deadly! */
 
@@ -763,7 +764,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
      * allocing any xenheap structures wanted in lower memory. */
     kexec_early_calculations();
 
Quoted 5 lines

xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p) · line 767

Quoted 2 lines
xen/arch/x86/setup.c +1 -1
-    hypervisor_probe();
+    hypervisor_name = hypervisor_probe();

... you no longer calling this function multiple time, why does patch 4 still put in a respective guard?

Quoted 4 lines

Remnant from previous iterations.

I can submit a follow-up patch to drop that -- do really want to invalidate all the reviews and acks I got so far.

According to my records patch 4 had no acks except mine, which you could keep with this change (in fact I was thinking of making it dependent upon the dropping of this leftover). Subsequent patches may only need re-basing, which doesn't imply dropping of any acks.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#15 lore raw

Re: [Xen-devel] [PATCH v5 7/8] x86: be more verbose when running on a hypervisor

Quoted 36 lines · Jan Beulich
Quoted 35 lines · Wei Liu
Quoted 6 lines · Jan Beulich
Quoted 3 lines · Wei Liu

Also replace reference to xen_guest.

Thanks.

Quoted 17 lines

However, ...

Quoted 14 lines
xen/arch/x86/setup.c +1 -0
@@ -700,6 +700,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
         .max_grant_frames = -1,
         .max_maptrack_frames = -1,
     };
+    const char *hypervisor_name;
 
     /* Critical region without IDT or TSS.  Any fault is deadly! */
 
@@ -763,7 +764,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
      * allocing any xenheap structures wanted in lower memory. */
     kexec_early_calculations();
 
Quoted 5 lines

xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p) · line 767

Quoted 2 lines
xen/arch/x86/setup.c +1 -1
-    hypervisor_probe();
+    hypervisor_name = hypervisor_probe();

... you no longer calling this function multiple time, why does patch 4 still put in a respective guard?

Remnant from previous iterations.

Quoted 7 lines
Quoted 2 lines

I can submit a follow-up patch to drop that -- do really want to invalidate all the reviews and acks I got so far.

According to my records patch 4 had no acks except mine, which you could keep with this change (in fact I was thinking of making it dependent upon the dropping of this leftover). Subsequent patches may only need re-basing, which doesn't imply dropping of any acks.

OK. In that case, I will drop it locally. If that causes any substantial changes, I will post another version; otherwise I will just keep all the tags and push this series soon-ish.

How does that sound to you?

Wei.

Quoted 2 lines

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#16 lore raw

Re: [Xen-devel] [PATCH v5 7/8] x86: be more verbose when running on a hypervisor

Quoted 45 lines · Wei Liu
Quoted 36 lines · Jan Beulich
Quoted 35 lines · Wei Liu
Quoted 6 lines · Jan Beulich
Quoted 3 lines · Wei Liu

Also replace reference to xen_guest.

Thanks.

Quoted 17 lines

However, ...

Quoted 14 lines
xen/arch/x86/setup.c +1 -0
@@ -700,6 +700,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
         .max_grant_frames = -1,
         .max_maptrack_frames = -1,
     };
+    const char *hypervisor_name;
 
     /* Critical region without IDT or TSS.  Any fault is deadly! */
 
@@ -763,7 +764,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
      * allocing any xenheap structures wanted in lower memory. */
     kexec_early_calculations();
 
Quoted 5 lines

xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p) · line 767

Quoted 2 lines
xen/arch/x86/setup.c +1 -1
-    hypervisor_probe();
+    hypervisor_name = hypervisor_probe();

... you no longer calling this function multiple time, why does patch 4 still put in a respective guard?

Remnant from previous iterations.

Quoted 7 lines
Quoted 2 lines

I can submit a follow-up patch to drop that -- do really want to invalidate all the reviews and acks I got so far.

According to my records patch 4 had no acks except mine, which you could keep with this change (in fact I was thinking of making it dependent upon the dropping of this leftover). Subsequent patches may only need re-basing, which doesn't imply dropping of any acks.

Quoted 5 lines

OK. In that case, I will drop it locally. If that causes any substantial changes, I will post another version; otherwise I will just keep all the tags and push this series soon-ish.

How does that sound to you?

And it turns out it is indeed trivial. Dropping that hunk in patch 4 only requires a minor fixup to patch 6.

Wei.

Quoted 5 lines

Wei.

Quoted 2 lines

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#17 lore raw

PATCH v5 8/8 x86: introduce CONFIG_HYPERV and detection code

In reply to Wei Liu

We use the same code structure as we did for Xen.

As starters, detect Hyper-V in probe routine. More complex functionalities will be added later.

---
 xen/arch/x86/Kconfig               |  8 +++++
 xen/arch/x86/guest/Makefile        |  1 +
 xen/arch/x86/guest/hyperv/Makefile |  1 +
 xen/arch/x86/guest/hyperv/hyperv.c | 54 ++++++++++++++++++++++++++++++
 xen/arch/x86/guest/hypervisor.c    |  8 +++++
 xen/include/asm-x86/guest.h        |  1 +
 xen/include/asm-x86/guest/hyperv.h | 43 ++++++++++++++++++++++++
 7 files changed, 116 insertions(+)
 create mode 100644 xen/arch/x86/guest/hyperv/Makefile
 create mode 100644 xen/arch/x86/guest/hyperv/hyperv.c
 create mode 100644 xen/include/asm-x86/guest/hyperv.h
xen/arch/x86/Kconfig +8 -0
index 18c8f6fd26..0a02b6ee3f 100644
@@ -164,6 +164,14 @@ endchoice
 config GUEST
 	bool
 
+config HYPERV_GUEST
+	bool "Hyper-V Guest"
+	select GUEST
+	---help---
+	  Support for Xen detecting when it is running under Hyper-V.
+
+	  If unsure, say N.
+
 config XEN_GUEST
 	bool "Xen Guest"
 	select GUEST
xen/arch/x86/guest/Makefile +1 -0
index f63d64bbee..f164196772 100644
@@ -1,3 +1,4 @@
 obj-y += hypervisor.o
 
+subdir-$(CONFIG_HYPERV_GUEST) += hyperv
 subdir-$(CONFIG_XEN_GUEST) += xen
xen/arch/x86/guest/hyperv/Makefile new file +1 -0
new file mode 100644
index 0000000000..68170109a9
@@ -0,0 +1 @@
+obj-y += hyperv.o
xen/arch/x86/guest/hyperv/hyperv.c new file +54 -0

54 lines not on this page · raw message

xen/arch/x86/guest/hypervisor.c +8 -0
index 6cd86d0c02..65c25115e0 100644
@@ -38,6 +38,14 @@ const char *__init hypervisor_probe(void)
     if ( ops )
         return ops->name;
 
+    /*
+     * Detection of Hyper-V must come after Xen to avoid false positive due
+     * to viridian support
+     */
+    ops = hyperv_probe();
+    if ( ops )
+        return ops->name;
+
     return NULL;
 }
 
xen/include/asm-x86/guest.h +1 -0
index 8e167165ae..94448606d4 100644
@@ -20,6 +20,7 @@
 #define __X86_GUEST_H__
 
 #include <asm/guest/hypercall.h>
+#include <asm/guest/hyperv.h>
 #include <asm/guest/hypervisor.h>
 #include <asm/guest/pvh-boot.h>
 #include <asm/guest/xen.h>
xen/include/asm-x86/guest/hyperv.h new file +43 -0

43 lines not on this page · raw message

Signature · 7 lines
2.20.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
author
#18 lore raw

Re: [Xen-devel] [PATCH v5 8/8] x86: introduce CONFIG_HYPERV and detection code

On Sat, Nov 30, 2019 at 11:57:37AM +0000, Wei Liu wrote:
[...]

xen/arch/x86/guest/hyperv/hyperv.c line 25

Quoted 6 lines

+ */

xen/arch/x86/guest/hyperv/hyperv.c new file +5 -0
+#include <xen/init.h>
+
+#include <asm/guest.h>
+
+static const struct hypervisor_ops hyperv_ops = {

Since xg_ops has lost its xg_ prefix, I also take the liberty to drop the hyperv_ prefix here to make things more consistent.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel