All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xen-devel] [PATCH for-next v2 0/9] Port Xen to Hyper-V
@ 2019-09-30 15:00 Wei Liu
  2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 1/9] x86: introduce CONFIG_GUEST and move code Wei Liu
                   ` (10 more replies)
  0 siblings, 11 replies; 28+ messages in thread
From: Wei Liu @ 2019-09-30 15:00 UTC (permalink / raw)
  To: Xen Development List
  Cc: Wei Liu, Wei Liu, Andrew Cooper, Michael Kelley, Jan Beulich,
	Roger Pau Monné

Hi all

This is version 2 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 piece meal when they are ready.

Questions and comments are welcome.

Thanks,
Wei.

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

Cc: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Wei Liu <wl@xen.org>
Cc: Roger Pau Monné <roger.pau@citrix.com>

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            | 69 ++++++++++++++++
 xen/arch/x86/guest/hypervisor.c               | 82 +++++++++++++++++++
 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        | 63 ++++++++++++++
 xen/include/asm-x86/guest/xen.h               | 24 ++----
 17 files changed, 321 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

-- 
2.20.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [Xen-devel] [PATCH for-next v2 1/9] x86: introduce CONFIG_GUEST and move code
  2019-09-30 15:00 [Xen-devel] [PATCH for-next v2 0/9] Port Xen to Hyper-V Wei Liu
@ 2019-09-30 15:00 ` Wei Liu
  2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 2/9] x86: include asm_defns.h directly in hypercall.h Wei Liu
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 28+ messages in thread
From: Wei Liu @ 2019-09-30 15:00 UTC (permalink / raw)
  To: Xen Development List
  Cc: Wei Liu, Wei Liu, Andrew Cooper, Michael Kelley, Jan Beulich,
	Roger Pau Monné

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.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 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%)

diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig
index 288dc6c042..584bdc1bb8 100644
--- a/xen/arch/x86/Kconfig
+++ b/xen/arch/x86/Kconfig
@@ -160,8 +160,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.
diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile
index 2443fd2cc5..99a12d0090 100644
--- a/xen/arch/x86/Makefile
+++ b/xen/arch/x86/Makefile
@@ -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
diff --git a/xen/arch/x86/guest/Makefile b/xen/arch/x86/guest/Makefile
index 26fb4b1007..6806f04947 100644
--- a/xen/arch/x86/guest/Makefile
+++ b/xen/arch/x86/guest/Makefile
@@ -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
diff --git a/xen/arch/x86/guest/xen/Makefile b/xen/arch/x86/guest/xen/Makefile
new file mode 100644
index 0000000000..26fb4b1007
--- /dev/null
+++ b/xen/arch/x86/guest/xen/Makefile
@@ -0,0 +1,4 @@
+obj-y += hypercall_page.o
+obj-y += xen.o
+
+obj-bin-$(CONFIG_PVH_GUEST) += pvh-boot.init.o
diff --git a/xen/arch/x86/guest/hypercall_page.S b/xen/arch/x86/guest/xen/hypercall_page.S
similarity index 100%
rename from xen/arch/x86/guest/hypercall_page.S
rename to xen/arch/x86/guest/xen/hypercall_page.S
diff --git a/xen/arch/x86/guest/pvh-boot.c b/xen/arch/x86/guest/xen/pvh-boot.c
similarity index 100%
rename from xen/arch/x86/guest/pvh-boot.c
rename to xen/arch/x86/guest/xen/pvh-boot.c
diff --git a/xen/arch/x86/guest/xen.c b/xen/arch/x86/guest/xen/xen.c
similarity index 100%
rename from xen/arch/x86/guest/xen.c
rename to xen/arch/x86/guest/xen/xen.c
-- 
2.20.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [Xen-devel] [PATCH for-next v2 2/9] x86: include asm_defns.h directly in hypercall.h
  2019-09-30 15:00 [Xen-devel] [PATCH for-next v2 0/9] Port Xen to Hyper-V Wei Liu
  2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 1/9] x86: introduce CONFIG_GUEST and move code Wei Liu
@ 2019-09-30 15:00 ` Wei Liu
  2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 3/9] x86: drop hypervisor_cpuid_base Wei Liu
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 28+ messages in thread
From: Wei Liu @ 2019-09-30 15:00 UTC (permalink / raw)
  To: Xen Development List
  Cc: Wei Liu, Wei Liu, Andrew Cooper, Michael Kelley, Jan Beulich,
	Roger Pau Monné

ASM_CALL_CONSTRAINT is defined there.

No functional change.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/include/asm-x86/guest/hypercall.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/xen/include/asm-x86/guest/hypercall.h b/xen/include/asm-x86/guest/hypercall.h
index d548816b30..c9deca6ffc 100644
--- a/xen/include/asm-x86/guest/hypercall.h
+++ b/xen/include/asm-x86/guest/hypercall.h
@@ -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>
-- 
2.20.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [Xen-devel] [PATCH for-next v2 3/9] x86: drop hypervisor_cpuid_base
  2019-09-30 15:00 [Xen-devel] [PATCH for-next v2 0/9] Port Xen to Hyper-V Wei Liu
  2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 1/9] x86: introduce CONFIG_GUEST and move code Wei Liu
  2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 2/9] x86: include asm_defns.h directly in hypercall.h Wei Liu
@ 2019-09-30 15:00 ` Wei Liu
  2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 4/9] x86: include xen/lib.h in guest/hypercall.h Wei Liu
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 28+ messages in thread
From: Wei Liu @ 2019-09-30 15:00 UTC (permalink / raw)
  To: Xen Development List
  Cc: Wei Liu, Wei Liu, Andrew Cooper, Michael Kelley, Jan Beulich,
	Roger Pau Monné

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

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 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(-)

diff --git a/xen/arch/x86/guest/xen/xen.c b/xen/arch/x86/guest/xen/xen.c
index 7b7a5badab..78fc603996 100644
--- a/xen/arch/x86/guest/xen/xen.c
+++ b/xen/arch/x86/guest/xen/xen.c
@@ -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();
diff --git a/xen/arch/x86/pv/shim.c b/xen/arch/x86/pv/shim.c
index 5edbcd9ac5..5441e89de2 100644
--- a/xen/arch/x86/pv/shim.c
+++ b/xen/arch/x86/pv/shim.c
@@ -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;
 }
diff --git a/xen/include/asm-x86/guest/xen.h b/xen/include/asm-x86/guest/xen.h
index 7e04e4a7ab..b015ed1883 100644
--- a/xen/include/asm-x86/guest/xen.h
+++ b/xen/include/asm-x86/guest/xen.h
@@ -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);
-- 
2.20.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [Xen-devel] [PATCH for-next v2 4/9] x86: include xen/lib.h in guest/hypercall.h
  2019-09-30 15:00 [Xen-devel] [PATCH for-next v2 0/9] Port Xen to Hyper-V Wei Liu
                   ` (2 preceding siblings ...)
  2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 3/9] x86: drop hypervisor_cpuid_base Wei Liu
@ 2019-09-30 15:00 ` Wei Liu
  2019-10-21  9:02   ` Roger Pau Monné
  2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 5/9] x86: introduce hypervisor framework Wei Liu
                   ` (6 subsequent siblings)
  10 siblings, 1 reply; 28+ messages in thread
From: Wei Liu @ 2019-09-30 15:00 UTC (permalink / raw)
  To: Xen Development List
  Cc: Wei Liu, Wei Liu, Andrew Cooper, Michael Kelley, Jan Beulich,
	Roger Pau Monné

We need ASSERT_UNREACHABLE.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
---
 xen/include/asm-x86/guest/hypercall.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/xen/include/asm-x86/guest/hypercall.h b/xen/include/asm-x86/guest/hypercall.h
index c9deca6ffc..d0d2f5022d 100644
--- a/xen/include/asm-x86/guest/hypercall.h
+++ b/xen/include/asm-x86/guest/hypercall.h
@@ -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(
-- 
2.20.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [Xen-devel] [PATCH for-next v2 5/9] x86: introduce hypervisor framework
  2019-09-30 15:00 [Xen-devel] [PATCH for-next v2 0/9] Port Xen to Hyper-V Wei Liu
                   ` (3 preceding siblings ...)
  2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 4/9] x86: include xen/lib.h in guest/hypercall.h Wei Liu
@ 2019-09-30 15:00 ` Wei Liu
  2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 6/9] x86: rename hypervisor_{alloc, free}_unused_page Wei Liu
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 28+ messages in thread
From: Wei Liu @ 2019-09-30 15:00 UTC (permalink / raw)
  To: Xen Development List
  Cc: Wei Liu, Wei Liu, Andrew Cooper, Michael Kelley, Jan Beulich,
	Roger Pau Monné

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.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
---
 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

diff --git a/xen/arch/x86/guest/Makefile b/xen/arch/x86/guest/Makefile
index 6806f04947..f63d64bbee 100644
--- a/xen/arch/x86/guest/Makefile
+++ b/xen/arch/x86/guest/Makefile
@@ -1 +1,3 @@
+obj-y += hypervisor.o
+
 subdir-$(CONFIG_XEN_GUEST) += xen
diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c
new file mode 100644
index 0000000000..89b9ae4de0
--- /dev/null
+++ b/xen/arch/x86/guest/hypervisor.c
@@ -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:
+ */
diff --git a/xen/include/asm-x86/guest.h b/xen/include/asm-x86/guest.h
index a38c6b5b3f..8e167165ae 100644
--- a/xen/include/asm-x86/guest.h
+++ b/xen/include/asm-x86/guest.h
@@ -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>
diff --git a/xen/include/asm-x86/guest/hypervisor.h b/xen/include/asm-x86/guest/hypervisor.h
new file mode 100644
index 0000000000..38344e2e89
--- /dev/null
+++ b/xen/include/asm-x86/guest/hypervisor.h
@@ -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:
+ */
diff --git a/xen/include/asm-x86/guest/xen.h b/xen/include/asm-x86/guest/xen.h
index b015ed1883..3145f75361 100644
--- a/xen/include/asm-x86/guest/xen.h
+++ b/xen/include/asm-x86/guest/xen.h
@@ -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


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [Xen-devel] [PATCH for-next v2 6/9] x86: rename hypervisor_{alloc, free}_unused_page
  2019-09-30 15:00 [Xen-devel] [PATCH for-next v2 0/9] Port Xen to Hyper-V Wei Liu
                   ` (4 preceding siblings ...)
  2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 5/9] x86: introduce hypervisor framework Wei Liu
@ 2019-09-30 15:00 ` Wei Liu
  2019-10-21  9:11   ` Roger Pau Monné
  2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 7/9] x86: switch xen implementation to use hypervisor framework Wei Liu
                   ` (4 subsequent siblings)
  10 siblings, 1 reply; 28+ messages in thread
From: Wei Liu @ 2019-09-30 15:00 UTC (permalink / raw)
  To: Xen Development List
  Cc: Wei Liu, Wei Liu, Andrew Cooper, Michael Kelley, Jan Beulich,
	Roger Pau Monné

They are used in Xen code only.

No functional change.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
---
 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(-)

diff --git a/xen/arch/x86/guest/xen/xen.c b/xen/arch/x86/guest/xen/xen.c
index 78fc603996..9895025d02 100644
--- a/xen/arch/x86/guest/xen/xen.c
+++ b/xen/arch/x86/guest/xen/xen.c
@@ -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));
 }
diff --git a/xen/arch/x86/pv/shim.c b/xen/arch/x86/pv/shim.c
index 5441e89de2..41b4665649 100644
--- a/xen/arch/x86/pv/shim.c
+++ b/xen/arch/x86/pv/shim.c
@@ -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;
                 }
 
diff --git a/xen/include/asm-x86/guest/xen.h b/xen/include/asm-x86/guest/xen.h
index 3145f75361..8221fc1325 100644
--- a/xen/include/asm-x86/guest/xen.h
+++ b/xen/include/asm-x86/guest/xen.h
@@ -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);
-- 
2.20.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [Xen-devel] [PATCH for-next v2 7/9] x86: switch xen implementation to use hypervisor framework
  2019-09-30 15:00 [Xen-devel] [PATCH for-next v2 0/9] Port Xen to Hyper-V Wei Liu
                   ` (5 preceding siblings ...)
  2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 6/9] x86: rename hypervisor_{alloc, free}_unused_page Wei Liu
@ 2019-09-30 15:00 ` Wei Liu
  2019-10-21  9:56   ` Roger Pau Monné
  2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 8/9] x86: be more verbose when running on a hypervisor Wei Liu
                   ` (3 subsequent siblings)
  10 siblings, 1 reply; 28+ messages in thread
From: Wei Liu @ 2019-09-30 15:00 UTC (permalink / raw)
  To: Xen Development List
  Cc: Wei Liu, Wei Liu, Andrew Cooper, Michael Kelley, Jan Beulich,
	Roger Pau Monné

Take the chance to change probe_hypervisor to hypervisor_probe.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
---
 xen/arch/x86/guest/hypervisor.c   | 31 +++++++++++++++++++++++++++++--
 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, 49 insertions(+), 18 deletions(-)

diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c
index 89b9ae4de0..30453b6a7a 100644
--- a/xen/arch/x86/guest/hypervisor.c
+++ b/xen/arch/x86/guest/hypervisor.c
@@ -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,7 +31,34 @@ bool hypervisor_probe(void)
     if ( hops )
         return true;
 
-    return false;
+    /* 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_hypervisor_ops;
+#endif
+
+    return !!hops;
+}
+
+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();
 }
 
 /*
diff --git a/xen/arch/x86/guest/xen/pvh-boot.c b/xen/arch/x86/guest/xen/pvh-boot.c
index ca8e156f7d..498625eae0 100644
--- a/xen/arch/x86/guest/xen/pvh-boot.c
+++ b/xen/arch/x86/guest/xen/pvh-boot.c
@@ -103,7 +103,7 @@ void __init pvh_init(multiboot_info_t **mbi, module_t **mod)
 {
     convert_pvh_info(mbi, mod);
 
-    probe_hypervisor();
+    hypervisor_probe();
     ASSERT(xen_guest);
 
     get_memory_map();
diff --git a/xen/arch/x86/guest/xen/xen.c b/xen/arch/x86/guest/xen/xen.c
index 9895025d02..a9d321e5eb 100644
--- a/xen/arch/x86/guest/xen/xen.c
+++ b/xen/arch/x86/guest/xen/xen.c
@@ -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)
+void __init xen_setup(void)
 {
     init_memmap();
 
@@ -277,7 +272,7 @@ void __init hypervisor_setup(void)
     init_evtchn();
 }
 
-void hypervisor_ap_setup(void)
+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)
+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_hypervisor_ops = {
+    .name = "Xen",
+    .setup = xen_setup,
+    .ap_setup = xen_ap_setup,
+    .resume = xen_resume,
+};
+
 /*
  * Local variables:
  * mode: C
diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
index dec60d0301..0ee11b15a6 100644
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -763,7 +763,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
      * allocing any xenheap structures wanted in lower memory. */
     kexec_early_calculations();
 
-    probe_hypervisor();
+    hypervisor_probe();
 
     parse_video_info();
 
diff --git a/xen/include/asm-x86/guest/xen.h b/xen/include/asm-x86/guest/xen.h
index 8221fc1325..7401c80a1a 100644
--- a/xen/include/asm-x86/guest/xen.h
+++ b/xen/include/asm-x86/guest/xen.h
@@ -23,6 +23,7 @@
 
 #include <asm/e820.h>
 #include <asm/fixmap.h>
+#include <asm/guest/hypervisor.h>
 
 #define XEN_shared_info ((struct shared_info *)fix_to_virt(FIX_XEN_SHARED_INFO))
 
@@ -31,8 +32,9 @@
 extern bool xen_guest;
 extern bool pv_console;
 extern uint32_t xen_cpuid_base;
+extern struct hypervisor_ops xen_hypervisor_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


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [Xen-devel] [PATCH for-next v2 8/9] x86: be more verbose when running on a hypervisor
  2019-09-30 15:00 [Xen-devel] [PATCH for-next v2 0/9] Port Xen to Hyper-V Wei Liu
                   ` (6 preceding siblings ...)
  2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 7/9] x86: switch xen implementation to use hypervisor framework Wei Liu
@ 2019-09-30 15:00 ` Wei Liu
  2019-10-21 10:00   ` Roger Pau Monné
  2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 9/9] x86: introduce CONFIG_HYPERV and detection code Wei Liu
                   ` (2 subsequent siblings)
  10 siblings, 1 reply; 28+ messages in thread
From: Wei Liu @ 2019-09-30 15:00 UTC (permalink / raw)
  To: Xen Development List
  Cc: Wei Liu, Wei Liu, Andrew Cooper, Michael Kelley, Jan Beulich,
	Roger Pau Monné

Signed-off-by: Wei Liu <liuwe@microsoft.com>
---
 xen/arch/x86/guest/hypervisor.c        | 5 +++++
 xen/arch/x86/setup.c                   | 6 +++++-
 xen/include/asm-x86/guest/hypervisor.h | 2 ++
 3 files changed, 12 insertions(+), 1 deletion(-)

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


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [Xen-devel] [PATCH for-next v2 9/9] x86: introduce CONFIG_HYPERV and detection code
  2019-09-30 15:00 [Xen-devel] [PATCH for-next v2 0/9] Port Xen to Hyper-V Wei Liu
                   ` (7 preceding siblings ...)
  2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 8/9] x86: be more verbose when running on a hypervisor Wei Liu
@ 2019-09-30 15:00 ` Wei Liu
  2019-09-30 15:04   ` Wei Liu
  2019-10-21 10:22   ` Roger Pau Monné
  2019-09-30 15:00 ` [Xen-devel] [PATCH for-next RFC 0/8] Port Xen to Hyper-V Wei Liu
  2019-10-21  8:58 ` [Xen-devel] [PATCH for-next v2 0/9] " Wei Liu
  10 siblings, 2 replies; 28+ messages in thread
From: Wei Liu @ 2019-09-30 15:00 UTC (permalink / raw)
  To: Xen Development List
  Cc: Wei Liu, Wei Liu, Andrew Cooper, Michael Kelley, Jan Beulich,
	Roger Pau Monné

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

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

Signed-off-by: Wei Liu <liuwe@microsoft.com>
---
 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 | 69 ++++++++++++++++++++++++++++++
 xen/arch/x86/guest/hypervisor.c    |  5 +++
 xen/include/asm-x86/guest.h        |  1 +
 xen/include/asm-x86/guest/hyperv.h | 45 +++++++++++++++++++
 7 files changed, 131 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

diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig
index 584bdc1bb8..c5a93babfe 100644
--- a/xen/arch/x86/Kconfig
+++ b/xen/arch/x86/Kconfig
@@ -163,6 +163,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
diff --git a/xen/arch/x86/guest/Makefile b/xen/arch/x86/guest/Makefile
index f63d64bbee..f164196772 100644
--- a/xen/arch/x86/guest/Makefile
+++ b/xen/arch/x86/guest/Makefile
@@ -1,3 +1,4 @@
 obj-y += hypervisor.o
 
+subdir-$(CONFIG_HYPERV_GUEST) += hyperv
 subdir-$(CONFIG_XEN_GUEST) += xen
diff --git a/xen/arch/x86/guest/hyperv/Makefile b/xen/arch/x86/guest/hyperv/Makefile
new file mode 100644
index 0000000000..68170109a9
--- /dev/null
+++ b/xen/arch/x86/guest/hyperv/Makefile
@@ -0,0 +1 @@
+obj-y += hyperv.o
diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c
new file mode 100644
index 0000000000..4494b87fe8
--- /dev/null
+++ b/xen/arch/x86/guest/hyperv/hyperv.c
@@ -0,0 +1,69 @@
+/******************************************************************************
+ * 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;
+    bool hyperv_guest = false;
+
+    cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
+    if ( (ebx == 0x7263694d) && /* "Micr" */
+         (ecx == 0x666f736f) && /* "osof" */
+         (edx == 0x76482074) )  /* "t Hv" */
+        hyperv_guest = true;
+
+    return hyperv_guest;
+}
+
+void __init hyperv_setup(void)
+{
+    /* Nothing yet */
+}
+
+void hyperv_ap_setup(void)
+{
+    /* Nothing yet */
+}
+
+void hyperv_resume(void)
+{
+    /* Nothing yet */
+}
+
+struct hypervisor_ops hyperv_hypervisor_ops = {
+    .name = "Hyper-V",
+    .setup = hyperv_setup,
+    .ap_setup = hyperv_ap_setup,
+    .resume = hyperv_resume,
+};
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c
index 8161b26c5a..87a195e888 100644
--- a/xen/arch/x86/guest/hypervisor.c
+++ b/xen/arch/x86/guest/hypervisor.c
@@ -40,6 +40,11 @@ bool hypervisor_probe(void)
         hops = &xen_hypervisor_ops;
 #endif
 
+#ifdef CONFIG_HYPERV_GUEST
+    if ( hyperv_probe() )
+        hops = &hyperv_hypervisor_ops;
+#endif
+
     return !!hops;
 }
 
diff --git a/xen/include/asm-x86/guest.h b/xen/include/asm-x86/guest.h
index 8e167165ae..94448606d4 100644
--- a/xen/include/asm-x86/guest.h
+++ b/xen/include/asm-x86/guest.h
@@ -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>
diff --git a/xen/include/asm-x86/guest/hyperv.h b/xen/include/asm-x86/guest/hyperv.h
new file mode 100644
index 0000000000..a2d8ee8987
--- /dev/null
+++ b/xen/include/asm-x86/guest/hyperv.h
@@ -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_hypervisor_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


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [Xen-devel] [PATCH for-next RFC 0/8] Port Xen to Hyper-V
  2019-09-30 15:00 [Xen-devel] [PATCH for-next v2 0/9] Port Xen to Hyper-V Wei Liu
                   ` (8 preceding siblings ...)
  2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 9/9] x86: introduce CONFIG_HYPERV and detection code Wei Liu
@ 2019-09-30 15:00 ` Wei Liu
  2019-10-21  8:58 ` [Xen-devel] [PATCH for-next v2 0/9] " Wei Liu
  10 siblings, 0 replies; 28+ messages in thread
From: Wei Liu @ 2019-09-30 15:00 UTC (permalink / raw)
  To: Xen Development List
  Cc: Wei Liu, Wei Liu, Andrew Cooper, Michael Kelley, Jan Beulich,
	Roger Pau Monné

Hi all

In case you're wondering, I can already run a fully fledged Xen system on
Hyper-V with emulated disk and network.

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 directory
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 piece meal when they are ready.

Questions and comments are welcome.

Thanks,
Wei.

Cc: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Wei Liu <wl@xen.org>
Cc: Roger Pau Monné <roger.pau@citrix.com>

Wei Liu (8):
  x86: introduce CONFIG_GUEST and move code
  x86: include asm_defns.h directly in hypercall.h
  x86: drop hypervisor_cpuid_base
  x86: factor out xen variants for hypervisor setup code
  x86: factor out hypervisor agnostic code
  x86: make probe_xen return boolean value
  x86: introduce CONFIG_HYPERV and hyperv directory
  x86: be more verbose when running nested

 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            |  63 ++++++++++
 xen/arch/x86/guest/hypervisor.c               | 116 ++++++++++++++++++
 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            |  73 ++---------
 xen/arch/x86/pv/shim.c                        |   2 +-
 xen/arch/x86/setup.c                          |  11 ++
 xen/include/asm-x86/guest.h                   |   2 +
 xen/include/asm-x86/guest/hypercall.h         |   2 +
 xen/include/asm-x86/guest/hyperv.h            |  48 ++++++++
 xen/include/asm-x86/guest/hypervisor.h        |  58 +++++++++
 xen/include/asm-x86/guest/xen.h               |  23 +---
 17 files changed, 337 insertions(+), 87 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 (100%)
 rename xen/arch/x86/guest/{ => xen}/xen.c (80%)
 create mode 100644 xen/include/asm-x86/guest/hyperv.h
 create mode 100644 xen/include/asm-x86/guest/hypervisor.h

-- 
2.20.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Xen-devel] [PATCH for-next v2 9/9] x86: introduce CONFIG_HYPERV and detection code
  2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 9/9] x86: introduce CONFIG_HYPERV and detection code Wei Liu
@ 2019-09-30 15:04   ` Wei Liu
  2019-10-21 10:22   ` Roger Pau Monné
  1 sibling, 0 replies; 28+ messages in thread
From: Wei Liu @ 2019-09-30 15:04 UTC (permalink / raw)
  To: Xen Development List
  Cc: Wei Liu, Wei Liu, Andrew Cooper, Michael Kelley, Jan Beulich,
	Roger Pau Monné

On Mon, Sep 30, 2019 at 04:00:43PM +0100, Wei Liu wrote:
> We use the same code structure as we die for Xen.

Urgh. There is a rather unfortunate typo. No software is worth dying
for. :-)

Wei.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Xen-devel] [PATCH for-next v2 0/9] Port Xen to Hyper-V
  2019-09-30 15:00 [Xen-devel] [PATCH for-next v2 0/9] Port Xen to Hyper-V Wei Liu
                   ` (9 preceding siblings ...)
  2019-09-30 15:00 ` [Xen-devel] [PATCH for-next RFC 0/8] Port Xen to Hyper-V Wei Liu
@ 2019-10-21  8:58 ` Wei Liu
  10 siblings, 0 replies; 28+ messages in thread
From: Wei Liu @ 2019-10-21  8:58 UTC (permalink / raw)
  To: Xen Development List
  Cc: Wei Liu, Wei Liu, Andrew Cooper, Michael Kelley, Jan Beulich,
	Roger Pau Monné

On Mon, Sep 30, 2019 at 04:00:34PM +0100, Wei Liu wrote:
> Hi all
> 
> This is version 2 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 piece meal when they are ready.
> 
> Questions and comments are welcome.
> 
> Thanks,
> Wei.
> 
> ---
> Changes in v2:
> 1. Introduce and use a hypervisor framework
> 2. Keep memmap infra under Xen for now

Ping?

Can I get an high level agreement on the code structure such that I can
continue building on top of this series?

Wei.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Xen-devel] [PATCH for-next v2 4/9] x86: include xen/lib.h in guest/hypercall.h
  2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 4/9] x86: include xen/lib.h in guest/hypercall.h Wei Liu
@ 2019-10-21  9:02   ` Roger Pau Monné
  0 siblings, 0 replies; 28+ messages in thread
From: Roger Pau Monné @ 2019-10-21  9:02 UTC (permalink / raw)
  To: Wei Liu
  Cc: Xen Development List, Andrew Cooper, Wei Liu, Jan Beulich,
	Michael Kelley

On Mon, Sep 30, 2019 at 04:00:38PM +0100, Wei Liu wrote:
> We need ASSERT_UNREACHABLE.
> 
> Signed-off-by: Wei Liu <liuwe@microsoft.com>

Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>

Thanks.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Xen-devel] [PATCH for-next v2 6/9] x86: rename hypervisor_{alloc, free}_unused_page
  2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 6/9] x86: rename hypervisor_{alloc, free}_unused_page Wei Liu
@ 2019-10-21  9:11   ` Roger Pau Monné
  0 siblings, 0 replies; 28+ messages in thread
From: Roger Pau Monné @ 2019-10-21  9:11 UTC (permalink / raw)
  To: Wei Liu
  Cc: Xen Development List, Andrew Cooper, Wei Liu, Jan Beulich,
	Michael Kelley

On Mon, Sep 30, 2019 at 04:00:40PM +0100, Wei Liu wrote:
> They are used in Xen code only.
> 
> No functional change.
> 
> Signed-off-by: Wei Liu <liuwe@microsoft.com>

Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>

Thanks.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Xen-devel] [PATCH for-next v2 7/9] x86: switch xen implementation to use hypervisor framework
  2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 7/9] x86: switch xen implementation to use hypervisor framework Wei Liu
@ 2019-10-21  9:56   ` Roger Pau Monné
  2019-10-21 14:35     ` Wei Liu
  0 siblings, 1 reply; 28+ messages in thread
From: Roger Pau Monné @ 2019-10-21  9:56 UTC (permalink / raw)
  To: Wei Liu
  Cc: Xen Development List, Andrew Cooper, Wei Liu, Jan Beulich,
	Michael Kelley

On Mon, Sep 30, 2019 at 04:00:41PM +0100, Wei Liu wrote:
> Take the chance to change probe_hypervisor to hypervisor_probe.

The implementation LGTM.

> 
> Signed-off-by: Wei Liu <liuwe@microsoft.com>
> ---
>  xen/arch/x86/guest/hypervisor.c   | 31 +++++++++++++++++++++++++++++--
>  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, 49 insertions(+), 18 deletions(-)
> 
> diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c
> index 89b9ae4de0..30453b6a7a 100644
> --- a/xen/arch/x86/guest/hypervisor.c
> +++ b/xen/arch/x86/guest/hypervisor.c
> @@ -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,7 +31,34 @@ bool hypervisor_probe(void)
>      if ( hops )
>          return true;
>  
> -    return false;
> +    /* 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_hypervisor_ops;
> +#endif

I think you likely want something like:

    if ( xen_probe() )
    {
        hops = &xen_hypervisor_ops;
	return true;
    }
    if ( hyperv_probe() )
    {
        ....
	return true;
    }

    return false;

In order to return after a successful probe, or else you lose cycles
probing for hypervisors when a match has been found, and also in the
Xen case you risk detecting the HyperV support in Xen and thus using
that instead of the Xen one.

Long term if we gain more guests support I would likely want to see
hypervisor_ops turning into an array and gaining a probe function so
that this can be done in a loop instead of having this function.

> +
> +    return !!hops;
> +}
> +
> +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();
>  }
>  
>  /*
> diff --git a/xen/arch/x86/guest/xen/pvh-boot.c b/xen/arch/x86/guest/xen/pvh-boot.c
> index ca8e156f7d..498625eae0 100644
> --- a/xen/arch/x86/guest/xen/pvh-boot.c
> +++ b/xen/arch/x86/guest/xen/pvh-boot.c
> @@ -103,7 +103,7 @@ void __init pvh_init(multiboot_info_t **mbi, module_t **mod)
>  {
>      convert_pvh_info(mbi, mod);
>  
> -    probe_hypervisor();
> +    hypervisor_probe();
>      ASSERT(xen_guest);
>  
>      get_memory_map();
> diff --git a/xen/arch/x86/guest/xen/xen.c b/xen/arch/x86/guest/xen/xen.c
> index 9895025d02..a9d321e5eb 100644
> --- a/xen/arch/x86/guest/xen/xen.c
> +++ b/xen/arch/x86/guest/xen/xen.c
> @@ -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)
> +void __init xen_setup(void)
>  {
>      init_memmap();
>  
> @@ -277,7 +272,7 @@ void __init hypervisor_setup(void)
>      init_evtchn();
>  }
>  
> -void hypervisor_ap_setup(void)
> +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)
> +void xen_resume(void)

I think xen_{setup/ap_setup/resume} can be made static now?

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Xen-devel] [PATCH for-next v2 8/9] x86: be more verbose when running on a hypervisor
  2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 8/9] x86: be more verbose when running on a hypervisor Wei Liu
@ 2019-10-21 10:00   ` Roger Pau Monné
  2019-10-21 14:35     ` Wei Liu
  2019-10-23 13:22     ` Jan Beulich
  0 siblings, 2 replies; 28+ messages in thread
From: Roger Pau Monné @ 2019-10-21 10:00 UTC (permalink / raw)
  To: Wei Liu
  Cc: Xen Development List, Andrew Cooper, Wei Liu, Jan Beulich,
	Michael Kelley

On Mon, Sep 30, 2019 at 04:00:42PM +0100, Wei Liu wrote:
> Signed-off-by: Wei Liu <liuwe@microsoft.com>
> ---
>  xen/arch/x86/guest/hypervisor.c        | 5 +++++
>  xen/arch/x86/setup.c                   | 6 +++++-
>  xen/include/asm-x86/guest/hypervisor.h | 2 ++
>  3 files changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c
> index 30453b6a7a..8161b26c5a 100644
> --- a/xen/arch/x86/guest/hypervisor.c
> +++ b/xen/arch/x86/guest/hypervisor.c
> @@ -43,6 +43,11 @@ bool hypervisor_probe(void)
>      return !!hops;
>  }
>  
> +const char *hypervisor_name(void)
> +{

I would maybe add ASSERT(hops);

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

I think you want an ASSERT_UNREACHABLE here, since hypervisor_name
shouldn't be called unless Xen has detected that's running as a guest,
which can only happen if CONFIG_GUEST is selected.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Xen-devel] [PATCH for-next v2 9/9] x86: introduce CONFIG_HYPERV and detection code
  2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 9/9] x86: introduce CONFIG_HYPERV and detection code Wei Liu
  2019-09-30 15:04   ` Wei Liu
@ 2019-10-21 10:22   ` Roger Pau Monné
  2019-10-21 10:26     ` Roger Pau Monné
  2019-10-21 14:56     ` Wei Liu
  1 sibling, 2 replies; 28+ messages in thread
From: Roger Pau Monné @ 2019-10-21 10:22 UTC (permalink / raw)
  To: Wei Liu
  Cc: Xen Development List, Andrew Cooper, Wei Liu, Jan Beulich,
	Michael Kelley

On Mon, Sep 30, 2019 at 04:00:43PM +0100, Wei Liu wrote:
> We use the same code structure as we die for Xen.
> 
> As starters, detect Hyper-V in probe routine. More complex
> functionalities will be added later.
> 
> Signed-off-by: Wei Liu <liuwe@microsoft.com>
> ---
>  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 | 69 ++++++++++++++++++++++++++++++
>  xen/arch/x86/guest/hypervisor.c    |  5 +++
>  xen/include/asm-x86/guest.h        |  1 +
>  xen/include/asm-x86/guest/hyperv.h | 45 +++++++++++++++++++
>  7 files changed, 131 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
> 
> diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig
> index 584bdc1bb8..c5a93babfe 100644
> --- a/xen/arch/x86/Kconfig
> +++ b/xen/arch/x86/Kconfig
> @@ -163,6 +163,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
> diff --git a/xen/arch/x86/guest/Makefile b/xen/arch/x86/guest/Makefile
> index f63d64bbee..f164196772 100644
> --- a/xen/arch/x86/guest/Makefile
> +++ b/xen/arch/x86/guest/Makefile
> @@ -1,3 +1,4 @@
>  obj-y += hypervisor.o
>  
> +subdir-$(CONFIG_HYPERV_GUEST) += hyperv
>  subdir-$(CONFIG_XEN_GUEST) += xen
> diff --git a/xen/arch/x86/guest/hyperv/Makefile b/xen/arch/x86/guest/hyperv/Makefile
> new file mode 100644
> index 0000000000..68170109a9
> --- /dev/null
> +++ b/xen/arch/x86/guest/hyperv/Makefile
> @@ -0,0 +1 @@
> +obj-y += hyperv.o
> diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c
> new file mode 100644
> index 0000000000..4494b87fe8
> --- /dev/null
> +++ b/xen/arch/x86/guest/hyperv/hyperv.c
> @@ -0,0 +1,69 @@
> +/******************************************************************************
> + * 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;
> +    bool hyperv_guest = false;

I don't think you need this local variable, you can return true in if
the if condition matches, and false otherwise.

> +
> +    cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
> +    if ( (ebx == 0x7263694d) && /* "Micr" */
> +         (ecx == 0x666f736f) && /* "osof" */
> +         (edx == 0x76482074) )  /* "t Hv" */

I guess there are no HyperV headers to import that have those values
defined?

Alternatively you could do something like the following I think:

static const char hyperv_sig[] __initconst = "Microsoft Hv";

bool __init hyperv_probe(void)
{
    uint32_t eax, sig[3];

    cpuid(0x40000000, &eax, &sig[0], &sig[1], &sig[2]);
    if ( !strncmp(hyperv_sig, sig, strncmp(hyperv_sig) )
        return true;

    return false;
}

> +        hyperv_guest = true;
> +
> +    return hyperv_guest;
> +}
> +
> +void __init hyperv_setup(void)
> +{
> +    /* Nothing yet */
> +}
> +
> +void hyperv_ap_setup(void)
> +{
> +    /* Nothing yet */
> +}
> +
> +void hyperv_resume(void)
> +{
> +    /* Nothing yet */
> +}

There's no need to introduce such dummy functions, just leaving the
pointers as NULL should work fine, and the functions can be introduced
when there's logic in them.

> +
> +struct hypervisor_ops hyperv_hypervisor_ops = {
> +    .name = "Hyper-V",
> +    .setup = hyperv_setup,
> +    .ap_setup = hyperv_ap_setup,
> +    .resume = hyperv_resume,
> +};
> +
> +/*
> + * Local variables:
> + * mode: C
> + * c-file-style: "BSD"
> + * c-basic-offset: 4
> + * tab-width: 4
> + * indent-tabs-mode: nil
> + * End:
> + */
> diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c
> index 8161b26c5a..87a195e888 100644
> --- a/xen/arch/x86/guest/hypervisor.c
> +++ b/xen/arch/x86/guest/hypervisor.c
> @@ -40,6 +40,11 @@ bool hypervisor_probe(void)
>          hops = &xen_hypervisor_ops;
>  #endif
>  
> +#ifdef CONFIG_HYPERV_GUEST
> +    if ( hyperv_probe() )
> +        hops = &hyperv_hypervisor_ops;
> +#endif

This won't work correctly if Xen has viridian extensions enabled,
since the HyperV probe will overwrite the Xen one.

> +
>      return !!hops;
>  }
>  
> diff --git a/xen/include/asm-x86/guest.h b/xen/include/asm-x86/guest.h
> index 8e167165ae..94448606d4 100644
> --- a/xen/include/asm-x86/guest.h
> +++ b/xen/include/asm-x86/guest.h
> @@ -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>
> diff --git a/xen/include/asm-x86/guest/hyperv.h b/xen/include/asm-x86/guest/hyperv.h
> new file mode 100644
> index 0000000000..a2d8ee8987
> --- /dev/null
> +++ b/xen/include/asm-x86/guest/hyperv.h
> @@ -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_hypervisor_ops;

hyperv_ops would be fine by me, seems kind of redundant to have
'hyper' twice in a name.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Xen-devel] [PATCH for-next v2 9/9] x86: introduce CONFIG_HYPERV and detection code
  2019-10-21 10:22   ` Roger Pau Monné
@ 2019-10-21 10:26     ` Roger Pau Monné
  2019-10-21 15:02       ` Andrew Cooper
  2019-10-21 14:56     ` Wei Liu
  1 sibling, 1 reply; 28+ messages in thread
