Port Xen to Hyper-V
v4 cover Port Xen to Hyper-V
Please see individual patches for changes.
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.hSignature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v4 1/8 x86: introduce CONFIG_GUEST and move code
Xen is able to run as a guest on Xen. We plan to make it able to run on Hyper-V as well.
Introduce CONFIG_GUEST which is set to true if either running on Xen or Hyper-V is desired. Restructure code hierarchy for new code to come.
No functional change intended.
---
xen/arch/x86/Kconfig | 4 ++++
xen/arch/x86/Makefile | 2 +-
xen/arch/x86/guest/Makefile | 5 +----
xen/arch/x86/guest/xen/Makefile | 4 ++++
xen/arch/x86/guest/{ => xen}/hypercall_page.S | 0
xen/arch/x86/guest/{ => xen}/pvh-boot.c | 0
xen/arch/x86/guest/{ => xen}/xen.c | 0
7 files changed, 10 insertions(+), 5 deletions(-)
create mode 100644 xen/arch/x86/guest/xen/Makefile
rename xen/arch/x86/guest/{ => xen}/hypercall_page.S (100%)
rename xen/arch/x86/guest/{ => xen}/pvh-boot.c (100%)
rename xen/arch/x86/guest/{ => xen}/xen.c (100%)xen/arch/x86/Kconfig +4 -0
@@ -161,8 +161,12 @@ config XEN_ALIGN_2M endchoice +config GUEST + bool + config XEN_GUEST def_bool n + select GUEST prompt "Xen Guest" ---help--- Support for Xen detecting when it is running under Xen.
xen/arch/x86/Makefile +1 -1
@@ -1,7 +1,7 @@ subdir-y += acpi subdir-y += cpu subdir-y += genapic -subdir-$(CONFIG_XEN_GUEST) += guest +subdir-$(CONFIG_GUEST) += guest subdir-$(CONFIG_HVM) += hvm subdir-y += mm subdir-$(CONFIG_XENOPROF) += oprofile
xen/arch/x86/guest/Makefile +1 -4
@@ -1,4 +1 @@ -obj-y += hypercall_page.o -obj-y += xen.o - -obj-bin-$(CONFIG_PVH_GUEST) += pvh-boot.init.o +subdir-$(CONFIG_XEN_GUEST) += xen
xen/arch/x86/guest/xen/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +obj-y += hypercall_page.o +obj-y += xen.o + +obj-bin-$(CONFIG_PVH_GUEST) += pvh-boot.init.o
xen/arch/x86/guest/xen/hypercall_page.S renamed from xen/arch/x86/guest/hypercall_page.S +0 -0
xen/arch/x86/guest/xen/pvh-boot.c renamed from xen/arch/x86/guest/pvh-boot.c +0 -0
xen/arch/x86/guest/xen/xen.c renamed from xen/arch/x86/guest/xen.c +0 -0
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v4 2/8 x86: add missing headers in hypercall.h
In reply to Wei LiuInclude asm_defns.h because ASM_CALL_CONSTRAINT is defined there.
Include xen/lib.h because we need ASSERT_UNREACHABLE.
No functional change.
--- xen/include/asm-x86/guest/hypercall.h | 4 ++++ 1 file changed, 4 insertions(+)
xen/include/asm-x86/guest/hypercall.h +4 -0
@@ -23,6 +23,8 @@#include <xen/types.h> +#include <asm/asm_defns.h> +#include <public/xen.h> #include <public/sched.h> #include <public/hvm/hvm_op.h>
@@ -180,6 +182,8 @@ static inline long xen_hypercall_set_evtchn_upcall_vector(#else /* CONFIG_XEN_GUEST */ +#include <xen/lib.h> +#include <public/sched.h> static inline void xen_hypercall_console_write(
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v4 3/8 x86: drop hypervisor_cpuid_base
In reply to Wei LiuThe only user is Xen specific code in PV shim. We can therefore export the variable directly.
Move __read_mostly to its standard place while at it.
--- xen/arch/x86/guest/xen/xen.c | 7 +------ xen/arch/x86/pv/shim.c | 2 +- xen/include/asm-x86/guest/xen.h | 2 +- 3 files changed, 3 insertions(+), 8 deletions(-)
xen/arch/x86/guest/xen/xen.c +1 -6
@@ -37,7 +37,7 @@bool __read_mostly xen_guest; -static __read_mostly uint32_t xen_cpuid_base; +uint32_t __read_mostly xen_cpuid_base;extern char hypercall_page[];static struct rangeset *mem;
@@ -297,11 +297,6 @@ int hypervisor_free_unused_page(mfn_t mfn)return rangeset_remove_range (mem,mfn_x (mfn),mfn_x (mfn)); } -uint32_t hypervisor_cpuid_base (void ) -{ -return xen_cpuid_base; -} -static void ap_resume (void *unused) {map_vcpuinfo ();
xen/arch/x86/pv/shim.c +1 -1
@@ -995,7 +995,7 @@ domid_t get_initial_domain_id(void)if ( !pv_shim )return 0 ; -cpuid (hypervisor_cpuid_base () +4 , &eax, &ebx, &ecx, &edx); +cpuid (xen_cpuid_base +4 , &eax, &ebx, &ecx, &edx);return (eax &XEN_HVM_CPUID_DOMID_PRESENT ) ? ecx :1 ; }
xen/include/asm-x86/guest/xen.h +1 -1
@@ -30,13 +30,13 @@extern bool xen_guest;extern bool pv_console; +extern uint32_t xen_cpuid_base;void probe_hypervisor (void );void hypervisor_setup (void );void hypervisor_ap_setup (void );int hypervisor_alloc_unused_page (mfn_t *mfn);int hypervisor_free_unused_page (mfn_t mfn); -uint32_t hypervisor_cpuid_base (void );void hypervisor_resume (void ); DECLARE_PER_CPU(unsigned int, vcpu_id);
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v4 4/8 x86: introduce hypervisor framework
In reply to Wei LiuWe will soon implement Hyper-V support for Xen. Add a framework for that.
This requires moving some of the hypervisor_* functions from xen.h to hypervisor.h.
---
Changes in 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
xen/arch/x86/guest/Makefile +2 -0
@@ -1 +1,3 @@ +obj-y += hypervisor.o + subdir-$(CONFIG_XEN_GUEST) += xen
xen/arch/x86/guest/hypervisor.c new file +42 -0
42 lines not on this page · raw message
xen/include/asm-x86/guest.h +1 -0
@@ -20,6 +20,7 @@#define __X86_GUEST_H__#include <asm/guest/hypercall.h> +#include <asm/guest/hypervisor.h> #include <asm/guest/pvh-boot.h> #include <asm/guest/xen.h> #include <asm/pv/shim.h>
xen/include/asm-x86/guest/hypervisor.h new file +62 -0
62 lines not on this page · raw message
xen/include/asm-x86/guest/xen.h +0 -12
@@ -33,11 +33,8 @@ extern bool pv_console;extern uint32_t xen_cpuid_base;void probe_hypervisor (void ); -void hypervisor_setup (void ); -void hypervisor_ap_setup (void );int hypervisor_alloc_unused_page (mfn_t *mfn);int hypervisor_free_unused_page (mfn_t mfn); -void hypervisor_resume (void ); DECLARE_PER_CPU(unsigned int, vcpu_id); DECLARE_PER_CPU(struct vcpu_info *, vcpu_info);
@@ -49,15 +46,6 @@ DECLARE_PER_CPU(struct vcpu_info *, vcpu_info);static inline void probe_hypervisor (void ) {} -static inline void hypervisor_setup (void ) -{ -ASSERT_UNREACHABLE (); -} -static inline void hypervisor_ap_setup (void ) -{ -ASSERT_UNREACHABLE (); -} -#endif /* CONFIG_XEN_GUEST */ #endif /* __X86_GUEST_XEN_H__ */
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v4 4/8] x86: introduce hypervisor framework
Quoted 10 lines
-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Wei Liu
Sent: 21 November 2019 19:51
To: Xen Development List <[email protected]>
Cc: Wei Liu <[email protected]>; Wei Liu <[email protected]>; Andrew Cooper <[email protected]>; Michael Kelley <[email protected]>; Jan Beulich <[email protected]>; Roger Pau Monné <[email protected]>
Subject: [Xen-devel] [PATCH v4 4/8] x86: introduce hypervisor framework
Quoted 7 lines
We will soon implement Hyper-V support for Xen. Add a framework for that.
This requires moving some of the hypervisor_* functions from
xen.htohypervisor.h.Signed-off-by Wei Liu <[email protected]>
Quoted 195 lines
---
Changes in v4:
1. AddASSERT_UNREACHABLEto 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.hxen/arch/x86/guest/Makefile +2
-0@@ -1 +1,3 @@ +obj-y += hypervisor.o + subdir-$(CONFIG_XEN_GUEST) += xenxen/arch/x86/guest/hypervisor.c new file +1
-0@@ -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.
+ */xen/arch/x86/guest/hypervisor.c new file +22
-0+ +#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: +*/ xen/include/asm-x86/guest.h +1
-0@@ -20,6 +20,7 @@#define __X86_GUEST_H__#include <asm/guest/hypercall.h> +#include <asm/guest/hypervisor.h> #include <asm/guest/pvh-boot.h> #include <asm/guest/xen.h> #include <asm/pv/shim.h> xen/include/asm- renamed from xen/include/asm-x86/guest/hypervisor.h +0
-0
x86/guest/hypervisor.h
new file mode 100644
index 0000000000..2ab15a7108xen/include/asm-x86/guest/hypervisor.h new file +1
-0@@ -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.
+ */xen/include/asm-x86/guest/hypervisor.h new file +28
-0+ +#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; }
xen/include/asm-x86/guest/hypervisor.h new file +17
-0+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: +*/ xen/include/asm- renamed from xen/include/asm-x86/guest/xen.h +0
-0
x86/guest/xen.h
indexb015ed1883..3145f75361100644xen/include/asm-x86/guest/xen.h +0
-13@@ -33,11 +33,8 @@ extern bool pv_console;extern uint32_t xen_cpuid_base;void probe_hypervisor (void ); -void hypervisor_setup (void ); -void hypervisor_ap_setup (void );int hypervisor_alloc_unused_page (mfn_t *mfn);int hypervisor_free_unused_page (mfn_t mfn); -void hypervisor_resume (void ); DECLARE_PER_CPU(unsigned int, vcpu_id); DECLARE_PER_CPU(struct vcpu_info *, vcpu_info);@@ -49,15 +46,6 @@ DECLARE_PER_CPU(struct vcpu_info *, vcpu_info);static inline void probe_hypervisor (void ) {} -static inline void hypervisor_setup (void ) -{ -ASSERT_UNREACHABLE (); -} -static inline void hypervisor_ap_setup (void ) -{ -ASSERT_UNREACHABLE (); -} -#endif /* CONFIG_XEN_GUEST */ #endif /* __X86_GUEST_XEN_H__ */ --2.20.1
Quoted 4 lines
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Jan Beulich
Acked-byRe: [Xen-devel] [PATCH v4 4/8] x86: introduce hypervisor framework
Quoted 13 lines · Paul
Quoted 13 lines
-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Wei Liu
Sent: 21 November 2019 19:51
To: Xen Development List <[email protected]>
Cc: Wei Liu <[email protected]>; Wei Liu <[email protected]>; Andrew Cooper <[email protected]>; Michael Kelley <[email protected]>; Jan Beulich <[email protected]>; Roger Pau Monné <[email protected]>
Subject: [Xen-devel] [PATCH v4 4/8] x86: introduce hypervisor frameworkWe will soon implement Hyper-V support for Xen. Add a framework for that.
Quoted 6 lines
Quoted 4 lines
This requires moving some of the hypervisor_* functions from
xen.htohypervisor.h.Signed-off-by Wei Liu <[email protected]>Reviewed-by Paul Durrant <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v4 4/8] x86: introduce hypervisor framework
In reply to Wei LiuQuoted 22 lines · Wei Liu
xen/arch/x86/guest/hypervisor.c new file +19
-0@@ -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.
xen/arch/x86/guest/hypervisor.c line 29
Quoted 10 lines
xen/arch/x86/guest/hypervisor.c new file +10
-0+*/ + +#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
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v4 4/8] x86: introduce hypervisor framework
In reply to Wei Liuxen/arch/x86/guest/hypervisor.c line 27
Quoted 6 lines · Wei Liu
xen/arch/x86/guest/hypervisor.c new file +6
-0+#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
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v4 4/8] x86: introduce hypervisor framework
Quoted 11 lines · Andrew Cooper
xen/arch/x86/guest/hypervisor.c line 27
Quoted 6 lines · Wei Liu
xen/arch/x86/guest/hypervisor.c new file +6
-0+#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
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v4 5/8 x86: rename hypervisor_{alloc, free}_unused_page
In reply to Wei LiuThey are used in Xen code only.
No functional change.
---
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(-)
xen/arch/x86/guest/xen/xen.c +3 -3
@@ -93,7 +93,7 @@ static void map_shared_info(void)unsigned int i;unsigned long rc; -if (hypervisor_alloc_unused_page (&mfn) ) +if (xg_alloc_unused_page (&mfn) )panic ("unable to reserve shared info memory page\n" ); xatp.gpfn =mfn_x (mfn);
@@ -280,7 +280,7 @@ void hypervisor_ap_setup(void)init_evtchn (); } -int hypervisor_alloc_unused_page (mfn_t *mfn) +int xg_alloc_unused_page (mfn_t *mfn) {unsigned long m;int rc;
@@ -292,7 +292,7 @@ int hypervisor_alloc_unused_page(mfn_t *mfn)return rc; } -int hypervisor_free_unused_page (mfn_t mfn) +int xg_free_unused_page (mfn_t mfn) {return rangeset_remove_range (mem,mfn_x (mfn),mfn_x (mfn)); }
xen/arch/x86/pv/shim.c +2 -2
@@ -742,7 +742,7 @@ static long pv_shim_grant_table_op(unsigned int cmd, };mfn_t mfn; - rc =hypervisor_alloc_unused_page (&mfn); + rc =xg_alloc_unused_page (&mfn);if ( rc ) { gprintk(XENLOG_ERR,
@@ -754,7 +754,7 @@ static long pv_shim_grant_table_op(unsigned int cmd, rc =xen_hypercall_memory_op (XENMEM_add_to_physmap, &xatp);if ( rc ) { -hypervisor_free_unused_page (mfn); +xg_free_unused_page (mfn);break ; }
xen/include/asm-x86/guest/xen.h +2 -2
@@ -33,8 +33,8 @@ extern bool pv_console;extern uint32_t xen_cpuid_base;void probe_hypervisor (void ); -int hypervisor_alloc_unused_page (mfn_t *mfn); -int hypervisor_free_unused_page (mfn_t mfn); +int xg_alloc_unused_page (mfn_t *mfn); +int xg_free_unused_page (mfn_t mfn); DECLARE_PER_CPU(unsigned int, vcpu_id); DECLARE_PER_CPU(struct vcpu_info *, vcpu_info);
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v4 5/8] x86: rename hypervisor_{alloc, free}_unused_page
Quoted 11 lines
-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Wei Liu
Sent: 21 November 2019 19:51
To: Xen Development List <[email protected]>
Cc: Wei Liu <[email protected]>; Wei Liu <[email protected]>; Andrew Cooper <[email protected]>; Michael Kelley <[email protected]>; Jan Beulich <[email protected]>; Roger Pau Monné <[email protected]>
Subject: [Xen-devel] [PATCH v4 5/8] x86: rename hypervisor_{alloc, free}_unused_page
Quoted 5 lines
They are used in Xen code only.
No functional change.
Signed-off-by Wei Liu <[email protected]>
Quoted 84 lines
---
Changes in v4:
1. Usexg_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(-)xen/arch/x86/guest/xen/xen.c +3
-3@@ -93,7 +93,7 @@ static void map_shared_info(void)unsigned int i;unsigned long rc; -if (hypervisor_alloc_unused_page (&mfn) ) +if (xg_alloc_unused_page (&mfn) )panic ("unable to reserve shared info memory page\n" ); xatp.gpfn =mfn_x (mfn);@@ -280,7 +280,7 @@ void hypervisor_ap_setup(void)init_evtchn (); } -int hypervisor_alloc_unused_page (mfn_t *mfn) +int xg_alloc_unused_page (mfn_t *mfn) {unsigned long m;int rc;@@ -292,7 +292,7 @@ int hypervisor_alloc_unused_page(mfn_t *mfn)return rc; } -int hypervisor_free_unused_page (mfn_t mfn) +int xg_free_unused_page (mfn_t mfn) {return rangeset_remove_range (mem,mfn_x (mfn),mfn_x (mfn)); }xen/arch/x86/pv/shim.c +2
-2@@ -742,7 +742,7 @@ static long pv_shim_grant_table_op(unsigned int cmd, };mfn_t mfn; - rc =hypervisor_alloc_unused_page (&mfn); + rc =xg_alloc_unused_page (&mfn);if ( rc ) { gprintk(XENLOG_ERR,@@ -754,7 +754,7 @@ static long pv_shim_grant_table_op(unsigned int cmd, rc =xen_hypercall_memory_op (XENMEM_add_to_physmap, &xatp);if ( rc ) { -hypervisor_free_unused_page (mfn); +xg_free_unused_page (mfn);break ; }xen/include/asm- renamed from xen/include/asm-x86/guest/xen.h +0
-0
x86/guest/xen.h
index3145f75361..01dc3ee6f6100644xen/include/asm-x86/guest/xen.h +2
-3@@ -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
Quoted 4 lines
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Jan Beulich
Acked-byRe: [Xen-devel] [PATCH v4 5/8] x86: rename hypervisor_{alloc, free}_unused_page
Quoted 11 lines · Paul
Quoted 11 lines
-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Wei Liu
Sent: 21 November 2019 19:51
To: Xen Development List <[email protected]>
Cc: Wei Liu <[email protected]>; Wei Liu <[email protected]>; Andrew Cooper <[email protected]>; Michael Kelley <[email protected]>; Jan Beulich <[email protected]>; Roger Pau Monné <[email protected]>
Subject: [Xen-devel] [PATCH v4 5/8] x86: rename hypervisor_{alloc, free}_unused_page
Quoted 7 lines
Quoted 5 lines
They are used in Xen code only.
No functional change.
Signed-off-by Wei Liu <[email protected]>Reviewed-by Paul Durrant <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v4 6/8 x86: switch xen guest implementation to use hypervisor framework
In reply to Wei Liu---
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(-)
xen/arch/x86/guest/hypervisor.c +31 -1
@@ -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
xen/arch/x86/guest/xen/pvh-boot.c +1 -1
@@ -103,7 +103,7 @@ void __init pvh_init(multiboot_info_t **mbi, module_t **mod) {convert_pvh_info (mbi, mod); -probe_hypervisor (); +hypervisor_probe ();ASSERT (xen_guest);get_memory_map ();
xen/arch/x86/guest/xen/xen.c +28 -19
77 lines not on this page · raw message
xen/arch/x86/setup.c +1 -1
@@ -763,7 +763,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)* allocing any xenheap structures wanted in lower memory. */ kexec_early_calculations (); -probe_hypervisor (); +hypervisor_probe ();parse_video_info ();
xen/include/asm-x86/guest/xen.h +3 -2
@@ -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__ */
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v4 6/8] x86: switch xen guest implementation to use hypervisor framework
Quoted 12 lines
-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Wei Liu
Sent: 21 November 2019 19:51
To: Xen Development List <[email protected]>
Cc: Wei Liu <[email protected]>; Wei Liu <[email protected]>; Andrew Cooper <[email protected]>; Michael Kelley <[email protected]>; Jan Beulich <[email protected]>; Roger Pau Monné <[email protected]>
Subject: [Xen-devel] [PATCH v4 6/8] x86: switch xen guest implementation to use hypervisor frameworkSigned-off-by Wei Liu <[email protected]>
[snip]
Quoted 24 lines
xen/include/asm- renamed from xen/include/asm-x86/guest/xen.h +0
-0
x86/guest/xen.h
index01dc3ee6f6..db90b550a7100644xen/include/asm-x86/guest/xen.h +2
-1@@ -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);
xen/include/asm-x86/guest/xen.h DECLARE_PER_CPU(struct vcpu_info *, vcpu_info); · line 46
Quoted 2 lines
xen/include/asm-x86/guest/xen.h +0
-0@@ -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,
Quoted 11 lines
xen/include/asm-x86/guest/xen.h +1
-2-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
Quoted 4 lines
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v4 6/8] x86: switch xen guest implementation to use hypervisor framework
Quoted 36 lines · Paul
Quoted 12 lines
-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Wei Liu
Sent: 21 November 2019 19:51
To: Xen Development List <[email protected]>
Cc: Wei Liu <[email protected]>; Wei Liu <[email protected]>; Andrew Cooper <[email protected]>; Michael Kelley <[email protected]>; Jan Beulich <[email protected]>; Roger Pau Monné <[email protected]>
Subject: [Xen-devel] [PATCH v4 6/8] x86: switch xen guest implementation to use hypervisor frameworkSigned-off-by Wei Liu <[email protected]>[snip]
Quoted 23 lines
xen/include/asm- renamed from xen/include/asm-x86/guest/xen.h +0
-0
x86/guest/xen.h
index01dc3ee6f6..db90b550a7100644xen/include/asm-x86/guest/xen.h +2
-1@@ -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);
Quoted 5 lines
xen/include/asm-x86/guest/xen.h DECLARE_PER_CPU(struct vcpu_info *, vcpu_info); · line 46
Quoted 3 lines
xen/include/asm-x86/guest/xen.h +0
-0@@ -44,7 +45,7 @@ DECLARE_PER_CPU(struct vcpu_info *, vcpu_info);#define xen_guest 0#define pv_console 0Nit: 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
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v4 6/8] x86: switch xen guest implementation to use hypervisor framework
In reply to Wei LiuQuoted 7 lines · Wei Liu
xen/arch/x86/guest/hypervisor.c +7
-0+void __init hypervisor_setup (void ) +{ +if ( hops && hops->setup ) + hops->setup (); +} + +void hypervisor_ap_setup (void )
xen/arch/x86/guest/hypervisor.c line 62
Quoted 10 lines
xen/arch/x86/guest/hypervisor.c +10
-0+{ +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.
xen/arch/x86/guest/xen/xen.c void hypervisor_resume(void) · line 313
Quoted 5 lines
xen/arch/x86/guest/xen/xen.c +1
-0@@ -326,6 +310,31 @@ void hypervisor_resume(void)pv_console_init (); } +static const struct hypervisor_ops xg_ops = {
With this new xg_ prefix, ...
xen/arch/x86/guest/xen/xen.c void hypervisor_resume(void) · line 317
Quoted 4 lines
xen/arch/x86/guest/xen/xen.c +4
-0+ .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).
xen/arch/x86/guest/xen/xen.c void hypervisor_resume(void) · line 320
Quoted 1 line
xen/arch/x86/guest/xen/xen.c +1
-0+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
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v4 6/8] x86: switch xen guest implementation to use hypervisor framework
Quoted 19 lines · Jan Beulich
Quoted 7 lines · Wei Liu
xen/arch/x86/guest/hypervisor.c +7
-0+void __init hypervisor_setup (void ) +{ +if ( hops && hops->setup ) + hops->setup (); +} + +void hypervisor_ap_setup (void )xen/arch/x86/guest/hypervisor.c line 62
Quoted 10 lines
xen/arch/x86/guest/hypervisor.c +10
-0+{ +if ( hops && hops->ap_setup ) + hops->ap_setup (); +} + +void hypervisor_resume (void ) +{ +if ( hops && hops->resume ) + hops->resume (); +}
Quoted 8 lines
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.
Quoted 8 lines
xen/arch/x86/guest/xen/xen.c void hypervisor_resume(void) · line 313
Quoted 5 lines
xen/arch/x86/guest/xen/xen.c +1
-0@@ -326,6 +310,31 @@ void hypervisor_resume(void)pv_console_init (); } +static const struct hypervisor_ops xg_ops = {With this new
xg_prefix, ...
Quoted 9 lines
xen/arch/x86/guest/xen/xen.c void hypervisor_resume(void) · line 317
Quoted 4 lines
xen/arch/x86/guest/xen/xen.c +4
-0+ .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.
Quoted 4 lines
xen/arch/x86/guest/xen/xen.c void hypervisor_resume(void) · line 320
Quoted 1 line
xen/arch/x86/guest/xen/xen.c +1
-0+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.
Quoted 3 lines
Nit: Strictly speaking there's a stray blank after *. We normally have ones only ahead of *, but not after.
Fixed.
Wei.
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v4 7/8 x86: be more verbose when running on a hypervisor
In reply to Wei LiuAlso replace xen_guest with running_on_hypervisor boolean.
---
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(-)
xen/arch/x86/setup.c +5 -2
@@ -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. */
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v4 7/8] x86: be more verbose when running on a hypervisor
Quoted 27 lines
-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Wei Liu
Sent: 21 November 2019 19:51
To: Xen Development List <[email protected]>
Cc: Wei Liu <[email protected]>; Wei Liu <[email protected]>; Andrew Cooper <[email protected]>; Michael Kelley <[email protected]>; Jan Beulich <[email protected]>; Roger Pau Monné <[email protected]>
Subject: [Xen-devel] [PATCH v4 7/8] x86: be more verbose when running on a hypervisorAlso replace
xen_guestwithrunning_on_hypervisorboolean.Signed-off-by Wei Liu <[email protected]>---
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(-)xen/arch/x86/setup.c +0
-0
xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p) · line 692
Quoted 4 lines
xen/arch/x86/setup.c +1
-0@@ -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...
Quoted 13 lines
xen/arch/x86/setup.c +1
-1struct ns16550_defaults ns16550 = { .data_bits =8 , .parity ='n' ,@@ -763,7 +764,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)* allocing any xenheap structures wanted in lower memory. */ kexec_early_calculations (); -hypervisor_probe (); + running_on_hypervisor = !!hypervisor_probe ();parse_video_info ();
xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p) · line 793
Quoted 5 lines
xen/arch/x86/setup.c +2
-0@@ -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
Quoted 13 lines
xen/arch/x86/setup.c +1
-1#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. */
Quoted 8 lines
--
2.20.1_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v4 7/8] x86: be more verbose when running on a hypervisor
In reply to Wei Liuxen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p) · line 767
Quoted 6 lines · Wei Liu
xen/arch/x86/setup.c +1
-1@@ -763,7 +764,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)* allocing any xenheap structures wanted in lower memory. */ kexec_early_calculations (); -hypervisor_probe (); + running_on_hypervisor = !!hypervisor_probe ();
No need for !! I think?
xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p) · line 793
Quoted 6 lines
xen/arch/x86/setup.c +2
-0@@ -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
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v4 7/8] x86: be more verbose when running on a hypervisor
Quoted 13 lines · Jan Beulich
xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p) · line 767
Quoted 6 lines · Wei Liu
xen/arch/x86/setup.c +1
-1@@ -763,7 +764,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)* allocing any xenheap structures wanted in lower memory. */ kexec_early_calculations (); -hypervisor_probe (); + running_on_hypervisor = !!hypervisor_probe ();No need for !! I think?
Quoted 3 lines
xen/arch/x86/setup.c +0
-0@@ -788,6 +789,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)printk ("Command line: %s\n" , cmdline);
Quoted 10 lines
xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p) · line 793
Quoted 3 lines
xen/arch/x86/setup.c +2
-0printk ("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 structhypervisor_opscan't be local toxen/arch/x86/guest/hypervisor.c, then I think once again that the name should be return fromhypervisor_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
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v4 7/8] x86: be more verbose when running on a hypervisor
In reply to Wei LiuQuoted 1 line · Wei Liu
Also replace
xen_guestwithrunning_on_hypervisorboolean.
I agree with dropping xen_guest, but...
Quoted 15 lines
Signed-off-by Wei Liu <[email protected]>---
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(-)xen/arch/x86/setup.c +0
-0
xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p) · line 692
Quoted 4 lines
xen/arch/x86/setup.c +1
-0@@ -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
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v4 7/8] x86: be more verbose when running on a hypervisor
Quoted 27 lines · Andrew Cooper
Quoted 1 line · Wei Liu
Also replace
xen_guestwithrunning_on_hypervisorboolean.I agree with dropping
xen_guest, but...Quoted 15 lines
Signed-off-by Wei Liu <[email protected]>---
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(-)xen/arch/x86/setup.c +0
-0xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p) · line 692
Quoted 4 lines
xen/arch/x86/setup.c +1
-0@@ -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.
Quoted 5 lines
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.
Quoted 2 lines
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v4 8/8 x86: introduce CONFIG_HYPERV and detection code
In reply to Wei LiuWe 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.
---
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
xen/arch/x86/Kconfig +9 -2
@@ -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.
xen/arch/x86/guest/Makefile +1 -0
@@ -1,3 +1,4 @@ obj-y += hypervisor.o +subdir-$(CONFIG_HYPERV_GUEST) += hyperv subdir-$(CONFIG_XEN_GUEST) += xen
xen/arch/x86/guest/hyperv/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-y += hyperv.o
xen/arch/x86/guest/hyperv/hyperv.c new file +54 -0
54 lines not on this page · raw message
xen/arch/x86/guest/hypervisor.c +8 -0
@@ -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; }
xen/include/asm-x86/guest.h +1 -0
@@ -20,6 +20,7 @@#define __X86_GUEST_H__#include <asm/guest/hypercall.h> +#include <asm/guest/hyperv.h> #include <asm/guest/hypervisor.h> #include <asm/guest/pvh-boot.h> #include <asm/guest/xen.h>
xen/include/asm-x86/guest/hyperv.h new file +43 -0
43 lines not on this page · raw message
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v4 8/8] x86: introduce CONFIG_HYPERV and detection code
Quoted 11 lines
-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Wei Liu
Sent: 21 November 2019 19:51
To: Xen Development List <[email protected]>
Cc: Wei Liu <[email protected]>; Wei Liu <[email protected]>; Andrew Cooper <[email protected]>; Michael Kelley <[email protected]>; Jan Beulich <[email protected]>; Roger Pau Monné <[email protected]>
Subject: [Xen-devel] [PATCH v4 8/8] x86: introduceCONFIG_HYPERVand detection code
Quoted 6 lines
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_GUESTinKconfig.
Would this fix be better in your earlier renaming patch?
Quoted 2 lines
Signed-off-by Wei Liu <[email protected]>
Either way...
Quoted 210 lines
---
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.hxen/arch/x86/Kconfig +9
-2@@ -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.xen/arch/x86/guest/Makefile +1
-0@@ -1,3 +1,4 @@ obj-y += hypervisor.o +subdir-$(CONFIG_HYPERV_GUEST) += hyperv subdir-$(CONFIG_XEN_GUEST) += xenxen/arch/x86/guest/hyperv/Makefile new file +1
-0@@ -0,0 +1 @@ +obj-y += hyperv.oxen/arch/x86/guest/hyperv/hyperv.c new file +1
-0@@ -0,0 +1,54 @@ +/************************************************************************ ******
+ *arch/x86/guest/hyperv/hyperv.c
+ *
+ * Support for detecting and running under Hyper-V.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (c) 2019 Microsoft.
+ */xen/arch/x86/guest/hyperv/hyperv.c new file +34
-0+#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: +*/ xen/arch/x86/guest/hypervisor.c +2
-0@@ -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
xen/arch/x86/guest/hypervisor.c +6
-0+* to viridian support +*/ + hops =hyperv_probe (); +if ( hops ) + goto out; + out:return hops; }xen/include/asm-x86/guest.h +1
-0@@ -20,6 +20,7 @@#define __X86_GUEST_H__#include <asm/guest/hypercall.h> +#include <asm/guest/hyperv.h> #include <asm/guest/hypervisor.h> #include <asm/guest/pvh-boot.h> #include <asm/guest/xen.h> xen/include/asm- renamed from xen/include/asm-x86/guest/hyperv.h +0
-0
x86/guest/hyperv.h
new file mode 100644
index 0000000000..3f88b94c77xen/include/asm-x86/guest/hyperv.h new file +1
-0@@ -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.
+ */xen/include/asm-x86/guest/hyperv.h new file +13
-0+ +#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) { returnNULL; }
xen/include/asm-x86/guest/hyperv.h new file +13
-1+ +#endif /* CONFIG_HYPERV_GUEST */ +#endif /* __X86_GUEST_HYPERV_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/ --2.20.1
Quoted 4 lines
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Jan Beulich
Acked-byRe: [Xen-devel] [PATCH v4 8/8] x86: introduce CONFIG_HYPERV and detection code
Quoted 18 lines · Paul
Quoted 11 lines
-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Wei Liu
Sent: 21 November 2019 19:51
To: Xen Development List <[email protected]>
Cc: Wei Liu <[email protected]>; Wei Liu <[email protected]>; Andrew Cooper <[email protected]>; Michael Kelley <[email protected]>; Jan Beulich <[email protected]>; Roger Pau Monné <[email protected]>
Subject: [Xen-devel] [PATCH v4 8/8] x86: introduceCONFIG_HYPERVand detection codeQuoted 6 lines
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_GUESTinKconfig.
Quoted 8 lines
Would this fix be better in your earlier renaming patch?
Quoted 2 lines
Signed-off-by Wei Liu <[email protected]>Either way...
Reviewed-by Paul Durrant <[email protected]>
(either way, as Paul says)
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel