All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xen-devel] [PATCH v4 0/8] Port Xen to Hyper-V
@ 2019-11-21 18:50 Wei Liu
  2019-11-21 18:50 ` [Xen-devel] [PATCH v4 1/8] x86: introduce CONFIG_GUEST and move code Wei Liu
                   ` (7 more replies)
  0 siblings, 8 replies; 27+ messages in thread
From: Wei Liu @ 2019-11-21 18:50 UTC (permalink / raw)
  To: Xen Development List
  Cc: Wei Liu, Wei Liu, Paul Durrant, Andrew Cooper, Michael Kelley,
	Jan Beulich, Roger Pau Monné

Please see individual patches for changes.

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> 
Cc: Paul Durrant <paul@xen.org>

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

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

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

* [Xen-devel] [PATCH v4 1/8] x86: introduce CONFIG_GUEST and move code
  2019-11-21 18:50 [Xen-devel] [PATCH v4 0/8] Port Xen to Hyper-V Wei Liu
@ 2019-11-21 18:50 ` Wei Liu
  2019-11-21 18:50 ` [Xen-devel] [PATCH v4 2/8] x86: add missing headers in hypercall.h Wei Liu
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 27+ messages in thread
From: Wei Liu @ 2019-11-21 18:50 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>
Acked-by: Jan Beulich <jbeulich@suse.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 a0b2f4ab15..7da5a2631e 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] 27+ messages in thread

* [Xen-devel] [PATCH v4 2/8] x86: add missing headers in hypercall.h
  2019-11-21 18:50 [Xen-devel] [PATCH v4 0/8] Port Xen to Hyper-V Wei Liu
  2019-11-21 18:50 ` [Xen-devel] [PATCH v4 1/8] x86: introduce CONFIG_GUEST and move code Wei Liu
@ 2019-11-21 18:50 ` Wei Liu
  2019-11-21 18:50 ` [Xen-devel] [PATCH v4 3/8] x86: drop hypervisor_cpuid_base Wei Liu
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 27+ messages in thread
From: Wei Liu @ 2019-11-21 18:50 UTC (permalink / raw)
  To: Xen Development List
  Cc: Wei Liu, Wei Liu, Andrew Cooper, Michael Kelley, Jan Beulich,
	Roger Pau Monné

Include asm_defns.h because ASM_CALL_CONSTRAINT is defined there.

Include xen/lib.h because we need ASSERT_UNREACHABLE.

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/include/asm-x86/guest/hypercall.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/xen/include/asm-x86/guest/hypercall.h b/xen/include/asm-x86/guest/hypercall.h
index d548816b30..d0d2f5022d 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>
@@ -180,6 +182,8 @@ static inline long xen_hypercall_set_evtchn_upcall_vector(
 
 #else /* CONFIG_XEN_GUEST */
 
+#include <xen/lib.h>
+
 #include <public/sched.h>
 
 static inline void xen_hypercall_console_write(
-- 
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] 27+ messages in thread

* [Xen-devel] [PATCH v4 3/8] x86: drop hypervisor_cpuid_base
  2019-11-21 18:50 [Xen-devel] [PATCH v4 0/8] Port Xen to Hyper-V Wei Liu
  2019-11-21 18:50 ` [Xen-devel] [PATCH v4 1/8] x86: introduce CONFIG_GUEST and move code Wei Liu
  2019-11-21 18:50 ` [Xen-devel] [PATCH v4 2/8] x86: add missing headers in hypercall.h Wei Liu
@ 2019-11-21 18:50 ` Wei Liu
  2019-11-21 18:50 ` [Xen-devel] [PATCH v4 4/8] x86: introduce hypervisor framework Wei Liu
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 27+ messages in thread
From: Wei Liu @ 2019-11-21 18:50 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.

Move __read_mostly to its standard place while at it.

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/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 a329e7c886..1e37086518 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;
+uint32_t __read_mostly xen_cpuid_base;
 extern char hypercall_page[];
 static struct rangeset *mem;
 
@@ -297,11 +297,6 @@ int hypervisor_free_unused_page(mfn_t mfn)
     return rangeset_remove_range(mem, mfn_x(mfn), mfn_x(mfn));
 }
 
-uint32_t hypervisor_cpuid_base(void)
-{
-    return xen_cpuid_base;
-}
-
 static void ap_resume(void *unused)
 {
     map_vcpuinfo();
diff --git a/xen/arch/x86/pv/shim.c b/xen/arch/x86/pv/shim.c
index 35bf3945ac..351da970ef 100644
--- a/xen/arch/x86/pv/shim.c
+++ b/xen/arch/x86/pv/shim.c
@@ -995,7 +995,7 @@ domid_t get_initial_domain_id(void)
     if ( !pv_shim )
         return 0;
 
-    cpuid(hypervisor_cpuid_base() + 4, &eax, &ebx, &ecx, &edx);
+    cpuid(xen_cpuid_base + 4, &eax, &ebx, &ecx, &edx);
 
     return (eax & XEN_HVM_CPUID_DOMID_PRESENT) ? ecx : 1;
 }
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] 27+ messages in thread

* [Xen-devel] [PATCH v4 4/8] x86: introduce hypervisor framework
  2019-11-21 18:50 [Xen-devel] [PATCH v4 0/8] Port Xen to Hyper-V Wei Liu
                   ` (2 preceding siblings ...)
  2019-11-21 18:50 ` [Xen-devel] [PATCH v4 3/8] x86: drop hypervisor_cpuid_base Wei Liu
@ 2019-11-21 18:50 ` Wei Liu
  2019-11-22 10:31   ` Durrant, Paul
                     ` (2 more replies)
  2019-11-21 18:50 ` [Xen-devel] [PATCH v4 5/8] x86: rename hypervisor_{alloc, free}_unused_page Wei Liu
                   ` (3 subsequent siblings)
  7 siblings, 3 replies; 27+ messages in thread
From: Wei Liu @ 2019-11-21 18:50 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>
---
Changes in v4:
1. Add ASSERT_UNREACHABLE to stubs.
2. Move __read_mostly.
3. Return hops directly.
4. Drop Paul's review tag.
---
 xen/arch/x86/guest/Makefile            |  2 +
 xen/arch/x86/guest/hypervisor.c        | 42 +++++++++++++++++
 xen/include/asm-x86/guest.h            |  1 +
 xen/include/asm-x86/guest/hypervisor.h | 62 ++++++++++++++++++++++++++
 xen/include/asm-x86/guest/xen.h        | 12 -----
 5 files changed, 107 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..103feba5d8
--- /dev/null
+++ b/xen/arch/x86/guest/hypervisor.c
@@ -0,0 +1,42 @@
+/******************************************************************************
+ * 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 const struct hypervisor_ops __read_mostly *hops;
+
+const struct hypervisor_ops *hypervisor_probe(void)
+{
+    return hops;
+}
+
+/*
+ * 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..2ab15a7108
--- /dev/null
+++ b/xen/include/asm-x86/guest/hypervisor.h
@@ -0,0 +1,62 @@
+/******************************************************************************
+ * 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__
+
+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);
+};
+
+#ifdef CONFIG_GUEST
+
+const struct hypervisor_ops *hypervisor_probe(void);
+void hypervisor_setup(void);
+void hypervisor_ap_setup(void);
+void hypervisor_resume(void);
+
+#else
+
+#include <xen/lib.h>
+#include <xen/types.h>
+
+static inline const struct hypervisor_ops *hypervisor_probe(void) { return NULL; }
+static inline void hypervisor_setup(void) { ASSERT_UNREACHABLE(); }
+static inline void hypervisor_ap_setup(void) { ASSERT_UNREACHABLE(); }
+static inline void hypervisor_resume(void) { ASSERT_UNREACHABLE(); }
+
+#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] 27+ messages in thread

* [Xen-devel] [PATCH v4 5/8] x86: rename hypervisor_{alloc, free}_unused_page
  2019-11-21 18:50 [Xen-devel] [PATCH v4 0/8] Port Xen to Hyper-V Wei Liu
                   ` (3 preceding siblings ...)
  2019-11-21 18:50 ` [Xen-devel] [PATCH v4 4/8] x86: introduce hypervisor framework Wei Liu
@ 2019-11-21 18:50 ` Wei Liu
  2019-11-22 10:57   ` Durrant, Paul
  2019-11-21 18:50 ` [Xen-devel] [PATCH v4 6/8] x86: switch xen guest implementation to use hypervisor framework Wei Liu
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 27+ messages in thread
From: Wei Liu @ 2019-11-21 18:50 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>
---
Changes in v4:
1. Use xg_ prefix instead.
2. Drop Roger's review tag.
---
 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 1e37086518..0f5b5267c5 100644
--- a/xen/arch/x86/guest/xen/xen.c
+++ b/xen/arch/x86/guest/xen/xen.c
@@ -93,7 +93,7 @@ static void map_shared_info(void)
     unsigned int i;
     unsigned long rc;
 
-    if ( hypervisor_alloc_unused_page(&mfn) )
+    if ( xg_alloc_unused_page(&mfn) )
         panic("unable to reserve shared info memory page\n");
 
     xatp.gpfn = mfn_x(mfn);
@@ -280,7 +280,7 @@ void hypervisor_ap_setup(void)
     init_evtchn();
 }
 
-int hypervisor_alloc_unused_page(mfn_t *mfn)
+int xg_alloc_unused_page(mfn_t *mfn)
 {
     unsigned long m;
     int rc;
@@ -292,7 +292,7 @@ int hypervisor_alloc_unused_page(mfn_t *mfn)
     return rc;
 }
 
-int hypervisor_free_unused_page(mfn_t mfn)
+int xg_free_unused_page(mfn_t mfn)
 {
     return rangeset_remove_range(mem, mfn_x(mfn), mfn_x(mfn));
 }
diff --git a/xen/arch/x86/pv/shim.c b/xen/arch/x86/pv/shim.c
index 351da970ef..7a898fdbe5 100644
--- a/xen/arch/x86/pv/shim.c
+++ b/xen/arch/x86/pv/shim.c
@@ -742,7 +742,7 @@ static long pv_shim_grant_table_op(unsigned int cmd,
                 };
                 mfn_t mfn;
 
-                rc = hypervisor_alloc_unused_page(&mfn);
+                rc = xg_alloc_unused_page(&mfn);
                 if ( rc )
                 {
                     gprintk(XENLOG_ERR,
@@ -754,7 +754,7 @@ static long pv_shim_grant_table_op(unsigned int cmd,
                 rc = xen_hypercall_memory_op(XENMEM_add_to_physmap, &xatp);
                 if ( rc )
                 {
-                    hypervisor_free_unused_page(mfn);
+                    xg_free_unused_page(mfn);
                     break;
                 }
 
diff --git a/xen/include/asm-x86/guest/xen.h b/xen/include/asm-x86/guest/xen.h
index 3145f75361..01dc3ee6f6 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 xg_alloc_unused_page(mfn_t *mfn);
+int xg_free_unused_page(mfn_t mfn);
 
 DECLARE_PER_CPU(unsigned int, vcpu_id);
 DECLARE_PER_CPU(struct vcpu_info *, vcpu_info);
-- 
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] 27+ messages in thread

* [Xen-devel] [PATCH v4 6/8] x86: switch xen guest implementation to use hypervisor framework
  2019-11-21 18:50 [Xen-devel] [PATCH v4 0/8] Port Xen to Hyper-V Wei Liu
                   ` (4 preceding siblings ...)
  2019-11-21 18:50 ` [Xen-devel] [PATCH v4 5/8] x86: rename hypervisor_{alloc, free}_unused_page Wei Liu
@ 2019-11-21 18:50 ` Wei Liu
  2019-11-22 11:02   ` Durrant, Paul
  2019-11-29 13:50   ` Jan Beulich
  2019-11-21 18:50 ` [Xen-devel] [PATCH v4 7/8] x86: be more verbose when running on a hypervisor Wei Liu
  2019-11-21 18:50 ` [Xen-devel] [PATCH v4 8/8] x86: introduce CONFIG_HYPERV and detection code Wei Liu
  7 siblings, 2 replies; 27+ messages in thread
From: Wei Liu @ 2019-11-21 18:50 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>
---
Changes in v4:
1. xen_probe returns address of ops directly.
2. Add __init to hypervisor_setup.
3. Drop Paul's review tag.
---
 xen/arch/x86/guest/hypervisor.c   | 32 ++++++++++++++++++++-
 xen/arch/x86/guest/xen/pvh-boot.c |  2 +-
 xen/arch/x86/guest/xen/xen.c      | 47 ++++++++++++++++++-------------
 xen/arch/x86/setup.c              |  2 +-
 xen/include/asm-x86/guest/xen.h   |  5 ++--
 5 files changed, 64 insertions(+), 24 deletions(-)

diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c
index 103feba5d8..a067cacecb 100644
--- a/xen/arch/x86/guest/hypervisor.c
+++ b/xen/arch/x86/guest/hypervisor.c
@@ -19,18 +19,48 @@
  * Copyright (c) 2019 Microsoft.
  */
 
+#include <xen/init.h>
 #include <xen/types.h>
 
 #include <asm/cache.h>
-#include <asm/guest/hypervisor.h>
+#include <asm/guest.h>
 
 static const struct hypervisor_ops __read_mostly *hops;
 
 const struct hypervisor_ops *hypervisor_probe(void)
 {
+    if ( hops )
+        goto out;
+
+    if ( !cpu_has_hypervisor )
+        goto out;
+
+    hops = xen_probe();
+    if ( hops )
+        goto out;
+
+ out:
     return hops;
 }
 
+void __init 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 0f5b5267c5..8cfe059887 100644
--- a/xen/arch/x86/guest/xen/xen.c
+++ b/xen/arch/x86/guest/xen/xen.c
@@ -67,22 +67,6 @@ static void __init find_xen_leaves(void)
     }
 }
 
-void __init probe_hypervisor(void)
-{
-    if ( xen_guest || !cpu_has_hypervisor )
-        return;
-
-    find_xen_leaves();
-
-    if ( !xen_cpuid_base )
-        return;
-
-    /* Fill the hypercall page. */
-    wrmsrl(cpuid_ebx(xen_cpuid_base + 2), __pa(hypercall_page));
-
-    xen_guest = true;
-}
-
 static void map_shared_info(void)
 {
     mfn_t mfn;
@@ -245,7 +229,7 @@ static void init_evtchn(void)
     }
 }
 
-void __init hypervisor_setup(void)
+static void __init xen_setup(void)
 {
     init_memmap();
 
@@ -273,7 +257,7 @@ void __init hypervisor_setup(void)
     init_evtchn();
 }
 
-void hypervisor_ap_setup(void)
+static void xen_ap_setup(void)
 {
     set_vcpu_id();
     map_vcpuinfo();
@@ -303,7 +287,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();
@@ -326,6 +310,31 @@ void hypervisor_resume(void)
         pv_console_init();
 }
 
+static const struct hypervisor_ops xg_ops = {
+    .name = "Xen",
+    .setup = xen_setup,
+    .ap_setup = xen_ap_setup,
+    .resume = xen_resume,
+};
+
+const struct hypervisor_ops * __init xen_probe(void)
+{
+    if ( xen_guest )
+        return &xg_ops;
+
+    find_xen_leaves();
+
+    if ( !xen_cpuid_base )
+        return NULL;
+
+    /* Fill the hypercall page. */
+    wrmsrl(cpuid_ebx(xen_cpuid_base + 2), __pa(hypercall_page));
+
+    xen_guest = true;
+
+    return &xg_ops;
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
index 00ee87bde5..19606d909b 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 01dc3ee6f6..db90b550a7 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))
 
@@ -32,7 +33,7 @@ extern bool xen_guest;
 extern bool pv_console;
 extern uint32_t xen_cpuid_base;
 
-void probe_hypervisor(void);
+const struct hypervisor_ops *xen_probe(void);
 int xg_alloc_unused_page(mfn_t *mfn);
 int xg_free_unused_page(mfn_t mfn);
 
@@ -44,7 +45,7 @@ DECLARE_PER_CPU(struct vcpu_info *, vcpu_info);
 #define xen_guest 0
 #define pv_console 0
 
-static inline void probe_hypervisor(void) {}
+static inline const struct hypervisor_ops *xen_probe(void) { return NULL; }
 
 #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] 27+ messages in thread

* [Xen-devel] [PATCH v4 7/8] x86: be more verbose when running on a hypervisor
  2019-11-21 18:50 [Xen-devel] [PATCH v4 0/8] Port Xen to Hyper-V Wei Liu
                   ` (5 preceding siblings ...)
  2019-11-21 18:50 ` [Xen-devel] [PATCH v4 6/8] x86: switch xen guest implementation to use hypervisor framework Wei Liu
@ 2019-11-21 18:50 ` Wei Liu
  2019-11-22 11:04   ` Durrant, Paul
                     ` (2 more replies)
  2019-11-21 18:50 ` [Xen-devel] [PATCH v4 8/8] x86: introduce CONFIG_HYPERV and detection code Wei Liu
  7 siblings, 3 replies; 27+ messages in thread
From: Wei Liu @ 2019-11-21 18:50 UTC (permalink / raw)
  To: Xen Development List
  Cc: Wei Liu, Wei Liu, Andrew Cooper, Michael Kelley, Jan Beulich,
	Roger Pau Monné

Also replace xen_guest with running_on_hypervisor boolean.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
---
Changes in v4:
1. Access ->name directly.
2. Drop Roger's review tag.
---
 xen/arch/x86/setup.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
index 19606d909b..123436b35a 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();
 
@@ -788,6 +789,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)
     printk("Command line: %s\n", cmdline);
 
     printk("Xen image load base address: %#lx\n", xen_phys_start);
+    if ( running_on_hypervisor )
+        printk("Running on %s\n", hypervisor_probe()->name);
 
 #ifdef CONFIG_VIDEO
     printk("Video information:\n");
@@ -1569,7 +1572,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
             max_cpus = nr_cpu_ids;
     }
 
-    if ( xen_guest )
+    if ( running_on_hypervisor )
         hypervisor_setup();
 
     /* Low mappings were only needed for some BIOS table parsing. */
-- 
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] 27+ messages in thread

* [Xen-devel] [PATCH v4 8/8] x86: introduce CONFIG_HYPERV and detection code
  2019-11-21 18:50 [Xen-devel] [PATCH v4 0/8] Port Xen to Hyper-V Wei Liu
                   ` (6 preceding siblings ...)
  2019-11-21 18:50 ` [Xen-devel] [PATCH v4 7/8] x86: be more verbose when running on a hypervisor Wei Liu
@ 2019-11-21 18:50 ` Wei Liu
  2019-11-22 11:11   ` Durrant, Paul
  7 siblings, 1 reply; 27+ messages in thread
From: Wei Liu @ 2019-11-21 18:50 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.

Take the chance to fix XEN_GUEST in Kconfig.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
---
Changes in V4:
1. Add comment regarding order of probe functions.
2. Adapt to changes in previous patches.
---
 xen/arch/x86/Kconfig               | 11 ++++--
 xen/arch/x86/guest/Makefile        |  1 +
 xen/arch/x86/guest/hyperv/Makefile |  1 +
 xen/arch/x86/guest/hyperv/hyperv.c | 54 ++++++++++++++++++++++++++++++
 xen/arch/x86/guest/hypervisor.c    |  8 +++++
 xen/include/asm-x86/guest.h        |  1 +
 xen/include/asm-x86/guest/hyperv.h | 43 ++++++++++++++++++++++++
 7 files changed, 117 insertions(+), 2 deletions(-)
 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..0a02b6ee3f 100644
--- a/xen/arch/x86/Kconfig
+++ b/xen/arch/x86/Kconfig
@@ -164,10 +164,17 @@ endchoice
 config GUEST
 	bool
 
+config HYPERV_GUEST
+	bool "Hyper-V Guest"
+	select GUEST
+	---help---
+	  Support for Xen detecting when it is running under Hyper-V.
+
+	  If unsure, say N.
+
 config XEN_GUEST
-	def_bool n
+	bool "Xen Guest"
 	select GUEST
-	prompt "Xen Guest"
 	---help---
 	  Support for Xen detecting when it is running under Xen.
 
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..916e08ff89
--- /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>
+
+static const struct hypervisor_ops hyperv_ops = {
+    .name = "Hyper-V",
+};
+
+const struct hypervisor_ops * __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 NULL;
+
+    cpuid(0x40000001, &eax, &ebx, &ecx, &edx);
+    if ( eax != 0x31237648 )    /* Hv#1 */
+        return NULL;
+
+    return &hyperv_ops;
+}
+
+/*
+ * 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 a067cacecb..c293e185cc 100644
--- a/xen/arch/x86/guest/hypervisor.c
+++ b/xen/arch/x86/guest/hypervisor.c
@@ -39,6 +39,14 @@ const struct hypervisor_ops *hypervisor_probe(void)
     if ( hops )
         goto out;
 
+    /*
+     * Detection of Hyper-V must come after Xen to avoid false positive due
+     * to viridian support
+     */
+    hops = hyperv_probe();
+    if ( hops )
+        goto out;
+
  out:
     return hops;
 }
diff --git a/xen/include/asm-x86/guest.h b/xen/include/asm-x86/guest.h
index 8e167165ae..94448606d4 100644
--- a/xen/include/asm-x86/guest.h
+++ b/xen/include/asm-x86/guest.h
@@ -20,6 +20,7 @@
 #define __X86_GUEST_H__
 
 #include <asm/guest/hypercall.h>
+#include <asm/guest/hyperv.h>
 #include <asm/guest/hypervisor.h>
 #include <asm/guest/pvh-boot.h>
 #include <asm/guest/xen.h>
diff --git a/xen/include/asm-x86/guest/hyperv.h b/xen/include/asm-x86/guest/hyperv.h
new file mode 100644
index 0000000000..3f88b94c77
--- /dev/null
+++ b/xen/include/asm-x86/guest/hyperv.h
@@ -0,0 +1,43 @@
+/******************************************************************************
+ * 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>
+
+const struct hypervisor_ops *hyperv_probe(void);
+
+#else
+
+static inline const struct hypervisor_ops *hyperv_probe(void) { return NULL; }
+
+#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] 27+ messages in thread

* Re: [Xen-devel] [PATCH v4 4/8] x86: introduce hypervisor framework
  2019-11-21 18:50 ` [Xen-devel] [PATCH v4 4/8] x86: introduce hypervisor framework Wei Liu
@ 2019-11-22 10:31   ` Durrant, Paul
  2019-11-29 13:38     ` Jan Beulich
  2019-11-29 13:43   ` Jan Beulich
  2019-11-29 18:08   ` Andrew Cooper
  2 siblings, 1 reply; 27+ messages in thread
From: Durrant, Paul @ 2019-11-22 10:31 UTC (permalink / raw)
  To: Wei Liu, Xen Development List
  Cc: Andrew Cooper, Roger Pau Monné,
	Wei Liu, Jan Beulich, Michael Kelley

> -----Original Message-----
> From: Xen-devel <xen-devel-bounces@lists.xenproject.org> On Behalf Of Wei
> Liu
> Sent: 21 November 2019 19:51
> To: Xen Development List <xen-devel@lists.xenproject.org>
> Cc: Wei Liu <liuwe@microsoft.com>; Wei Liu <wl@xen.org>; Andrew Cooper
> <andrew.cooper3@citrix.com>; Michael Kelley <mikelley@microsoft.com>; Jan
> Beulich <jbeulich@suse.com>; Roger Pau Monné <roger.pau@citrix.com>
> Subject: [Xen-devel] [PATCH v4 4/8] x86: introduce hypervisor framework
> 
> 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 <pdurrant@amazon.com>

> ---
> Changes in v4:
> 1. Add ASSERT_UNREACHABLE to stubs.
> 2. Move __read_mostly.
> 3. Return hops directly.
> 4. Drop Paul's review tag.
> ---
>  xen/arch/x86/guest/Makefile            |  2 +
>  xen/arch/x86/guest/hypervisor.c        | 42 +++++++++++++++++
>  xen/include/asm-x86/guest.h            |  1 +
>  xen/include/asm-x86/guest/hypervisor.h | 62 ++++++++++++++++++++++++++
>  xen/include/asm-x86/guest/xen.h        | 12 -----
>  5 files changed, 107 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..103feba5d8
> --- /dev/null
> +++ b/xen/arch/x86/guest/hypervisor.c
> @@ -0,0 +1,42 @@
> +/************************************************************************
> ******
> + * 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 const struct hypervisor_ops __read_mostly *hops;
> +
> +const struct hypervisor_ops *hypervisor_probe(void)
> +{
> +    return hops;
> +}
> +
> +/*
> + * 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..2ab15a7108
> --- /dev/null
> +++ b/xen/include/asm-x86/guest/hypervisor.h
> @@ -0,0 +1,62 @@
> +/************************************************************************
> ******
> + * 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__
> +
> +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);
> +};
> +
> +#ifdef CONFIG_GUEST
> +
> +const struct hypervisor_ops *hypervisor_probe(void);
> +void hypervisor_setup(void);
> +void hypervisor_ap_setup(void);
> +void hypervisor_resume(void);
> +
> +#else
> +
> +#include <xen/lib.h>
> +#include <xen/types.h>
> +
> +static inline const struct hypervisor_ops *hypervisor_probe(void) {
> return NULL; }
> +static inline void hypervisor_setup(void) { ASSERT_UNREACHABLE(); }
> +static inline void hypervisor_ap_setup(void) { ASSERT_UNREACHABLE(); }
> +static inline void hypervisor_resume(void) { ASSERT_UNREACHABLE(); }
> +
> +#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] 27+ messages in thread

* Re: [Xen-devel] [PATCH v4 5/8] x86: rename hypervisor_{alloc, free}_unused_page
  2019-11-21 18:50 ` [Xen-devel] [PATCH v4 5/8] x86: rename hypervisor_{alloc, free}_unused_page Wei Liu
@ 2019-11-22 10:57   ` Durrant, Paul
  2019-11-29 13:39     ` Jan Beulich
  0 siblings, 1 reply; 27+ messages in thread
From: Durrant, Paul @ 2019-11-22 10:57 UTC (permalink / raw)
  To: Wei Liu, Xen Development List
  Cc: Andrew Cooper, Roger Pau Monné,
	Wei Liu, Jan Beulich, Michael Kelley

> -----Original Message-----
> From: Xen-devel <xen-devel-bounces@lists.xenproject.org> On Behalf Of Wei
> Liu
> Sent: 21 November 2019 19:51
> To: Xen Development List <xen-devel@lists.xenproject.org>
> Cc: Wei Liu <liuwe@microsoft.com>; Wei Liu <wl@xen.org>; Andrew Cooper
> <andrew.cooper3@citrix.com>; Michael Kelley <mikelley@microsoft.com>; Jan
> Beulich <jbeulich@suse.com>; Roger Pau Monné <roger.pau@citrix.com>
> Subject: [Xen-devel] [PATCH v4 5/8] x86: rename hypervisor_{alloc,
> free}_unused_page
> 
> They are used in Xen code only.
> 
> No functional change.
> 
> Signed-off-by: Wei Liu <liuwe@microsoft.com>

Reviewed-by: Paul Durrant <pdurrant@amazon.com>

> ---
> Changes in v4:
> 1. Use xg_ prefix instead.
> 2. Drop Roger's review tag.
> ---
>  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 1e37086518..0f5b5267c5 100644
> --- a/xen/arch/x86/guest/xen/xen.c
> +++ b/xen/arch/x86/guest/xen/xen.c
> @@ -93,7 +93,7 @@ static void map_shared_info(void)
>      unsigned int i;
>      unsigned long rc;
> 
> -    if ( hypervisor_alloc_unused_page(&mfn) )
> +    if ( xg_alloc_unused_page(&mfn) )
>          panic("unable to reserve shared info memory page\n");
> 
>      xatp.gpfn = mfn_x(mfn);
> @@ -280,7 +280,7 @@ void hypervisor_ap_setup(void)
>      init_evtchn();
>  }
> 
> -int hypervisor_alloc_unused_page(mfn_t *mfn)
> +int xg_alloc_unused_page(mfn_t *mfn)
>  {
>      unsigned long m;
>      int rc;
> @@ -292,7 +292,7 @@ int hypervisor_alloc_unused_page(mfn_t *mfn)
>      return rc;
>  }
> 
> -int hypervisor_free_unused_page(mfn_t mfn)
> +int xg_free_unused_page(mfn_t mfn)
>  {
>      return rangeset_remove_range(mem, mfn_x(mfn), mfn_x(mfn));
>  }
> diff --git a/xen/arch/x86/pv/shim.c b/xen/arch/x86/pv/shim.c
> index 351da970ef..7a898fdbe5 100644
> --- a/xen/arch/x86/pv/shim.c
> +++ b/xen/arch/x86/pv/shim.c
> @@ -742,7 +742,7 @@ static long pv_shim_grant_table_op(unsigned int cmd,
>                  };
>                  mfn_t mfn;
> 
> -                rc = hypervisor_alloc_unused_page(&mfn);
> +                rc = xg_alloc_unused_page(&mfn);
>                  if ( rc )
>                  {
>                      gprintk(XENLOG_ERR,
> @@ -754,7 +754,7 @@ static long pv_shim_grant_table_op(unsigned int cmd,
>                  rc = xen_hypercall_memory_op(XENMEM_add_to_physmap,
> &xatp);
>                  if ( rc )
>                  {
> -                    hypervisor_free_unused_page(mfn);
> +                    xg_free_unused_page(mfn);
>                      break;
>                  }
> 
> diff --git a/xen/include/asm-x86/guest/xen.h b/xen/include/asm-
> x86/guest/xen.h
> index 3145f75361..01dc3ee6f6 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 xg_alloc_unused_page(mfn_t *mfn);
> +int xg_free_unused_page(mfn_t mfn);
> 
>  DECLARE_PER_CPU(unsigned int, vcpu_id);
>  DECLARE_PER_CPU(struct vcpu_info *, vcpu_info);
> --
> 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] 27+ messages in thread

* Re: [Xen-devel] [PATCH v4 6/8] x86: switch xen guest implementation to use hypervisor framework
  2019-11-21 18:50 ` [Xen-devel] [PATCH v4 6/8] x86: switch xen guest implementation to use hypervisor framework Wei Liu
@ 2019-11-22 11:02   ` Durrant, Paul
  2019-11-22 11:51     ` Wei Liu
  2019-11-29 13:50   ` Jan Beulich
  1 sibling, 1 reply; 27+ messages in thread
From: Durrant, Paul @ 2019-11-22 11:02 UTC (permalink / raw)
  To: Wei Liu, Xen Development List
  Cc: Andrew Cooper, Roger Pau Monné,
	Wei Liu, Jan Beulich, Michael Kelley

> -----Original Message-----
> From: Xen-devel <xen-devel-bounces@lists.xenproject.org> On Behalf Of Wei
> Liu
> Sent: 21 November 2019 19:51
> To: Xen Development List <xen-devel@lists.xenproject.org>
> Cc: Wei Liu <liuwe@microsoft.com>; Wei Liu <wl@xen.org>; Andrew Cooper
> <andrew.cooper3@citrix.com>; Michael Kelley <mikelley@microsoft.com>; Jan
> Beulich <jbeulich@suse.com>; Roger Pau Monné <roger.pau@citrix.com>
> Subject: [Xen-devel] [PATCH v4 6/8] x86: switch xen guest implementation
> to use hypervisor framework
> 
> Signed-off-by: Wei Liu <liuwe@microsoft.com>
[snip] 
> diff --git a/xen/include/asm-x86/guest/xen.h b/xen/include/asm-
> x86/guest/xen.h
> index 01dc3ee6f6..db90b550a7 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))
> 
> @@ -32,7 +33,7 @@ extern bool xen_guest;
>  extern bool pv_console;
>  extern uint32_t xen_cpuid_base;
> 
> -void probe_hypervisor(void);
> +const struct hypervisor_ops *xen_probe(void);
>  int xg_alloc_unused_page(mfn_t *mfn);
>  int xg_free_unused_page(mfn_t mfn);
> 
> @@ -44,7 +45,7 @@ DECLARE_PER_CPU(struct vcpu_info *, vcpu_info);
>  #define xen_guest 0
>  #define pv_console 0

Nit: These should be #defined to false rather than 0. The rest LGTM so with those fixed,

Reviewed-by: Paul Durrant <pdurrant@amazon.com>



> 
> -static inline void probe_hypervisor(void) {}
> +static inline const struct hypervisor_ops *xen_probe(void) { return NULL;
> }
> 
>  #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] 27+ messages in thread

* Re: [Xen-devel] [PATCH v4 7/8] x86: be more verbose when running on a hypervisor
  2019-11-21 18:50 ` [Xen-devel] [PATCH v4 7/8] x86: be more verbose when running on a hypervisor Wei Liu
@ 2019-11-22 11:04   ` Durrant, Paul
  2019-11-29 14:31   ` Jan Beulich
  2019-11-29 18:15   ` Andrew Cooper
  2 siblings, 0 replies; 27+ messages in thread
From: Durrant, Paul @ 2019-11-22 11:04 UTC (permalink / raw)
  To: Wei Liu, Xen Development List
  Cc: Andrew Cooper, Roger Pau Monné,
	Wei Liu, Jan Beulich, Michael Kelley

> -----Original Message-----
> From: Xen-devel <xen-devel-bounces@lists.xenproject.org> On Behalf Of Wei
> Liu
> Sent: 21 November 2019 19:51
> To: Xen Development List <xen-devel@lists.xenproject.org>
> Cc: Wei Liu <liuwe@microsoft.com>; Wei Liu <wl@xen.org>; Andrew Cooper
> <andrew.cooper3@citrix.com>; Michael Kelley <mikelley@microsoft.com>; Jan
> Beulich <jbeulich@suse.com>; Roger Pau Monné <roger.pau@citrix.com>
> Subject: [Xen-devel] [PATCH v4 7/8] x86: be more verbose when running on a
> hypervisor
> 
> Also replace xen_guest with running_on_hypervisor boolean.
> 
> Signed-off-by: Wei Liu <liuwe@microsoft.com>
> ---
> Changes in v4:
> 1. Access ->name directly.
> 2. Drop Roger's review tag.
> ---
>  xen/arch/x86/setup.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
> index 19606d909b..123436b35a 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;

Why not stash hops here? Then you can...

>      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();
> 
> @@ -788,6 +789,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)
>      printk("Command line: %s\n", cmdline);
> 
>      printk("Xen image load base address: %#lx\n", xen_phys_start);
> +    if ( running_on_hypervisor )
> +        printk("Running on %s\n", hypervisor_probe()->name);

...avoid calling hypervisor_probe() again here.

  Paul

> 
>  #ifdef CONFIG_VIDEO
>      printk("Video information:\n");
> @@ -1569,7 +1572,7 @@ void __init noreturn __start_xen(unsigned long
> mbi_p)
>              max_cpus = nr_cpu_ids;
>      }
> 
> -    if ( xen_guest )
> +    if ( running_on_hypervisor )
>          hypervisor_setup();
> 
>      /* Low mappings were only needed for some BIOS table parsing. */
> --
> 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] 27+ messages in thread