From: Roger Pau Monné @ 2019-10-21 10:26 UTC (permalink / raw)
  To: Wei Liu
  Cc: Xen Development List, Michael Kelley, Wei Liu, Jan Beulich,
	Andrew Cooper

On Mon, Oct 21, 2019 at 12:22:25PM +0200, Roger Pau Monné wrote:
> On Mon, Sep 30, 2019 at 04:00:43PM +0100, Wei Liu wrote:
> > We use the same code structure as we die for Xen.
> > 
> > As starters, detect Hyper-V in probe routine. More complex
> > functionalities will be added later.
> > 
> > Signed-off-by: Wei Liu <liuwe@microsoft.com>
> > ---
> >  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 | 69 ++++++++++++++++++++++++++++++
> >  xen/arch/x86/guest/hypervisor.c    |  5 +++
> >  xen/include/asm-x86/guest.h        |  1 +
> >  xen/include/asm-x86/guest/hyperv.h | 45 +++++++++++++++++++
> >  7 files changed, 131 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
> > 
> > diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig
> > index 584bdc1bb8..c5a93babfe 100644
> > --- a/xen/arch/x86/Kconfig
> > +++ b/xen/arch/x86/Kconfig
> > @@ -163,6 +163,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
> > diff --git a/xen/arch/x86/guest/Makefile b/xen/arch/x86/guest/Makefile
> > index f63d64bbee..f164196772 100644
> > --- a/xen/arch/x86/guest/Makefile
> > +++ b/xen/arch/x86/guest/Makefile
> > @@ -1,3 +1,4 @@
> >  obj-y += hypervisor.o
> >  
> > +subdir-$(CONFIG_HYPERV_GUEST) += hyperv
> >  subdir-$(CONFIG_XEN_GUEST) += xen
> > diff --git a/xen/arch/x86/guest/hyperv/Makefile b/xen/arch/x86/guest/hyperv/Makefile
> > new file mode 100644
> > index 0000000000..68170109a9
> > --- /dev/null
> > +++ b/xen/arch/x86/guest/hyperv/Makefile
> > @@ -0,0 +1 @@
> > +obj-y += hyperv.o
> > diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c
> > new file mode 100644
> > index 0000000000..4494b87fe8
> > --- /dev/null
> > +++ b/xen/arch/x86/guest/hyperv/hyperv.c
> > @@ -0,0 +1,69 @@
> > +/******************************************************************************
> > + * 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;
> > +    bool hyperv_guest = false;
> 
> I don't think you need this local variable, you can return true in if
> the if condition matches, and false otherwise.
> 
> > +
> > +    cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
> > +    if ( (ebx == 0x7263694d) && /* "Micr" */
> > +         (ecx == 0x666f736f) && /* "osof" */
> > +         (edx == 0x76482074) )  /* "t Hv" */
> 
> I guess there are no HyperV headers to import that have those values
> defined?
> 
> Alternatively you could do something like the following I think:
> 
> static const char hyperv_sig[] __initconst = "Microsoft Hv";
> 
> bool __init hyperv_probe(void)
> {
>     uint32_t eax, sig[3];
> 
>     cpuid(0x40000000, &eax, &sig[0], &sig[1], &sig[2]);
>     if ( !strncmp(hyperv_sig, sig, strncmp(hyperv_sig) )

Urg, I've made a mistake here, the line should be:

!strncmp(hyperv_sig, sig, strlen(hyperv_sig))

And you can likely declare hyperv_sig inside the probe function also.

Roger.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Xen-devel] [PATCH for-next v2 7/9] x86: switch xen implementation to use hypervisor framework
  2019-10-21  9:56   ` Roger Pau Monné
@ 2019-10-21 14:35     ` Wei Liu
  0 siblings, 0 replies; 28+ messages in thread
From: Wei Liu @ 2019-10-21 14:35 UTC (permalink / raw)
  To: Roger Pau Monné
  Cc: Wei Liu, Wei Liu, Andrew Cooper, Michael Kelley, Jan Beulich,
	Xen Development List

On Mon, Oct 21, 2019 at 11:56:36AM +0200, Roger Pau Monné wrote:
[...]
> >  static struct hypervisor_ops *hops __read_mostly;
> >  
> > @@ -31,7 +31,34 @@ bool hypervisor_probe(void)
> >      if ( hops )
> >          return true;
> >  
> > -    return false;
> > +    /* 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_hypervisor_ops;
> > +#endif
> 
> I think you likely want something like:
> 
>     if ( xen_probe() )
>     {
>         hops = &xen_hypervisor_ops;
> 	return true;
>     }
>     if ( hyperv_probe() )
>     {
>         ....
> 	return true;
>     }
> 
>     return false;
> 
> In order to return after a successful probe, or else you lose cycles
> probing for hypervisors when a match has been found, and also in the
> Xen case you risk detecting the HyperV support in Xen and thus using
> that instead of the Xen one.
> 

Good point.

> Long term if we gain more guests support I would likely want to see
> hypervisor_ops turning into an array and gaining a probe function so
> that this can be done in a loop instead of having this function.
> 

That was my plan from the get-go but Xen lacked appropriate
infrastructure, hence I resorted to something akin to HVM hooks.

[...]
> > -void __init hypervisor_setup(void)
> > +void __init xen_setup(void)
> >  {
> >      init_memmap();
> >  
> > @@ -277,7 +272,7 @@ void __init hypervisor_setup(void)
> >      init_evtchn();
> >  }
> >  
> > -void hypervisor_ap_setup(void)
> > +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)
> > +void xen_resume(void)
> 
> I think xen_{setup/ap_setup/resume} can be made static now?

Indeed. I will fix this.

Wei.

> 
> Thanks, Roger.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Xen-devel] [PATCH for-next v2 8/9] x86: be more verbose when running on a hypervisor
  2019-10-21 10:00   ` Roger Pau Monné
@ 2019-10-21 14:35     ` Wei Liu
  2019-10-23 13:22     ` Jan Beulich
  1 sibling, 0 replies; 28+ messages in thread
From: Wei Liu @ 2019-10-21 14:35 UTC (permalink / raw)
  To: Roger Pau Monné
  Cc: Wei Liu, Wei Liu, Andrew Cooper, Michael Kelley, Jan Beulich,
	Xen Development List

On Mon, Oct 21, 2019 at 12:00:38PM +0200, Roger Pau Monné wrote:
> On Mon, Sep 30, 2019 at 04:00:42PM +0100, Wei Liu wrote:
> > Signed-off-by: Wei Liu <liuwe@microsoft.com>
> > ---
> >  xen/arch/x86/guest/hypervisor.c        | 5 +++++
> >  xen/arch/x86/setup.c                   | 6 +++++-
> >  xen/include/asm-x86/guest/hypervisor.h | 2 ++
> >  3 files changed, 12 insertions(+), 1 deletion(-)
> > 
> > diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c
> > index 30453b6a7a..8161b26c5a 100644
> > --- a/xen/arch/x86/guest/hypervisor.c
> > +++ b/xen/arch/x86/guest/hypervisor.c
> > @@ -43,6 +43,11 @@ bool hypervisor_probe(void)
> >      return !!hops;
> >  }
> >  
> > +const char *hypervisor_name(void)
> > +{
> 
> I would maybe add ASSERT(hops);
> 
> > +    return hops->name;
> > +}
> > +
[...]
> > diff --git a/xen/include/asm-x86/guest/hypervisor.h b/xen/include/asm-x86/guest/hypervisor.h
> > index 38344e2e89..a7d75bf9cf 100644
> > --- a/xen/include/asm-x86/guest/hypervisor.h
> > +++ b/xen/include/asm-x86/guest/hypervisor.h
> > @@ -36,6 +36,7 @@ bool hypervisor_probe(void);
> >  void hypervisor_setup(void);
> >  void hypervisor_ap_setup(void);
> >  void hypervisor_resume(void);
> > +const char *hypervisor_name(void);
> >  
> >  #else
> >  
> > @@ -45,6 +46,7 @@ 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) { return NULL; }
> 
> I think you want an ASSERT_UNREACHABLE here, since hypervisor_name
> shouldn't be called unless Xen has detected that's running as a guest,
> which can only happen if CONFIG_GUEST is selected.

Ack to both comments.

Wei.

> 
> Thanks, Roger.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Xen-devel] [PATCH for-next v2 9/9] x86: introduce CONFIG_HYPERV and detection code
  2019-10-21 10:22   ` Roger Pau Monné
  2019-10-21 10:26     ` Roger Pau Monné
@ 2019-10-21 14:56     ` Wei Liu
  2019-10-21 15:11       ` Roger Pau Monné
  1 sibling, 1 reply; 28+ messages in thread
From: Wei Liu @ 2019-10-21 14:56 UTC (permalink / raw)
  To: Roger Pau Monné
  Cc: Wei Liu, Wei Liu, Andrew Cooper, Michael Kelley, Jan Beulich,
	Xen Development List

On Mon, Oct 21, 2019 at 12:22:25PM +0200, Roger Pau Monné wrote:
[...]
> > +bool __init hyperv_probe(void)
> > +{
> > +    uint32_t eax, ebx, ecx, edx;
> > +    bool hyperv_guest = false;
> 
> I don't think you need this local variable, you can return true in if
> the if condition matches, and false otherwise.
> 

Sure. I can drop it for now and reintroduce it when necessary.

> > +
> > +    cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
> > +    if ( (ebx == 0x7263694d) && /* "Micr" */
> > +         (ecx == 0x666f736f) && /* "osof" */
> > +         (edx == 0x76482074) )  /* "t Hv" */
> 
> I guess there are no HyperV headers to import that have those values
> defined?
> 

