Skip to contentSkip to conversation

Port Xen to Hyper-V

PATCH Superseded Wei Liu 3 participants 31 messages Oct 21, 2019 – Nov 21, 2019

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

v3 cover Port Xen to Hyper-V

Hi all

This is version 3 of the patch series.

This is the very first stage for porting Xen to run on Hyper-V with all the goodies Hyper-V has to offer. With this series, Xen can successfully detect Hyper-V and prints out a message. I would like to first get the code structure and kconfig options agreed upon.

There are two major areas to be worked on:
* Make Dom0 able to use Hyper-V's synthetic devices.
* Make Xen use of the synthetic timer, reference TSC and enlightenment VMCS and other interfaces.

They aren't trivial, and time can be scarce on my side, so I intend to post patches piecemeal when they are ready.

Questions and comments are welcome.

Thanks,
Wei.

---
Changes in v3: See invididual patches

Changes in v2:
1. Introduce and use a hypervisor framework
2. Keep memmap infra under Xen for now

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

Wei Liu (9):
x86: introduce CONFIG_GUEST and move code
x86: include asm_defns.h directly in hypercall.h
x86: drop hypervisor_cpuid_base
x86: include xen/lib.h in guest/hypercall.h
x86: introduce hypervisor framework
x86: rename hypervisor_{alloc,free}_unused_page
x86: switch xen 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                          | 13 +++
 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               | 89 +++++++++++++++++++
 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            | 39 ++++----
 xen/arch/x86/pv/shim.c                        |  6 +-
 xen/arch/x86/setup.c                          |  6 +-
 xen/include/asm-x86/guest.h                   |  2 +
 xen/include/asm-x86/guest/hypercall.h         |  4 +
 xen/include/asm-x86/guest/hyperv.h            | 45 ++++++++++
 xen/include/asm-x86/guest/hypervisor.h        | 64 +++++++++++++
 xen/include/asm-x86/guest/xen.h               | 24 ++---
 17 files changed, 314 insertions(+), 47 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 (93%)
 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 v3 1/9 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                          | 4 ++++
 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, 10 insertions(+), 5 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 +4 -0
index 28b3b4692a..867de857e8 100644
@@ -161,8 +161,12 @@ config XEN_ALIGN_2M
 
 endchoice
 
+config GUEST
+	bool
+
 config XEN_GUEST
 	def_bool n
+	select GUEST
 	prompt "Xen Guest"
 	---help---
 	  Support for Xen detecting when it is running under Xen.
xen/arch/x86/Makefile +1 -1
index 2443fd2cc5..99a12d0090 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
#2 lore raw

Re: [Xen-devel] [PATCH for-next v3 1/9] x86: introduce CONFIG_GUEST and move code

Quoted 33 lines · Wei Liu

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                          | 4 ++++
 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, 10 insertions(+), 5 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 +0 -0
index 28b3b4692a..867de857e8 100644
@@ -161,8 +161,12 @@ config XEN_ALIGN_2M
 
 endchoice

xen/arch/x86/Kconfig config XEN_ALIGN_2M · line 172

Quoted 10 lines
xen/arch/x86/Kconfig +4 -0
 
+config GUEST
+       bool
+
 config XEN_GUEST
        def_bool n
+       select GUEST
        prompt "Xen Guest"
        ---help---
          Support for Xen detecting when it is running under Xen.

This text needs to be modified. Perhaps just say 'when it is running in a virtual machine'. That should be future-proof.

Paul

Quoted 49 lines
xen/arch/x86/Makefile +1 -1
index 2443fd2cc5..99a12d0090 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 -1
similarity index 100%
rename from xen/arch/x86/guest/xen.c
rename to xen/arch/x86/guest/xen/xen.c
--

2.20.1

Quoted 4 lines

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

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

author
#3 lore raw

Re: [Xen-devel] [PATCH for-next v3 1/9] x86: introduce CONFIG_GUEST and move code

Quoted 35 lines · Paul Durrant
Quoted 34 lines · Wei Liu

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                          | 4 ++++
 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, 10 insertions(+), 5 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 +0 -0
index 28b3b4692a..867de857e8 100644
@@ -161,8 +161,12 @@ config XEN_ALIGN_2M
 
 endchoice
 
Quoted 13 lines

xen/arch/x86/Kconfig config XEN_ALIGN_2M · line 172

Quoted 9 lines
xen/arch/x86/Kconfig +4 -0
+config GUEST
+       bool
+
 config XEN_GUEST
        def_bool n
+       select GUEST
        prompt "Xen Guest"
        ---help---
          Support for Xen detecting when it is running under Xen.

This text needs to be modified. Perhaps just say 'when it is running in a virtual machine'. That should be future-proof.

I don't think it should be modified -- XEN_GUEST here really means specifically running under Xen but not others.

We will later introduced HYPERV_GUEST.

Wei.

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

Acked-by on v3 1/9
#4 lore raw

Re: [Xen-devel] [PATCH for-next v3 1/9] x86: introduce CONFIG_GUEST and move code

In reply to Wei Liu
Quoted 11 lines · Wei Liu

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-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#5 lore raw

PATCH v3 2/9 x86: include asm_defns.h directly in hypercall.h

In reply to Wei Liu

ASM_CALL_CONSTRAINT is defined there.

No functional change.

---
 xen/include/asm-x86/guest/hypercall.h | 2 ++
 1 file changed, 2 insertions(+)
xen/include/asm-x86/guest/hypercall.h +2 -0
index d548816b30..c9deca6ffc 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>
Signature · 7 lines
2.20.1


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

Re: [Xen-devel] [PATCH for-next v3 2/9] x86: include asm_defns.h directly in hypercall.h

Quoted 6 lines · Wei Liu

ASM_CALL_CONSTRAINT is defined there.

No functional change.

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

author
#7 lore raw

PATCH v3 3/9 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.

---
 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 7b7a5badab..78fc603996 100644
@@ -37,7 +37,7 @@
 
 bool __read_mostly xen_guest;
 
-static __read_mostly uint32_t xen_cpuid_base;
+__read_mostly uint32_t xen_cpuid_base;
 extern char hypercall_page[];
 static struct rangeset *mem;
 
@@ -301,11 +301,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 5edbcd9ac5..5441e89de2 100644
@@ -990,7 +990,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
Acked-by on v3 3/9
#8 lore raw

Re: [Xen-devel] [PATCH for-next v3 3/9] x86: drop hypervisor_cpuid_base

Quoted 5 lines · Wei Liu

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

with, at this occasion, ...

xen/arch/x86/guest/xen/xen.c line 40

Quoted 8 lines
xen/arch/x86/guest/xen/xen.c +1 -1
@@ -37,7 +37,7 @@
 
 bool __read_mostly xen_guest;
 
-static __read_mostly uint32_t xen_cpuid_base;
+__read_mostly uint32_t xen_cpuid_base;

... the __read_mostly moved to its more standard place (an example is in context).

Jan

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

author
#9 lore raw

PATCH v3 4/9 x86: include xen/lib.h in guest/hypercall.h

In reply to Wei Liu

We need ASSERT_UNREACHABLE.

---
 xen/include/asm-x86/guest/hypercall.h | 2 ++
 1 file changed, 2 insertions(+)
xen/include/asm-x86/guest/hypercall.h +2 -0
index c9deca6ffc..d0d2f5022d 100644
@@ -182,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
Acked-by on v3 4/9
#10 lore raw

Re: [Xen-devel] [PATCH for-next v3 4/9] x86: include xen/lib.h in guest/hypercall.h

Quoted 4 lines · Wei Liu

We need ASSERT_UNREACHABLE.

Albeit perhaps fold into patch 2?

Jan

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

author
#11 lore raw

PATCH v3 5/9 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.

---
 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 | 61 ++++++++++++++++++++++++++
 xen/include/asm-x86/guest/xen.h        | 12 -----
 5 files changed, 109 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 +61 -0

61 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
Reviewed-by on v3 5/9
#12 lore raw

Re: [Xen-devel] [PATCH for-next v3 5/9] x86: introduce hypervisor framework

Quoted 8 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 184 lines
---
 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 | 61 ++++++++++++++++++++++++++
 xen/include/asm-x86/guest/xen.h        | 12 -----
 5 files changed, 109 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
new file mode 100644
index 0000000000..89b9ae4de0
@@ -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/>.
+ *
+ * Copyright (c) 2019 Microsoft.
+ */
+
+#include <xen/types.h>
+
+#include <asm/cache.h>
+#include <asm/guest/hypervisor.h>
+
+static struct hypervisor_ops *hops __read_mostly;
+
+bool hypervisor_probe(void)
+{
+    if ( hops )
+        return true;
+
+    return false;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
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 +61 -0
new file mode 100644
index 0000000000..38344e2e89
@@ -0,0 +1,61 @@
+/******************************************************************************
+ * asm-x86/guest/hypervisor.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms and conditions of the GNU General Public
+ * License, version 2, as published by the Free Software Foundation.
+ *
+ * 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/>.
+ *
+ * Copyright (c) 2019 Microsoft.
+ */
+
+#ifndef __X86_HYPERVISOR_H__
+#define __X86_HYPERVISOR_H__
+
+#ifdef CONFIG_GUEST
+
+struct hypervisor_ops {
+    /* Name of the hypervisor */
+    const char *name;
+    /* Main setup routine */
+    void (*setup)(void);
+    /* AP setup */
+    void (*ap_setup)(void);
+    /* Resume from suspension */
+    void (*resume)(void);
+};
+
+bool hypervisor_probe(void);
+void hypervisor_setup(void);
+void hypervisor_ap_setup(void);
+void hypervisor_resume(void);
+
+#else
+
+#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) {}
+
+#endif  /* CONFIG_GUEST */
+
+#endif /* __X86_HYPERVISOR_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/include/asm-x86/guest/xen.h +0 -13
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__ */
 
--

2.20.1

Quoted 4 lines

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

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

#13 lore raw

Re: [Xen-devel] [PATCH for-next v3 5/9] x86: introduce hypervisor framework

In reply to Wei Liu
Quoted 20 lines · Wei Liu
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/types.h>
+
+#include <asm/cache.h>
+#include <asm/guest/hypervisor.h>
+
+static struct hypervisor_ops *hops __read_mostly;

The __read_mostly wants to again go between type and identifier.

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

Quoted 6 lines
xen/arch/x86/guest/hypervisor.c new file +6 -0
+bool hypervisor_probe(void)
+{
+    if ( hops )
+        return true;
+
+    return false;

I assume this isn't simply "return hops" because more is going to be added here?

Quoted 25 lines
xen/include/asm-x86/guest/hypervisor.h new file +22 -0
@@ -0,0 +1,61 @@
+/******************************************************************************
+ * asm-x86/guest/hypervisor.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms and conditions of the GNU General Public
+ * License, version 2, as published by the Free Software Foundation.
+ *
+ * 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/>.
+ *
+ * Copyright (c) 2019 Microsoft.
+ */
+
+#ifndef __X86_HYPERVISOR_H__
+#define __X86_HYPERVISOR_H__
+
+#ifdef CONFIG_GUEST

xen/include/asm-x86/guest/hypervisor.h line 32

Quoted 10 lines
xen/include/asm-x86/guest/hypervisor.h new file +10 -0
+
+struct hypervisor_ops {
+    /* Name of the hypervisor */
+    const char *name;
+    /* Main setup routine */
+    void (*setup)(void);
+    /* AP setup */
+    void (*ap_setup)(void);
+    /* Resume from suspension */
+    void (*resume)(void);

None of these fields look to be used, despite ...

xen/include/asm-x86/guest/hypervisor.h line 38

Quoted 6 lines
xen/include/asm-x86/guest/hypervisor.h new file +6 -0
+};
+
+bool hypervisor_probe(void);
+void hypervisor_setup(void);
+void hypervisor_ap_setup(void);
+void hypervisor_resume(void);

... the latter three of these being the apparent wrappers for them. Perhaps just a side effect of how exactly this series was split up, so not strictly a request to change anything.

xen/include/asm-x86/guest/hypervisor.h DECLARE_PER_CPU(struct vcpu_info *, vcpu_info); · line 59

Quoted 12 lines
xen/include/asm-x86/guest/hypervisor.h new file +0 -8
@@ -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();
-}

Why did the ASSERT_UNREACHABLE() get lost?

Jan

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

author
#14 lore raw

Re: [Xen-devel] [PATCH for-next v3 5/9] x86: introduce hypervisor framework

Quoted 25 lines · Jan Beulich
Quoted 24 lines · Wei Liu
xen/arch/x86/guest/hypervisor.c new file +21 -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/>.
+ *
+ * Copyright (c) 2019 Microsoft.
+ */
+
Quoted 8 lines

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

Quoted 6 lines
xen/arch/x86/guest/hypervisor.c new file +6 -0
+#include <xen/types.h>
+
+#include <asm/cache.h>
+#include <asm/guest/hypervisor.h>
+
+static struct hypervisor_ops *hops __read_mostly;

The __read_mostly wants to again go between type and identifier.

Ack.

Quoted 11 lines

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

Quoted 7 lines
xen/arch/x86/guest/hypervisor.c new file +6 -0
+bool hypervisor_probe(void)
+{
+    if ( hops )
+        return true;
+
+    return false;

I assume this isn't simply "return hops" because more is going to be added here?

That's right.

[...]

Quoted 4 lines
Quoted 4 lines
xen/arch/x86/guest/hypervisor.c new file +0 -0
@@ -49,15 +46,6 @@ DECLARE_PER_CPU(struct vcpu_info *, vcpu_info);
 
 static inline void probe_hypervisor(void) {}
 
Quoted 10 lines

xen/arch/x86/guest/hypervisor.c DECLARE_PER_CPU(struct vcpu_info *, vcpu_info); · line 59

Quoted 8 lines
xen/arch/x86/guest/hypervisor.c new file +0 -8
-static inline void hypervisor_setup(void)
-{
-    ASSERT_UNREACHABLE();
-}
-static inline void hypervisor_ap_setup(void)
-{
-    ASSERT_UNREACHABLE();
-}

Why did the ASSERT_UNREACHABLE() get lost?

I will add it back to all those stubs.

Wei.

Quoted 2 lines

Jan

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

author
#15 lore raw

PATCH v3 6/9 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 78fc603996..9895025d02 100644
@@ -97,7 +97,7 @@ static void map_shared_info(void)
     unsigned int i;
     unsigned long rc;
 
-    if ( hypervisor_alloc_unused_page(&mfn) )
+    if ( xen_alloc_unused_page(&mfn) )
         panic("unable to reserve shared info memory page\n");
 
     xatp.gpfn = mfn_x(mfn);
@@ -284,7 +284,7 @@ void hypervisor_ap_setup(void)
     init_evtchn();
 }
 
-int hypervisor_alloc_unused_page(mfn_t *mfn)
+int xen_alloc_unused_page(mfn_t *mfn)
 {
     unsigned long m;
     int rc;
@@ -296,7 +296,7 @@ int hypervisor_alloc_unused_page(mfn_t *mfn)
     return rc;
 }
 
-int hypervisor_free_unused_page(mfn_t mfn)
+int xen_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 5441e89de2..41b4665649 100644
@@ -739,7 +739,7 @@ static long pv_shim_grant_table_op(unsigned int cmd,
                 };
                 mfn_t mfn;
 
-                rc = hypervisor_alloc_unused_page(&mfn);
+                rc = xen_alloc_unused_page(&mfn);
                 if ( rc )
                 {
                     gprintk(XENLOG_ERR,
@@ -751,7 +751,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);
+                    xen_free_unused_page(mfn);
                     break;
                 }
 
xen/include/asm-x86/guest/xen.h +2 -2
index 3145f75361..8221fc1325 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 xen_alloc_unused_page(mfn_t *mfn);
+int xen_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
#16 lore raw

Re: [Xen-devel] [PATCH for-next v3 6/9] x86: rename hypervisor_{alloc, free}_unused_page

xen/arch/x86/guest/xen/xen.c static void map_shared_info(void) · line 100

Quoted 8 lines · Wei Liu
xen/arch/x86/guest/xen/xen.c +1 -1
@@ -97,7 +97,7 @@ static void map_shared_info(void)
     unsigned int i;
     unsigned long rc;
 
-    if ( hypervisor_alloc_unused_page(&mfn) )
+    if ( xen_alloc_unused_page(&mfn) )

But is just "xen_" as a prefix a good name in Xen code? Perhaps "xen_guest_" or (shorter) "xg_"?

Jan

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

author
#17 lore raw

Re: [Xen-devel] [PATCH for-next v3 6/9] x86: rename hypervisor_{alloc, free}_unused_page

Quoted 7 lines · Jan Beulich
Quoted 6 lines · Wei Liu
xen/arch/x86/guest/xen/xen.c +0 -0
@@ -97,7 +97,7 @@ static void map_shared_info(void)
     unsigned int i;
     unsigned long rc;
 
Quoted 5 lines

xen/arch/x86/guest/xen/xen.c static void map_shared_info(void) · line 100

Quoted 2 lines
xen/arch/x86/guest/xen/xen.c +1 -1
-    if ( hypervisor_alloc_unused_page(&mfn) )
+    if ( xen_alloc_unused_page(&mfn) )

But is just "xen_" as a prefix a good name in Xen code? Perhaps "xen_guest_" or (shorter) "xg_"?

That's fine by me.

Wei.

Quoted 2 lines

Jan

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

author
#18 lore raw

PATCH v3 7/9 x86: switch xen implementation to use hypervisor framework

In reply to Wei Liu

Take the chance to change probe_hypervisor to hypervisor_probe.

---
V3:
1. Address Roger's comments
2. Change xen_hypervisor_ops to xen_ops

---
 xen/arch/x86/guest/hypervisor.c   | 32 ++++++++++++++++++++++++++++++-
 xen/arch/x86/guest/xen/pvh-boot.c |  2 +-
 xen/arch/x86/guest/xen/xen.c      | 26 +++++++++++++------------
 xen/arch/x86/setup.c              |  2 +-
 xen/include/asm-x86/guest/xen.h   |  6 ++++--
 5 files changed, 51 insertions(+), 17 deletions(-)
xen/arch/x86/guest/hypervisor.c +31 -1
index 89b9ae4de0..33bf1a769d 100644
@@ -22,7 +22,7 @@
 #include <xen/types.h>
 
 #include <asm/cache.h>
-#include <asm/guest/hypervisor.h>
+#include <asm/guest.h>
 
 static struct hypervisor_ops *hops __read_mostly;
 
@@ -31,9 +31,39 @@ bool hypervisor_probe(void)
     if ( hops )
         return true;
 
+    /* Too early to use cpu_has_hypervisor */
+    if ( !(cpuid_ecx(1) & cpufeat_mask(X86_FEATURE_HYPERVISOR)) )
+        return false;
+
+#ifdef CONFIG_XEN_GUEST
+    if ( xen_probe() )
+    {
+        hops = &xen_ops;
+        return true;
+    }
+#endif
+
     return false;
 }
 
