diff mbox series

[for-next,RFC,7/8] x86: introduce CONFIG_HYPERV and hyperv directory

Message ID 20190923100931.29670-8-liuwe@microsoft.com (mailing list archive)
State Superseded
Headers show
Series Port Xen to Hyper-V | expand

Commit Message

Wei Liu Sept. 23, 2019, 10:09 a.m. UTC
We use the same code structure as we did for Xen code.

As starters, detect Hyper-V in probe_hyperv. More complex
functionality will be added later.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
---
 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 | 63 ++++++++++++++++++++++++++++++
 xen/arch/x86/guest/hypervisor.c    |  3 +-
 xen/include/asm-x86/guest.h        |  1 +
 xen/include/asm-x86/guest/hyperv.h | 48 +++++++++++++++++++++++
 7 files changed, 125 insertions(+), 1 deletion(-)
 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

Comments

Roger Pau Monné Sept. 25, 2019, 10:48 a.m. UTC | #1
On Mon, Sep 23, 2019 at 11:09:30AM +0100, Wei Liu wrote:
> We use the same code structure as we did for Xen code.
> 
> As starters, detect Hyper-V in probe_hyperv. More complex
> functionality will be added later.
> 
> Signed-off-by: Wei Liu <liuwe@microsoft.com>
> ---
>  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 | 63 ++++++++++++++++++++++++++++++
>  xen/arch/x86/guest/hypervisor.c    |  3 +-
>  xen/include/asm-x86/guest.h        |  1 +
>  xen/include/asm-x86/guest/hyperv.h | 48 +++++++++++++++++++++++
>  7 files changed, 125 insertions(+), 1 deletion(-)
>  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 584bdc1bb8..c5a93babfe 100644
> --- a/xen/arch/x86/Kconfig
> +++ b/xen/arch/x86/Kconfig
> @@ -163,6 +163,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..488e9c14a3
> --- /dev/null
> +++ b/xen/arch/x86/guest/hyperv/hyperv.c
> @@ -0,0 +1,63 @@
> +/******************************************************************************
> + * 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 __read_mostly hyperv_guest;

static?

> +
> +bool __init probe_hyperv(void)
> +{
> +    uint32_t eax, ebx, ecx, edx;
> +
> +    if ( hyperv_guest )
> +        return true;
> +
> +    cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
> +    if ( (ebx == 0x7263694d) && /* "Micr" */
> +         (ecx == 0x666f736f) && /* "osof" */
> +         (edx == 0x76482074) )  /* "t Hv" */
> +        hyperv_guest = true;
> +
> +    return hyperv_guest;
> +}
> +
> +void __init hyperv_setup(void)
> +{
> +}
> +
> +void hyperv_ap_setup(void)
> +{
> +}
> +
> +void hyperv_resume(void)
> +{
> +}

Seems kind of pointless to add those dummy hyperv_ functions, AFAICT
they don't have any callers yet?

I would prefer that you introduce such dummy callers when they are
used.

Thanks, Roger.
Wei Liu Sept. 27, 2019, 11:18 a.m. UTC | #2
On Wed, Sep 25, 2019 at 12:48:42PM +0200, Roger Pau Monné wrote:
> On Mon, Sep 23, 2019 at 11:09:30AM +0100, Wei Liu wrote:
> > We use the same code structure as we did for Xen code.
> > 
> > As starters, detect Hyper-V in probe_hyperv. More complex
> > functionality will be added later.
> > 
> > Signed-off-by: Wei Liu <liuwe@microsoft.com>
> > ---
> >  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 | 63 ++++++++++++++++++++++++++++++
> >  xen/arch/x86/guest/hypervisor.c    |  3 +-
> >  xen/include/asm-x86/guest.h        |  1 +
> >  xen/include/asm-x86/guest/hyperv.h | 48 +++++++++++++++++++++++
> >  7 files changed, 125 insertions(+), 1 deletion(-)
> >  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 584bdc1bb8..c5a93babfe 100644
> > --- a/xen/arch/x86/Kconfig
> > +++ b/xen/arch/x86/Kconfig
> > @@ -163,6 +163,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..488e9c14a3
> > --- /dev/null
> > +++ b/xen/arch/x86/guest/hyperv/hyperv.c
> > @@ -0,0 +1,63 @@
> > +/******************************************************************************
> > + * 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 __read_mostly hyperv_guest;
> 
> static?
> 

I expected this to be referenced elsewhere, hence I made it non-static.

> > +
> > +bool __init probe_hyperv(void)
> > +{
> > +    uint32_t eax, ebx, ecx, edx;
> > +
> > +    if ( hyperv_guest )
> > +        return true;
> > +
> > +    cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
> > +    if ( (ebx == 0x7263694d) && /* "Micr" */
> > +         (ecx == 0x666f736f) && /* "osof" */
> > +         (edx == 0x76482074) )  /* "t Hv" */
> > +        hyperv_guest = true;
> > +
> > +    return hyperv_guest;
> > +}
> > +
> > +void __init hyperv_setup(void)
> > +{
> > +}
> > +
> > +void hyperv_ap_setup(void)
> > +{
> > +}
> > +
> > +void hyperv_resume(void)
> > +{
> > +}
> 
> Seems kind of pointless to add those dummy hyperv_ functions, AFAICT
> they don't have any callers yet?
> 
> I would prefer that you introduce such dummy callers when they are
> used.
> 

No problem.

Wei.

> Thanks, Roger.
diff mbox series

Patch

diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig
index 584bdc1bb8..c5a93babfe 100644
--- a/xen/arch/x86/Kconfig
+++ b/xen/arch/x86/Kconfig
@@ -163,6 +163,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..488e9c14a3
--- /dev/null
+++ b/xen/arch/x86/guest/hyperv/hyperv.c
@@ -0,0 +1,63 @@ 
+/******************************************************************************
+ * 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 __read_mostly hyperv_guest;
+
+bool __init probe_hyperv(void)
+{
+    uint32_t eax, ebx, ecx, edx;
+
+    if ( hyperv_guest )
+        return true;
+
+    cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
+    if ( (ebx == 0x7263694d) && /* "Micr" */
+         (ecx == 0x666f736f) && /* "osof" */
+         (edx == 0x76482074) )  /* "t Hv" */
+        hyperv_guest = true;
+
+    return hyperv_guest;
+}
+
+void __init hyperv_setup(void)
+{
+}
+
+void hyperv_ap_setup(void)
+{
+}
+
+void hyperv_resume(void)
+{
+}
+
+/*
+ * 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 fb572b0402..17d56cd05e 100644
--- a/xen/arch/x86/guest/hypervisor.c
+++ b/xen/arch/x86/guest/hypervisor.c
@@ -37,7 +37,8 @@  void __init probe_hypervisor(void)
     if ( probe_xen() )
         return;
 
-    /* Hyper-V probing to follow. */
+    if ( probe_hyperv() )
+        return;
 }
 
 static void __init init_memmap(void)
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..30e5135a72
--- /dev/null
+++ b/xen/include/asm-x86/guest/hyperv.h
@@ -0,0 +1,48 @@ 
+/******************************************************************************
+ * 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
+
+extern bool hyperv_guest;
+
+bool probe_hyperv(void);
+void hyperv_setup(void);
+void hyperv_ap_setup(void);
+void hyperv_resume(void);
+
+#else
+
+#define hyperv_guest 0
+
+static inline bool probe_hyperv(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:
+ */