Not yet. I have plan to import a header from Linux. When that's done
these will be replaced by some macros.

So I will keep this as-is for now.

[...]
> > +#ifndef __X86_GUEST_HYPERV_H__
> > +#define __X86_GUEST_HYPERV_H__
> > +
> > +#ifdef CONFIG_HYPERV_GUEST
> > +
> > +#include <asm/guest/hypervisor.h>
> > +
> > +extern struct hypervisor_ops hyperv_hypervisor_ops;
> 
> hyperv_ops would be fine by me, seems kind of redundant to have
> 'hyper' twice in a name.
> 

In that case I will also change xen_hypervisor_ops to xen_ops to remain
consistent.

Wei.

> Thanks, Roger.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Xen-devel] [PATCH for-next v2 9/9] x86: introduce CONFIG_HYPERV and detection code
  2019-10-21 10:26     ` Roger Pau Monné
@ 2019-10-21 15:02       ` Andrew Cooper
  2019-10-21 15:26         ` Wei Liu
  0 siblings, 1 reply; 28+ messages in thread
From: Andrew Cooper @ 2019-10-21 15:02 UTC (permalink / raw)
  To: Roger Pau Monné, Wei Liu
  Cc: Xen Development List, Wei Liu, Jan Beulich, Michael Kelley

On 21/10/2019 11:26, Roger Pau Monné wrote:
>>> +
>>> +    cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
>>> +    if ( (ebx == 0x7263694d) && /* "Micr" */
>>> +         (ecx == 0x666f736f) && /* "osof" */
>>> +         (edx == 0x76482074) )  /* "t Hv" */
>> I guess there are no HyperV headers to import that have those values
>> defined?
>>
>> Alternatively you could do something like the following I think:
>>
>> static const char hyperv_sig[] __initconst = "Microsoft Hv";
>>
>> bool __init hyperv_probe(void)
>> {
>>     uint32_t eax, sig[3];
>>
>>     cpuid(0x40000000, &eax, &sig[0], &sig[1], &sig[2]);
>>     if ( !strncmp(hyperv_sig, sig, strncmp(hyperv_sig) )
> Urg, I've made a mistake here, the line should be:
>
> !strncmp(hyperv_sig, sig, strlen(hyperv_sig))

Just because the leaves form an ascii string, doesn't mean that using
string comparisons are the sane way to check.  3x 32bit compares are
substantially more efficient, and far harder to get wrong.

Wei: On your detection algorithm, you also need to find HV#1 in
0x40000001.eax to detect conformance to the viridian spec.

~Andrew

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Xen-devel] [PATCH for-next v2 9/9] x86: introduce CONFIG_HYPERV and detection code
  2019-10-21 14:56     ` Wei Liu
@ 2019-10-21 15:11       ` Roger Pau Monné
  2019-10-21 15:20         ` Wei Liu
  0 siblings, 1 reply; 28+ messages in thread
From: Roger Pau Monné @ 2019-10-21 15:11 UTC (permalink / raw)
  To: Wei Liu
  Cc: Xen Development List, Andrew Cooper, Wei Liu, Jan Beulich,
	Michael Kelley

On Mon, Oct 21, 2019 at 03:56:51PM +0100, Wei Liu wrote:
> On Mon, Oct 21, 2019 at 12:22:25PM +0200, Roger Pau Monné wrote:
> [...]
> > > +bool __init hyperv_probe(void)
> > > +{
> > > +    uint32_t eax, ebx, ecx, edx;
> > > +    bool hyperv_guest = false;
> > 
> > I don't think you need this local variable, you can return true in if
> > the if condition matches, and false otherwise.
> > 
> 
> Sure. I can drop it for now and reintroduce it when necessary.
> 
> > > +
> > > +    cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
> > > +    if ( (ebx == 0x7263694d) && /* "Micr" */
> > > +         (ecx == 0x666f736f) && /* "osof" */
> > > +         (edx == 0x76482074) )  /* "t Hv" */
> > 
> > I guess there are no HyperV headers to import that have those values
> > defined?
> > 
> 
> Not yet. I have plan to import a header from Linux. When that's done
> these will be replaced by some macros.
> 
> So I will keep this as-is for now.

Is it really cumbersome to introduce the header now?

IMO it would be better to avoid deferring this to when you introduce
the header, since it's easy to miss it.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Xen-devel] [PATCH for-next v2 9/9] x86: introduce CONFIG_HYPERV and detection code
  2019-10-21 15:11       ` Roger Pau Monné
@ 2019-10-21 15:20         ` Wei Liu
  0 siblings, 0 replies; 28+ messages in thread
From: Wei Liu @ 2019-10-21 15:20 UTC (permalink / raw)
  To: Roger Pau Monné
  Cc: Wei Liu, Wei Liu, Andrew Cooper, Michael Kelley, Jan Beulich,
	Xen Development List

On Mon, Oct 21, 2019 at 05:11:26PM +0200, Roger Pau Monné wrote:
> On Mon, Oct 21, 2019 at 03:56:51PM +0100, Wei Liu wrote:
> > On Mon, Oct 21, 2019 at 12:22:25PM +0200, Roger Pau Monné wrote:
> > [...]
> > > > +bool __init hyperv_probe(void)
> > > > +{
> > > > +    uint32_t eax, ebx, ecx, edx;
> > > > +    bool hyperv_guest = false;
> > > 
> > > I don't think you need this local variable, you can return true in if
> > > the if condition matches, and false otherwise.
> > > 
> > 
> > Sure. I can drop it for now and reintroduce it when necessary.
> > 
> > > > +
> > > > +    cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
> > > > +    if ( (ebx == 0x7263694d) && /* "Micr" */
> > > > +         (ecx == 0x666f736f) && /* "osof" */
> > > > +         (edx == 0x76482074) )  /* "t Hv" */
> > > 
> > > I guess there are no HyperV headers to import that have those values
> > > defined?
> > > 
> > 
> > Not yet. I have plan to import a header from Linux. When that's done
> > these will be replaced by some macros.
> > 
> > So I will keep this as-is for now.
> 
> Is it really cumbersome to introduce the header now?
> 
> IMO it would be better to avoid deferring this to when you introduce
> the header, since it's easy to miss it.

The header in Linux is not without its problems. It certainly doesn't
have the signature values in it yet, so whether importing it now or
later is immaterial to this issue at hand. I will have to go through
that header file first but -ETIME.

Wei.

> 
> Thanks, Roger.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Xen-devel] [PATCH for-next v2 9/9] x86: introduce CONFIG_HYPERV and detection code
  2019-10-21 15:02       ` Andrew Cooper
@ 2019-10-21 15:26         ` Wei Liu
  0 siblings, 0 replies; 28+ messages in thread
From: Wei Liu @ 2019-10-21 15:26 UTC (permalink / raw)
  To: Andrew Cooper
  Cc: Wei Liu, Wei Liu, Michael Kelley, Jan Beulich,
	Xen Development List, Roger Pau Monné

On Mon, Oct 21, 2019 at 04:02:33PM +0100, Andrew Cooper wrote:
> On 21/10/2019 11:26, Roger Pau Monné wrote:
> >>> +
> >>> +    cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
> >>> +    if ( (ebx == 0x7263694d) && /* "Micr" */
> >>> +         (ecx == 0x666f736f) && /* "osof" */
> >>> +         (edx == 0x76482074) )  /* "t Hv" */
> >> I guess there are no HyperV headers to import that have those values
> >> defined?
> >>
> >> Alternatively you could do something like the following I think:
> >>
> >> static const char hyperv_sig[] __initconst = "Microsoft Hv";
> >>
> >> bool __init hyperv_probe(void)
> >> {
> >>     uint32_t eax, sig[3];
> >>
> >>     cpuid(0x40000000, &eax, &sig[0], &sig[1], &sig[2]);
> >>     if ( !strncmp(hyperv_sig, sig, strncmp(hyperv_sig) )
> > Urg, I've made a mistake here, the line should be:
> >
> > !strncmp(hyperv_sig, sig, strlen(hyperv_sig))
> 
> Just because the leaves form an ascii string, doesn't mean that using
> string comparisons are the sane way to check.  3x 32bit compares are
> substantially more efficient, and far harder to get wrong.
> 
> Wei: On your detection algorithm, you also need to find HV#1 in
> 0x40000001.eax to detect conformance to the viridian spec.

Sure I can do that.

I'm not sure it matters that much in practice though.

Wei.

> 
> ~Andrew

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Xen-devel] [PATCH for-next v2 8/9] x86: be more verbose when running on a hypervisor
  2019-10-21 10:00   ` Roger Pau Monné
  2019-10-21 14:35     ` Wei Liu
@ 2019-10-23 13:22     ` Jan Beulich
  2019-11-05 11:17       ` Wei Liu
  1 sibling, 1 reply; 28+ messages in thread
From: Jan Beulich @ 2019-10-23 13:22 UTC (permalink / raw)
  To: Wei Liu
  Cc: Xen Development List, Michael Kelley, Wei Liu, Andrew Cooper,
	Roger Pau Monné

On 21.10.2019 12:00, Roger Pau Monné wrote:
> On Mon, Sep 30, 2019 at 04:00:42PM +0100, Wei Liu wrote:
>> --- a/xen/include/asm-x86/guest/hypervisor.h
>> +++ b/xen/include/asm-x86/guest/hypervisor.h
>> @@ -36,6 +36,7 @@ bool hypervisor_probe(void);
>>  void hypervisor_setup(void);
>>  void hypervisor_ap_setup(void);
>>  void hypervisor_resume(void);
>> +const char *hypervisor_name(void);
>>  
>>  #else
>>  
>> @@ -45,6 +46,7 @@ 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) { return NULL; }
> 
> I think you want an ASSERT_UNREACHABLE here, since hypervisor_name
> shouldn't be called unless Xen has detected that's running as a guest,
> which can only happen if CONFIG_GUEST is selected.

And please bring prototype and stub in sync return-type-wise.

Jan

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Xen-devel] [PATCH for-next v2 8/9] x86: be more verbose when running on a hypervisor
  2019-10-23 13:22     ` Jan Beulich
@ 2019-11-05 11:17       ` Wei Liu
  0 siblings, 0 replies; 28+ messages in thread
From: Wei Liu @ 2019-11-05 11:17 UTC (permalink / raw)
  To: Jan Beulich
  Cc: Wei Liu, Wei Liu, Andrew Cooper, Michael Kelley,
	Xen Development List, Roger Pau Monné

On Wed, Oct 23, 2019 at 03:22:24PM +0200, Jan Beulich wrote:
> On 21.10.2019 12:00, Roger Pau Monné wrote:
> > On Mon, Sep 30, 2019 at 04:00:42PM +0100, Wei Liu wrote:
> >> --- a/xen/include/asm-x86/guest/hypervisor.h
> >> +++ b/xen/include/asm-x86/guest/hypervisor.h
> >> @@ -36,6 +36,7 @@ bool hypervisor_probe(void);
> >>  void hypervisor_setup(void);
> >>  void hypervisor_ap_setup(void);
> >>  void hypervisor_resume(void);
> >> +const char *hypervisor_name(void);
> >>  
> >>  #else
> >>  
> >> @@ -45,6 +46,7 @@ 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) { return NULL; }
> > 
> > I think you want an ASSERT_UNREACHABLE here, since hypervisor_name
> > shouldn't be called unless Xen has detected that's running as a guest,
> > which can only happen if CONFIG_GUEST is selected.
> 
> And please bring prototype and stub in sync return-type-wise.

Missed this comment.

I will handle this if I haven't already.

Wei.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2019-11-05 11:17 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-30 15:00 [Xen-devel] [PATCH for-next v2 0/9] Port Xen to Hyper-V Wei Liu
2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 1/9] x86: introduce CONFIG_GUEST and move code Wei Liu
2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 2/9] x86: include asm_defns.h directly in hypercall.h Wei Liu
2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 3/9] x86: drop hypervisor_cpuid_base Wei Liu
2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 4/9] x86: include xen/lib.h in guest/hypercall.h Wei Liu
2019-10-21  9:02   ` Roger Pau Monné
2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 5/9] x86: introduce hypervisor framework Wei Liu
2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 6/9] x86: rename hypervisor_{alloc, free}_unused_page Wei Liu
2019-10-21  9:11   ` Roger Pau Monné
2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 7/9] x86: switch xen implementation to use hypervisor framework Wei Liu
2019-10-21  9:56   ` Roger Pau Monné
2019-10-21 14:35     ` Wei Liu
2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 8/9] x86: be more verbose when running on a hypervisor Wei Liu
2019-10-21 10:00   ` Roger Pau Monné
2019-10-21 14:35     ` Wei Liu
2019-10-23 13:22     ` Jan Beulich
2019-11-05 11:17       ` Wei Liu
2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 9/9] x86: introduce CONFIG_HYPERV and detection code Wei Liu
2019-09-30 15:04   ` Wei Liu
2019-10-21 10:22   ` Roger Pau Monné
2019-10-21 10:26     ` Roger Pau Monné
2019-10-21 15:02       ` Andrew Cooper
2019-10-21 15:26         ` Wei Liu
2019-10-21 14:56     ` Wei Liu
2019-10-21 15:11       ` Roger Pau Monné
2019-10-21 15:20         ` Wei Liu
2019-09-30 15:00 ` [Xen-devel] [PATCH for-next RFC 0/8] Port Xen to Hyper-V Wei Liu
2019-10-21  8:58 ` [Xen-devel] [PATCH for-next v2 0/9] " Wei Liu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.