qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Marcelo Tosatti <mtosatti@redhat.com>, gleb@redhat.com
Cc: Anthony Liguori <aliguori@us.ibm.com>,
	qemu-devel@nongnu.org, kvm@vger.kernel.org,
	Vadim Rozenfeld <vrozenfe@redhat.com>
Subject: [Qemu-devel] kvm: let's add HYPERV capabilities (was Re: [PATCH 01/20] hyper-v: introduce Hyper-V support infrastructure.)
Date: Wed, 28 Nov 2012 16:39:06 +0200	[thread overview]
Message-ID: <20121128134232.GB17196@redhat.com> (raw)
In-Reply-To: <28f52cc04d341045e810bd487a478fa9ec5f40be.1327080406.git.mtosatti@redhat.com>

On Fri, Jan 20, 2012 at 03:26:27PM -0200, Marcelo Tosatti wrote:
> From: Vadim Rozenfeld <vrozenfe@redhat.com>
> 
> [Jan: fix build with CONFIG_USER_ONLY]
> 
> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
> ---
>  Makefile.target      |    2 +
>  target-i386/cpuid.c  |   14 +++++++++++
>  target-i386/hyperv.c |   64 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  target-i386/hyperv.h |   43 +++++++++++++++++++++++++++++++++
>  4 files changed, 123 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 06d79b8..798dd30 100644
> --- a/Makefile.target
> +++ b/Makefile.target
> @@ -199,6 +199,8 @@ obj-$(CONFIG_NO_KVM) += kvm-stub.o
>  obj-y += memory.o savevm.o
>  LIBS+=-lz
>  
> +obj-i386-y +=hyperv.o
> +
>  QEMU_CFLAGS += $(VNC_TLS_CFLAGS)
>  QEMU_CFLAGS += $(VNC_SASL_CFLAGS)
>  QEMU_CFLAGS += $(VNC_JPEG_CFLAGS)
> diff --git a/target-i386/cpuid.c b/target-i386/cpuid.c
> index 91a104b..b9bfeaf 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_enable_relaxed_timing(true);
> +        } else if (!strcmp(featurestr, "hv_vapic")) {
> +            hyperv_enable_vapic_recommended(true);
>          } 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..f284e99
> --- /dev/null
> +++ b/target-i386/hyperv.c
> @@ -0,0 +1,64 @@
> +/*
> + * 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 bool hyperv_vapic;
> +static bool hyperv_relaxed_timing;
> +static int hyperv_spinlock_attempts = HYPERV_SPINLOCK_NEVER_RETRY;
> +
> +void hyperv_enable_vapic_recommended(bool val)
> +{
> +    hyperv_vapic = val;
> +}
> +
> +void hyperv_enable_relaxed_timing(bool 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;
> +    }
> +}
> +
> +bool hyperv_enabled(void)
> +{
> +    return hyperv_hypercall_available() || hyperv_relaxed_timing_enabled();
> +}
> +
> +bool hyperv_hypercall_available(void)
> +{
> +    if (hyperv_vapic ||
> +        (hyperv_spinlock_attempts != HYPERV_SPINLOCK_NEVER_RETRY)) {
> +      return true;
> +    }
> +    return false;
> +}
> +
> +bool hyperv_vapic_recommended(void)
> +{
> +    return hyperv_vapic;
> +}
> +
> +bool hyperv_relaxed_timing_enabled(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..15467bf
> --- /dev/null
> +++ b/target-i386/hyperv.h
> @@ -0,0 +1,43 @@
> +/*
> + * 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 "qemu-common.h"
> +#include <asm/hyperv.h>
> +
> +#ifndef HYPERV_SPINLOCK_NEVER_RETRY
> +#define HYPERV_SPINLOCK_NEVER_RETRY             0xFFFFFFFF
> +#endif
> +
> +#ifndef KVM_CPUID_SIGNATURE_NEXT
> +#define KVM_CPUID_SIGNATURE_NEXT                0x40000100
> +#endif
> +
> +#ifndef CONFIG_USER_ONLY
> +void hyperv_enable_vapic_recommended(bool val);
> +void hyperv_enable_relaxed_timing(bool val);
> +void hyperv_set_spinlock_retries(int val);
> +#else
> +static inline void hyperv_enable_vapic_recommended(bool val) { }
> +static inline void hyperv_enable_relaxed_timing(bool val) { }
> +static inline void hyperv_set_spinlock_retries(int val) { }
> +#endif
> +
> +bool hyperv_enabled(void);
> +bool hyperv_hypercall_available(void);
> +bool hyperv_vapic_recommended(void);
> +bool hyperv_relaxed_timing_enabled(void);
> +int hyperv_get_spinlock_retries(void);
> +
> +#endif /* QEMU_HW_HYPERV_H */
> -- 
> 1.7.6.4


