Port Xen to Hyper-V
v3 cover Port Xen to Hyper-V
Hi all
This is version 3 of the patch series.
This is the very first stage for porting Xen to run on Hyper-V with all the goodies Hyper-V has to offer. With this series, Xen can successfully detect Hyper-V and prints out a message. I would like to first get the code structure and kconfig options agreed upon.
There are two major areas to be worked on:
* Make Dom0 able to use Hyper-V's synthetic devices.
* Make Xen use of the synthetic timer, reference TSC and enlightenment VMCS and other interfaces.
They aren't trivial, and time can be scarce on my side, so I intend to post patches piecemeal when they are ready.
Questions and comments are welcome.
Thanks,
Wei.
---
Changes in v3: See invididual patches
Changes in v2:
1. Introduce and use a hypervisor framework
2. Keep memmap infra under Xen for now
Wei Liu (9):
x86: introduce CONFIG_GUEST and move code
x86: include asm_defns.h directly in hypercall.h
x86: drop hypervisor_cpuid_base
x86: include xen/lib.h in guest/hypercall.h
x86: introduce hypervisor framework
x86: rename hypervisor_{alloc,free}_unused_page
x86: switch xen implementation to use hypervisor framework
x86: be more verbose when running on a hypervisor
x86: introduce CONFIG_HYPERV and detection code
xen/arch/x86/Kconfig | 13 +++
xen/arch/x86/Makefile | 2 +-
xen/arch/x86/guest/Makefile | 6 +-
xen/arch/x86/guest/hyperv/Makefile | 1 +
xen/arch/x86/guest/hyperv/hyperv.c | 54 +++++++++++
xen/arch/x86/guest/hypervisor.c | 89 +++++++++++++++++++
xen/arch/x86/guest/xen/Makefile | 4 +
xen/arch/x86/guest/{ => xen}/hypercall_page.S | 0
xen/arch/x86/guest/{ => xen}/pvh-boot.c | 2 +-
xen/arch/x86/guest/{ => xen}/xen.c | 39 ++++----
xen/arch/x86/pv/shim.c | 6 +-
xen/arch/x86/setup.c | 6 +-
xen/include/asm-x86/guest.h | 2 +
xen/include/asm-x86/guest/hypercall.h | 4 +
xen/include/asm-x86/guest/hyperv.h | 45 ++++++++++
xen/include/asm-x86/guest/hypervisor.h | 64 +++++++++++++
xen/include/asm-x86/guest/xen.h | 24 ++---
17 files changed, 314 insertions(+), 47 deletions(-)
create mode 100644 xen/arch/x86/guest/hyperv/Makefile
create mode 100644 xen/arch/x86/guest/hyperv/hyperv.c
create mode 100644 xen/arch/x86/guest/hypervisor.c
create mode 100644 xen/arch/x86/guest/xen/Makefile
rename xen/arch/x86/guest/{ => xen}/hypercall_page.S (100%)
rename xen/arch/x86/guest/{ => xen}/pvh-boot.c (99%)
rename xen/arch/x86/guest/{ => xen}/xen.c (93%)
create mode 100644 xen/include/asm-x86/guest/hyperv.h
create mode 100644 xen/include/asm-x86/guest/hypervisor.hSignature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 1/9 x86: introduce CONFIG_GUEST and move code
Xen is able to run as a guest on Xen. We plan to make it able to run on Hyper-V as well.
Introduce CONFIG_GUEST which is set to true if either running on Xen or Hyper-V is desired. Restructure code hierarchy for new code to come.
No functional change intended.
---
xen/arch/x86/Kconfig | 4 ++++
xen/arch/x86/Makefile | 2 +-
xen/arch/x86/guest/Makefile | 5 +----
xen/arch/x86/guest/xen/Makefile | 4 ++++
xen/arch/x86/guest/{ => xen}/hypercall_page.S | 0
xen/arch/x86/guest/{ => xen}/pvh-boot.c | 0
xen/arch/x86/guest/{ => xen}/xen.c | 0
7 files changed, 10 insertions(+), 5 deletions(-)
create mode 100644 xen/arch/x86/guest/xen/Makefile
rename xen/arch/x86/guest/{ => xen}/hypercall_page.S (100%)
rename xen/arch/x86/guest/{ => xen}/pvh-boot.c (100%)
rename xen/arch/x86/guest/{ => xen}/xen.c (100%)xen/arch/x86/Kconfig +4 -0
@@ -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
Re: [Xen-devel] [PATCH for-next v3 1/9] x86: introduce CONFIG_GUEST and move code
Quoted 33 lines · Wei Liu
Xen is able to run as a guest on Xen. We plan to make it able to run on Hyper-V as well.
Introduce
CONFIG_GUESTwhich 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 <[email protected]>Reviewed-by Roger Pau Monné <[email protected]>--- xen/arch/x86/Kconfig | 4 ++++ xen/arch/x86/Makefile | 2 +- xen/arch/x86/guest/Makefile | 5 +---- xen/arch/x86/guest/xen/Makefile | 4 ++++ xen/arch/x86/guest/{ => xen}/hypercall_page.S | 0 xen/arch/x86/guest/{ => xen}/pvh-boot.c | 0 xen/arch/x86/guest/{ => xen}/xen.c | 0 7 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 xen/arch/x86/guest/xen/Makefile rename xen/arch/x86/guest/{ => xen}/hypercall_page.S (100%) rename xen/arch/x86/guest/{ => xen}/pvh-boot.c (100%) rename xen/arch/x86/guest/{ => xen}/xen.c (100%)xen/arch/x86/Kconfig +0
-0@@ -161,8 +161,12 @@ config XEN_ALIGN_2M endchoice
xen/arch/x86/Kconfig config XEN_ALIGN_2M · line 172
Quoted 10 lines
xen/arch/x86/Kconfig +4
-0+config GUEST + bool + config XEN_GUEST def_bool n + select GUEST prompt "Xen Guest" ---help--- Support for Xen detecting when it is running under Xen.
This text needs to be modified. Perhaps just say 'when it is running in a virtual machine'. That should be future-proof.
Paul
Quoted 49 lines
xen/arch/x86/Makefile +1
-1@@ -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) += oprofilexen/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) += xenxen/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.oxen/arch/x86/guest/xen/hypercall_page.S renamed from xen/arch/x86/guest/hypercall_page.S +0
-0xen/arch/x86/guest/xen/pvh-boot.c renamed from xen/arch/x86/guest/pvh-boot.c +0
-0xen/arch/x86/guest/xen/xen.c renamed from xen/arch/x86/guest/xen.c +0
-1--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 for-next v3 1/9] x86: introduce CONFIG_GUEST and move code
Quoted 35 lines · Paul Durrant
Quoted 34 lines · Wei Liu
Xen is able to run as a guest on Xen. We plan to make it able to run on Hyper-V as well.
Introduce
CONFIG_GUESTwhich 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 <[email protected]>Reviewed-by Roger Pau Monné <[email protected]>--- xen/arch/x86/Kconfig | 4 ++++ xen/arch/x86/Makefile | 2 +- xen/arch/x86/guest/Makefile | 5 +---- xen/arch/x86/guest/xen/Makefile | 4 ++++ xen/arch/x86/guest/{ => xen}/hypercall_page.S | 0 xen/arch/x86/guest/{ => xen}/pvh-boot.c | 0 xen/arch/x86/guest/{ => xen}/xen.c | 0 7 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 xen/arch/x86/guest/xen/Makefile rename xen/arch/x86/guest/{ => xen}/hypercall_page.S (100%) rename xen/arch/x86/guest/{ => xen}/pvh-boot.c (100%) rename xen/arch/x86/guest/{ => xen}/xen.c (100%)xen/arch/x86/Kconfig +0
-0@@ -161,8 +161,12 @@ config XEN_ALIGN_2M endchoice
Quoted 13 lines
xen/arch/x86/Kconfig config XEN_ALIGN_2M · line 172
Quoted 9 lines
xen/arch/x86/Kconfig +4
-0+config GUEST + bool + config XEN_GUEST def_bool n + select GUEST prompt "Xen Guest" ---help--- Support for Xen detecting when it is running under Xen.This text needs to be modified. Perhaps just say 'when it is running in a virtual machine'. That should be future-proof.
I don't think it should be modified -- XEN_GUEST here really means specifically running under Xen but not others.
We will later introduced HYPERV_GUEST.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH for-next v3 1/9] x86: introduce CONFIG_GUEST and move code
In reply to Wei LiuQuoted 11 lines · Wei Liu
Xen is able to run as a guest on Xen. We plan to make it able to run on Hyper-V as well.
Introduce
CONFIG_GUESTwhich 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 <[email protected]>Reviewed-by Roger Pau Monné <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 2/9 x86: include asm_defns.h directly in hypercall.h
In reply to Wei LiuASM_CALL_CONSTRAINT is defined there.
No functional change.
--- xen/include/asm-x86/guest/hypercall.h | 2 ++ 1 file changed, 2 insertions(+)
xen/include/asm-x86/guest/hypercall.h +2 -0
@@ -23,6 +23,8 @@#include <xen/types.h> +#include <asm/asm_defns.h> +#include <public/xen.h> #include <public/sched.h> #include <public/hvm/hvm_op.h>
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH for-next v3 2/9] x86: include asm_defns.h directly in hypercall.h
Quoted 6 lines · Wei Liu
ASM_CALL_CONSTRAINTis defined there.No functional change.
Signed-off-by Wei Liu <[email protected]>Reviewed-by Roger Pau Monné <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 3/9 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.
--- 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; +__read_mostly uint32_t xen_cpuid_base;extern char hypercall_page[];static struct rangeset *mem;
@@ -301,11 +301,6 @@ int hypervisor_free_unused_page(mfn_t mfn)return rangeset_remove_range (mem,mfn_x (mfn),mfn_x (mfn)); } -uint32_t hypervisor_cpuid_base (void ) -{ -return xen_cpuid_base; -} -static void ap_resume (void *unused) {map_vcpuinfo ();
xen/arch/x86/pv/shim.c +1 -1
@@ -990,7 +990,7 @@ domid_t get_initial_domain_id(void)if ( !pv_shim )return 0 ; -cpuid (hypervisor_cpuid_base () +4 , &eax, &ebx, &ecx, &edx); +cpuid (xen_cpuid_base +4 , &eax, &ebx, &ecx, &edx);return (eax &XEN_HVM_CPUID_DOMID_PRESENT ) ? ecx :1 ; }
xen/include/asm-x86/guest/xen.h +1 -1
@@ -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
Re: [Xen-devel] [PATCH for-next v3 3/9] x86: drop hypervisor_cpuid_base
Quoted 5 lines · Wei Liu
The only user is Xen specific code in PV shim. We can therefore export the variable directly.
Signed-off-by Wei Liu <[email protected]>Reviewed-by Roger Pau Monné <[email protected]>
with, at this occasion, ...
xen/arch/x86/guest/xen/xen.c line 40
Quoted 8 lines
xen/arch/x86/guest/xen/xen.c +1
-1@@ -37,7 +37,7 @@bool __read_mostly xen_guest; -static __read_mostly uint32_t xen_cpuid_base; +__read_mostly uint32_t xen_cpuid_base;
... the __read_mostly moved to its more standard place (an example is in context).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 4/9 x86: include xen/lib.h in guest/hypercall.h
In reply to Wei LiuWe need ASSERT_UNREACHABLE.
--- xen/include/asm-x86/guest/hypercall.h | 2 ++ 1 file changed, 2 insertions(+)
xen/include/asm-x86/guest/hypercall.h +2 -0
@@ -182,6 +182,8 @@ static inline long xen_hypercall_set_evtchn_upcall_vector(#else /* CONFIG_XEN_GUEST */ +#include <xen/lib.h> +#include <public/sched.h> static inline void xen_hypercall_console_write(
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH for-next v3 4/9] x86: include xen/lib.h in guest/hypercall.h
Quoted 4 lines · Wei Liu
We need
ASSERT_UNREACHABLE.Signed-off-by Wei Liu <[email protected]>Reviewed-by Roger Pau Monné <[email protected]>
Albeit perhaps fold into patch 2?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 5/9 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.
--- xen/arch/x86/guest/Makefile | 2 + xen/arch/x86/guest/hypervisor.c | 45 +++++++++++++++++++ xen/include/asm-x86/guest.h | 1 + xen/include/asm-x86/guest/hypervisor.h | 61 ++++++++++++++++++++++++++ xen/include/asm-x86/guest/xen.h | 12 ----- 5 files changed, 109 insertions(+), 12 deletions(-) create mode 100644 xen/arch/x86/guest/hypervisor.c create mode 100644 xen/include/asm-x86/guest/hypervisor.h
xen/arch/x86/guest/Makefile +2 -0
@@ -1 +1,3 @@ +obj-y += hypervisor.o + subdir-$(CONFIG_XEN_GUEST) += xen
xen/arch/x86/guest/hypervisor.c new file +45 -0
45 lines not on this page · raw message
xen/include/asm-x86/guest.h +1 -0
@@ -20,6 +20,7 @@#define __X86_GUEST_H__#include <asm/guest/hypercall.h> +#include <asm/guest/hypervisor.h> #include <asm/guest/pvh-boot.h> #include <asm/guest/xen.h> #include <asm/pv/shim.h>
xen/include/asm-x86/guest/hypervisor.h new file +61 -0
61 lines not on this page · raw message
xen/include/asm-x86/guest/xen.h +0 -12
@@ -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 for-next v3 5/9] x86: introduce hypervisor framework
Quoted 8 lines · Wei Liu
We will soon implement Hyper-V support for Xen. Add a framework for that.
This requires moving some of the hypervisor_* functions from
xen.htohypervisor.h.Signed-off-by Wei Liu <[email protected]>
Quoted 184 lines
--- xen/arch/x86/guest/Makefile | 2 + xen/arch/x86/guest/hypervisor.c | 45 +++++++++++++++++++ xen/include/asm-x86/guest.h | 1 + xen/include/asm-x86/guest/hypervisor.h | 61 ++++++++++++++++++++++++++ xen/include/asm-x86/guest/xen.h | 12 ----- 5 files changed, 109 insertions(+), 12 deletions(-) create mode 100644 xen/arch/x86/guest/hypervisor.c create mode 100644 xen/include/asm-x86/guest/hypervisor.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 +45
-0@@ -0,0 +1,45 @@ +/****************************************************************************** +* arch/x86/guest/hypervisor.c +* +* Support for detecting and running under a hypervisor. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; If not, see <http://www.gnu.org/licenses/>. +* +* Copyright (c) 2019 Microsoft. +*/ + +#include <xen/types.h> + +#include <asm/cache.h> +#include <asm/guest/hypervisor.h> + +static struct hypervisor_ops *hops__read_mostly ; + +bool hypervisor_probe (void ) +{ +if ( hops ) +return true; + +return false; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/ xen/include/asm-x86/guest.h +1
-0@@ -20,6 +20,7 @@#define __X86_GUEST_H__#include <asm/guest/hypercall.h> +#include <asm/guest/hypervisor.h> #include <asm/guest/pvh-boot.h> #include <asm/guest/xen.h> #include <asm/pv/shim.h> xen/include/asm-x86/guest/hypervisor.h new file +61
-0@@ -0,0 +1,61 @@ +/****************************************************************************** +* asm-x86/guest/hypervisor.h +* +* This program is free software; you can redistribute it and/or +* modify it under the terms and conditions of the GNU General Public +* License, version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public +* License along with this program; If not, see <http://www.gnu.org/licenses/>. +* +* Copyright (c) 2019 Microsoft. +*/ + +#ifndef __X86_HYPERVISOR_H__ +#define __X86_HYPERVISOR_H__ + +#ifdef CONFIG_GUEST + +struct hypervisor_ops { +/* Name of the hypervisor */ +const char *name; +/* Main setup routine */ +void (*setup)(void ); +/* AP setup */ +void (*ap_setup)(void ); +/* Resume from suspension */ +void (*resume)(void ); +}; + +bool hypervisor_probe (void ); +void hypervisor_setup (void ); +void hypervisor_ap_setup (void ); +void hypervisor_resume (void ); + +#else + +#include <xen/types.h> + +static inline bool hypervisor_probe (void ) {return false; } +static inline void hypervisor_setup (void ) {} +static inline void hypervisor_ap_setup (void ) {} +static inline void hypervisor_resume (void ) {} + +#endif /* CONFIG_GUEST */ + +#endif /* __X86_HYPERVISOR_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/ xen/include/asm-x86/guest/xen.h +0
-13@@ -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
Re: [Xen-devel] [PATCH for-next v3 5/9] x86: introduce hypervisor framework
In reply to Wei LiuQuoted 20 lines · Wei Liu
xen/arch/x86/guest/hypervisor.c new file +17
-0@@ -0,0 +1,45 @@ +/****************************************************************************** +* arch/x86/guest/hypervisor.c +* +* Support for detecting and running under a hypervisor. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; If not, see <http://www.gnu.org/licenses/>.
xen/arch/x86/guest/hypervisor.c line 27
Quoted 10 lines
xen/arch/x86/guest/hypervisor.c new file +10
-0+* +* Copyright (c) 2019 Microsoft. +*/ + +#include <xen/types.h> + +#include <asm/cache.h> +#include <asm/guest/hypervisor.h> + +static struct hypervisor_ops *hops__read_mostly ;
The __read_mostly wants to again go between type and identifier.
xen/arch/x86/guest/hypervisor.c line 34
Quoted 6 lines
xen/arch/x86/guest/hypervisor.c new file +6
-0+bool hypervisor_probe (void ) +{ +if ( hops ) +return true; + +return false;
I assume this isn't simply "return hops" because more is going to be added here?
Quoted 25 lines
xen/include/asm-x86/guest/hypervisor.h new file +22
-0@@ -0,0 +1,61 @@ +/****************************************************************************** +* asm-x86/guest/hypervisor.h +* +* This program is free software; you can redistribute it and/or +* modify it under the terms and conditions of the GNU General Public +* License, version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public +* License along with this program; If not, see <http://www.gnu.org/licenses/>. +* +* Copyright (c) 2019 Microsoft. +*/ + +#ifndef __X86_HYPERVISOR_H__ +#define __X86_HYPERVISOR_H__ + +#ifdef CONFIG_GUEST
xen/include/asm-x86/guest/hypervisor.h line 32
Quoted 10 lines
xen/include/asm-x86/guest/hypervisor.h new file +10
-0+ +struct hypervisor_ops { +/* Name of the hypervisor */ +const char *name; +/* Main setup routine */ +void (*setup)(void ); +/* AP setup */ +void (*ap_setup)(void ); +/* Resume from suspension */ +void (*resume)(void );
None of these fields look to be used, despite ...
xen/include/asm-x86/guest/hypervisor.h line 38
Quoted 6 lines
xen/include/asm-x86/guest/hypervisor.h new file +6
-0+}; + +bool hypervisor_probe (void ); +void hypervisor_setup (void ); +void hypervisor_ap_setup (void ); +void hypervisor_resume (void );
... the latter three of these being the apparent wrappers for them. Perhaps just a side effect of how exactly this series was split up, so not strictly a request to change anything.
xen/include/asm-x86/guest/hypervisor.h DECLARE_PER_CPU(struct vcpu_info *, vcpu_info); · line 59
Quoted 12 lines
xen/include/asm-x86/guest/hypervisor.h new file +0
-8@@ -49,15 +46,6 @@ DECLARE_PER_CPU(struct vcpu_info *, vcpu_info);static inline void probe_hypervisor (void ) {} -static inline void hypervisor_setup (void ) -{ -ASSERT_UNREACHABLE (); -} -static inline void hypervisor_ap_setup (void ) -{ -ASSERT_UNREACHABLE (); -}
Why did the ASSERT_UNREACHABLE() get lost?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH for-next v3 5/9] x86: introduce hypervisor framework
Quoted 25 lines · Jan Beulich
Quoted 24 lines · Wei Liu
xen/arch/x86/guest/hypervisor.c new file +21
-0@@ -0,0 +1,45 @@ +/****************************************************************************** +* arch/x86/guest/hypervisor.c +* +* Support for detecting and running under a hypervisor. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; If not, see <http://www.gnu.org/licenses/>. +* +* Copyright (c) 2019 Microsoft. +*/ +
Quoted 8 lines
xen/arch/x86/guest/hypervisor.c line 27
Quoted 6 lines
xen/arch/x86/guest/hypervisor.c new file +6
-0+#include <xen/types.h> + +#include <asm/cache.h> +#include <asm/guest/hypervisor.h> + +static struct hypervisor_ops *hops__read_mostly ;The
__read_mostlywants to again go between type and identifier.
Ack.
Quoted 11 lines
xen/arch/x86/guest/hypervisor.c line 34
Quoted 7 lines
xen/arch/x86/guest/hypervisor.c new file +6
-0+bool hypervisor_probe (void ) +{ +if ( hops ) +return true; + +return false;I assume this isn't simply "return hops" because more is going to be added here?
That's right.
[...]
Quoted 4 lines
Quoted 4 lines
xen/arch/x86/guest/hypervisor.c new file +0
-0@@ -49,15 +46,6 @@ DECLARE_PER_CPU(struct vcpu_info *, vcpu_info);static inline void probe_hypervisor (void ) {}
Quoted 10 lines
xen/arch/x86/guest/hypervisor.c DECLARE_PER_CPU(struct vcpu_info *, vcpu_info); · line 59
Quoted 8 lines
xen/arch/x86/guest/hypervisor.c new file +0
-8-static inline void hypervisor_setup (void ) -{ -ASSERT_UNREACHABLE (); -} -static inline void hypervisor_ap_setup (void ) -{ -ASSERT_UNREACHABLE (); -}Why did the
ASSERT_UNREACHABLE()get lost?
I will add it back to all those stubs.
Wei.
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 6/9 x86: rename hypervisor_{alloc, free}_unused_page
In reply to Wei LiuThey are used in Xen code only.
No functional change.
--- xen/arch/x86/guest/xen/xen.c | 6 +++--- xen/arch/x86/pv/shim.c | 4 ++-- xen/include/asm-x86/guest/xen.h | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-)
xen/arch/x86/guest/xen/xen.c +3 -3
@@ -97,7 +97,7 @@ static void map_shared_info(void)unsigned int i;unsigned long rc; -if (hypervisor_alloc_unused_page (&mfn) ) +if (xen_alloc_unused_page (&mfn) )panic ("unable to reserve shared info memory page\n" ); xatp.gpfn =mfn_x (mfn);
@@ -284,7 +284,7 @@ void hypervisor_ap_setup(void)init_evtchn (); } -int hypervisor_alloc_unused_page (mfn_t *mfn) +int xen_alloc_unused_page (mfn_t *mfn) {unsigned long m;int rc;
@@ -296,7 +296,7 @@ int hypervisor_alloc_unused_page(mfn_t *mfn)return rc; } -int hypervisor_free_unused_page (mfn_t mfn) +int xen_free_unused_page (mfn_t mfn) {return rangeset_remove_range (mem,mfn_x (mfn),mfn_x (mfn)); }
xen/arch/x86/pv/shim.c +2 -2
@@ -739,7 +739,7 @@ static long pv_shim_grant_table_op(unsigned int cmd, };mfn_t mfn; - rc =hypervisor_alloc_unused_page (&mfn); + rc =xen_alloc_unused_page (&mfn);if ( rc ) { gprintk(XENLOG_ERR,
@@ -751,7 +751,7 @@ static long pv_shim_grant_table_op(unsigned int cmd, rc =xen_hypercall_memory_op (XENMEM_add_to_physmap, &xatp);if ( rc ) { -hypervisor_free_unused_page (mfn); +xen_free_unused_page (mfn);break ; }
xen/include/asm-x86/guest/xen.h +2 -2
@@ -33,8 +33,8 @@ extern bool pv_console;extern uint32_t xen_cpuid_base;void probe_hypervisor (void ); -int hypervisor_alloc_unused_page (mfn_t *mfn); -int hypervisor_free_unused_page (mfn_t mfn); +int xen_alloc_unused_page (mfn_t *mfn); +int xen_free_unused_page (mfn_t mfn); DECLARE_PER_CPU(unsigned int, vcpu_id); DECLARE_PER_CPU(struct vcpu_info *, vcpu_info);
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH for-next v3 6/9] x86: rename hypervisor_{alloc, free}_unused_page
xen/arch/x86/guest/xen/xen.c static void map_shared_info(void) · line 100
Quoted 8 lines · Wei Liu
xen/arch/x86/guest/xen/xen.c +1
-1@@ -97,7 +97,7 @@ static void map_shared_info(void)unsigned int i;unsigned long rc; -if (hypervisor_alloc_unused_page (&mfn) ) +if (xen_alloc_unused_page (&mfn) )
But is just "xen_" as a prefix a good name in Xen code? Perhaps "xen_guest_" or (shorter) "xg_"?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH for-next v3 6/9] x86: rename hypervisor_{alloc, free}_unused_page
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Wei Liu
xen/arch/x86/guest/xen/xen.c +0
-0@@ -97,7 +97,7 @@ static void map_shared_info(void)unsigned int i;unsigned long rc;
Quoted 5 lines
xen/arch/x86/guest/xen/xen.c static void map_shared_info(void) · line 100
Quoted 2 lines
xen/arch/x86/guest/xen/xen.c +1
-1-if (hypervisor_alloc_unused_page (&mfn) ) +if (xen_alloc_unused_page (&mfn) )But is just "
xen_" as a prefix a good name in Xen code? Perhaps "xen_guest_" or (shorter) "xg_"?
That's fine by me.
Wei.
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 7/9 x86: switch xen implementation to use hypervisor framework
In reply to Wei LiuTake the chance to change probe_hypervisor to hypervisor_probe.
---
V3:
1. Address Roger's comments
2. Change xen_hypervisor_ops to xen_ops
--- xen/arch/x86/guest/hypervisor.c | 32 ++++++++++++++++++++++++++++++- xen/arch/x86/guest/xen/pvh-boot.c | 2 +- xen/arch/x86/guest/xen/xen.c | 26 +++++++++++++------------ xen/arch/x86/setup.c | 2 +- xen/include/asm-x86/guest/xen.h | 6 ++++-- 5 files changed, 51 insertions(+), 17 deletions(-)
xen/arch/x86/guest/hypervisor.c +31 -1
@@ -22,7 +22,7 @@#include <xen/types.h> #include <asm/cache.h> -#include <asm/guest/hypervisor.h> +#include <asm/guest.h> static struct hypervisor_ops *hops__read_mostly ;
@@ -31,9 +31,39 @@ bool hypervisor_probe(void)if ( hops )return true; +/* Too early to use cpu_has_hypervisor */ +if ( !(cpuid_ecx (1 ) &cpufeat_mask (X86_FEATURE_HYPERVISOR )) ) +return false; + +#ifdef CONFIG_XEN_GUEST +if (xen_probe () ) + { + hops = &xen_ops; +return true; + } +#endif +return false; } +void hypervisor_setup (void ) +{ +if ( hops && hops->setup ) + hops->setup (); +} + +void hypervisor_ap_setup (void ) +{ +if ( hops && hops->ap_setup ) + hops->ap_setup (); +} + +void hypervisor_resume (void ) +{ +if ( hops && hops->resume ) + hops->resume (); +} +/* * Local variables: * mode: C
xen/arch/x86/guest/xen/pvh-boot.c +1 -1
@@ -103,7 +103,7 @@ void __init pvh_init(multiboot_info_t **mbi, module_t **mod) {convert_pvh_info (mbi, mod); -probe_hypervisor (); +hypervisor_probe ();ASSERT (xen_guest);get_memory_map ();
xen/arch/x86/guest/xen/xen.c +14 -12
@@ -67,24 +67,19 @@ static void __init find_xen_leaves(void) } } -void __init probe_hypervisor (void ) +bool __init xen_probe (void ) { -if ( xen_guest ) -return ; - -/* Too early to use cpu_has_hypervisor */ -if ( !(cpuid_ecx (1 ) &cpufeat_mask (X86_FEATURE_HYPERVISOR )) ) -return ; -find_xen_leaves ();if ( !xen_cpuid_base ) -return ; +return false;/* Fill the hypercall page. */ wrmsrl (cpuid_ebx (xen_cpuid_base +2 ),__pa (hypercall_page)); xen_guest = true; + +return true; }static void map_shared_info (void )
@@ -249,7 +244,7 @@ static void init_evtchn(void) } } -void __init hypervisor_setup (void ) +static void __init xen_setup (void ) {init_memmap ();
@@ -277,7 +272,7 @@ void __init hypervisor_setup(void)init_evtchn (); } -void hypervisor_ap_setup (void ) +static void xen_ap_setup (void ) {set_vcpu_id ();map_vcpuinfo ();
@@ -307,7 +302,7 @@ static void ap_resume(void *unused)init_evtchn (); } -void hypervisor_resume (void ) +static void xen_resume (void ) {/* Reset shared info page. */ map_shared_info ();
@@ -330,6 +325,13 @@ void hypervisor_resume(void)pv_console_init (); } +struct hypervisor_ops xen_ops = { + .name ="Xen" , + .setup = xen_setup, + .ap_setup = xen_ap_setup, + .resume = xen_resume, +}; +/* * Local variables: * mode: C
xen/arch/x86/setup.c +1 -1
@@ -763,7 +763,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)* allocing any xenheap structures wanted in lower memory. */ kexec_early_calculations (); -probe_hypervisor (); +hypervisor_probe ();parse_video_info ();
xen/include/asm-x86/guest/xen.h +4 -2
@@ -23,6 +23,7 @@#include <asm/e820.h> #include <asm/fixmap.h> +#include <asm/guest/hypervisor.h> #define XEN_shared_info ((struct shared_info *)fix_to_virt(FIX_XEN_SHARED_INFO))
@@ -31,8 +32,9 @@extern bool xen_guest;extern bool pv_console;extern uint32_t xen_cpuid_base; +extern struct hypervisor_ops xen_ops; -void probe_hypervisor (void ); +bool xen_probe (void );int xen_alloc_unused_page (mfn_t *mfn);int xen_free_unused_page (mfn_t mfn);
@@ -44,7 +46,7 @@ DECLARE_PER_CPU(struct vcpu_info *, vcpu_info);#define xen_guest 0#define pv_console 0 -static inline void probe_hypervisor (void ) {} +static inline bool xen_probe (void ) {return false; }#endif /* CONFIG_XEN_GUEST */ #endif /* __X86_GUEST_XEN_H__ */
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH for-next v3 7/9] x86: switch xen implementation to use hypervisor framework
Quoted 4 lines · Wei Liu
Take the chance to change
probe_hypervisortohypervisor_probe.Signed-off-by Wei Liu <[email protected]>
Quoted 201 lines
---
V3:
1. Address Roger's comments
2. Changexen_hypervisor_opstoxen_ops--- xen/arch/x86/guest/hypervisor.c | 32 ++++++++++++++++++++++++++++++- xen/arch/x86/guest/xen/pvh-boot.c | 2 +- xen/arch/x86/guest/xen/xen.c | 26 +++++++++++++------------ xen/arch/x86/setup.c | 2 +- xen/include/asm-x86/guest/xen.h | 6 ++++-- 5 files changed, 51 insertions(+), 17 deletions(-)xen/arch/x86/guest/hypervisor.c +31
-1@@ -22,7 +22,7 @@#include <xen/types.h> #include <asm/cache.h> -#include <asm/guest/hypervisor.h> +#include <asm/guest.h> static struct hypervisor_ops *hops__read_mostly ;@@ -31,9 +31,39 @@ bool hypervisor_probe(void)if ( hops )return true; +/* Too early to use cpu_has_hypervisor */ +if ( !(cpuid_ecx (1 ) &cpufeat_mask (X86_FEATURE_HYPERVISOR )) ) +return false; + +#ifdef CONFIG_XEN_GUEST +if (xen_probe () ) + { + hops = &xen_ops; +return true; + } +#endif +return false; } +void hypervisor_setup (void ) +{ +if ( hops && hops->setup ) + hops->setup (); +} + +void hypervisor_ap_setup (void ) +{ +if ( hops && hops->ap_setup ) + hops->ap_setup (); +} + +void hypervisor_resume (void ) +{ +if ( hops && hops->resume ) + hops->resume (); +} +/* * Local variables: * mode: C xen/arch/x86/guest/xen/pvh-boot.c +1
-1@@ -103,7 +103,7 @@ void __init pvh_init(multiboot_info_t **mbi, module_t **mod) {convert_pvh_info (mbi, mod); -probe_hypervisor (); +hypervisor_probe ();ASSERT (xen_guest);get_memory_map ();xen/arch/x86/guest/xen/xen.c +14
-12@@ -67,24 +67,19 @@ static void __init find_xen_leaves(void) } } -void __init probe_hypervisor (void ) +bool __init xen_probe (void ) { -if ( xen_guest ) -return ; - -/* Too early to use cpu_has_hypervisor */ -if ( !(cpuid_ecx (1 ) &cpufeat_mask (X86_FEATURE_HYPERVISOR )) ) -return ; -find_xen_leaves ();if ( !xen_cpuid_base ) -return ; +return false;/* Fill the hypercall page. */ wrmsrl (cpuid_ebx (xen_cpuid_base +2 ),__pa (hypercall_page)); xen_guest = true; + +return true; }static void map_shared_info (void )@@ -249,7 +244,7 @@ static void init_evtchn(void) } } -void __init hypervisor_setup (void ) +static void __init xen_setup (void ) {init_memmap ();@@ -277,7 +272,7 @@ void __init hypervisor_setup(void)init_evtchn (); } -void hypervisor_ap_setup (void ) +static void xen_ap_setup (void ) {set_vcpu_id ();map_vcpuinfo ();@@ -307,7 +302,7 @@ static void ap_resume(void *unused)init_evtchn (); } -void hypervisor_resume (void ) +static void xen_resume (void ) {/* Reset shared info page. */ map_shared_info ();@@ -330,6 +325,13 @@ void hypervisor_resume(void)pv_console_init (); } +struct hypervisor_ops xen_ops = { + .name ="Xen" , + .setup = xen_setup, + .ap_setup = xen_ap_setup, + .resume = xen_resume, +}; +/* * Local variables: * mode: C xen/arch/x86/setup.c +1
-1@@ -763,7 +763,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)* allocing any xenheap structures wanted in lower memory. */ kexec_early_calculations (); -probe_hypervisor (); +hypervisor_probe ();parse_video_info ();xen/include/asm-x86/guest/xen.h +4
-3@@ -23,6 +23,7 @@#include <asm/e820.h> #include <asm/fixmap.h> +#include <asm/guest/hypervisor.h> #define XEN_shared_info ((struct shared_info *)fix_to_virt(FIX_XEN_SHARED_INFO))@@ -31,8 +32,9 @@extern bool xen_guest;extern bool pv_console;extern uint32_t xen_cpuid_base; +extern struct hypervisor_ops xen_ops; -void probe_hypervisor (void ); +bool xen_probe (void );int xen_alloc_unused_page (mfn_t *mfn);int xen_free_unused_page (mfn_t mfn);@@ -44,7 +46,7 @@ DECLARE_PER_CPU(struct vcpu_info *, vcpu_info);#define xen_guest 0#define pv_console 0 -static inline void probe_hypervisor (void ) {} +static inline bool xen_probe (void ) {return false; }#endif /* CONFIG_XEN_GUEST */ #endif /* __X86_GUEST_XEN_H__ */ --2.20.1
Quoted 4 lines
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH for-next v3 7/9] x86: switch xen implementation to use hypervisor framework
In reply to Wei LiuQuoted 10 lines · Wei Liu
xen/arch/x86/guest/hypervisor.c +6
-0@@ -31,9 +31,39 @@ bool hypervisor_probe(void)if ( hops )return true; +/* Too early to use cpu_has_hypervisor */ +if ( !(cpuid_ecx (1 ) &cpufeat_mask (X86_FEATURE_HYPERVISOR )) ) +return false; + +#ifdef CONFIG_XEN_GUEST +if (xen_probe () )
xen/arch/x86/guest/hypervisor.c bool hypervisor_probe(void) · line 49
Quoted 10 lines
xen/arch/x86/guest/hypervisor.c +7
-0+ { + hops = &xen_ops; +return true; + } +#endif +return false; } +void hypervisor_setup (void )
__init?
xen/arch/x86/guest/xen/xen.c void hypervisor_resume(void) · line 328
Quoted 5 lines
xen/arch/x86/guest/xen/xen.c +1
-0@@ -330,6 +325,13 @@ void hypervisor_resume(void)pv_console_init (); } +struct hypervisor_ops xen_ops = {
const (will require a corresponding adjustment in the earlier patch then too)?
With these taken care of and the naming possibly adjusted according to whatever the decision on the earlier patch s going to be
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 8/9 x86: be more verbose when running on a hypervisor
In reply to Wei Liu---
V3: Address Roger's comment, add ASSERTs
--- xen/arch/x86/guest/hypervisor.c | 6 ++++++ xen/arch/x86/setup.c | 6 +++++- xen/include/asm-x86/guest/hypervisor.h | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-)
xen/arch/x86/guest/hypervisor.c +6 -0
@@ -46,6 +46,12 @@ bool hypervisor_probe(void)return false; } +const char *hypervisor_name (void ) +{ +ASSERT (hops); +return hops->name; +} +void hypervisor_setup (void ) {if ( hops && hops->setup )
xen/arch/x86/setup.c +5 -1
@@ -689,6 +689,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)int i, j, e820_warn =0 , bytes =0 ;bool acpi_boot_table_init_done = false, relocated = false;int ret; +bool running_on_hypervisor;struct ns16550_defaults ns16550 = { .data_bits =8 , .parity ='n' ,
@@ -763,7 +764,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)* allocing any xenheap structures wanted in lower memory. */ kexec_early_calculations (); -hypervisor_probe (); + running_on_hypervisor =hypervisor_probe ();parse_video_info ();
@@ -789,6 +790,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)printk ("Xen image load base address: %#lx\n" , xen_phys_start); +if ( running_on_hypervisor ) +printk ("Running on %s\n" ,hypervisor_name ()); +#ifdef CONFIG_VIDEO printk ("Video information:\n" );
xen/include/asm-x86/guest/hypervisor.h +3 -0
@@ -36,15 +36,18 @@ bool hypervisor_probe(void);void hypervisor_setup (void );void hypervisor_ap_setup (void );void hypervisor_resume (void ); +const char *hypervisor_name (void );#else +#include <xen/lib.h> #include <xen/types.h> static inline bool hypervisor_probe (void ) {return false; }static inline void hypervisor_setup (void ) {}static inline void hypervisor_ap_setup (void ) {}static inline void hypervisor_resume (void ) {} +static inline char *hypervisor_name (void ) {ASSERT_UNREACHABLE ();return NULL ; }#endif /* CONFIG_GUEST */
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH for-next v3 8/9] x86: be more verbose when running on a hypervisor
Quoted 2 lines · Wei Liu
Signed-off-by Wei Liu <[email protected]>
Quoted 83 lines
---
V3: Address Roger's comment, add ASSERTs--- xen/arch/x86/guest/hypervisor.c | 6 ++++++ xen/arch/x86/setup.c | 6 +++++- xen/include/asm-x86/guest/hypervisor.h | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-)xen/arch/x86/guest/hypervisor.c +6
-0@@ -46,6 +46,12 @@ bool hypervisor_probe(void)return false; } +const char *hypervisor_name (void ) +{ +ASSERT (hops); +return hops->name; +} +void hypervisor_setup (void ) {if ( hops && hops->setup )xen/arch/x86/setup.c +5
-1@@ -689,6 +689,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)int i, j, e820_warn =0 , bytes =0 ;bool acpi_boot_table_init_done = false, relocated = false;int ret; +bool running_on_hypervisor;struct ns16550_defaults ns16550 = { .data_bits =8 , .parity ='n' ,@@ -763,7 +764,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)* allocing any xenheap structures wanted in lower memory. */ kexec_early_calculations (); -hypervisor_probe (); + running_on_hypervisor =hypervisor_probe ();parse_video_info ();@@ -789,6 +790,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)printk ("Xen image load base address: %#lx\n" , xen_phys_start); +if ( running_on_hypervisor ) +printk ("Running on %s\n" ,hypervisor_name ()); +#ifdef CONFIG_VIDEO printk ("Video information:\n" );xen/include/asm-x86/guest/hypervisor.h +3
-1@@ -36,15 +36,18 @@ bool hypervisor_probe(void);void hypervisor_setup (void );void hypervisor_ap_setup (void );void hypervisor_resume (void ); +const char *hypervisor_name (void );#else +#include <xen/lib.h> #include <xen/types.h> static inline bool hypervisor_probe (void ) {return false; }static inline void hypervisor_setup (void ) {}static inline void hypervisor_ap_setup (void ) {}static inline void hypervisor_resume (void ) {} +static inline char *hypervisor_name (void ) {ASSERT_UNREACHABLE ();return NULL ; }#endif /* CONFIG_GUEST */ --2.20.1
Quoted 4 lines
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH for-next v3 8/9] x86: be more verbose when running on a hypervisor
In reply to Wei LiuQuoted 20 lines · Wei Liu
xen/arch/x86/setup.c +2
-1@@ -689,6 +689,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)int i, j, e820_warn =0 , bytes =0 ;bool acpi_boot_table_init_done = false, relocated = false;int ret; +bool running_on_hypervisor;struct ns16550_defaults ns16550 = { .data_bits =8 , .parity ='n' ,@@ -763,7 +764,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)* allocing any xenheap structures wanted in lower memory. */ kexec_early_calculations (); -hypervisor_probe (); + running_on_hypervisor =hypervisor_probe ();parse_video_info ();
xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p) · line 794
Quoted 5 lines
xen/arch/x86/setup.c +2
-0@@ -789,6 +790,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)printk ("Xen image load base address: %#lx\n" , xen_phys_start); +if ( running_on_hypervisor ) +printk ("Running on %s\n" ,hypervisor_name ());
Instead of a bool, why don't you make hypervisor_probe() return the name (or NULL), avoiding the separate hypervisor_name() (and making it moot for me to ask for it to become __init)?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 9/9 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.
---
V3:
1. Remove some unused code
2. Rename structure
3. Also detect HV#1 signature
--- xen/arch/x86/Kconfig | 9 +++++ xen/arch/x86/guest/Makefile | 1 + xen/arch/x86/guest/hyperv/Makefile | 1 + xen/arch/x86/guest/hyperv/hyperv.c | 54 ++++++++++++++++++++++++++++++ xen/arch/x86/guest/hypervisor.c | 8 +++++ xen/include/asm-x86/guest.h | 1 + xen/include/asm-x86/guest/hyperv.h | 45 +++++++++++++++++++++++++ 7 files changed, 119 insertions(+) create mode 100644 xen/arch/x86/guest/hyperv/Makefile create mode 100644 xen/arch/x86/guest/hyperv/hyperv.c create mode 100644 xen/include/asm-x86/guest/hyperv.h
xen/arch/x86/Kconfig +9 -0
@@ -164,6 +164,15 @@ endchoice config GUEST bool +config HYPERV_GUEST + def_bool n + select GUEST + prompt "Hyper-V Guest" + ---help--- + Support for Xen detecting when it is running under Hyper-V. + + If unsure, say N. + config XEN_GUEST def_bool n select GUEST
xen/arch/x86/guest/Makefile +1 -0
@@ -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
@@ -43,6 +43,14 @@ bool hypervisor_probe(void) }#endif +#ifdef CONFIG_HYPERV_GUEST +if (hyperv_probe () ) + { + hops = &hyperv_ops; +return true; + } +#endif +return false; }
xen/include/asm-x86/guest.h +1 -0
@@ -20,6 +20,7 @@#define __X86_GUEST_H__#include <asm/guest/hypercall.h> +#include <asm/guest/hyperv.h> #include <asm/guest/hypervisor.h> #include <asm/guest/pvh-boot.h> #include <asm/guest/xen.h>
xen/include/asm-x86/guest/hyperv.h new file +45 -0
45 lines not on this page · raw message
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH for-next v3 9/9] x86: introduce CONFIG_HYPERV and detection code
Quoted 7 lines · Wei Liu
We use the same code structure as we did for Xen.
As starters, detect Hyper-V in probe routine. More complex functionalities will be added later.
Signed-off-by Wei Liu <[email protected]>
...with one suggestion...
Quoted 119 lines
---
V3:
1. Remove some unused code
2. Rename structure
3. Also detect HV#1 signature--- xen/arch/x86/Kconfig | 9 +++++ xen/arch/x86/guest/Makefile | 1 + xen/arch/x86/guest/hyperv/Makefile | 1 + xen/arch/x86/guest/hyperv/hyperv.c | 54 ++++++++++++++++++++++++++++++ xen/arch/x86/guest/hypervisor.c | 8 +++++ xen/include/asm-x86/guest.h | 1 + xen/include/asm-x86/guest/hyperv.h | 45 +++++++++++++++++++++++++ 7 files changed, 119 insertions(+) create mode 100644 xen/arch/x86/guest/hyperv/Makefile create mode 100644 xen/arch/x86/guest/hyperv/hyperv.c create mode 100644 xen/include/asm-x86/guest/hyperv.hxen/arch/x86/Kconfig +9
-0@@ -164,6 +164,15 @@ endchoice config GUEST bool +config HYPERV_GUEST + def_bool n + select GUEST + prompt "Hyper-V Guest" + ---help--- + Support for Xen detecting when it is running under Hyper-V. + + If unsure, say N. + config XEN_GUEST def_bool n select GUESTxen/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 +54
-0@@ -0,0 +1,54 @@ +/****************************************************************************** +* arch/x86/guest/hyperv/hyperv.c +* +* Support for detecting and running under Hyper-V. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; If not, see <http://www.gnu.org/licenses/>. +* +* Copyright (c) 2019 Microsoft. +*/ +#include <xen/init.h> + +#include <asm/guest.h> + +bool __init hyperv_probe (void ) +{ +uint32_t eax, ebx, ecx, edx; + +cpuid (0x40000000 , &eax, &ebx, &ecx, &edx); +if ( !((ebx ==0x7263694d ) &&/* "Micr" */ + (ecx ==0x666f736f ) &&/* "osof" */ + (edx ==0x76482074 )) )/* "t Hv" */ +return false; + +cpuid (0x40000001 , &eax, &ebx, &ecx, &edx); +if ( eax !=0x31237648 )/* Hv#1 */ +return false; + +return true; +} + +struct hypervisor_ops hyperv_ops = { + .name ="Hyper-V" , +}; + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/ xen/arch/x86/guest/hypervisor.c +0
-0
xen/arch/x86/guest/hypervisor.c bool hypervisor_probe(void) · line 45
Quoted 3 lines
xen/arch/x86/guest/hypervisor.c +0
-0@@ -43,6 +43,14 @@ bool hypervisor_probe(void) }#endif
Add a comment here to point out that hyperv_probe() needs to be called after xen_probe() to avoid a false positive due to viridian support.
Quoted 78 lines
xen/arch/x86/guest/hypervisor.c +8
-0+#ifdef CONFIG_HYPERV_GUEST +if (hyperv_probe () ) + { + hops = &hyperv_ops; +return true; + } +#endif +return false; }xen/include/asm-x86/guest.h +1
-0@@ -20,6 +20,7 @@#define __X86_GUEST_H__#include <asm/guest/hypercall.h> +#include <asm/guest/hyperv.h> #include <asm/guest/hypervisor.h> #include <asm/guest/pvh-boot.h> #include <asm/guest/xen.h> xen/include/asm-x86/guest/hyperv.h new file +45
-1@@ -0,0 +1,45 @@ +/****************************************************************************** +* asm-x86/guest/hyperv.h +* +* This program is free software; you can redistribute it and/or +* modify it under the terms and conditions of the GNU General Public +* License, version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public +* License along with this program; If not, see <http://www.gnu.org/licenses/>. +* +* Copyright (c) 2019 Microsoft. +*/ + +#ifndef __X86_GUEST_HYPERV_H__ +#define __X86_GUEST_HYPERV_H__ + +#ifdef CONFIG_HYPERV_GUEST + +#include <asm/guest/hypervisor.h> + +extern struct hypervisor_ops hyperv_ops; + +bool hyperv_probe (void ); + +#else + +static inline bool hyperv_probe (void ) {return false; } + +#endif /* CONFIG_HYPERV_GUEST */ +#endif /* __X86_GUEST_HYPERV_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/ --2.20.1
Quoted 4 lines
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH for-next v3 9/9] x86: introduce CONFIG_HYPERV and detection code
Quoted 10 lines · Paul Durrant
Quoted 7 lines · Wei Liu
We use the same code structure as we did for Xen.
As starters, detect Hyper-V in probe routine. More complex functionalities will be added later.
Signed-off-by Wei Liu <[email protected]>Reviewed-by Paul Durrant <[email protected]>
Thanks.
[...]
Quoted 12 lines
xen/arch/x86/guest/hypervisor.c bool hypervisor_probe(void) · line 45
Quoted 8 lines
xen/arch/x86/guest/hypervisor.c +0
-0@@ -43,6 +43,14 @@ bool hypervisor_probe(void) }#endif Add a comment here to point out that
hyperv_probe()needs to be called afterxen_probe()to avoid a false positive due to viridian support.
Yes I can do that.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH for-next v3 9/9] x86: introduce CONFIG_HYPERV and detection code
In reply to Wei Liuxen/arch/x86/Kconfig endchoice · line 170
Quoted 10 lines · Wei Liu
xen/arch/x86/Kconfig +4
-0@@ -164,6 +164,15 @@ endchoice config GUEST bool +config HYPERV_GUEST + def_bool n + select GUEST + prompt "Hyper-V Guest"
Please can you avoid following the bad example XEN_GUEST gives (and perhaps even take the opportunity here or in the earlier patch adding GUEST to change that one as well)? What you want is
config HYPERV_GUEST
bool "Hyper-V Guest"
select GUEST
Quoted 35 lines
xen/arch/x86/guest/hyperv/hyperv.c new file +32
-0@@ -0,0 +1,54 @@ +/****************************************************************************** +* arch/x86/guest/hyperv/hyperv.c +* +* Support for detecting and running under Hyper-V. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; If not, see <http://www.gnu.org/licenses/>. +* +* Copyright (c) 2019 Microsoft. +*/ +#include <xen/init.h> + +#include <asm/guest.h> + +bool __init hyperv_probe (void ) +{ +uint32_t eax, ebx, ecx, edx; + +cpuid (0x40000000 , &eax, &ebx, &ecx, &edx); +if ( !((ebx ==0x7263694d ) &&/* "Micr" */ + (ecx ==0x666f736f ) &&/* "osof" */ + (edx ==0x76482074 )) )/* "t Hv" */
xen/arch/x86/guest/hyperv/hyperv.c line 42
Quoted 10 lines
xen/arch/x86/guest/hyperv/hyperv.c new file +10
-0+return false; + +cpuid (0x40000001 , &eax, &ebx, &ecx, &edx); +if ( eax !=0x31237648 )/* Hv#1 */ +return false; + +return true; +} + +struct hypervisor_ops hyperv_ops = {
const again.
xen/arch/x86/guest/hypervisor.c bool hypervisor_probe(void) · line 52
Quoted 13 lines
xen/arch/x86/guest/hypervisor.c +7
-0@@ -43,6 +43,14 @@ bool hypervisor_probe(void) }#endif +#ifdef CONFIG_HYPERV_GUEST +if (hyperv_probe () ) + { + hops = &hyperv_ops; +return true; + } +#endif
This recurring #ifdef CONFIG_*_GUEST is going to start looking ugly the latest when one or two more get added. Perhaps better providing *_probe() stubs returning false, and (like we do elsewhere) rely on DCE to get rid of the *_ops reference? (And really you already have such a stub - all you need to do is put the hyperv_ops declaration outside the #ifdef (but read on).
Also how about having *_probe() return the address of *_ops, such that the latter could all become static?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH for-next v3 9/9] x86: introduce CONFIG_HYPERV and detection code
Quoted 16 lines · Jan Beulich
xen/arch/x86/Kconfig endchoice · line 170
Quoted 10 lines · Wei Liu
xen/arch/x86/Kconfig +4
-0@@ -164,6 +164,15 @@ endchoice config GUEST bool +config HYPERV_GUEST + def_bool n + select GUEST + prompt "Hyper-V Guest"Please can you avoid following the bad example
XEN_GUESTgives (and perhaps even take the opportunity here or in the earlier patch adding GUEST to change that one as well)? What you want is
Quoted 3 lines
config
HYPERV_GUEST
bool "Hyper-V Guest"
select GUEST
Ack.
Quoted 70 lines
Quoted 36 lines
xen/arch/x86/guest/hyperv/hyperv.c new file +32
-0@@ -0,0 +1,54 @@ +/****************************************************************************** +* arch/x86/guest/hyperv/hyperv.c +* +* Support for detecting and running under Hyper-V. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; If not, see <http://www.gnu.org/licenses/>. +* +* Copyright (c) 2019 Microsoft. +*/ +#include <xen/init.h> + +#include <asm/guest.h> + +bool __init hyperv_probe (void ) +{ +uint32_t eax, ebx, ecx, edx; + +cpuid (0x40000000 , &eax, &ebx, &ecx, &edx); +if ( !((ebx ==0x7263694d ) &&/* "Micr" */ + (ecx ==0x666f736f ) &&/* "osof" */ + (edx ==0x76482074 )) )/* "t Hv" */ xen/arch/x86/guest/hyperv/hyperv.c line 42
Quoted 10 lines
xen/arch/x86/guest/hyperv/hyperv.c new file +10
-0+return false; + +cpuid (0x40000001 , &eax, &ebx, &ecx, &edx); +if ( eax !=0x31237648 )/* Hv#1 */ +return false; + +return true; +} + +struct hypervisor_ops hyperv_ops = {const again.
xen/arch/x86/guest/hypervisor.c bool hypervisor_probe(void) · line 52
Quoted 13 lines
xen/arch/x86/guest/hypervisor.c +7
-0@@ -43,6 +43,14 @@ bool hypervisor_probe(void) }#endif +#ifdef CONFIG_HYPERV_GUEST +if (hyperv_probe () ) + { + hops = &hyperv_ops; +return true; + } +#endif This recurring #ifdef CONFIG_*_GUEST is going to start looking ugly the latest when one or two more get added. Perhaps better providing
*_probe()stubs returning false, and (like we do elsewhere) rely on DCE to get rid of the*_opsreference? (And really you already have such a stub - all you need to do is put thehyperv_opsdeclaration outside the #ifdef (but read on).
Quoted 2 lines
Also how about having
*_probe()return the address of*_ops, such that the latter could all become static?
Previously you made a suggestion to make probe return the name of the hypervisor. Here you ask for address of ops. I actually prefer the method suggested here, but this means I will need to keep hypervisor_name around.
Wei.
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH for-next v3 9/9] x86: introduce CONFIG_HYPERV and detection code
Quoted 93 lines · Wei Liu
Quoted 16 lines · Jan Beulich
xen/arch/x86/Kconfig endchoice · line 170
Quoted 10 lines · Wei Liu
xen/arch/x86/Kconfig +4
-0@@ -164,6 +164,15 @@ endchoice config GUEST bool +config HYPERV_GUEST + def_bool n + select GUEST + prompt "Hyper-V Guest"Please can you avoid following the bad example
XEN_GUESTgives (and perhaps even take the opportunity here or in the earlier patch adding GUEST to change that one as well)? What you want isQuoted 3 lines
config
HYPERV_GUEST
bool "Hyper-V Guest"
select GUESTAck.
Quoted 70 lines
Quoted 36 lines
xen/arch/x86/guest/hyperv/hyperv.c new file +32
-0@@ -0,0 +1,54 @@ +/****************************************************************************** +* arch/x86/guest/hyperv/hyperv.c +* +* Support for detecting and running under Hyper-V. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; If not, see <http://www.gnu.org/licenses/>. +* +* Copyright (c) 2019 Microsoft. +*/ +#include <xen/init.h> + +#include <asm/guest.h> + +bool __init hyperv_probe (void ) +{ +uint32_t eax, ebx, ecx, edx; + +cpuid (0x40000000 , &eax, &ebx, &ecx, &edx); +if ( !((ebx ==0x7263694d ) &&/* "Micr" */ + (ecx ==0x666f736f ) &&/* "osof" */ + (edx ==0x76482074 )) )/* "t Hv" */ xen/arch/x86/guest/hyperv/hyperv.c line 42
Quoted 10 lines
xen/arch/x86/guest/hyperv/hyperv.c new file +10
-0+return false; + +cpuid (0x40000001 , &eax, &ebx, &ecx, &edx); +if ( eax !=0x31237648 )/* Hv#1 */ +return false; + +return true; +} + +struct hypervisor_ops hyperv_ops = {const again.
xen/arch/x86/guest/hypervisor.c bool hypervisor_probe(void) · line 52
Quoted 13 lines
xen/arch/x86/guest/hypervisor.c +7
-0@@ -43,6 +43,14 @@ bool hypervisor_probe(void) }#endif +#ifdef CONFIG_HYPERV_GUEST +if (hyperv_probe () ) + { + hops = &hyperv_ops; +return true; + } +#endif This recurring #ifdef CONFIG_*_GUEST is going to start looking ugly the latest when one or two more get added. Perhaps better providing
*_probe()stubs returning false, and (like we do elsewhere) rely on DCE to get rid of the*_opsreference? (And really you already have such a stub - all you need to do is put thehyperv_opsdeclaration outside the #ifdef (but read on).
Quoted 7 lines
Quoted 2 lines
Also how about having
*_probe()return the address of*_ops, such that the latter could all become static?Previously you made a suggestion to make probe return the name of the hypervisor. Here you ask for address of ops. I actually prefer the method suggested here, but this means I will need to keep
hypervisor_namearound.
Is there actually any user of the name field other than the caller of probe? If not, surely that caller could access the name field without a hypervisor_name() wrapper.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH for-next v3 9/9] x86: introduce CONFIG_HYPERV and detection code
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 3 lines
Also how about having
*_probe()return the address of*_ops, such that the latter could all become static?
Quoted 8 lines
Quoted 4 lines
Previously you made a suggestion to make probe return the name of the hypervisor. Here you ask for address of ops. I actually prefer the method suggested here, but this means I will need to keep
hypervisor_namearound.Is there actually any user of the name field other than the caller of probe? If not, surely that caller could access the name field without a
hypervisor_name()wrapper.
I don't envision more users at this stage.
I'm fine with accessing that field directly. We can always introduce the function again if it becomes necessary.
Wei.
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel