Patchwork [RFC,v1,1/2] hyper-v: introduce Hyper-V support infrastructure.

login
register
mail settings
Submitter Vadim Rozenfeld
Date Oct. 17, 2011, 9:17 a.m.
Message ID <1318843022-20344-2-git-send-email-vrozenfe@redhat.com>
Download mbox | patch
Permalink /patch/120116/
State New
Headers show

Comments

Vadim Rozenfeld - Oct. 17, 2011, 9:17 a.m.
with the following series of patches we are starting to implement
some basic Microsoft Hyper-V Enlightenment functionality, like relaxed
timing, spinlock, and virtual apic support.

For more Hyper-V related information please see:
"Hypervisor Functional Specification v2.0: For Windows Server 2008 R2" at
http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=18673
---
 Makefile.target                    |    2 +
 default-configs/i386-softmmu.mak   |    1 +
 default-configs/x86_64-softmmu.mak |    1 +
 target-i386/cpuid.c                |   14 +++++++
 target-i386/hyperv.c               |   69 ++++++++++++++++++++++++++++++++++++
 target-i386/hyperv.h               |   30 +++++++++++++++
 6 files changed, 117 insertions(+), 0 deletions(-)
 create mode 100644 target-i386/hyperv.c
 create mode 100644 target-i386/hyperv.h
Kevin Wolf - Oct. 17, 2011, 9:30 a.m.
Am 17.10.2011 11:17, schrieb Vadim Rozenfeld:
> with the following series of patches we are starting to implement
> some basic Microsoft Hyper-V Enlightenment functionality, like relaxed
> timing, spinlock, and virtual apic support.
> 
> For more Hyper-V related information please see:
> "Hypervisor Functional Specification v2.0: For Windows Server 2008 R2" at
> http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=18673
> ---
>  Makefile.target                    |    2 +
>  default-configs/i386-softmmu.mak   |    1 +
>  default-configs/x86_64-softmmu.mak |    1 +
>  target-i386/cpuid.c                |   14 +++++++
>  target-i386/hyperv.c               |   69 ++++++++++++++++++++++++++++++++++++
>  target-i386/hyperv.h               |   30 +++++++++++++++
>  6 files changed, 117 insertions(+), 0 deletions(-)
>  create mode 100644 target-i386/hyperv.c
>  create mode 100644 target-i386/hyperv.h
> 
> diff --git a/Makefile.target b/Makefile.target
> index 40cc592..2c8e1b8 100644
> --- a/Makefile.target
> +++ b/Makefile.target
> @@ -202,6 +202,8 @@ obj-$(CONFIG_NO_KVM) += kvm-stub.o
>  obj-y += memory.o
>  LIBS+=-lz
>  
> +obj-$(CONFIG_HYPERV) += hyperv.o
> +

The patch doesn't look to me as if it could build successfully without
CONFIG_HYPERV. An option with only one working value seems a bit pointless.

Kevin
Jan Kiszka - Oct. 17, 2011, 9:37 a.m.
On 2011-10-17 11:17, Vadim Rozenfeld wrote:
> with the following series of patches we are starting to implement
> some basic Microsoft Hyper-V Enlightenment functionality, like relaxed
> timing, spinlock, and virtual apic support.
> 
> For more Hyper-V related information please see:
> "Hypervisor Functional Specification v2.0: For Windows Server 2008 R2" at
> http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=18673
> ---
>  Makefile.target                    |    2 +
>  default-configs/i386-softmmu.mak   |    1 +
>  default-configs/x86_64-softmmu.mak |    1 +
>  target-i386/cpuid.c                |   14 +++++++
>  target-i386/hyperv.c               |   69 ++++++++++++++++++++++++++++++++++++
>  target-i386/hyperv.h               |   30 +++++++++++++++
>  6 files changed, 117 insertions(+), 0 deletions(-)
>  create mode 100644 target-i386/hyperv.c
>  create mode 100644 target-i386/hyperv.h
> 
> diff --git a/Makefile.target b/Makefile.target
> index 40cc592..2c8e1b8 100644
> --- a/Makefile.target
> +++ b/Makefile.target
> @@ -202,6 +202,8 @@ obj-$(CONFIG_NO_KVM) += kvm-stub.o
>  obj-y += memory.o
>  LIBS+=-lz
>  
> +obj-$(CONFIG_HYPERV) += hyperv.o