So basically, this means that you enable hyperv
features unconditionally when user requests them.
If you run qemu on an old kernel without hyperv support and request
hyperv features through flags, guest will crash.

This is not a friendly way to do this.

Linux currently exposes:

linux-headers/linux/kvm.h:#define KVM_CAP_HYPERV 44
linux-headers/linux/kvm.h:#define KVM_CAP_HYPERV_VAPIC 45
linux-headers/linux/kvm.h:#define KVM_CAP_HYPERV_SPIN 46

I think qemu should be fixed to check the appropriate
capability before enabling features:
KVM_CAP_HYPERV for relaxed
KVM_CAP_HYPERV_VAPIC for vapic
KVM_CAP_HYPERV_SPIN for spinlocks

As we will add more features we will have to add more
capabilities.
Are there any features implemented now that lack a
capability? It doesn't look like there are any ...


> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2012-11-28 14:36 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-20 17:26 [Qemu-devel] [PATCH 00/20] [PULL] qemu-kvm.git uq/master queue Marcelo Tosatti
2012-01-20 17:26 ` [Qemu-devel] [PATCH 01/20] hyper-v: introduce Hyper-V support infrastructure Marcelo Tosatti
2012-11-28 14:39   ` Michael S. Tsirkin [this message]
2012-01-20 17:26 ` [Qemu-devel] [PATCH 02/20] hyper-v: initialize Hyper-V CPUID leaves Marcelo Tosatti
2012-01-20 17:26 ` [Qemu-devel] [PATCH 03/20] msi: Generalize msix_supported to msi_supported Marcelo Tosatti
2012-01-20 17:26 ` [Qemu-devel] [PATCH 04/20] kvm: Move kvmclock into hw/kvm folder Marcelo Tosatti
2012-01-20 17:26 ` [Qemu-devel] [PATCH 05/20] apic: Stop timer on reset Marcelo Tosatti
2012-01-20 17:26 ` [Qemu-devel] [PATCH 06/20] apic: Inject external NMI events via LINT1 Marcelo Tosatti
2012-01-20 17:26 ` [Qemu-devel] [PATCH 07/20] apic: Introduce apic_report_irq_delivered Marcelo Tosatti
2012-01-20 17:26 ` [Qemu-devel] [PATCH 08/20] apic: Factor out base class for KVM reuse Marcelo Tosatti
2012-01-20 17:26 ` [Qemu-devel] [PATCH 09/20] apic: Open-code timer save/restore Marcelo Tosatti
2012-01-20 17:26 ` [Qemu-devel] [PATCH 10/20] i8259: Completely privatize PicState Marcelo Tosatti
2012-01-20 17:26 ` [Qemu-devel] [PATCH 11/20] i8259: Factor out base class for KVM reuse Marcelo Tosatti
2012-01-20 17:26 ` [Qemu-devel] [PATCH 12/20] ioapic: Drop post-load irr initialization Marcelo Tosatti
2012-01-20 17:26 ` [Qemu-devel] [PATCH 13/20] ioapic: Factor out base class for KVM reuse Marcelo Tosatti
2012-01-20 17:26 ` [Qemu-devel] [PATCH 14/20] memory: Introduce memory_region_init_reservation Marcelo Tosatti
2012-01-20 17:26 ` [Qemu-devel] [PATCH 15/20] kvm: Introduce core services for in-kernel irqchip support Marcelo Tosatti
2012-01-20 17:26 ` [Qemu-devel] [PATCH 16/20] kvm: x86: Establish IRQ0 override control Marcelo Tosatti
2012-01-20 17:26 ` [Qemu-devel] [PATCH 17/20] kvm: x86: Add user space part for in-kernel APIC Marcelo Tosatti
2012-01-20 17:26 ` [Qemu-devel] [PATCH 18/20] kvm: x86: Add user space part for in-kernel i8259 Marcelo Tosatti
2012-01-20 17:26 ` [Qemu-devel] [PATCH 19/20] kvm: x86: Add user space part for in-kernel IOAPIC Marcelo Tosatti
2012-01-20 17:26 ` [Qemu-devel] [PATCH 20/20] kvm: Activate in-kernel irqchip support Marcelo Tosatti
2012-01-23 17:44 ` [Qemu-devel] [PATCH 00/20] [PULL] qemu-kvm.git uq/master queue Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20121128134232.GB17196@redhat.com \
    --to=mst@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=gleb@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=vrozenfe@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).