We use the same code structure as we did for Xen.
As starters, detect Hyper-V in probe routine. More complex
functionalities will be added later.
Signed-off-by: Wei Liu <liuwe@microsoft.com>
---
V3:
1. Remove some unused code
2. Rename structure
3. Also detect HV#1 signature
---
xen/arch/x86/Kconfig | 9 +++++
xen/arch/x86/guest/Makefile | 1 +
xen/arch/x86/guest/hyperv/Makefile | 1 +
xen/arch/x86/guest/hyperv/hyperv.c | 54 ++++++++++++++++++++++++++++++
xen/arch/x86/guest/hypervisor.c | 8 +++++
xen/include/asm-x86/guest.h | 1 +
xen/include/asm-x86/guest/hyperv.h | 45 +++++++++++++++++++++++++
7 files changed, 119 insertions(+)
create mode 100644 xen/arch/x86/guest/hyperv/Makefile
create mode 100644 xen/arch/x86/guest/hyperv/hyperv.c
create mode 100644 xen/include/asm-x86/guest/hyperv.h
diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig
index 867de857e8..56513c771c 100644
--- a/xen/arch/x86/Kconfig
+++ b/xen/arch/x86/Kconfig
@@ -164,6 +164,15 @@ endchoice
config GUEST
bool
+config HYPERV_GUEST
+ def_bool n
+ select GUEST
+ prompt "Hyper-V Guest"
+ ---help---
+ Support for Xen detecting when it is running under Hyper-V.
+
+ If unsure, say N.
+
config XEN_GUEST
def_bool n
select GUEST
diff --git a/xen/arch/x86/guest/Makefile b/xen/arch/x86/guest/Makefile
index f63d64bbee..f164196772 100644
--- a/xen/arch/x86/guest/Makefile
+++ b/xen/arch/x86/guest/Makefile
@@ -1,3 +1,4 @@
obj-y += hypervisor.o
+subdir-$(CONFIG_HYPERV_GUEST) += hyperv
subdir-$(CONFIG_XEN_GUEST) += xen
diff --git a/xen/arch/x86/guest/hyperv/Makefile b/xen/arch/x86/guest/hyperv/Makefile
new file mode 100644
index 0000000000..68170109a9
--- /dev/null
+++ b/xen/arch/x86/guest/hyperv/Makefile
@@ -0,0 +1 @@
+obj-y += hyperv.o
diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c
new file mode 100644
index 0000000000..7ab4b127f3
--- /dev/null
+++ b/xen/arch/x86/guest/hyperv/hyperv.c
@@ -0,0 +1,54 @@
+/******************************************************************************
+ * arch/x86/guest/hyperv/hyperv.c
+ *
+ * Support for detecting and running under Hyper-V.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (c) 2019 Microsoft.
+ */
+#include <xen/init.h>
+
+#include <asm/guest.h>
+
+bool __init hyperv_probe(void)
+{
+ uint32_t eax, ebx, ecx, edx;
+
+ cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
+ if ( !((ebx == 0x7263694d) && /* "Micr" */
+ (ecx == 0x666f736f) && /* "osof" */
+ (edx == 0x76482074)) ) /* "t Hv" */
+ return false;
+
+ cpuid(0x40000001, &eax, &ebx, &ecx, &edx);
+ if ( eax != 0x31237648 ) /* Hv#1 */
+ return false;
+
+ return true;
+}
+
+struct hypervisor_ops hyperv_ops = {
+ .name = "Hyper-V",
+};
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c
index a666ad9526..17392d1ffa 100644
--- a/xen/arch/x86/guest/hypervisor.c
+++ b/xen/arch/x86/guest/hypervisor.c
@@ -43,6 +43,14 @@ bool hypervisor_probe(void)
}
#endif
+#ifdef CONFIG_HYPERV_GUEST
+ if ( hyperv_probe() )
+ {
+ hops = &hyperv_ops;
+ return true;
+ }
+#endif
+
return false;
}
diff --git a/xen/include/asm-x86/guest.h b/xen/include/asm-x86/guest.h
index 8e167165ae..94448606d4 100644
--- a/xen/include/asm-x86/guest.h
+++ b/xen/include/asm-x86/guest.h
@@ -20,6 +20,7 @@
#define __X86_GUEST_H__
#include <asm/guest/hypercall.h>
+#include <asm/guest/hyperv.h>
#include <asm/guest/hypervisor.h>
#include <asm/guest/pvh-boot.h>
#include <asm/guest/xen.h>
diff --git a/xen/include/asm-x86/guest/hyperv.h b/xen/include/asm-x86/guest/hyperv.h
new file mode 100644
index 0000000000..4b9cc5a836
--- /dev/null
+++ b/xen/include/asm-x86/guest/hyperv.h
@@ -0,0 +1,45 @@
+/******************************************************************************
+ * asm-x86/guest/hyperv.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms and conditions of the GNU General Public
+ * License, version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (c) 2019 Microsoft.
+ */
+
+#ifndef __X86_GUEST_HYPERV_H__
+#define __X86_GUEST_HYPERV_H__
+
+#ifdef CONFIG_HYPERV_GUEST
+
+#include <asm/guest/hypervisor.h>
+
+extern struct hypervisor_ops hyperv_ops;
+
+bool hyperv_probe(void);
+
+#else
+
+static inline bool hyperv_probe(void) { return false; }
+
+#endif /* CONFIG_HYPERV_GUEST */
+#endif /* __X86_GUEST_HYPERV_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
--
2.20.1
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
On Mon, 21 Oct 2019 at 17:01, Wei Liu <wl@xen.org> wrote:
>
> We use the same code structure as we did for Xen.
>
> As starters, detect Hyper-V in probe routine. More complex
> functionalities will be added later.
>
> Signed-off-by: Wei Liu <liuwe@microsoft.com>
Reviewed-by: Paul Durrant <paul@xen.org>
...with one suggestion...
> ---
> V3:
> 1. Remove some unused code
> 2. Rename structure
> 3. Also detect HV#1 signature
> ---
> xen/arch/x86/Kconfig | 9 +++++
> xen/arch/x86/guest/Makefile | 1 +
> xen/arch/x86/guest/hyperv/Makefile | 1 +
> xen/arch/x86/guest/hyperv/hyperv.c | 54 ++++++++++++++++++++++++++++++
> xen/arch/x86/guest/hypervisor.c | 8 +++++
> xen/include/asm-x86/guest.h | 1 +
> xen/include/asm-x86/guest/hyperv.h | 45 +++++++++++++++++++++++++
> 7 files changed, 119 insertions(+)
> create mode 100644 xen/arch/x86/guest/hyperv/Makefile
> create mode 100644 xen/arch/x86/guest/hyperv/hyperv.c
> create mode 100644 xen/include/asm-x86/guest/hyperv.h
>
> diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig
> index 867de857e8..56513c771c 100644
> --- a/xen/arch/x86/Kconfig
> +++ b/xen/arch/x86/Kconfig
> @@ -164,6 +164,15 @@ endchoice
> config GUEST
> bool
>
> +config HYPERV_GUEST
> + def_bool n
> + select GUEST
> + prompt "Hyper-V Guest"
> + ---help---
> + Support for Xen detecting when it is running under Hyper-V.
> +
> + If unsure, say N.
> +
> config XEN_GUEST
> def_bool n
> select GUEST
> diff --git a/xen/arch/x86/guest/Makefile b/xen/arch/x86/guest/Makefile
> index f63d64bbee..f164196772 100644
> --- a/xen/arch/x86/guest/Makefile
> +++ b/xen/arch/x86/guest/Makefile
> @@ -1,3 +1,4 @@
> obj-y += hypervisor.o
>
> +subdir-$(CONFIG_HYPERV_GUEST) += hyperv
> subdir-$(CONFIG_XEN_GUEST) += xen
> diff --git a/xen/arch/x86/guest/hyperv/Makefile b/xen/arch/x86/guest/hyperv/Makefile
> new file mode 100644
> index 0000000000..68170109a9
> --- /dev/null
> +++ b/xen/arch/x86/guest/hyperv/Makefile
> @@ -0,0 +1 @@
> +obj-y += hyperv.o
> diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c
> new file mode 100644
> index 0000000000..7ab4b127f3
> --- /dev/null
> +++ b/xen/arch/x86/guest/hyperv/hyperv.c
> @@ -0,0 +1,54 @@
> +/******************************************************************************
> + * arch/x86/guest/hyperv/hyperv.c
> + *
> + * Support for detecting and running under Hyper-V.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; If not, see <http://www.gnu.org/licenses/>.
> + *
> + * Copyright (c) 2019 Microsoft.
> + */
> +#include <xen/init.h>
> +
> +#include <asm/guest.h>
> +
> +bool __init hyperv_probe(void)
> +{
> + uint32_t eax, ebx, ecx, edx;
> +
> + cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
> + if ( !((ebx == 0x7263694d) && /* "Micr" */
> + (ecx == 0x666f736f) && /* "osof" */
> + (edx == 0x76482074)) ) /* "t Hv" */
> + return false;
> +
> + cpuid(0x40000001, &eax, &ebx, &ecx, &edx);
> + if ( eax != 0x31237648 ) /* Hv#1 */
> + return false;
> +
> + return true;
> +}
> +
> +struct hypervisor_ops hyperv_ops = {
> + .name = "Hyper-V",
> +};
> +
> +/*
> + * Local variables:
> + * mode: C
> + * c-file-style: "BSD"
> + * c-basic-offset: 4
> + * tab-width: 4
> + * indent-tabs-mode: nil
> + * End:
> + */
> diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c
> index a666ad9526..17392d1ffa 100644
> --- a/xen/arch/x86/guest/hypervisor.c
> +++ b/xen/arch/x86/guest/hypervisor.c
> @@ -43,6 +43,14 @@ bool hypervisor_probe(void)
> }
> #endif
>
Add a comment here to point out that hyperv_probe() needs to be called
after xen_probe() to avoid a false positive due to viridian support.
> +#ifdef CONFIG_HYPERV_GUEST
> + if ( hyperv_probe() )
> + {
> + hops = &hyperv_ops;
> + return true;
> + }
> +#endif
> +
> return false;
> }
>
> diff --git a/xen/include/asm-x86/guest.h b/xen/include/asm-x86/guest.h
> index 8e167165ae..94448606d4 100644
> --- a/xen/include/asm-x86/guest.h
> +++ b/xen/include/asm-x86/guest.h
> @@ -20,6 +20,7 @@
> #define __X86_GUEST_H__
>
> #include <asm/guest/hypercall.h>
> +#include <asm/guest/hyperv.h>
> #include <asm/guest/hypervisor.h>
> #include <asm/guest/pvh-boot.h>
> #include <asm/guest/xen.h>
> diff --git a/xen/include/asm-x86/guest/hyperv.h b/xen/include/asm-x86/guest/hyperv.h
> new file mode 100644
> index 0000000000..4b9cc5a836
> --- /dev/null
> +++ b/xen/include/asm-x86/guest/hyperv.h
> @@ -0,0 +1,45 @@
> +/******************************************************************************
> + * asm-x86/guest/hyperv.h
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms and conditions of the GNU General Public
> + * License, version 2, as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + * General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public
> + * License along with this program; If not, see <http://www.gnu.org/licenses/>.
> + *
> + * Copyright (c) 2019 Microsoft.
> + */
> +
> +#ifndef __X86_GUEST_HYPERV_H__
> +#define __X86_GUEST_HYPERV_H__
> +
> +#ifdef CONFIG_HYPERV_GUEST
> +
> +#include <asm/guest/hypervisor.h>
> +
> +extern struct hypervisor_ops hyperv_ops;
> +
> +bool hyperv_probe(void);
> +
> +#else
> +
> +static inline bool hyperv_probe(void) { return false; }
> +
> +#endif /* CONFIG_HYPERV_GUEST */
> +#endif /* __X86_GUEST_HYPERV_H__ */
> +
> +/*
> + * Local variables:
> + * mode: C
> + * c-file-style: "BSD"
> + * c-basic-offset: 4
> + * tab-width: 4
> + * indent-tabs-mode: nil
> + * End:
> + */
> --
> 2.20.1
>
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xenproject.org
> https://lists.xenproject.org/mailman/listinfo/xen-devel
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
On Wed, Oct 23, 2019 at 10:07:24AM +0100, Paul Durrant wrote: > On Mon, 21 Oct 2019 at 17:01, Wei Liu <wl@xen.org> wrote: > > > > We use the same code structure as we did for Xen. > > > > As starters, detect Hyper-V in probe routine. More complex > > functionalities will be added later. > > > > Signed-off-by: Wei Liu <liuwe@microsoft.com> > > Reviewed-by: Paul Durrant <paul@xen.org> Thanks. [...] > > diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c > > index a666ad9526..17392d1ffa 100644 > > --- a/xen/arch/x86/guest/hypervisor.c > > +++ b/xen/arch/x86/guest/hypervisor.c > > @@ -43,6 +43,14 @@ bool hypervisor_probe(void) > > } > > #endif > > > > Add a comment here to point out that hyperv_probe() needs to be called > after xen_probe() to avoid a false positive due to viridian support. > Yes I can do that. Wei. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel
On 21.10.2019 17:57, Wei Liu wrote:
> --- a/xen/arch/x86/Kconfig
> +++ b/xen/arch/x86/Kconfig
> @@ -164,6 +164,15 @@ endchoice
> config GUEST
> bool
>
> +config HYPERV_GUEST
> + def_bool n
> + select GUEST
> + prompt "Hyper-V Guest"
Please can you avoid following the bad example XEN_GUEST gives (and
perhaps even take the opportunity here or in the earlier patch
adding GUEST to change that one as well)? What you want is
config HYPERV_GUEST
bool "Hyper-V Guest"
select GUEST
> --- /dev/null
> +++ b/xen/arch/x86/guest/hyperv/hyperv.c
> @@ -0,0 +1,54 @@
> +/******************************************************************************
> + * arch/x86/guest/hyperv/hyperv.c
> + *
> + * Support for detecting and running under Hyper-V.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; If not, see <http://www.gnu.org/licenses/>.
> + *
> + * Copyright (c) 2019 Microsoft.
> + */
> +#include <xen/init.h>
> +
> +#include <asm/guest.h>
> +
> +bool __init hyperv_probe(void)
> +{
> + uint32_t eax, ebx, ecx, edx;
> +
> + cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
> + if ( !((ebx == 0x7263694d) && /* "Micr" */
> + (ecx == 0x666f736f) && /* "osof" */
> + (edx == 0x76482074)) ) /* "t Hv" */
> + return false;
> +
> + cpuid(0x40000001, &eax, &ebx, &ecx, &edx);
> + if ( eax != 0x31237648 ) /* Hv#1 */
> + return false;
> +
> + return true;
> +}
> +
> +struct hypervisor_ops hyperv_ops = {
const again.
> --- a/xen/arch/x86/guest/hypervisor.c
> +++ b/xen/arch/x86/guest/hypervisor.c
> @@ -43,6 +43,14 @@ bool hypervisor_probe(void)
> }
> #endif
>
> +#ifdef CONFIG_HYPERV_GUEST
> + if ( hyperv_probe() )
> + {
> + hops = &hyperv_ops;
> + return true;
> + }
> +#endif
This recurring #ifdef CONFIG_*_GUEST is going to start looking ugly
the latest when one or two more get added. Perhaps better providing
*_probe() stubs returning false, and (like we do elsewhere) rely on
DCE to get rid of the *_ops reference? (And really you already have
such a stub - all you need to do is put the hyperv_ops declaration
outside the #ifdef (but read on).
Also how about having *_probe() return the address of *_ops, such
that the latter could all become static?
Jan
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
On Fri, Nov 15, 2019 at 03:07:29PM +0100, Jan Beulich wrote:
> On 21.10.2019 17:57, Wei Liu wrote:
> > --- a/xen/arch/x86/Kconfig
> > +++ b/xen/arch/x86/Kconfig
> > @@ -164,6 +164,15 @@ endchoice
> > config GUEST
> > bool
> >
> > +config HYPERV_GUEST
> > + def_bool n
> > + select GUEST
> > + prompt "Hyper-V Guest"
>
> Please can you avoid following the bad example XEN_GUEST gives (and
> perhaps even take the opportunity here or in the earlier patch
> adding GUEST to change that one as well)? What you want is
>
> config HYPERV_GUEST
> bool "Hyper-V Guest"
> select GUEST
Ack.
>
> > --- /dev/null
> > +++ b/xen/arch/x86/guest/hyperv/hyperv.c
> > @@ -0,0 +1,54 @@
> > +/******************************************************************************
> > + * arch/x86/guest/hyperv/hyperv.c
> > + *
> > + * Support for detecting and running under Hyper-V.
> > + *
> > + * This program is free software; you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License as published by
> > + * the Free Software Foundation; either version 2 of the License, or
> > + * (at your option) any later version.
> > + *
> > + * This program is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> > + * GNU General Public License for more details.
> > + *
> > + * You should have received a copy of the GNU General Public License
> > + * along with this program; If not, see <http://www.gnu.org/licenses/>.
> > + *
> > + * Copyright (c) 2019 Microsoft.
> > + */
> > +#include <xen/init.h>
> > +
> > +#include <asm/guest.h>
> > +
> > +bool __init hyperv_probe(void)
> > +{
> > + uint32_t eax, ebx, ecx, edx;
> > +
> > + cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
> > + if ( !((ebx == 0x7263694d) && /* "Micr" */
> > + (ecx == 0x666f736f) && /* "osof" */
> > + (edx == 0x76482074)) ) /* "t Hv" */
> > + return false;
> > +
> > + cpuid(0x40000001, &eax, &ebx, &ecx, &edx);
> > + if ( eax != 0x31237648 ) /* Hv#1 */
> > + return false;
> > +
> > + return true;
> > +}
> > +
> > +struct hypervisor_ops hyperv_ops = {
>
> const again.
>
> > --- a/xen/arch/x86/guest/hypervisor.c
> > +++ b/xen/arch/x86/guest/hypervisor.c
> > @@ -43,6 +43,14 @@ bool hypervisor_probe(void)
> > }
> > #endif
> >
> > +#ifdef CONFIG_HYPERV_GUEST
> > + if ( hyperv_probe() )
> > + {
> > + hops = &hyperv_ops;
> > + return true;
> > + }
> > +#endif
>
> This recurring #ifdef CONFIG_*_GUEST is going to start looking ugly
> the latest when one or two more get added. Perhaps better providing
> *_probe() stubs returning false, and (like we do elsewhere) rely on
> DCE to get rid of the *_ops reference? (And really you already have
> such a stub - all you need to do is put the hyperv_ops declaration
> outside the #ifdef (but read on).
>
> Also how about having *_probe() return the address of *_ops, such
> that the latter could all become static?
Previously you made a suggestion to make probe return the name of the
hypervisor. Here you ask for address of ops. I actually prefer the
method suggested here, but this means I will need to keep
hypervisor_name around.
Wei.
>
> Jan
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
On 21.11.2019 17:27, Wei Liu wrote:
> On Fri, Nov 15, 2019 at 03:07:29PM +0100, Jan Beulich wrote:
>> On 21.10.2019 17:57, Wei Liu wrote:
>>> --- a/xen/arch/x86/Kconfig
>>> +++ b/xen/arch/x86/Kconfig
>>> @@ -164,6 +164,15 @@ endchoice
>>> config GUEST
>>> bool
>>>
>>> +config HYPERV_GUEST
>>> + def_bool n
>>> + select GUEST
>>> + prompt "Hyper-V Guest"
>>
>> Please can you avoid following the bad example XEN_GUEST gives (and
>> perhaps even take the opportunity here or in the earlier patch
>> adding GUEST to change that one as well)? What you want is
>>
>> config HYPERV_GUEST
>> bool "Hyper-V Guest"
>> select GUEST
>
> Ack.
>
>>
>>> --- /dev/null
>>> +++ b/xen/arch/x86/guest/hyperv/hyperv.c
>>> @@ -0,0 +1,54 @@
>>> +/******************************************************************************
>>> + * arch/x86/guest/hyperv/hyperv.c
>>> + *
>>> + * Support for detecting and running under Hyper-V.
>>> + *
>>> + * This program is free software; you can redistribute it and/or modify
>>> + * it under the terms of the GNU General Public License as published by
>>> + * the Free Software Foundation; either version 2 of the License, or
>>> + * (at your option) any later version.
>>> + *
>>> + * This program is distributed in the hope that it will be useful,
>>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>>> + * GNU General Public License for more details.
>>> + *
>>> + * You should have received a copy of the GNU General Public License
>>> + * along with this program; If not, see <http://www.gnu.org/licenses/>.
>>> + *
>>> + * Copyright (c) 2019 Microsoft.
>>> + */
>>> +#include <xen/init.h>
>>> +
>>> +#include <asm/guest.h>
>>> +
>>> +bool __init hyperv_probe(void)
>>> +{
>>> + uint32_t eax, ebx, ecx, edx;
>>> +
>>> + cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
>>> + if ( !((ebx == 0x7263694d) && /* "Micr" */
>>> + (ecx == 0x666f736f) && /* "osof" */
>>> + (edx == 0x76482074)) ) /* "t Hv" */
>>> + return false;
>>> +
>>> + cpuid(0x40000001, &eax, &ebx, &ecx, &edx);
>>> + if ( eax != 0x31237648 ) /* Hv#1 */
>>> + return false;
>>> +
>>> + return true;
>>> +}
>>> +
>>> +struct hypervisor_ops hyperv_ops = {
>>
>> const again.
>>
>>> --- a/xen/arch/x86/guest/hypervisor.c
>>> +++ b/xen/arch/x86/guest/hypervisor.c
>>> @@ -43,6 +43,14 @@ bool hypervisor_probe(void)
>>> }
>>> #endif
>>>
>>> +#ifdef CONFIG_HYPERV_GUEST
>>> + if ( hyperv_probe() )
>>> + {
>>> + hops = &hyperv_ops;
>>> + return true;
>>> + }
>>> +#endif
>>
>> This recurring #ifdef CONFIG_*_GUEST is going to start looking ugly
>> the latest when one or two more get added. Perhaps better providing
>> *_probe() stubs returning false, and (like we do elsewhere) rely on
>> DCE to get rid of the *_ops reference? (And really you already have
>> such a stub - all you need to do is put the hyperv_ops declaration
>> outside the #ifdef (but read on).
>>
>> Also how about having *_probe() return the address of *_ops, such
>> that the latter could all become static?
>
> Previously you made a suggestion to make probe return the name of the
> hypervisor. Here you ask for address of ops. I actually prefer the
> method suggested here, but this means I will need to keep
> hypervisor_name around.
Is there actually any user of the name field other than the caller
of probe? If not, surely that caller could access the name field
without a hypervisor_name() wrapper.
Jan
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
On Thu, Nov 21, 2019 at 05:59:16PM +0100, Jan Beulich wrote: > >> > >> Also how about having *_probe() return the address of *_ops, such > >> that the latter could all become static? > > > > Previously you made a suggestion to make probe return the name of the > > hypervisor. Here you ask for address of ops. I actually prefer the > > method suggested here, but this means I will need to keep > > hypervisor_name around. > > Is there actually any user of the name field other than the caller > of probe? If not, surely that caller could access the name field > without a hypervisor_name() wrapper. I don't envision more users at this stage. I'm fine with accessing that field directly. We can always introduce the function again if it becomes necessary. Wei. > > Jan _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel
© 2016 - 2026 Red Hat, Inc.