obj-i386-y

> +
>  QEMU_CFLAGS += $(VNC_TLS_CFLAGS)
>  QEMU_CFLAGS += $(VNC_SASL_CFLAGS)
>  QEMU_CFLAGS += $(VNC_JPEG_CFLAGS)
> diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
> index 55589fa..ee69a0a 100644
> --- a/default-configs/i386-softmmu.mak
> +++ b/default-configs/i386-softmmu.mak
> @@ -21,3 +21,4 @@ CONFIG_PIIX_PCI=y
>  CONFIG_SOUND=y
>  CONFIG_HPET=y
>  CONFIG_APPLESMC=y
> +CONFIG_HYPERV=y
> diff --git a/default-configs/x86_64-softmmu.mak b/default-configs/x86_64-softmmu.mak
> index 8895028..35b1c00 100644
> --- a/default-configs/x86_64-softmmu.mak
> +++ b/default-configs/x86_64-softmmu.mak
> @@ -21,3 +21,4 @@ CONFIG_PIIX_PCI=y
>  CONFIG_SOUND=y
>  CONFIG_HPET=y
>  CONFIG_APPLESMC=y
> +CONFIG_HYPERV=y

Useless config options (that do not work anyway as Kevin noted).

> diff --git a/target-i386/cpuid.c b/target-i386/cpuid.c
> index 1e8bcff..50b2d0e 100644
> --- a/target-i386/cpuid.c
> +++ b/target-i386/cpuid.c
> @@ -27,6 +27,8 @@
>  #include "qemu-option.h"
>  #include "qemu-config.h"
>  
> +#include "hyperv.h"
> +
>  /* feature flags taken from "Intel Processor Identification and the CPUID
>   * Instruction" and AMD's "CPUID Specification".  In cases of disagreement
>   * between feature naming conventions, aliases may be added.
> @@ -716,6 +718,14 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model)
>                      goto error;
>                  }
>                  x86_cpu_def->tsc_khz = tsc_freq / 1000;
> +            } else if (!strcmp(featurestr, "hv_spinlocks")) {
> +               char* err;
> +               numvalue = strtoul(val, &err, 0);
> +               if (!*val || *err) {
> +                    fprintf(stderr, "bad numerical value %s\n", val);
> +                    goto error;
> +                }
> +                hyperv_set_spinlock_retries(numvalue);
>              } else {
>                  fprintf(stderr, "unrecognized feature %s\n", featurestr);
>                  goto error;
> @@ -724,6 +734,10 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model)
>              check_cpuid = 1;
>          } else if (!strcmp(featurestr, "enforce")) {
>              check_cpuid = enforce_cpuid = 1;
> +        } else if (!strcmp(featurestr, "hv_relaxed")) {
> +            hyperv_set_relaxed_timing(1);
> +        } else if (!strcmp(featurestr, "hv_vapic")) {
> +            hyperv_set_vapic_recommended(1);            
>          } else {
>              fprintf(stderr, "feature string `%s' not in format (+feature|-feature|feature=xyz)\n", featurestr);
>              goto error;
> diff --git a/target-i386/hyperv.c b/target-i386/hyperv.c
> new file mode 100644
> index 0000000..bed859e
> --- /dev/null
> +++ b/target-i386/hyperv.c
> @@ -0,0 +1,69 @@
> +/*
> + * QEMU Hyper-V support
> + *
> + * Copyright Red Hat, Inc. 2011
> + *
> + * Author: Vadim Rozenfeld     <vrozenfe@redhat.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + *
> + */
> +
> +#include "hyperv.h"
> +
> +static int hyperv_vapic;
> +static int hyperv_relaxed_timing;
> +static int hyperv_spinlock_attempts = HYPERV_SPINLOCK_NEVER_RETRY;
> +
> +void hyperv_set_vapic_recommended(int val)
> +{
> +    hyperv_vapic = val;
> +}
> +
> +void hyperv_set_relaxed_timing(int val)
> +{
> +    hyperv_relaxed_timing = val;
> +}
> +
> +void hyperv_set_spinlock_retries(int val)
> +{
> +    hyperv_spinlock_attempts = val;
> +    if (hyperv_spinlock_attempts < 0xFFF) {
> +        hyperv_spinlock_attempts = 0xFFF;
> +    }
> +}

hyperv_enabled_x(bool enable) would be nicer.

> +
> +int hyperv_enabled(void)
> +{
> +    return hyperv_hypercall_available() || hyperv_get_relaxed_timing();
> +}
> +
> +int hyperv_hypercall_available(void)
> +{
> +    if (hyperv_vapic ||
> +        (hyperv_spinlock_attempts != HYPERV_SPINLOCK_NEVER_RETRY)) {
> +      return 1;
> +    }
> +    return 0;
> +}
> +
> +int hyperv_get_vapic_recommended(void)
> +{
> +#ifdef KVM_CAP_IRQCHIP

This is x86-only code, and x86 supports KVM_CAP_IRQCHIP. So drop this
#ifdef.

> +    return hyperv_vapic;
> +#else
> +    return 0;
> +#endif
> +}
> +
> +int hyperv_get_relaxed_timing(void)
> +{
> +    return hyperv_relaxed_timing;
> +}
> +
> +int hyperv_get_spinlock_retries(void)
> +{
> +    return hyperv_spinlock_attempts;
> +}

bool hyperv_vapic_recommend(void), hyperv_relaxed_timing_enabled etc.
"get" implies to me that there is actual a non-boolean value returned
which is not.

> +
> diff --git a/target-i386/hyperv.h b/target-i386/hyperv.h
> new file mode 100644
> index 0000000..1ea5e99
> --- /dev/null
> +++ b/target-i386/hyperv.h
> @@ -0,0 +1,30 @@
> +/*
> + * QEMU Hyper-V support
> + *
> + * Copyright Red Hat, Inc. 2011
> + *
> + * Author: Vadim Rozenfeld     <vrozenfe@redhat.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + *
> + */
> +
> +#ifndef QEMU_HW_HYPERV_H
> +#define QEMU_HW_HYPERV_H 1
> +
> +#include <asm/hyperv.h>
> +
> +#define HYPERV_SPINLOCK_NEVER_RETRY             0xFFFFFFFF
> +
> +void hyperv_set_vapic_recommended(int val);
> +void hyperv_set_relaxed_timing(int val);
> +void hyperv_set_spinlock_retries(int val);
> +
> +int hyperv_enabled(void);
> +int hyperv_hypercall_available(void);
> +int hyperv_get_vapic_recommended(void);
> +int hyperv_get_relaxed_timing(void);
> +int hyperv_get_spinlock_retries(void);
> +
> +#endif /* QEMU_HW_HYPERV_H */

Looks good otherwise.

Jan

Patch

diff --git a/Makefile.target b/Makefile.target
index 40cc592..2c8e1b8 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -202,6 +202,8 @@  obj-$(CONFIG_NO_KVM) += kvm-stub.o
 obj-y += memory.o
 LIBS+=-lz
 
+obj-$(CONFIG_HYPERV) += hyperv.o
+
 QEMU_CFLAGS += $(VNC_TLS_CFLAGS)
 QEMU_CFLAGS += $(VNC_SASL_CFLAGS)
 QEMU_CFLAGS += $(VNC_JPEG_CFLAGS)
diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
index 55589fa..ee69a0a 100644
--- a/default-configs/i386-softmmu.mak
+++ b/default-configs/i386-softmmu.mak
@@ -21,3 +21,4 @@  CONFIG_PIIX_PCI=y
 CONFIG_SOUND=y
 CONFIG_HPET=y
 CONFIG_APPLESMC=y
+CONFIG_HYPERV=y
diff --git a/default-configs/x86_64-softmmu.mak b/default-configs/x86_64-softmmu.mak
index 8895028..35b1c00 100644
--- a/default-configs/x86_64-softmmu.mak
+++ b/default-configs/x86_64-softmmu.mak
@@ -21,3 +21,4 @@  CONFIG_PIIX_PCI=y
 CONFIG_SOUND=y
 CONFIG_HPET=y
 CONFIG_APPLESMC=y
+CONFIG_HYPERV=y
diff --git a/target-i386/cpuid.c b/target-i386/cpuid.c
index 1e8bcff..50b2d0e 100644
--- a/target-i386/cpuid.c
+++ b/target-i386/cpuid.c
@@ -27,6 +27,8 @@ 
 #include "qemu-option.h"
 #include "qemu-config.h"
 
+#include "hyperv.h"
+
 /* feature flags taken from "Intel Processor Identification and the CPUID
  * Instruction" and AMD's "CPUID Specification".  In cases of disagreement
  * between feature naming conventions, aliases may be added.
@@ -716,6 +718,14 @@  static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model)
                     goto error;
                 }
                 x86_cpu_def->tsc_khz = tsc_freq / 1000;
+            } else if (!strcmp(featurestr, "hv_spinlocks")) {
+               char* err;
+               numvalue = strtoul(val, &err, 0);
+               if (!*val || *err) {
+                    fprintf(stderr, "bad numerical value %s\n", val);
+                    goto error;
+                }
+                hyperv_set_spinlock_retries(numvalue);
             } else {
                 fprintf(stderr, "unrecognized feature %s\n", featurestr);
                 goto error;
@@ -724,6 +734,10 @@  static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model)
             check_cpuid = 1;
         } else if (!strcmp(featurestr, "enforce")) {
             check_cpuid = enforce_cpuid = 1;
+        } else if (!strcmp(featurestr, "hv_relaxed")) {
+            hyperv_set_relaxed_timing(1);
+        } else if (!strcmp(featurestr, "hv_vapic")) {
+            hyperv_set_vapic_recommended(1);            
         } else {
             fprintf(stderr, "feature string `%s' not in format (+feature|-feature|feature=xyz)\n", featurestr);
             goto error;
diff --git a/target-i386/hyperv.c b/target-i386/hyperv.c
new file mode 100644
index 0000000..bed859e
--- /dev/null
+++ b/target-i386/hyperv.c
@@ -0,0 +1,69 @@ 
+/*
+ * QEMU Hyper-V support
+ *
+ * Copyright Red Hat, Inc. 2011
+ *
+ * Author: Vadim Rozenfeld     <vrozenfe@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "hyperv.h"
+
+static int hyperv_vapic;
+static int hyperv_relaxed_timing;
+static int hyperv_spinlock_attempts = HYPERV_SPINLOCK_NEVER_RETRY;
+
+void hyperv_set_vapic_recommended(int val)
+{
+    hyperv_vapic = val;
+}
+
+void hyperv_set_relaxed_timing(int val)
+{
+    hyperv_relaxed_timing = val;
+}
+
+void hyperv_set_spinlock_retries(int val)
+{
+    hyperv_spinlock_attempts = val;
+    if (hyperv_spinlock_attempts < 0xFFF) {
+        hyperv_spinlock_attempts = 0xFFF;
+    }
+}
+
+int hyperv_enabled(void)
+{
+    return hyperv_hypercall_available() || hyperv_get_relaxed_timing();
+}
+
+int hyperv_hypercall_available(void)
+{
+    if (hyperv_vapic ||
+        (hyperv_spinlock_attempts != HYPERV_SPINLOCK_NEVER_RETRY)) {
+      return 1;
+    }
+    return 0;
+}
+
+int hyperv_get_vapic_recommended(void)
+{
+#ifdef KVM_CAP_IRQCHIP
+    return hyperv_vapic;
+#else
+    return 0;
+#endif
+}
+
+int hyperv_get_relaxed_timing(void)
+{
+    return hyperv_relaxed_timing;
+}
+
+int hyperv_get_spinlock_retries(void)
+{
+    return hyperv_spinlock_attempts;
+}
+
diff --git a/target-i386/hyperv.h b/target-i386/hyperv.h
new file mode 100644
index 0000000..1ea5e99
--- /dev/null
+++ b/target-i386/hyperv.h
@@ -0,0 +1,30 @@ 
+/*
+ * QEMU Hyper-V support
+ *
+ * Copyright Red Hat, Inc. 2011
+ *
+ * Author: Vadim Rozenfeld     <vrozenfe@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef QEMU_HW_HYPERV_H
+#define QEMU_HW_HYPERV_H 1
+
+#include <asm/hyperv.h>
+
+#define HYPERV_SPINLOCK_NEVER_RETRY             0xFFFFFFFF
+
+void hyperv_set_vapic_recommended(int val);
+void hyperv_set_relaxed_timing(int val);
+void hyperv_set_spinlock_retries(int val);
+
+int hyperv_enabled(void);
+int hyperv_hypercall_available(void);
+int hyperv_get_vapic_recommended(void);
+int hyperv_get_relaxed_timing(void);
+int hyperv_get_spinlock_retries(void);
+
+#endif /* QEMU_HW_HYPERV_H */