All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xen-devel] [PATCH for-next v3 0/9] Port Xen to Hyper-V
@ 2019-10-21 15:57 Wei Liu
  2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 1/9] x86: introduce CONFIG_GUEST and move code Wei Liu
                   ` (8 more replies)
  0 siblings, 9 replies; 31+ messages in thread
From: Wei Liu @ 2019-10-21 15:57 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 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 <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            | 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

-- 
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] 31+ messages in thread

* [Xen-devel] [PATCH for-next v3 1/9] x86: introduce CONFIG_GUEST and move code
  2019-10-21 15:57 [Xen-devel] [PATCH for-next v3 0/9] Port Xen to Hyper-V Wei Liu
@ 2019-10-21 15:57 ` Wei Liu
  2019-10-23  7:55   ` Paul Durrant
  2019-11-15 13:34   ` Jan Beulich
  2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 2/9] x86: include asm_defns.h directly in hypercall.h Wei Liu
                   ` (7 subsequent siblings)
  8 siblings, 2 replies; 31+ messages in thread
From: Wei Liu @ 2019-10-21 15:57 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 28b3b4692a..867de857e8 100644
--- a/xen/arch/x86/Kconfig
+++ b/xen/arch/x86/Kconfig
@@ -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.
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] 31+ messages in thread

* [Xen-devel] [PATCH for-next v3 2/9] x86: include asm_defns.h directly in hypercall.h
  2019-10-21 15:57 [Xen-devel] [PATCH for-next v3 0/9] Port Xen to Hyper-V Wei Liu
  2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 1/9] x86: introduce CONFIG_GUEST and move code Wei Liu
@ 2019-10-21 15:57 ` Wei Liu
  2019-11-15 13:36   ` Jan Beulich
  2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 3/9] x86: drop hypervisor_cpuid_base Wei Liu
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 31+ messages in thread
From: Wei Liu @ 2019-10-21 15:57 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] 31+ messages in thread

* [Xen-devel] [PATCH for-next v3 3/9] x86: drop hypervisor_cpuid_base
  2019-10-21 15:57 [Xen-devel] [PATCH for-next v3 0/9] Port Xen to Hyper-V Wei Liu
  2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 1/9] x86: introduce CONFIG_GUEST and move code Wei Liu
  2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 2/9] x86: include asm_defns.h directly in hypercall.h Wei Liu
@ 2019-10-21 15:57 ` Wei Liu
  2019-11-15 13:39   ` Jan Beulich
  2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 4/9] x86: include xen/lib.h in guest/hypercall.h Wei Liu
                   ` (5 subsequent siblings)
  8 siblings, 1 reply; 31+ messages in thread
From: Wei Liu @ 2019-10-21 15:57 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] 31+ messages in thread

* [Xen-devel] [PATCH for-next v3 4/9] x86: include xen/lib.h in guest/hypercall.h
  2019-10-21 15:57 [Xen-devel] [PATCH for-next v3 0/9] Port Xen to Hyper-V Wei Liu
                   ` (2 preceding siblings ...)
  2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 3/9] x86: drop hypervisor_cpuid_base Wei Liu
@ 2019-10-21 15:57 ` Wei Liu
  2019-11-15 13:40   ` Jan Beulich
  2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 5/9] x86: introduce hypervisor framework Wei Liu
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 31+ messages in thread
From: Wei Liu @ 2019-10-21 15:57 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>
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 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] 31+ messages in thread

* [Xen-devel] [PATCH for-next v3 5/9] x86: introduce hypervisor framework
  2019-10-21 15:57 [Xen-devel] [PATCH for-next v3 0/9] Port Xen to Hyper-V Wei Liu
                   ` (3 preceding siblings ...)
  2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 4/9] x86: include xen/lib.h in guest/hypercall.h Wei Liu
@ 2019-10-21 15:57 ` Wei Liu
  2019-10-23  8:19   ` Paul Durrant
  2019-11-15 13:48   ` Jan Beulich
  2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 6/9] x86: rename hypervisor_{alloc, free}_unused_page Wei Liu
                   ` (3 subsequent siblings)
  8 siblings, 2 replies; 31+ messages in thread
From: Wei Liu @ 2019-10-21 15:57 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] 31+ messages in thread

* [Xen-devel] [PATCH for-next v3 6/9] x86: rename hypervisor_{alloc, free}_unused_page
  2019-10-21 15:57 [Xen-devel] [PATCH for-next v3 0/9] Port Xen to Hyper-V Wei Liu
                   ` (4 preceding siblings ...)
  2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 5/9] x86: introduce hypervisor framework Wei Liu
@ 2019-10-21 15:57 ` Wei Liu
  2019-11-15 13:49   ` Jan Beulich
  2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 7/9] x86: switch xen implementation to use hypervisor framework Wei Liu
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 31+ messages in thread
From: Wei Liu @ 2019-10-21 15:57 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>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.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] 31+ messages in thread

* [Xen-devel] [PATCH for-next v3 7/9] x86: switch xen implementation to use hypervisor framework
  2019-10-21 15:57 [Xen-devel] [PATCH for-next v3 0/9] Port Xen to Hyper-V Wei Liu
                   ` (5 preceding siblings ...)
  2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 6/9] x86: rename hypervisor_{alloc, free}_unused_page Wei Liu
@ 2019-10-21 15:57 ` Wei Liu
  2019-10-23  9:02   ` Paul Durrant
  2019-11-15 13:56   ` Jan Beulich
  2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 8/9] x86: be more verbose when running on a hypervisor Wei Liu
  2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 9/9] x86: introduce CONFIG_HYPERV and detection code Wei Liu
  8 siblings, 2 replies; 31+ messages in thread
From: Wei Liu @ 2019-10-21 15:57 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>
---
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(-)

diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c
index 89b9ae4de0..33bf1a769d 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,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
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..655435c1f7 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)
+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
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..c3c6bea24f 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_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] 31+ messages in thread

* [Xen-devel] [PATCH for-next v3 8/9] x86: be more verbose when running on a hypervisor
  2019-10-21 15:57 [Xen-devel] [PATCH for-next v3 0/9] Port Xen to Hyper-V Wei Liu
                   ` (6 preceding siblings ...)
  2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 7/9] x86: switch xen implementation to use hypervisor framework Wei Liu
@ 2019-10-21 15:57 ` Wei Liu
  2019-10-23  9:03   ` Paul Durrant
  2019-11-15 13:59   ` Jan Beulich
  2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 9/9] x86: introduce CONFIG_HYPERV and detection code Wei Liu
  8 siblings, 2 replies; 31+ messages in thread
From: Wei Liu @ 2019-10-21 15:57 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>
---
V3: Address Roger's comment, add ASSERTs
---
 xen/arch/x86/guest/hypervisor.c        | 6 ++++++
 xen/arch/x86/setup.c                   | 6 +++++-
 xen/include/asm-x86/guest/hypervisor.h | 3 +++
 3 files changed, 14 insertions(+), 1 deletion(-)

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


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

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

* [Xen-devel] [PATCH for-next v3 9/9] x86: introduce CONFIG_HYPERV and detection code
  2019-10-21 15:57 [Xen-devel] [PATCH for-next v3 0/9] Port Xen to Hyper-V Wei Liu
                   ` (7 preceding siblings ...)
  2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 8/9] x86: be more verbose when running on a hypervisor Wei Liu
@ 2019-10-21 15:57 ` Wei Liu
  2019-10-23  9:07   ` Paul Durrant
  2019-11-15 14:07   ` Jan Beulich
  8 siblings, 2 replies; 31+ messages in thread
From: Wei Liu @ 2019-10-21 15:57 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 did 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>
---
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

diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig
index 867de857e8..56513c771c 100644
--- a/xen/arch/x86/Kconfig
+++ b/xen/arch/x86/Kconfig
@@ -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
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..7ab4b127f3
--- /dev/null
+++ b/xen/arch/x86/guest/hyperv/hyperv.c
@@ -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:
+ */
diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c
index a666ad9526..17392d1ffa 100644
--- a/xen/arch/x86/guest/hypervisor.c
+++ b/xen/arch/x86/guest/hypervisor.c
@@ -43,6 +43,14 @@ bool hypervisor_probe(void)
     }
 #endif
 
+#ifdef CONFIG_HYPERV_GUEST
+    if ( hyperv_probe() )
+    {
+        hops = &hyperv_ops;
+        return true;
+    }
+#endif
+
     return false;
 }
 
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..4b9cc5a836
--- /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_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] 31+ messages in thread

* Re: [Xen-devel] [PATCH for-next v3 1/9] x86: introduce CONFIG_GUEST and move code
  2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 1/9] x86: introduce CONFIG_GUEST and move code Wei Liu
@ 2019-10-23  7:55   ` Paul Durrant
  2019-10-23 10:49     ` Wei Liu
  2019-11-15 13:34   ` Jan Beulich
  1 sibling, 1 reply; 31+ messages in thread
From: Paul Durrant @ 2019-10-23  7:55 UTC (permalink / raw)
  To: Wei Liu
  Cc: Wei Liu, Andrew Cooper, Michael Kelley, Jan Beulich,
	Xen Development List, Roger Pau Monné

On Mon, 21 Oct 2019 at 16:59, Wei Liu <wl@xen.org> wrote:
>
> 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 28b3b4692a..867de857e8 100644
> --- a/xen/arch/x86/Kconfig
> +++ b/xen/arch/x86/Kconfig
> @@ -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.

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

  Paul

> 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

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

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

* Re: [Xen-devel] [PATCH for-next v3 5/9] x86: introduce hypervisor framework
  2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 5/9] x86: introduce hypervisor framework Wei Liu
@ 2019-10-23  8:19   ` Paul Durrant
  2019-11-15 13:48   ` Jan Beulich
  1 sibling, 0 replies; 31+ messages in thread
From: Paul Durrant @ 2019-10-23  8:19 UTC (permalink / raw)
  To: Wei Liu
  Cc: Wei Liu, Andrew Cooper, Michael Kelley, Jan Beulich,
	Xen Development List, Roger Pau Monné

On Mon, 21 Oct 2019 at 17:01, Wei Liu <wl@xen.org> wrote:
>
> 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>

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

> ---
>  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

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

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

* Re: [Xen-devel] [PATCH for-next v3 7/9] x86: switch xen implementation to use hypervisor framework
  2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 7/9] x86: switch xen implementation to use hypervisor framework Wei Liu
@ 2019-10-23  9:02   ` Paul Durrant
  2019-11-15 13:56   ` Jan Beulich
  1 sibling, 0 replies; 31+ messages in thread
From: Paul Durrant @ 2019-10-23  9:02 UTC (permalink / raw)
  To: Wei Liu
  Cc: Wei Liu, Andrew Cooper, Michael Kelley, Jan Beulich,
	Xen Development List, Roger Pau Monné

On Mon, 21 Oct 2019 at 17:00, Wei Liu <wl@xen.org> wrote:
>
> Take the chance to change probe_hypervisor to hypervisor_probe.
>
> Signed-off-by: Wei Liu <liuwe@microsoft.com>

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

> ---
> 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(-)
>
> diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c
> index 89b9ae4de0..33bf1a769d 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,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
> 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..655435c1f7 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)
> +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
> 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..c3c6bea24f 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_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

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

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

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

On Mon, 21 Oct 2019 at 17:00, Wei Liu <wl@xen.org> wrote:
>
> Signed-off-by: Wei Liu <liuwe@microsoft.com>

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

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

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

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

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

On Mon, 21 Oct 2019 at 17:01, Wei Liu <wl@xen.org> wrote:
>
> 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.
>
> Signed-off-by: Wei Liu <liuwe@microsoft.com>

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

...with one suggestion...

> ---
> 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
>
> diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig
> index 867de857e8..56513c771c 100644
> --- a/xen/arch/x86/Kconfig
> +++ b/xen/arch/x86/Kconfig
> @@ -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
> 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..7ab4b127f3
> --- /dev/null
> +++ b/xen/arch/x86/guest/hyperv/hyperv.c
> @@ -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:
> + */
> diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c
> index a666ad9526..17392d1ffa 100644
> --- a/xen/arch/x86/guest/hypervisor.c
> +++ b/xen/arch/x86/guest/hypervisor.c
> @@ -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.

> +#ifdef CONFIG_HYPERV_GUEST
> +    if ( hyperv_probe() )
> +    {
> +        hops = &hyperv_ops;
> +        return true;
> +    }
> +#endif
> +
>      return false;
>  }
>
> 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..4b9cc5a836
> --- /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_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

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

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

* Re: [Xen-devel] [PATCH for-next v3 1/9] x86: introduce CONFIG_GUEST and move code
  2019-10-23  7:55   ` Paul Durrant
@ 2019-10-23 10:49     ` Wei Liu
  0 siblings, 0 replies; 31+ messages in thread
From: Wei Liu @ 2019-10-23 10:49 UTC (permalink / raw)
  To: Paul Durrant
  Cc: Wei Liu, Wei Liu, Andrew Cooper, Michael Kelley, Jan Beulich,
	Xen Development List, Roger Pau Monné

On Wed, Oct 23, 2019 at 08:55:24AM +0100, Paul Durrant wrote:
> On Mon, 21 Oct 2019 at 16:59, Wei Liu <wl@xen.org> wrote:
> >
> > 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 28b3b4692a..867de857e8 100644
> > --- a/xen/arch/x86/Kconfig
> > +++ b/xen/arch/x86/Kconfig
> > @@ -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.
> 
> 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
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

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

On Wed, Oct 23, 2019 at 10:07:24AM +0100, Paul Durrant wrote:
> On Mon, 21 Oct 2019 at 17:01, Wei Liu <wl@xen.org> wrote:
> >
> > 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.
> >
> > Signed-off-by: Wei Liu <liuwe@microsoft.com>
> 
> Reviewed-by: Paul Durrant <paul@xen.org>

Thanks.

[...]
> > diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c
> > index a666ad9526..17392d1ffa 100644
> > --- a/xen/arch/x86/guest/hypervisor.c
> > +++ b/xen/arch/x86/guest/hypervisor.c
> > @@ -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
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

* Re: [Xen-devel] [PATCH for-next v3 1/9] x86: introduce CONFIG_GUEST and move code
  2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 1/9] x86: introduce CONFIG_GUEST and move code Wei Liu
  2019-10-23  7:55   ` Paul Durrant
@ 2019-11-15 13:34   ` Jan Beulich
  1 sibling, 0 replies; 31+ messages in thread
From: Jan Beulich @ 2019-11-15 13:34 UTC (permalink / raw)
  To: Wei Liu
  Cc: Xen Development List, Roger Pau Monné,
	Wei Liu, Andrew Cooper, Michael Kelley

On 21.10.2019 17:57, Wei Liu wrote:
> 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>

Acked-by: Jan Beulich <jbeulich@suse.com>

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

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

* Re: [Xen-devel] [PATCH for-next v3 2/9] x86: include asm_defns.h directly in hypercall.h
  2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 2/9] x86: include asm_defns.h directly in hypercall.h Wei Liu
@ 2019-11-15 13:36   ` Jan Beulich
  0 siblings, 0 replies; 31+ messages in thread
From: Jan Beulich @ 2019-11-15 13:36 UTC (permalink / raw)
  To: Wei Liu
  Cc: Xen Development List, Roger Pau Monné,
	Wei Liu, Andrew Cooper, Michael Kelley

On 21.10.2019 17:57, Wei Liu wrote:
> 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>

Acked-by: Jan Beulich <jbeulich@suse.com>

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

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

* Re: [Xen-devel] [PATCH for-next v3 3/9] x86: drop hypervisor_cpuid_base
  2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 3/9] x86: drop hypervisor_cpuid_base Wei Liu
@ 2019-11-15 13:39   ` Jan Beulich
  0 siblings, 0 replies; 31+ messages in thread
From: Jan Beulich @ 2019-11-15 13:39 UTC (permalink / raw)
  To: Wei Liu
  Cc: Xen Development List, Roger Pau Monné,
	Wei Liu, Andrew Cooper, Michael Kelley

On 21.10.2019 17:57, Wei Liu wrote:
> 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>

Acked-by: Jan Beulich <jbeulich@suse.com>
with, at this occasion, ...

> --- 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;

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

Jan

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

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

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

On 21.10.2019 17:57, Wei Liu wrote:
> We need ASSERT_UNREACHABLE.
> 
> Signed-off-by: Wei Liu <liuwe@microsoft.com>
> Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>

Acked-by: Jan Beulich <jbeulich@suse.com>

Albeit perhaps fold into patch 2?

Jan

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

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

* Re: [Xen-devel] [PATCH for-next v3 5/9] x86: introduce hypervisor framework
  2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 5/9] x86: introduce hypervisor framework Wei Liu
  2019-10-23  8:19   ` Paul Durrant
@ 2019-11-15 13:48   ` Jan Beulich
  2019-11-21 16:27     ` Wei Liu
  1 sibling, 1 reply; 31+ messages in thread
From: Jan Beulich @ 2019-11-15 13:48 UTC (permalink / raw)
  To: Wei Liu
  Cc: Xen Development List, Andrew Cooper, Wei Liu,
	Roger Pau Monné,
	Michael Kelley

On 21.10.2019 17:57, Wei Liu wrote:
> --- /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;

The __read_mostly wants to again go between type and identifier.

> +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?

> --- /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);

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

> +};
> +
> +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.

> @@ -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
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

* Re: [Xen-devel] [PATCH for-next v3 6/9] x86: rename hypervisor_{alloc, free}_unused_page
  2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 6/9] x86: rename hypervisor_{alloc, free}_unused_page Wei Liu
@ 2019-11-15 13:49   ` Jan Beulich
  2019-11-21 16:27     ` Wei Liu
  0 siblings, 1 reply; 31+ messages in thread
From: Jan Beulich @ 2019-11-15 13:49 UTC (permalink / raw)
  To: Wei Liu
  Cc: Xen Development List, Roger Pau Monné,
	Wei Liu, Andrew Cooper, Michael Kelley

On 21.10.2019 17:57, Wei Liu wrote:
> --- 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) )

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

Jan

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

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

* Re: [Xen-devel] [PATCH for-next v3 7/9] x86: switch xen implementation to use hypervisor framework
  2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 7/9] x86: switch xen implementation to use hypervisor framework Wei Liu
  2019-10-23  9:02   ` Paul Durrant
@ 2019-11-15 13:56   ` Jan Beulich
  1 sibling, 0 replies; 31+ messages in thread
From: Jan Beulich @ 2019-11-15 13:56 UTC (permalink / raw)
  To: Wei Liu
  Cc: Xen Development List, Andrew Cooper, Wei Liu,
	Roger Pau Monné,
	Michael Kelley

On 21.10.2019 17:57, Wei Liu wrote:
> @@ -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)

__init?

> @@ -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
Acked-by: Jan Beulich <jbeulich@suse.com>

Jan

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

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

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

On 21.10.2019 17:57, Wei Liu wrote:
> --- a/xen/arch/x86/setup.c
> +++ b/xen/arch/x86/setup.c
> @@ -689,6 +689,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
>      int i, j, e820_warn = 0, bytes = 0;
>      bool acpi_boot_table_init_done = false, relocated = false;
>      int ret;
> +    bool running_on_hypervisor;
>      struct ns16550_defaults ns16550 = {
>          .data_bits = 8,
>          .parity    = 'n',
> @@ -763,7 +764,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
>       * allocing any xenheap structures wanted in lower memory. */
>      kexec_early_calculations();
>  
> -    hypervisor_probe();
> +    running_on_hypervisor = hypervisor_probe();
>  
>      parse_video_info();
>  
> @@ -789,6 +790,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)
>  
>      printk("Xen image load base address: %#lx\n", xen_phys_start);
>  
> +    if ( running_on_hypervisor )
> +        printk("Running on %s\n", hypervisor_name());

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

Jan

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

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

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

On 21.10.2019 17:57, Wei Liu wrote:
> --- a/xen/arch/x86/Kconfig
> +++ b/xen/arch/x86/Kconfig
> @@ -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

> --- /dev/null
> +++ b/xen/arch/x86/guest/hyperv/hyperv.c
> @@ -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 = {

const again.

> --- a/xen/arch/x86/guest/hypervisor.c
> +++ b/xen/arch/x86/guest/hypervisor.c
> @@ -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
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

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

On Fri, Nov 15, 2019 at 03:07:29PM +0100, Jan Beulich wrote:
> On 21.10.2019 17:57, Wei Liu wrote:
> > --- a/xen/arch/x86/Kconfig
> > +++ b/xen/arch/x86/Kconfig
> > @@ -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

Ack.

> 
> > --- /dev/null
> > +++ b/xen/arch/x86/guest/hyperv/hyperv.c
> > @@ -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 = {
> 
> const again.
> 
> > --- a/xen/arch/x86/guest/hypervisor.c
> > +++ b/xen/arch/x86/guest/hypervisor.c
> > @@ -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?

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.

> 
> Jan

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

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

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

On Fri, Nov 15, 2019 at 02:49:57PM +0100, Jan Beulich wrote:
> On 21.10.2019 17:57, Wei Liu wrote:
> > --- 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) )
> 
> 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.

> 
> Jan

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

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

* Re: [Xen-devel] [PATCH for-next v3 5/9] x86: introduce hypervisor framework
  2019-11-15 13:48   ` Jan Beulich
@ 2019-11-21 16:27     ` Wei Liu
  0 siblings, 0 replies; 31+ messages in thread
From: Wei Liu @ 2019-11-21 16:27 UTC (permalink / raw)
  To: Jan Beulich
  Cc: Wei Liu, Wei Liu, Andrew Cooper, Michael Kelley,
	Xen Development List, Roger Pau Monné

On Fri, Nov 15, 2019 at 02:48:18PM +0100, Jan Beulich wrote:
> On 21.10.2019 17:57, Wei Liu wrote:
> > --- /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;
> 
> The __read_mostly wants to again go between type and identifier.

Ack.

> 
> > +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.

[...]
> > @@ -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?

I will add it back to all those stubs.

Wei.

> 
> Jan

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

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

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

On 21.11.2019 17:27, Wei Liu wrote:
> On Fri, Nov 15, 2019 at 03:07:29PM +0100, Jan Beulich wrote:
>> On 21.10.2019 17:57, Wei Liu wrote:
>>> --- a/xen/arch/x86/Kconfig
>>> +++ b/xen/arch/x86/Kconfig
>>> @@ -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
> 
> Ack.
> 
>>
>>> --- /dev/null
>>> +++ b/xen/arch/x86/guest/hyperv/hyperv.c
>>> @@ -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 = {
>>
>> const again.
>>
>>> --- a/xen/arch/x86/guest/hypervisor.c
>>> +++ b/xen/arch/x86/guest/hypervisor.c
>>> @@ -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?
> 
> 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
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

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

On Thu, Nov 21, 2019 at 05:59:16PM +0100, Jan Beulich wrote:
> >>
> >> 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.

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.

> 
> Jan

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

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

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

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-21 15:57 [Xen-devel] [PATCH for-next v3 0/9] Port Xen to Hyper-V Wei Liu
2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 1/9] x86: introduce CONFIG_GUEST and move code Wei Liu
2019-10-23  7:55   ` Paul Durrant
2019-10-23 10:49     ` Wei Liu
2019-11-15 13:34   ` Jan Beulich
2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 2/9] x86: include asm_defns.h directly in hypercall.h Wei Liu
2019-11-15 13:36   ` Jan Beulich
2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 3/9] x86: drop hypervisor_cpuid_base Wei Liu
2019-11-15 13:39   ` Jan Beulich
2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 4/9] x86: include xen/lib.h in guest/hypercall.h Wei Liu
2019-11-15 13:40   ` Jan Beulich
2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 5/9] x86: introduce hypervisor framework Wei Liu
2019-10-23  8:19   ` Paul Durrant
2019-11-15 13:48   ` Jan Beulich
2019-11-21 16:27     ` Wei Liu
2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 6/9] x86: rename hypervisor_{alloc, free}_unused_page Wei Liu
2019-11-15 13:49   ` Jan Beulich
2019-11-21 16:27     ` Wei Liu
2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 7/9] x86: switch xen implementation to use hypervisor framework Wei Liu
2019-10-23  9:02   ` Paul Durrant
2019-11-15 13:56   ` Jan Beulich
2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 8/9] x86: be more verbose when running on a hypervisor Wei Liu
2019-10-23  9:03   ` Paul Durrant
2019-11-15 13:59   ` Jan Beulich
2019-10-21 15:57 ` [Xen-devel] [PATCH for-next v3 9/9] x86: introduce CONFIG_HYPERV and detection code Wei Liu
2019-10-23  9:07   ` Paul Durrant
2019-10-23 10:50     ` Wei Liu
2019-11-15 14:07   ` Jan Beulich
2019-11-21 16:27     ` Wei Liu
2019-11-21 16:59       ` Jan Beulich
2019-11-21 17:02         ` 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.