+void hypervisor_setup(void)
+{
+    if ( hops && hops->setup )
+        hops->setup();
+}
+
+void hypervisor_ap_setup(void)
+{
+    if ( hops && hops->ap_setup )
+        hops->ap_setup();
+}
+
+void hypervisor_resume(void)
+{
+    if ( hops && hops->resume )
+        hops->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 +14 -12
index 9895025d02..655435c1f7 100644
@@ -67,24 +67,19 @@ static void __init find_xen_leaves(void)
     }
 }
 
-void __init probe_hypervisor(void)
+bool __init xen_probe(void)
 {
-    if ( xen_guest )
-        return;
-
-    /* Too early to use cpu_has_hypervisor */
-    if ( !(cpuid_ecx(1) & cpufeat_mask(X86_FEATURE_HYPERVISOR)) )
-        return;
-
     find_xen_leaves();
 
     if ( !xen_cpuid_base )
-        return;
+        return false;
 
     /* Fill the hypercall page. */
     wrmsrl(cpuid_ebx(xen_cpuid_base + 2), __pa(hypercall_page));
 
     xen_guest = true;
+
+    return true;
 }
 
 static void map_shared_info(void)
@@ -249,7 +244,7 @@ static void init_evtchn(void)
     }
 }
 
-void __init hypervisor_setup(void)
+static void __init xen_setup(void)
 {
     init_memmap();
 
@@ -277,7 +272,7 @@ void __init hypervisor_setup(void)
     init_evtchn();
 }
 
-void hypervisor_ap_setup(void)
+static void xen_ap_setup(void)
 {
     set_vcpu_id();
     map_vcpuinfo();
@@ -307,7 +302,7 @@ static void ap_resume(void *unused)
     init_evtchn();
 }
 
-void hypervisor_resume(void)
+static void xen_resume(void)
 {
     /* Reset shared info page. */
     map_shared_info();
@@ -330,6 +325,13 @@ void hypervisor_resume(void)
         pv_console_init();
 }
 
+struct hypervisor_ops xen_ops = {
+    .name = "Xen",
+    .setup = xen_setup,
+    .ap_setup = xen_ap_setup,
+    .resume = xen_resume,
+};
+
 /*
  * Local variables:
  * mode: C
xen/arch/x86/setup.c +1 -1
index dec60d0301..0ee11b15a6 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 +4 -2
index 8221fc1325..c3c6bea24f 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))
 
@@ -31,8 +32,9 @@
 extern bool xen_guest;
 extern bool pv_console;
 extern uint32_t xen_cpuid_base;
+extern struct hypervisor_ops xen_ops;
 
-void probe_hypervisor(void);
+bool xen_probe(void);
 int xen_alloc_unused_page(mfn_t *mfn);
 int xen_free_unused_page(mfn_t mfn);
 
@@ -44,7 +46,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 bool xen_probe(void) { return false; }
 
 #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
Reviewed-by on v3 7/9
#19 lore raw

Re: [Xen-devel] [PATCH for-next v3 7/9] x86: switch xen implementation to use hypervisor framework

Quoted 4 lines · Wei Liu

Take the chance to change probe_hypervisor to hypervisor_probe.

Quoted 201 lines

---
V3:
1. Address Roger's comments
2. Change xen_hypervisor_ops to xen_ops

---
 xen/arch/x86/guest/hypervisor.c   | 32 ++++++++++++++++++++++++++++++-
 xen/arch/x86/guest/xen/pvh-boot.c |  2 +-
 xen/arch/x86/guest/xen/xen.c      | 26 +++++++++++++------------
 xen/arch/x86/setup.c              |  2 +-
 xen/include/asm-x86/guest/xen.h   |  6 ++++--
 5 files changed, 51 insertions(+), 17 deletions(-)
xen/arch/x86/guest/hypervisor.c +31 -1
index 89b9ae4de0..33bf1a769d 100644
@@ -22,7 +22,7 @@
 #include <xen/types.h>
 
 #include <asm/cache.h>
-#include <asm/guest/hypervisor.h>
+#include <asm/guest.h>
 
 static struct hypervisor_ops *hops __read_mostly;
 
@@ -31,9 +31,39 @@ bool hypervisor_probe(void)
     if ( hops )
         return true;
 
+    /* Too early to use cpu_has_hypervisor */
+    if ( !(cpuid_ecx(1) & cpufeat_mask(X86_FEATURE_HYPERVISOR)) )
+        return false;
+
+#ifdef CONFIG_XEN_GUEST
+    if ( xen_probe() )
+    {
+        hops = &xen_ops;
+        return true;
+    }
+#endif
+
     return false;
 }
 
+void hypervisor_setup(void)
+{
+    if ( hops && hops->setup )
+        hops->setup();
+}
+
+void hypervisor_ap_setup(void)
+{
+    if ( hops && hops->ap_setup )
+        hops->ap_setup();
+}
+
+void hypervisor_resume(void)
+{
+    if ( hops && hops->resume )
+        hops->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 +14 -12
index 9895025d02..655435c1f7 100644
@@ -67,24 +67,19 @@ static void __init find_xen_leaves(void)
     }
 }
 
-void __init probe_hypervisor(void)
+bool __init xen_probe(void)
 {
-    if ( xen_guest )
-        return;
-
-    /* Too early to use cpu_has_hypervisor */
-    if ( !(cpuid_ecx(1) & cpufeat_mask(X86_FEATURE_HYPERVISOR)) )
-        return;
-
     find_xen_leaves();
 
     if ( !xen_cpuid_base )
-        return;
+        return false;
 
     /* Fill the hypercall page. */
     wrmsrl(cpuid_ebx(xen_cpuid_base + 2), __pa(hypercall_page));
 
     xen_guest = true;
+
+    return true;
 }
 
 static void map_shared_info(void)
@@ -249,7 +244,7 @@ static void init_evtchn(void)
     }
 }
 
-void __init hypervisor_setup(void)
+static void __init xen_setup(void)
 {
     init_memmap();
 
@@ -277,7 +272,7 @@ void __init hypervisor_setup(void)
     init_evtchn();
 }
 
-void hypervisor_ap_setup(void)
+static void xen_ap_setup(void)
 {
     set_vcpu_id();
     map_vcpuinfo();
@@ -307,7 +302,7 @@ static void ap_resume(void *unused)
     init_evtchn();
 }
 
-void hypervisor_resume(void)
+static void xen_resume(void)
 {
     /* Reset shared info page. */
     map_shared_info();
@@ -330,6 +325,13 @@ void hypervisor_resume(void)
         pv_console_init();
 }
 
+struct hypervisor_ops xen_ops = {
+    .name = "Xen",
+    .setup = xen_setup,
+    .ap_setup = xen_ap_setup,
+    .resume = xen_resume,
+};
+
 /*
  * Local variables:
  * mode: C
xen/arch/x86/setup.c +1 -1
index dec60d0301..0ee11b15a6 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 +4 -3
index 8221fc1325..c3c6bea24f 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))
 
@@ -31,8 +32,9 @@
 extern bool xen_guest;
 extern bool pv_console;
 extern uint32_t xen_cpuid_base;
+extern struct hypervisor_ops xen_ops;
 
-void probe_hypervisor(void);
+bool xen_probe(void);
 int xen_alloc_unused_page(mfn_t *mfn);
 int xen_free_unused_page(mfn_t mfn);
 
@@ -44,7 +46,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 bool xen_probe(void) { return false; }
 
 #endif /* CONFIG_XEN_GUEST */
 #endif /* __X86_GUEST_XEN_H__ */
--

2.20.1

Quoted 4 lines

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

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

Acked-by on v3 7/9
#20 lore raw

Re: [Xen-devel] [PATCH for-next v3 7/9] x86: switch xen implementation to use hypervisor framework

In reply to Wei Liu
Quoted 10 lines · Wei Liu
xen/arch/x86/guest/hypervisor.c +6 -0
@@ -31,9 +31,39 @@ bool hypervisor_probe(void)
     if ( hops )
         return true;
 
+    /* Too early to use cpu_has_hypervisor */
+    if ( !(cpuid_ecx(1) & cpufeat_mask(X86_FEATURE_HYPERVISOR)) )
+        return false;
+
+#ifdef CONFIG_XEN_GUEST
+    if ( xen_probe() )

xen/arch/x86/guest/hypervisor.c bool hypervisor_probe(void) · line 49

Quoted 10 lines
xen/arch/x86/guest/hypervisor.c +7 -0
+    {
+        hops = &xen_ops;
+        return true;
+    }
+#endif
+
     return false;
 }
 
+void hypervisor_setup(void)

__init?

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

Quoted 5 lines
xen/arch/x86/guest/xen/xen.c +1 -0
@@ -330,6 +325,13 @@ void hypervisor_resume(void)
         pv_console_init();
 }
 
+struct hypervisor_ops xen_ops = {

const (will require a corresponding adjustment in the earlier patch then too)?

With these taken care of and the naming possibly adjusted according to whatever the decision on the earlier patch s going to be

Jan

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

author
#21 lore raw

PATCH v3 8/9 x86: be more verbose when running on a hypervisor

In reply to Wei Liu

---
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(-)
xen/arch/x86/guest/hypervisor.c +6 -0
index 33bf1a769d..a666ad9526 100644
@@ -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 )
xen/arch/x86/setup.c +5 -1
index 0ee11b15a6..cf5a7b8e1e 100644
@@ -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");
 
xen/include/asm-x86/guest/hypervisor.h +3 -0
index 38344e2e89..b583722f5d 100644
@@ -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 */
 
Signature · 7 lines
2.20.1


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

Re: [Xen-devel] [PATCH for-next v3 8/9] x86: be more verbose when running on a hypervisor

Quoted 2 lines · Wei Liu
Quoted 83 lines

---
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(-)
xen/arch/x86/guest/hypervisor.c +6 -0
index 33bf1a769d..a666ad9526 100644
@@ -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 )
xen/arch/x86/setup.c +5 -1
index 0ee11b15a6..cf5a7b8e1e 100644
@@ -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");
 
xen/include/asm-x86/guest/hypervisor.h +3 -1
index 38344e2e89..b583722f5d 100644
@@ -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

Quoted 4 lines

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

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

#23 lore raw

Re: [Xen-devel] [PATCH for-next v3 8/9] x86: be more verbose when running on a hypervisor

In reply to Wei Liu
Quoted 20 lines · Wei Liu
xen/arch/x86/setup.c +2 -1
@@ -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();
 

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

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

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

author
#24 lore raw

PATCH v3 9/9 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.

---
V3:
1. Remove some unused code
2. Rename structure
3. Also detect HV#1 signature

---
 xen/arch/x86/Kconfig               |  9 +++++
 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 | 45 +++++++++++++++++++++++++
 7 files changed, 119 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 +9 -0
index 867de857e8..56513c771c 100644
@@ -164,6 +164,15 @@ endchoice
 config GUEST
 	bool
 
+config HYPERV_GUEST
+	def_bool n
+	select GUEST
+	prompt "Hyper-V Guest"
+	---help---
+	  Support for Xen detecting when it is running under Hyper-V.
+
+	  If unsure, say N.
+
 config XEN_GUEST
 	def_bool n
 	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 a666ad9526..17392d1ffa 100644
@@ -43,6 +43,14 @@ bool hypervisor_probe(void)
     }
 #endif
 
+#ifdef CONFIG_HYPERV_GUEST
+    if ( hyperv_probe() )
+    {
+        hops = &hyperv_ops;
+        return true;
+    }
+#endif
+
     return false;
 }
 
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 +45 -0

45 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
Reviewed-by on v3 9/9
#25 lore raw

Re: [Xen-devel] [PATCH for-next v3 9/9] x86: introduce CONFIG_HYPERV and detection code

Quoted 7 lines · 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.

...with one suggestion...

Quoted 119 lines

---
V3:
1. Remove some unused code
2. Rename structure
3. Also detect HV#1 signature

---
 xen/arch/x86/Kconfig               |  9 +++++
 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 | 45 +++++++++++++++++++++++++
 7 files changed, 119 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 +9 -0
index 867de857e8..56513c771c 100644
@@ -164,6 +164,15 @@ endchoice
 config GUEST
        bool
 
+config HYPERV_GUEST
+       def_bool n
+       select GUEST
+       prompt "Hyper-V Guest"
+       ---help---
+         Support for Xen detecting when it is running under Hyper-V.
+
+         If unsure, say N.
+
 config XEN_GUEST
        def_bool n
        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
new file mode 100644
index 0000000000..7ab4b127f3
@@ -0,0 +1,54 @@
+/******************************************************************************
+ * arch/x86/guest/hyperv/hyperv.c
+ *
+ * Support for detecting and running under Hyper-V.
+ *
+ * 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/>.
+ *
+ * Copyright (c) 2019 Microsoft.
+ */
+#include <xen/init.h>
+
+#include <asm/guest.h>
+
+bool __init hyperv_probe(void)
+{
+    uint32_t eax, ebx, ecx, edx;
+
+    cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
+    if ( !((ebx == 0x7263694d) &&  /* "Micr" */
+           (ecx == 0x666f736f) &&  /* "osof" */
+           (edx == 0x76482074)) )  /* "t Hv" */
+        return false;
+
+    cpuid(0x40000001, &eax, &ebx, &ecx, &edx);
+    if ( eax != 0x31237648 )    /* Hv#1 */
+        return false;
+
+    return true;
+}
+
+struct hypervisor_ops hyperv_ops = {
+    .name = "Hyper-V",
+};
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/arch/x86/guest/hypervisor.c +0 -0
index a666ad9526..17392d1ffa 100644

xen/arch/x86/guest/hypervisor.c bool hypervisor_probe(void) · line 45

Quoted 3 lines
xen/arch/x86/guest/hypervisor.c +0 -0
@@ -43,6 +43,14 @@ bool hypervisor_probe(void)
     }
 #endif
 

Add a comment here to point out that hyperv_probe() needs to be called after xen_probe() to avoid a false positive due to viridian support.

Quoted 78 lines
xen/arch/x86/guest/hypervisor.c +8 -0
+#ifdef CONFIG_HYPERV_GUEST
+    if ( hyperv_probe() )
+    {
+        hops = &hyperv_ops;
+        return true;
+    }
+#endif
+
     return false;
 }
 
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 +45 -1
new file mode 100644
index 0000000000..4b9cc5a836
@@ -0,0 +1,45 @@
+/******************************************************************************
+ * asm-x86/guest/hyperv.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms and conditions of the GNU General Public
+ * License, version 2, as published by the Free Software Foundation.
+ *
+ * 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/>.
+ *
+ * Copyright (c) 2019 Microsoft.
+ */
+
+#ifndef __X86_GUEST_HYPERV_H__
+#define __X86_GUEST_HYPERV_H__
+
+#ifdef CONFIG_HYPERV_GUEST
+
+#include <asm/guest/hypervisor.h>
+
+extern struct hypervisor_ops hyperv_ops;
+
+bool hyperv_probe(void);
+
+#else
+
+static inline bool hyperv_probe(void) { return false; }
+
+#endif /* CONFIG_HYPERV_GUEST */
+#endif /* __X86_GUEST_HYPERV_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
--

2.20.1

Quoted 4 lines

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

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

author
#26 lore raw

Re: [Xen-devel] [PATCH for-next v3 9/9] x86: introduce CONFIG_HYPERV and detection code

Quoted 10 lines · Paul Durrant
Quoted 7 lines · 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.

Thanks.

[...]

Quoted 12 lines

xen/arch/x86/guest/hypervisor.c bool hypervisor_probe(void) · line 45

Quoted 8 lines
xen/arch/x86/guest/hypervisor.c +0 -0
index a666ad9526..17392d1ffa 100644
@@ -43,6 +43,14 @@ bool hypervisor_probe(void)
     }
 #endif
 

Add a comment here to point out that hyperv_probe() needs to be called after xen_probe() to avoid a false positive due to viridian support.

Yes I can do that.

Wei.

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

#27 lore raw

Re: [Xen-devel] [PATCH for-next v3 9/9] x86: introduce CONFIG_HYPERV and detection code

In reply to Wei Liu

xen/arch/x86/Kconfig endchoice · line 170

Quoted 10 lines · Wei Liu
xen/arch/x86/Kconfig +4 -0
@@ -164,6 +164,15 @@ endchoice
 config GUEST
 	bool
 
+config HYPERV_GUEST
+	def_bool n
+	select GUEST
+	prompt "Hyper-V Guest"

Please can you avoid following the bad example XEN_GUEST gives (and perhaps even take the opportunity here or in the earlier patch adding GUEST to change that one as well)? What you want is

config HYPERV_GUEST
bool "Hyper-V Guest"
select GUEST

Quoted 35 lines
xen/arch/x86/guest/hyperv/hyperv.c new file +32 -0
@@ -0,0 +1,54 @@
+/******************************************************************************
+ * arch/x86/guest/hyperv/hyperv.c
+ *
+ * Support for detecting and running under Hyper-V.
+ *
+ * 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/>.
+ *
+ * Copyright (c) 2019 Microsoft.
+ */
+#include <xen/init.h>
+
+#include <asm/guest.h>
+
+bool __init hyperv_probe(void)
+{
+    uint32_t eax, ebx, ecx, edx;
+
+    cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
+    if ( !((ebx == 0x7263694d) &&  /* "Micr" */
+           (ecx == 0x666f736f) &&  /* "osof" */
+           (edx == 0x76482074)) )  /* "t Hv" */

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

Quoted 10 lines
xen/arch/x86/guest/hyperv/hyperv.c new file +10 -0
+        return false;
+
+    cpuid(0x40000001, &eax, &ebx, &ecx, &edx);
+    if ( eax != 0x31237648 )    /* Hv#1 */
+        return false;
+
+    return true;
+}
+
+struct hypervisor_ops hyperv_ops = {

const again.

xen/arch/x86/guest/hypervisor.c bool hypervisor_probe(void) · line 52

Quoted 13 lines
xen/arch/x86/guest/hypervisor.c +7 -0
@@ -43,6 +43,14 @@ bool hypervisor_probe(void)
     }
 #endif
 
+#ifdef CONFIG_HYPERV_GUEST
+    if ( hyperv_probe() )
+    {
+        hops = &hyperv_ops;
+        return true;
+    }
+#endif

This recurring #ifdef CONFIG_*_GUEST is going to start looking ugly the latest when one or two more get added. Perhaps better providing *_probe() stubs returning false, and (like we do elsewhere) rely on DCE to get rid of the *_ops reference? (And really you already have such a stub - all you need to do is put the hyperv_ops declaration outside the #ifdef (but read on).

Also how about having *_probe() return the address of *_ops, such that the latter could all become static?

Jan

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

author
#28 lore raw

Re: [Xen-devel] [PATCH for-next v3 9/9] x86: introduce CONFIG_HYPERV and detection code

Quoted 16 lines · Jan Beulich

xen/arch/x86/Kconfig endchoice · line 170

Quoted 10 lines · Wei Liu
xen/arch/x86/Kconfig +4 -0
@@ -164,6 +164,15 @@ endchoice
 config GUEST
 	bool
 
+config HYPERV_GUEST
+	def_bool n
+	select GUEST
+	prompt "Hyper-V Guest"

Please can you avoid following the bad example XEN_GUEST gives (and perhaps even take the opportunity here or in the earlier patch adding GUEST to change that one as well)? What you want is

Quoted 3 lines

config HYPERV_GUEST
bool "Hyper-V Guest"
select GUEST

Ack.

