diff mbox series

[for-next,v3,5/9] x86: introduce hypervisor framework

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

Commit Message

Wei Liu Oct. 21, 2019, 3:57 p.m. UTC
We 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.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
---
 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

Comments

Paul Durrant Oct. 23, 2019, 8:19 a.m. UTC | #1
On Mon, 21 Oct 2019 at 17:01, Wei Liu <wl@xen.org> wrote:
>
> We 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.
>
> Signed-off-by: Wei Liu <liuwe@microsoft.com>

Reviewed-by: Paul Durrant <paul@xen.org>

> ---
>  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
>
> diff --git a/xen/arch/x86/guest/Makefile b/xen/arch/x86/guest/Makefile
> index 6806f04947..f63d64bbee 100644
> --- a/xen/arch/x86/guest/Makefile
> +++ b/xen/arch/x86/guest/Makefile
> @@ -1 +1,3 @@
> +obj-y += hypervisor.o
> +
>  subdir-$(CONFIG_XEN_GUEST) += xen
> diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c
> new file mode 100644
> index 0000000000..89b9ae4de0
> --- /dev/null
> +++ b/xen/arch/x86/guest/hypervisor.c
> @@ -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:
> + */
> diff --git a/xen/include/asm-x86/guest.h b/xen/include/asm-x86/guest.h
> index a38c6b5b3f..8e167165ae 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/hypervisor.h>
>  #include <asm/guest/pvh-boot.h>
>  #include <asm/guest/xen.h>
>  #include <asm/pv/shim.h>
> diff --git a/xen/include/asm-x86/guest/hypervisor.h b/xen/include/asm-x86/guest/hypervisor.h
> new file mode 100644
> index 0000000000..38344e2e89
> --- /dev/null
> +++ b/xen/include/asm-x86/guest/hypervisor.h
> @@ -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:
> + */
> diff --git a/xen/include/asm-x86/guest/xen.h b/xen/include/asm-x86/guest/xen.h
> index b015ed1883..3145f75361 100644
> --- a/xen/include/asm-x86/guest/xen.h
> +++ b/xen/include/asm-x86/guest/xen.h
> @@ -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
>
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xenproject.org
> https://lists.xenproject.org/mailman/listinfo/xen-devel
Jan Beulich Nov. 15, 2019, 1:48 p.m. UTC | #2
On 21.10.2019 17:57, Wei Liu wrote:
> --- /dev/null
> +++ b/xen/arch/x86/guest/hypervisor.c
> @@ -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;

The __read_mostly wants to again go between type and identifier.

> +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?

> --- /dev/null
> +++ b/xen/include/asm-x86/guest/hypervisor.h
> @@ -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);

None of these fields look to be used, despite ...

> +};
> +
> +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.

> @@ -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
Wei Liu Nov. 21, 2019, 4:27 p.m. UTC | #3
On Fri, Nov 15, 2019 at 02:48:18PM +0100, Jan Beulich wrote:
> On 21.10.2019 17:57, Wei Liu wrote:
> > --- /dev/null
> > +++ b/xen/arch/x86/guest/hypervisor.c
> > @@ -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;
> 
> The __read_mostly wants to again go between type and identifier.

Ack.

> 
> > +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.

[...]
> > @@ -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?

I will add it back to all those stubs.

Wei.

> 
> Jan
diff mbox series

Patch

diff --git a/xen/arch/x86/guest/Makefile b/xen/arch/x86/guest/Makefile
index 6806f04947..f63d64bbee 100644
--- a/xen/arch/x86/guest/Makefile
+++ b/xen/arch/x86/guest/Makefile
@@ -1 +1,3 @@ 
+obj-y += hypervisor.o
+
 subdir-$(CONFIG_XEN_GUEST) += xen
diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c
new file mode 100644
index 0000000000..89b9ae4de0
--- /dev/null
+++ b/xen/arch/x86/guest/hypervisor.c
@@ -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:
+ */
diff --git a/xen/include/asm-x86/guest.h b/xen/include/asm-x86/guest.h
index a38c6b5b3f..8e167165ae 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/hypervisor.h>
 #include <asm/guest/pvh-boot.h>
 #include <asm/guest/xen.h>
 #include <asm/pv/shim.h>
diff --git a/xen/include/asm-x86/guest/hypervisor.h b/xen/include/asm-x86/guest/hypervisor.h
new file mode 100644
index 0000000000..38344e2e89
--- /dev/null
+++ b/xen/include/asm-x86/guest/hypervisor.h
@@ -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:
+ */
diff --git a/xen/include/asm-x86/guest/xen.h b/xen/include/asm-x86/guest/xen.h
index b015ed1883..3145f75361 100644
--- a/xen/include/asm-x86/guest/xen.h
+++ b/xen/include/asm-x86/guest/xen.h
@@ -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__ */