Message ID | 20191121185049.16666-9-liuwe@microsoft.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Port Xen to Hyper-V | expand |
> -----Original Message----- > From: Xen-devel <xen-devel-bounces@lists.xenproject.org> On Behalf Of Wei > Liu > Sent: 21 November 2019 19:51 > To: Xen Development List <xen-devel@lists.xenproject.org> > Cc: Wei Liu <liuwe@microsoft.com>; Wei Liu <wl@xen.org>; Andrew Cooper > <andrew.cooper3@citrix.com>; Michael Kelley <mikelley@microsoft.com>; Jan > Beulich <jbeulich@suse.com>; Roger Pau Monné <roger.pau@citrix.com> > Subject: [Xen-devel] [PATCH v4 8/8] x86: introduce CONFIG_HYPERV and > detection code > > We use the same code structure as we did for Xen. > > As starters, detect Hyper-V in probe routine. More complex > functionalities will be added later. > > Take the chance to fix XEN_GUEST in Kconfig. Would this fix be better in your earlier renaming patch? > > Signed-off-by: Wei Liu <liuwe@microsoft.com> Either way... Reviewed-by: Paul Durrant <pdurrant@amazon.com> > --- > Changes in V4: > 1. Add comment regarding order of probe functions. > 2. Adapt to changes in previous patches. > --- > xen/arch/x86/Kconfig | 11 ++++-- > xen/arch/x86/guest/Makefile | 1 + > xen/arch/x86/guest/hyperv/Makefile | 1 + > xen/arch/x86/guest/hyperv/hyperv.c | 54 ++++++++++++++++++++++++++++++ > xen/arch/x86/guest/hypervisor.c | 8 +++++ > xen/include/asm-x86/guest.h | 1 + > xen/include/asm-x86/guest/hyperv.h | 43 ++++++++++++++++++++++++ > 7 files changed, 117 insertions(+), 2 deletions(-) > create mode 100644 xen/arch/x86/guest/hyperv/Makefile > create mode 100644 xen/arch/x86/guest/hyperv/hyperv.c > create mode 100644 xen/include/asm-x86/guest/hyperv.h > > diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig > index 867de857e8..0a02b6ee3f 100644 > --- a/xen/arch/x86/Kconfig > +++ b/xen/arch/x86/Kconfig > @@ -164,10 +164,17 @@ endchoice > config GUEST > bool > > +config HYPERV_GUEST > + bool "Hyper-V Guest" > + select GUEST > + ---help--- > + Support for Xen detecting when it is running under Hyper-V. > + > + If unsure, say N. > + > config XEN_GUEST > - def_bool n > + bool "Xen Guest" > select GUEST > - prompt "Xen Guest" > ---help--- > Support for Xen detecting when it is running under Xen. > > diff --git a/xen/arch/x86/guest/Makefile b/xen/arch/x86/guest/Makefile > index f63d64bbee..f164196772 100644 > --- a/xen/arch/x86/guest/Makefile > +++ b/xen/arch/x86/guest/Makefile > @@ -1,3 +1,4 @@ > obj-y += hypervisor.o > > +subdir-$(CONFIG_HYPERV_GUEST) += hyperv > subdir-$(CONFIG_XEN_GUEST) += xen > diff --git a/xen/arch/x86/guest/hyperv/Makefile > b/xen/arch/x86/guest/hyperv/Makefile > new file mode 100644 > index 0000000000..68170109a9 > --- /dev/null > +++ b/xen/arch/x86/guest/hyperv/Makefile > @@ -0,0 +1 @@ > +obj-y += hyperv.o > diff --git a/xen/arch/x86/guest/hyperv/hyperv.c > b/xen/arch/x86/guest/hyperv/hyperv.c > new file mode 100644 > index 0000000000..916e08ff89 > --- /dev/null > +++ b/xen/arch/x86/guest/hyperv/hyperv.c > @@ -0,0 +1,54 @@ > +/************************************************************************ > ****** > + * arch/x86/guest/hyperv/hyperv.c > + * > + * Support for detecting and running under Hyper-V. > + * > + * This program is free software; you can redistribute it and/or modify > + * it under the terms of the GNU General Public License as published by > + * the Free Software Foundation; either version 2 of the License, or > + * (at your option) any later version. > + * > + * This program is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + * GNU General Public License for more details. > + * > + * You should have received a copy of the GNU General Public License > + * along with this program; If not, see <http://www.gnu.org/licenses/>. > + * > + * Copyright (c) 2019 Microsoft. > + */ > +#include <xen/init.h> > + > +#include <asm/guest.h> > + > +static const struct hypervisor_ops hyperv_ops = { > + .name = "Hyper-V", > +}; > + > +const struct hypervisor_ops * __init hyperv_probe(void) > +{ > + uint32_t eax, ebx, ecx, edx; > + > + cpuid(0x40000000, &eax, &ebx, &ecx, &edx); > + if ( !((ebx == 0x7263694d) && /* "Micr" */ > + (ecx == 0x666f736f) && /* "osof" */ > + (edx == 0x76482074)) ) /* "t Hv" */ > + return NULL; > + > + cpuid(0x40000001, &eax, &ebx, &ecx, &edx); > + if ( eax != 0x31237648 ) /* Hv#1 */ > + return NULL; > + > + return &hyperv_ops; > +} > + > +/* > + * Local variables: > + * mode: C > + * c-file-style: "BSD" > + * c-basic-offset: 4 > + * tab-width: 4 > + * indent-tabs-mode: nil > + * End: > + */ > diff --git a/xen/arch/x86/guest/hypervisor.c > b/xen/arch/x86/guest/hypervisor.c > index a067cacecb..c293e185cc 100644 > --- a/xen/arch/x86/guest/hypervisor.c > +++ b/xen/arch/x86/guest/hypervisor.c > @@ -39,6 +39,14 @@ const struct hypervisor_ops *hypervisor_probe(void) > if ( hops ) > goto out; > > + /* > + * Detection of Hyper-V must come after Xen to avoid false positive > due > + * to viridian support > + */ > + hops = hyperv_probe(); > + if ( hops ) > + goto out; > + > out: > return hops; > } > diff --git a/xen/include/asm-x86/guest.h b/xen/include/asm-x86/guest.h > index 8e167165ae..94448606d4 100644 > --- a/xen/include/asm-x86/guest.h > +++ b/xen/include/asm-x86/guest.h > @@ -20,6 +20,7 @@ > #define __X86_GUEST_H__ > > #include <asm/guest/hypercall.h> > +#include <asm/guest/hyperv.h> > #include <asm/guest/hypervisor.h> > #include <asm/guest/pvh-boot.h> > #include <asm/guest/xen.h> > diff --git a/xen/include/asm-x86/guest/hyperv.h b/xen/include/asm- > x86/guest/hyperv.h > new file mode 100644 > index 0000000000..3f88b94c77 > --- /dev/null > +++ b/xen/include/asm-x86/guest/hyperv.h > @@ -0,0 +1,43 @@ > +/************************************************************************ > ****** > + * asm-x86/guest/hyperv.h > + * > + * This program is free software; you can redistribute it and/or > + * modify it under the terms and conditions of the GNU General Public > + * License, version 2, as published by the Free Software Foundation. > + * > + * This program is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + * General Public License for more details. > + * > + * You should have received a copy of the GNU General Public > + * License along with this program; If not, see > <http://www.gnu.org/licenses/>. > + * > + * Copyright (c) 2019 Microsoft. > + */ > + > +#ifndef __X86_GUEST_HYPERV_H__ > +#define __X86_GUEST_HYPERV_H__ > + > +#ifdef CONFIG_HYPERV_GUEST > + > +#include <asm/guest/hypervisor.h> > + > +const struct hypervisor_ops *hyperv_probe(void); > + > +#else > + > +static inline const struct hypervisor_ops *hyperv_probe(void) { return > NULL; } > + > +#endif /* CONFIG_HYPERV_GUEST */ > +#endif /* __X86_GUEST_HYPERV_H__ */ > + > +/* > + * Local variables: > + * mode: C > + * c-file-style: "BSD" > + * c-basic-offset: 4 > + * tab-width: 4 > + * indent-tabs-mode: nil > + * End: > + */ > -- > 2.20.1 > > > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xenproject.org > https://lists.xenproject.org/mailman/listinfo/xen-devel
On 22.11.2019 12:11, Durrant, Paul wrote: >> -----Original Message----- >> From: Xen-devel <xen-devel-bounces@lists.xenproject.org> On Behalf Of Wei >> Liu >> Sent: 21 November 2019 19:51 >> To: Xen Development List <xen-devel@lists.xenproject.org> >> Cc: Wei Liu <liuwe@microsoft.com>; Wei Liu <wl@xen.org>; Andrew Cooper >> <andrew.cooper3@citrix.com>; Michael Kelley <mikelley@microsoft.com>; Jan >> Beulich <jbeulich@suse.com>; Roger Pau Monné <roger.pau@citrix.com> >> Subject: [Xen-devel] [PATCH v4 8/8] x86: introduce CONFIG_HYPERV and >> detection code >> >> We use the same code structure as we did for Xen. >> >> As starters, detect Hyper-V in probe routine. More complex >> functionalities will be added later. >> >> Take the chance to fix XEN_GUEST in Kconfig. > > Would this fix be better in your earlier renaming patch? > >> >> Signed-off-by: Wei Liu <liuwe@microsoft.com> > > Either way... > > Reviewed-by: Paul Durrant <pdurrant@amazon.com> Acked-by: Jan Beulich <jbeulich@suse.com> (either way, as Paul says)
diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig index 867de857e8..0a02b6ee3f 100644 --- a/xen/arch/x86/Kconfig +++ b/xen/arch/x86/Kconfig @@ -164,10 +164,17 @@ endchoice config GUEST bool +config HYPERV_GUEST + bool "Hyper-V Guest" + select GUEST + ---help--- + Support for Xen detecting when it is running under Hyper-V. + + If unsure, say N. + config XEN_GUEST - def_bool n + bool "Xen Guest" select GUEST - prompt "Xen Guest" ---help--- Support for Xen detecting when it is running under Xen. diff --git a/xen/arch/x86/guest/Makefile b/xen/arch/x86/guest/Makefile index f63d64bbee..f164196772 100644 --- a/xen/arch/x86/guest/Makefile +++ b/xen/arch/x86/guest/Makefile @@ -1,3 +1,4 @@ obj-y += hypervisor.o +subdir-$(CONFIG_HYPERV_GUEST) += hyperv subdir-$(CONFIG_XEN_GUEST) += xen diff --git a/xen/arch/x86/guest/hyperv/Makefile b/xen/arch/x86/guest/hyperv/Makefile new file mode 100644 index 0000000000..68170109a9 --- /dev/null +++ b/xen/arch/x86/guest/hyperv/Makefile @@ -0,0 +1 @@ +obj-y += hyperv.o diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c new file mode 100644 index 0000000000..916e08ff89 --- /dev/null +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -0,0 +1,54 @@ +/****************************************************************************** + * arch/x86/guest/hyperv/hyperv.c + * + * Support for detecting and running under Hyper-V. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; If not, see <http://www.gnu.org/licenses/>. + * + * Copyright (c) 2019 Microsoft. + */ +#include <xen/init.h> + +#include <asm/guest.h> + +static const struct hypervisor_ops hyperv_ops = { + .name = "Hyper-V", +}; + +const struct hypervisor_ops * __init hyperv_probe(void) +{ + uint32_t eax, ebx, ecx, edx; + + cpuid(0x40000000, &eax, &ebx, &ecx, &edx); + if ( !((ebx == 0x7263694d) && /* "Micr" */ + (ecx == 0x666f736f) && /* "osof" */ + (edx == 0x76482074)) ) /* "t Hv" */ + return NULL; + + cpuid(0x40000001, &eax, &ebx, &ecx, &edx); + if ( eax != 0x31237648 ) /* Hv#1 */ + return NULL; + + return &hyperv_ops; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c index a067cacecb..c293e185cc 100644 --- a/xen/arch/x86/guest/hypervisor.c +++ b/xen/arch/x86/guest/hypervisor.c @@ -39,6 +39,14 @@ const struct hypervisor_ops *hypervisor_probe(void) if ( hops ) goto out; + /* + * Detection of Hyper-V must come after Xen to avoid false positive due + * to viridian support + */ + hops = hyperv_probe(); + if ( hops ) + goto out; + out: return hops; } diff --git a/xen/include/asm-x86/guest.h b/xen/include/asm-x86/guest.h index 8e167165ae..94448606d4 100644 --- a/xen/include/asm-x86/guest.h +++ b/xen/include/asm-x86/guest.h @@ -20,6 +20,7 @@ #define __X86_GUEST_H__ #include <asm/guest/hypercall.h> +#include <asm/guest/hyperv.h> #include <asm/guest/hypervisor.h> #include <asm/guest/pvh-boot.h> #include <asm/guest/xen.h> diff --git a/xen/include/asm-x86/guest/hyperv.h b/xen/include/asm-x86/guest/hyperv.h new file mode 100644 index 0000000000..3f88b94c77 --- /dev/null +++ b/xen/include/asm-x86/guest/hyperv.h @@ -0,0 +1,43 @@ +/****************************************************************************** + * asm-x86/guest/hyperv.h + * + * This program is free software; you can redistribute it and/or + * modify it under the terms and conditions of the GNU General Public + * License, version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; If not, see <http://www.gnu.org/licenses/>. + * + * Copyright (c) 2019 Microsoft. + */ + +#ifndef __X86_GUEST_HYPERV_H__ +#define __X86_GUEST_HYPERV_H__ + +#ifdef CONFIG_HYPERV_GUEST + +#include <asm/guest/hypervisor.h> + +const struct hypervisor_ops *hyperv_probe(void); + +#else + +static inline const struct hypervisor_ops *hyperv_probe(void) { return NULL; } + +#endif /* CONFIG_HYPERV_GUEST */ +#endif /* __X86_GUEST_HYPERV_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */
We use the same code structure as we did for Xen. As starters, detect Hyper-V in probe routine. More complex functionalities will be added later. Take the chance to fix XEN_GUEST in Kconfig. Signed-off-by: Wei Liu <liuwe@microsoft.com> --- Changes in V4: 1. Add comment regarding order of probe functions. 2. Adapt to changes in previous patches. --- xen/arch/x86/Kconfig | 11 ++++-- xen/arch/x86/guest/Makefile | 1 + xen/arch/x86/guest/hyperv/Makefile | 1 + xen/arch/x86/guest/hyperv/hyperv.c | 54 ++++++++++++++++++++++++++++++ xen/arch/x86/guest/hypervisor.c | 8 +++++ xen/include/asm-x86/guest.h | 1 + xen/include/asm-x86/guest/hyperv.h | 43 ++++++++++++++++++++++++ 7 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 xen/arch/x86/guest/hyperv/Makefile create mode 100644 xen/arch/x86/guest/hyperv/hyperv.c create mode 100644 xen/include/asm-x86/guest/hyperv.h