* Re: [Xen-devel] [PATCH v4 8/8] x86: introduce CONFIG_HYPERV and detection code
  2019-11-21 18:50 ` [Xen-devel] [PATCH v4 8/8] x86: introduce CONFIG_HYPERV and detection code Wei Liu
@ 2019-11-22 11:11   ` Durrant, Paul
  2019-11-29 14:35     ` Jan Beulich
  0 siblings, 1 reply; 27+ messages in thread
From: Durrant, Paul @ 2019-11-22 11:11 UTC (permalink / raw)
  To: Wei Liu, Xen Development List
  Cc: Andrew Cooper, Roger Pau Monné,
	Wei Liu, Jan Beulich, Michael Kelley

> -----Original Message-----
> From: Xen-devel <xen-devel-bounces@lists.xenproject.org> On Behalf Of Wei
> Liu
> Sent: 21 November 2019 19:51
> To: Xen Development List <xen-devel@lists.xenproject.org>
> Cc: Wei Liu <liuwe@microsoft.com>; Wei Liu <wl@xen.org>; Andrew Cooper
> <andrew.cooper3@citrix.com>; Michael Kelley <mikelley@microsoft.com>; Jan
> Beulich <jbeulich@suse.com>; Roger Pau Monné <roger.pau@citrix.com>
> Subject: [Xen-devel] [PATCH v4 8/8] x86: introduce CONFIG_HYPERV and
> detection code
> 
> 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.
> 
> Take the chance to fix XEN_GUEST in Kconfig.

Would this fix be better in your earlier renaming patch?

> 
> Signed-off-by: Wei Liu <liuwe@microsoft.com>

Either way...

Reviewed-by: Paul Durrant <pdurrant@amazon.com>

> ---
> Changes in V4:
> 1. Add comment regarding order of probe functions.
> 2. Adapt to changes in previous patches.
> ---
>  xen/arch/x86/Kconfig               | 11 ++++--
>  xen/arch/x86/guest/Makefile        |  1 +
>  xen/arch/x86/guest/hyperv/Makefile |  1 +
>  xen/arch/x86/guest/hyperv/hyperv.c | 54 ++++++++++++++++++++++++++++++
>  xen/arch/x86/guest/hypervisor.c    |  8 +++++
>  xen/include/asm-x86/guest.h        |  1 +
>  xen/include/asm-x86/guest/hyperv.h | 43 ++++++++++++++++++++++++
>  7 files changed, 117 insertions(+), 2 deletions(-)
>  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..0a02b6ee3f 100644
> --- a/xen/arch/x86/Kconfig
> +++ b/xen/arch/x86/Kconfig
> @@ -164,10 +164,17 @@ endchoice
>  config GUEST
>  	bool
> 
> +config HYPERV_GUEST
> +	bool "Hyper-V Guest"
> +	select GUEST
> +	---help---
> +	  Support for Xen detecting when it is running under Hyper-V.
> +
> +	  If unsure, say N.
> +
>  config XEN_GUEST
> -	def_bool n
> +	bool "Xen Guest"
>  	select GUEST
> -	prompt "Xen Guest"
>  	---help---
>  	  Support for Xen detecting when it is running under Xen.
> 
> 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..916e08ff89
> --- /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>
> +
> +static const struct hypervisor_ops hyperv_ops = {
> +    .name = "Hyper-V",
> +};
> +
> +const struct hypervisor_ops * __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 NULL;
> +
> +    cpuid(0x40000001, &eax, &ebx, &ecx, &edx);
> +    if ( eax != 0x31237648 )    /* Hv#1 */
> +        return NULL;
> +
> +    return &hyperv_ops;
> +}
> +
> +/*
> + * 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 a067cacecb..c293e185cc 100644
> --- a/xen/arch/x86/guest/hypervisor.c
> +++ b/xen/arch/x86/guest/hypervisor.c
> @@ -39,6 +39,14 @@ const struct hypervisor_ops *hypervisor_probe(void)
>      if ( hops )
>          goto out;
> 
> +    /*
> +     * Detection of Hyper-V must come after Xen to avoid false positive
> due
> +     * to viridian support
> +     */
> +    hops = hyperv_probe();
> +    if ( hops )
> +        goto out;
> +
>   out:
>      return hops;
>  }
> diff --git a/xen/include/asm-x86/guest.h b/xen/include/asm-x86/guest.h
> index 8e167165ae..94448606d4 100644
> --- a/xen/include/asm-x86/guest.h
> +++ b/xen/include/asm-x86/guest.h
> @@ -20,6 +20,7 @@
>  #define __X86_GUEST_H__
> 
>  #include <asm/guest/hypercall.h>
> +#include <asm/guest/hyperv.h>
>  #include <asm/guest/hypervisor.h>
>  #include <asm/guest/pvh-boot.h>
>  #include <asm/guest/xen.h>
> diff --git a/xen/include/asm-x86/guest/hyperv.h b/xen/include/asm-
> x86/guest/hyperv.h
> new file mode 100644
> index 0000000000..3f88b94c77
> --- /dev/null
> +++ b/xen/include/asm-x86/guest/hyperv.h
> @@ -0,0 +1,43 @@
> +/************************************************************************
> ******
> + * 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>
> +
> +const struct hypervisor_ops *hyperv_probe(void);
> +
> +#else
> +
> +static inline const struct hypervisor_ops *hyperv_probe(void) { return
> NULL; }
> +
> +#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] 27+ messages in thread

* Re: [Xen-devel] [PATCH v4 6/8] x86: switch xen guest implementation to use hypervisor framework
  2019-11-22 11:02   ` Durrant, Paul
@ 2019-11-22 11:51     ` Wei Liu
  0 siblings, 0 replies; 27+ messages in thread
From: Wei Liu @ 2019-11-22 11:51 UTC (permalink / raw)
  To: Durrant, Paul
  Cc: Wei Liu, Wei Liu, Andrew Cooper, Michael Kelley, Jan Beulich,
	Xen Development List, Roger Pau Monné

On Fri, Nov 22, 2019 at 11:02:30AM +0000, Durrant, Paul wrote:
> > -----Original Message-----
> > From: Xen-devel <xen-devel-bounces@lists.xenproject.org> On Behalf Of Wei
> > Liu
> > Sent: 21 November 2019 19:51
> > To: Xen Development List <xen-devel@lists.xenproject.org>
> > Cc: Wei Liu <liuwe@microsoft.com>; Wei Liu <wl@xen.org>; Andrew Cooper
> > <andrew.cooper3@citrix.com>; Michael Kelley <mikelley@microsoft.com>; Jan
> > Beulich <jbeulich@suse.com>; Roger Pau Monné <roger.pau@citrix.com>
> > Subject: [Xen-devel] [PATCH v4 6/8] x86: switch xen guest implementation
> > to use hypervisor framework
> > 
> > Signed-off-by: Wei Liu <liuwe@microsoft.com>
> [snip] 
> > diff --git a/xen/include/asm-x86/guest/xen.h b/xen/include/asm-
> > x86/guest/xen.h
> > index 01dc3ee6f6..db90b550a7 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))
> > 
> > @@ -32,7 +33,7 @@ extern bool xen_guest;
> >  extern bool pv_console;
> >  extern uint32_t xen_cpuid_base;
> > 
> > -void probe_hypervisor(void);
> > +const struct hypervisor_ops *xen_probe(void);
> >  int xg_alloc_unused_page(mfn_t *mfn);
> >  int xg_free_unused_page(mfn_t mfn);
> > 
> > @@ -44,7 +45,7 @@ DECLARE_PER_CPU(struct vcpu_info *, vcpu_info);
> >  #define xen_guest 0
> >  #define pv_console 0
> 
> Nit: These should be #defined to false rather than 0. The rest LGTM so with those fixed,

They were part of existing code so I didn't touch them.

Wei.

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

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

* Re: [Xen-devel] [PATCH v4 4/8] x86: introduce hypervisor framework
  2019-11-22 10:31   ` Durrant, Paul
@ 2019-11-29 13:38     ` Jan Beulich
  0 siblings, 0 replies; 27+ messages in thread
From: Jan Beulich @ 2019-11-29 13:38 UTC (permalink / raw)
  To: Wei Liu
  Cc: Wei Liu, Andrew Cooper, Durrant, Paul, Michael Kelley,
	Xen Development List, Roger Pau Monné

On 22.11.2019 11:31,  Durrant, Paul  wrote:
>> -----Original Message-----
>> From: Xen-devel <xen-devel-bounces@lists.xenproject.org> On Behalf Of Wei
>> Liu
>> Sent: 21 November 2019 19:51
>> To: Xen Development List <xen-devel@lists.xenproject.org>
>> Cc: Wei Liu <liuwe@microsoft.com>; Wei Liu <wl@xen.org>; Andrew Cooper
>> <andrew.cooper3@citrix.com>; Michael Kelley <mikelley@microsoft.com>; Jan
>> Beulich <jbeulich@suse.com>; Roger Pau Monné <roger.pau@citrix.com>
>> Subject: [Xen-devel] [PATCH v4 4/8] x86: introduce hypervisor framework
>>
>> 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 <pdurrant@amazon.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] 27+ messages in thread

* Re: [Xen-devel] [PATCH v4 5/8] x86: rename hypervisor_{alloc, free}_unused_page
  2019-11-22 10:57   ` Durrant, Paul
@ 2019-11-29 13:39     ` Jan Beulich
  0 siblings, 0 replies; 27+ messages in thread
From: Jan Beulich @ 2019-11-29 13:39 UTC (permalink / raw)
  To: Wei Liu
  Cc: Wei Liu, Andrew Cooper, Durrant, Paul, Michael Kelley,
	Xen Development List, Roger Pau Monné

On 22.11.2019 11:57,  Durrant, Paul  wrote:
>> -----Original Message-----
>> From: Xen-devel <xen-devel-bounces@lists.xenproject.org> On Behalf Of Wei
>> Liu
>> Sent: 21 November 2019 19:51
>> To: Xen Development List <xen-devel@lists.xenproject.org>
>> Cc: Wei Liu <liuwe@microsoft.com>; Wei Liu <wl@xen.org>; Andrew Cooper
>> <andrew.cooper3@citrix.com>; Michael Kelley <mikelley@microsoft.com>; Jan
>> Beulich <jbeulich@suse.com>; Roger Pau Monné <roger.pau@citrix.com>
>> Subject: [Xen-devel] [PATCH v4 5/8] x86: rename hypervisor_{alloc,
>> free}_unused_page
>>
>> They are used in Xen code only.
>>
>> No functional change.
>>
>> Signed-off-by: Wei Liu <liuwe@microsoft.com>
> 
> Reviewed-by: Paul Durrant <pdurrant@amazon.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] 27+ messages in thread

* Re: [Xen-devel] [PATCH v4 4/8] x86: introduce hypervisor framework
  2019-11-21 18:50 ` [Xen-devel] [PATCH v4 4/8] x86: introduce hypervisor framework Wei Liu
  2019-11-22 10:31   ` Durrant, Paul
@ 2019-11-29 13:43   ` Jan Beulich
  2019-11-29 18:08   ` Andrew Cooper
  2 siblings, 0 replies; 27+ messages in thread
From: Jan Beulich @ 2019-11-29 13:43 UTC (permalink / raw)
  To: Wei Liu
  Cc: Xen Development List, Roger Pau Monné,
	Wei Liu, Michael Kelley, Andrew Cooper

On 21.11.2019 19:50, Wei Liu wrote:
> --- /dev/null
> +++ b/xen/arch/x86/guest/hypervisor.c
> @@ -0,0 +1,42 @@
> +/******************************************************************************
> + * 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 const struct hypervisor_ops __read_mostly *hops;
> +
> +const struct hypervisor_ops *hypervisor_probe(void)

Despite my earlier ack - __init?

Jan

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

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

* Re: [Xen-devel] [PATCH v4 6/8] x86: switch xen guest implementation to use hypervisor framework
  2019-11-21 18:50 ` [Xen-devel] [PATCH v4 6/8] x86: switch xen guest implementation to use hypervisor framework Wei Liu
  2019-11-22 11:02   ` Durrant, Paul
@ 2019-11-29 13:50   ` Jan Beulich
  2019-11-30 11:49     ` Wei Liu
  1 sibling, 1 reply; 27+ messages in thread
From: Jan Beulich @ 2019-11-29 13:50 UTC (permalink / raw)
  To: Wei Liu
  Cc: Xen Development List, Roger Pau Monné,
	Wei Liu, Michael Kelley, Andrew Cooper

On 21.11.2019 19:50, Wei Liu wrote:
> +void __init 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();
> +}

I assume these don't get executed frequently enough for
alternatives indirect call patching to matter? Down the road, if
any more frequently executed hooks should appear, we will want
to switch to that model though. This has the added benefit of
there then being only one runtime instance of struct
hypervisor_ops; all per-hypervisor ones would become
__initconstrel.

> @@ -326,6 +310,31 @@ void hypervisor_resume(void)
>          pv_console_init();
>  }
>  
> +static const struct hypervisor_ops xg_ops = {

With this new xg_ prefix, ...

> +    .name = "Xen",
> +    .setup = xen_setup,
> +    .ap_setup = xen_ap_setup,
> +    .resume = xen_resume,

... I'd like to suggest to use it for these ones too (if they
need to have a prefix in the first place, which I doubt, but
which I know others view differently).

> +const struct hypervisor_ops * __init xen_probe(void)

For this one the call is a little more difficult, but for
consistency I think xg_ would be slightly better here as well.

Nit: Strictly speaking there's a stray blank after *. We
normally have ones only ahead of *, but not after.

Jan

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

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

* Re: [Xen-devel] [PATCH v4 7/8] x86: be more verbose when running on a hypervisor
  2019-11-21 18:50 ` [Xen-devel] [PATCH v4 7/8] x86: be more verbose when running on a hypervisor Wei Liu
  2019-11-22 11:04   ` Durrant, Paul
@ 2019-11-29 14:31   ` Jan Beulich
  2019-11-29 14:34     ` Jan Beulich
  2019-11-29 18:15   ` Andrew Cooper
  2 siblings, 1 reply; 27+ messages in thread
From: Jan Beulich @ 2019-11-29 14:31 UTC (permalink / raw)
  To: Wei Liu
  Cc: Xen Development List, Roger Pau Monné,
	Wei Liu, Michael Kelley, Andrew Cooper

On 21.11.2019 19:50, Wei Liu wrote:
> @@ -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();

No need for !! I think?

> @@ -788,6 +789,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)
>      printk("Command line: %s\n", cmdline);
>  
>      printk("Xen image load base address: %#lx\n", xen_phys_start);
> +    if ( running_on_hypervisor )
> +        printk("Running on %s\n", hypervisor_probe()->name);

Invoking hypervisor_probe() twice seems odd to me. I realize
the function copes, but why do everything a 2nd time when
not running on any hypervisor? Furthermore if this use is
the only reason why struct hypervisor_ops can't be local to
xen/arch/x86/guest/hypervisor.c, then I think once again
that the name should be return from hypervisor_probe(). The
initial if() in there then could also go away.

Jan

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

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

* Re: [Xen-devel] [PATCH v4 7/8] x86: be more verbose when running on a hypervisor
  2019-11-29 14:31   ` Jan Beulich
@ 2019-11-29 14:34     ` Jan Beulich
  0 siblings, 0 replies; 27+ messages in thread
From: Jan Beulich @ 2019-11-29 14:34 UTC (permalink / raw)
  To: Wei Liu
  Cc: Andrew Cooper, Michael Kelley, Wei Liu, Xen Development List,
	Roger Pau Monné

On 29.11.2019 15:31, Jan Beulich wrote:
> On 21.11.2019 19:50, Wei Liu wrote:
>> @@ -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();
> 
> No need for !! I think?
> 
>> @@ -788,6 +789,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)
>>      printk("Command line: %s\n", cmdline);
>>  
>>      printk("Xen image load base address: %#lx\n", xen_phys_start);
>> +    if ( running_on_hypervisor )
>> +        printk("Running on %s\n", hypervisor_probe()->name);
> 
> Invoking hypervisor_probe() twice seems odd to me. I realize
> the function copes, but why do everything a 2nd time when
> not running on any hypervisor? Furthermore if this use is
> the only reason why struct hypervisor_ops can't be local to
> xen/arch/x86/guest/hypervisor.c, then I think once again
> that the name should be return from hypervisor_probe().

"Local to xen/arch/x86/guest/hypervisor.c" was rubbish of
course; local to xen/arch/x86/guest/ would be more correct.

Jan

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

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

* Re: [Xen-devel] [PATCH v4 8/8] x86: introduce CONFIG_HYPERV and detection code
  2019-11-22 11:11   ` Durrant, Paul
@ 2019-11-29 14:35     ` Jan Beulich
  0 siblings, 0 replies; 27+ messages in thread
From: Jan Beulich @ 2019-11-29 14:35 UTC (permalink / raw)
  To: Wei Liu
  Cc: Wei Liu, Andrew Cooper, Durrant, Paul, Michael Kelley,
	Xen Development List, Roger Pau Monné

On 22.11.2019 12:11,  Durrant, Paul  wrote:
>> -----Original Message-----
>> From: Xen-devel <xen-devel-bounces@lists.xenproject.org> On Behalf Of Wei
>> Liu
>> Sent: 21 November 2019 19:51
>> To: Xen Development List <xen-devel@lists.xenproject.org>
>> Cc: Wei Liu <liuwe@microsoft.com>; Wei Liu <wl@xen.org>; Andrew Cooper
>> <andrew.cooper3@citrix.com>; Michael Kelley <mikelley@microsoft.com>; Jan
>> Beulich <jbeulich@suse.com>; Roger Pau Monné <roger.pau@citrix.com>
>> Subject: [Xen-devel] [PATCH v4 8/8] x86: introduce CONFIG_HYPERV and
>> detection code
>>
>> 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.
>>
>> Take the chance to fix XEN_GUEST in Kconfig.
> 
> Would this fix be better in your earlier renaming patch?
> 
>>
>> Signed-off-by: Wei Liu <liuwe@microsoft.com>
> 
> Either way...
> 
> Reviewed-by: Paul Durrant <pdurrant@amazon.com>

Acked-by: Jan Beulich <jbeulich@suse.com>
(either way, as Paul says)

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

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

* Re: [Xen-devel] [PATCH v4 4/8] x86: introduce hypervisor framework
  2019-11-21 18:50 ` [Xen-devel] [PATCH v4 4/8] x86: introduce hypervisor framework Wei Liu
  2019-11-22 10:31   ` Durrant, Paul
  2019-11-29 13:43   ` Jan Beulich
@ 2019-11-29 18:08   ` Andrew Cooper
  2019-11-30 11:48     ` Wei Liu
  2 siblings, 1 reply; 27+ messages in thread
From: Andrew Cooper @ 2019-11-29 18:08 UTC (permalink / raw)
  To: Wei Liu, Xen Development List
  Cc: Roger Pau Monné, Wei Liu, Jan Beulich, Michael Kelley

On 21/11/2019 18:50, Wei Liu wrote:
> +#include <xen/types.h>
> +
> +#include <asm/cache.h>
> +#include <asm/guest/hypervisor.h>
> +
> +static const struct hypervisor_ops __read_mostly *hops;

Could I talk you into using just plain 'ops' here.  This is mostly
plumbing and doesn't appear to grow significantly.  I don't think there
is a risk of gaining ambiguity.

~Andrew

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

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

* Re: [Xen-devel] [PATCH v4 7/8] x86: be more verbose when running on a hypervisor
  2019-11-21 18:50 ` [Xen-devel] [PATCH v4 7/8] x86: be more verbose when running on a hypervisor Wei Liu
  2019-11-22 11:04   ` Durrant, Paul
  2019-11-29 14:31   ` Jan Beulich
@ 2019-11-29 18:15   ` Andrew Cooper
  2019-11-30 11:49     ` Wei Liu
  2 siblings, 1 reply; 27+ messages in thread
From: Andrew Cooper @ 2019-11-29 18:15 UTC (permalink / raw)
  To: Wei Liu, Xen Development List
  Cc: Roger Pau Monné, Wei Liu, Jan Beulich, Michael Kelley

On 21/11/2019 18:50, Wei Liu wrote:
> Also replace xen_guest with running_on_hypervisor boolean.

I agree with dropping xen_guest, but...

>
> Signed-off-by: Wei Liu <liuwe@microsoft.com>
> ---
> Changes in v4:
> 1. Access ->name directly.
> 2. Drop Roger's review tag.
> ---
>  xen/arch/x86/setup.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
> index 19606d909b..123436b35a 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;

... this is semantically ambiguous with cpu_has_hypervisor.

Where they differ is whether Xen has managed to recognise the hypervisor
it is running under, or not.

Given that the hypervisor_*() hooks are nops by default, I'd suggest
just making blind calls.

~Andrew

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

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

* Re: [Xen-devel] [PATCH v4 4/8] x86: introduce hypervisor framework
  2019-11-29 18:08   ` Andrew Cooper
@ 2019-11-30 11:48     ` Wei Liu
  0 siblings, 0 replies; 27+ messages in thread
From: Wei Liu @ 2019-11-30 11:48 UTC (permalink / raw)
  To: Andrew Cooper
  Cc: Wei Liu, Wei Liu, Michael Kelley, Jan Beulich,
	Xen Development List, Roger Pau Monné

On Fri, Nov 29, 2019 at 06:08:16PM +0000, Andrew Cooper wrote:
> On 21/11/2019 18:50, Wei Liu wrote:
> > +#include <xen/types.h>
> > +
> > +#include <asm/cache.h>
> > +#include <asm/guest/hypervisor.h>
> > +
> > +static const struct hypervisor_ops __read_mostly *hops;
> 
> Could I talk you into using just plain 'ops' here.  This is mostly
> plumbing and doesn't appear to grow significantly.  I don't think there
> is a risk of gaining ambiguity.

This is done.

Wei.

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

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

* Re: [Xen-devel] [PATCH v4 6/8] x86: switch xen guest implementation to use hypervisor framework
  2019-11-29 13:50   ` Jan Beulich
@ 2019-11-30 11:49     ` Wei Liu
  0 siblings, 0 replies; 27+ messages in thread
From: Wei Liu @ 2019-11-30 11:49 UTC (permalink / raw)
  To: Jan Beulich
  Cc: Wei Liu, Wei Liu, Andrew Cooper, Michael Kelley,
	Xen Development List, Roger Pau Monné

On Fri, Nov 29, 2019 at 02:50:18PM +0100, Jan Beulich wrote:
> On 21.11.2019 19:50, Wei Liu wrote:
> > +void __init 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();
> > +}
> 
> I assume these don't get executed frequently enough for
> alternatives indirect call patching to matter? Down the road, if
> any more frequently executed hooks should appear, we will want
> to switch to that model though. This has the added benefit of
> there then being only one runtime instance of struct
> hypervisor_ops; all per-hypervisor ones would become
> __initconstrel.
> 

All the routines listed here are run very infrequently.

I agree that when more frequently executed hooks appear we will want to
look into alternatives.

> > @@ -326,6 +310,31 @@ void hypervisor_resume(void)
> >          pv_console_init();
> >  }
> >  
> > +static const struct hypervisor_ops xg_ops = {
> 
> With this new xg_ prefix, ...
> 
> > +    .name = "Xen",
> > +    .setup = xen_setup,
> > +    .ap_setup = xen_ap_setup,
> > +    .resume = xen_resume,
> 
> ... I'd like to suggest to use it for these ones too (if they
> need to have a prefix in the first place, which I doubt, but
> which I know others view differently).
> 

Since they are only visible to this file I think not having a prefix
should be fine. 

> > +const struct hypervisor_ops * __init xen_probe(void)
> 
> For this one the call is a little more difficult, but for
> consistency I think xg_ would be slightly better here as well.

No problem. Changed it to xg_probe.

> 
> Nit: Strictly speaking there's a stray blank after *. We
> normally have ones only ahead of *, but not after.

Fixed.

Wei.

> 
> Jan

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

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

* Re: [Xen-devel] [PATCH v4 7/8] x86: be more verbose when running on a hypervisor
  2019-11-29 18:15   ` Andrew Cooper
@ 2019-11-30 11:49     ` Wei Liu
  0 siblings, 0 replies; 27+ messages in thread
From: Wei Liu @ 2019-11-30 11:49 UTC (permalink / raw)
  To: Andrew Cooper
  Cc: Wei Liu, Wei Liu, Michael Kelley, Jan Beulich,
	Xen Development List, Roger Pau Monné

On Fri, Nov 29, 2019 at 06:15:52PM +0000, Andrew Cooper wrote:
> On 21/11/2019 18:50, Wei Liu wrote:
> > Also replace xen_guest with running_on_hypervisor boolean.
> 
> I agree with dropping xen_guest, but...
> 
> >
> > Signed-off-by: Wei Liu <liuwe@microsoft.com>
> > ---
> > Changes in v4:
> > 1. Access ->name directly.
> > 2. Drop Roger's review tag.
> > ---
> >  xen/arch/x86/setup.c | 7 +++++--
> >  1 file changed, 5 insertions(+), 2 deletions(-)
> >
> > diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
> > index 19606d909b..123436b35a 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;
> 
> ... this is semantically ambiguous with cpu_has_hypervisor.
> 
> Where they differ is whether Xen has managed to recognise the hypervisor
> it is running under, or not.
> 
> Given that the hypervisor_*() hooks are nops by default, I'd suggest
> just making blind calls.

Well Jan asked to drop the hypervisor_name hook. I can't make blind
calls here. He's unhappy with calling hypervisor_probe twice either.

I can, however, do the following:

 1. Change hypervisor_probe to return NULL or a string
 2. Cache and use that return value inside this function

This should make both of you happy.

Wei.

> 
> ~Andrew

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

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

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

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-21 18:50 [Xen-devel] [PATCH v4 0/8] Port Xen to Hyper-V Wei Liu
2019-11-21 18:50 ` [Xen-devel] [PATCH v4 1/8] x86: introduce CONFIG_GUEST and move code Wei Liu
2019-11-21 18:50 ` [Xen-devel] [PATCH v4 2/8] x86: add missing headers in hypercall.h Wei Liu
2019-11-21 18:50 ` [Xen-devel] [PATCH v4 3/8] x86: drop hypervisor_cpuid_base Wei Liu
2019-11-21 18:50 ` [Xen-devel] [PATCH v4 4/8] x86: introduce hypervisor framework Wei Liu
2019-11-22 10:31   ` Durrant, Paul
2019-11-29 13:38     ` Jan Beulich
2019-11-29 13:43   ` Jan Beulich
2019-11-29 18:08   ` Andrew Cooper
2019-11-30 11:48     ` Wei Liu
2019-11-21 18:50 ` [Xen-devel] [PATCH v4 5/8] x86: rename hypervisor_{alloc, free}_unused_page Wei Liu
2019-11-22 10:57   ` Durrant, Paul
2019-11-29 13:39     ` Jan Beulich
2019-11-21 18:50 ` [Xen-devel] [PATCH v4 6/8] x86: switch xen guest implementation to use hypervisor framework Wei Liu
2019-11-22 11:02   ` Durrant, Paul
2019-11-22 11:51     ` Wei Liu
2019-11-29 13:50   ` Jan Beulich
2019-11-30 11:49     ` Wei Liu
2019-11-21 18:50 ` [Xen-devel] [PATCH v4 7/8] x86: be more verbose when running on a hypervisor Wei Liu
2019-11-22 11:04   ` Durrant, Paul
2019-11-29 14:31   ` Jan Beulich
2019-11-29 14:34     ` Jan Beulich
2019-11-29 18:15   ` Andrew Cooper
2019-11-30 11:49     ` Wei Liu
2019-11-21 18:50 ` [Xen-devel] [PATCH v4 8/8] x86: introduce CONFIG_HYPERV and detection code Wei Liu
2019-11-22 11:11   ` Durrant, Paul
2019-11-29 14:35     ` Jan Beulich

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.