Quoted 70 lines
Quoted 36 lines
xen/arch/x86/guest/hyperv/hyperv.c new file +32 -0
@@ -0,0 +1,54 @@
+/******************************************************************************
+ * arch/x86/guest/hyperv/hyperv.c
+ *
+ * Support for detecting and running under Hyper-V.
+ *
+ * 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/>.
+ *
+ * Copyright (c) 2019 Microsoft.
+ */
+#include <xen/init.h>
+
+#include <asm/guest.h>
+
+bool __init hyperv_probe(void)
+{
+    uint32_t eax, ebx, ecx, edx;
+
+    cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
+    if ( !((ebx == 0x7263694d) &&  /* "Micr" */
+           (ecx == 0x666f736f) &&  /* "osof" */
+           (edx == 0x76482074)) )  /* "t Hv" */

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

Quoted 10 lines
xen/arch/x86/guest/hyperv/hyperv.c new file +10 -0
+        return false;
+
+    cpuid(0x40000001, &eax, &ebx, &ecx, &edx);
+    if ( eax != 0x31237648 )    /* Hv#1 */
+        return false;
+
+    return true;
+}
+
+struct hypervisor_ops hyperv_ops = {

const again.

xen/arch/x86/guest/hypervisor.c bool hypervisor_probe(void) · line 52

Quoted 13 lines
xen/arch/x86/guest/hypervisor.c +7 -0
@@ -43,6 +43,14 @@ bool hypervisor_probe(void)
     }
 #endif
 
+#ifdef CONFIG_HYPERV_GUEST
+    if ( hyperv_probe() )
+    {
+        hops = &hyperv_ops;
+        return true;
+    }
+#endif

This recurring #ifdef CONFIG_*_GUEST is going to start looking ugly the latest when one or two more get added. Perhaps better providing *_probe() stubs returning false, and (like we do elsewhere) rely on DCE to get rid of the *_ops reference? (And really you already have such a stub - all you need to do is put the hyperv_ops declaration outside the #ifdef (but read on).

Quoted 2 lines

Also how about having *_probe() return the address of *_ops, such that the latter could all become static?

Previously you made a suggestion to make probe return the name of the hypervisor. Here you ask for address of ops. I actually prefer the method suggested here, but this means I will need to keep hypervisor_name around.

Wei.

Quoted 2 lines

Jan

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

#29 lore raw

Re: [Xen-devel] [PATCH for-next v3 9/9] x86: introduce CONFIG_HYPERV and detection code

Quoted 93 lines · Wei Liu
Quoted 16 lines · Jan Beulich

xen/arch/x86/Kconfig endchoice · line 170

Quoted 10 lines · Wei Liu
xen/arch/x86/Kconfig +4 -0
@@ -164,6 +164,15 @@ endchoice
 config GUEST
 	bool
 
+config HYPERV_GUEST
+	def_bool n
+	select GUEST
+	prompt "Hyper-V Guest"

Please can you avoid following the bad example XEN_GUEST gives (and perhaps even take the opportunity here or in the earlier patch adding GUEST to change that one as well)? What you want is

Quoted 3 lines

config HYPERV_GUEST
bool "Hyper-V Guest"
select GUEST

Ack.

Quoted 70 lines
Quoted 36 lines
xen/arch/x86/guest/hyperv/hyperv.c new file +32 -0
@@ -0,0 +1,54 @@
+/******************************************************************************
+ * arch/x86/guest/hyperv/hyperv.c
+ *
+ * Support for detecting and running under Hyper-V.
+ *
+ * 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/>.
+ *
+ * Copyright (c) 2019 Microsoft.
+ */
+#include <xen/init.h>
+
+#include <asm/guest.h>
+
+bool __init hyperv_probe(void)
+{
+    uint32_t eax, ebx, ecx, edx;
+
+    cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
+    if ( !((ebx == 0x7263694d) &&  /* "Micr" */
+           (ecx == 0x666f736f) &&  /* "osof" */
+           (edx == 0x76482074)) )  /* "t Hv" */

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

Quoted 10 lines
xen/arch/x86/guest/hyperv/hyperv.c new file +10 -0
+        return false;
+
+    cpuid(0x40000001, &eax, &ebx, &ecx, &edx);
+    if ( eax != 0x31237648 )    /* Hv#1 */
+        return false;
+
+    return true;
+}
+
+struct hypervisor_ops hyperv_ops = {

const again.

xen/arch/x86/guest/hypervisor.c bool hypervisor_probe(void) · line 52

Quoted 13 lines
xen/arch/x86/guest/hypervisor.c +7 -0
@@ -43,6 +43,14 @@ bool hypervisor_probe(void)
     }
 #endif
 
+#ifdef CONFIG_HYPERV_GUEST
+    if ( hyperv_probe() )
+    {
+        hops = &hyperv_ops;
+        return true;
+    }
+#endif

This recurring #ifdef CONFIG_*_GUEST is going to start looking ugly the latest when one or two more get added. Perhaps better providing *_probe() stubs returning false, and (like we do elsewhere) rely on DCE to get rid of the *_ops reference? (And really you already have such a stub - all you need to do is put the hyperv_ops declaration outside the #ifdef (but read on).

Quoted 7 lines
Quoted 2 lines

Also how about having *_probe() return the address of *_ops, such that the latter could all become static?

Previously you made a suggestion to make probe return the name of the hypervisor. Here you ask for address of ops. I actually prefer the method suggested here, but this means I will need to keep hypervisor_name around.

Is there actually any user of the name field other than the caller of probe? If not, surely that caller could access the name field without a hypervisor_name() wrapper.

Jan

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

author
#30 lore raw

Re: [Xen-devel] [PATCH for-next v3 9/9] x86: introduce CONFIG_HYPERV and detection code

Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 3 lines

Also how about having *_probe() return the address of *_ops, such that the latter could all become static?

Quoted 8 lines
Quoted 4 lines

Previously you made a suggestion to make probe return the name of the hypervisor. Here you ask for address of ops. I actually prefer the method suggested here, but this means I will need to keep hypervisor_name around.

Is there actually any user of the name field other than the caller of probe? If not, surely that caller could access the name field without a hypervisor_name() wrapper.

I don't envision more users at this stage.

I'm fine with accessing that field directly. We can always introduce the function again if it becomes necessary.

Wei.

Quoted 2 lines

Jan

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