From patchwork Sun Oct 23 15:39:48 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vadim Rozenfeld X-Patchwork-Id: 121236 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C0A391007D1 for ; Mon, 24 Oct 2011 02:40:27 +1100 (EST) Received: from localhost ([::1]:58954 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RI09w-0006hA-QW for incoming@patchwork.ozlabs.org; Sun, 23 Oct 2011 11:40:24 -0400 Received: from eggs.gnu.org ([140.186.70.92]:58741) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RI09i-0006W3-KS for qemu-devel@nongnu.org; Sun, 23 Oct 2011 11:40:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RI09g-0006xY-E4 for qemu-devel@nongnu.org; Sun, 23 Oct 2011 11:40:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:28067) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RI09g-0006wS-21 for qemu-devel@nongnu.org; Sun, 23 Oct 2011 11:40:08 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p9NFe2g0018849 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 23 Oct 2011 11:40:07 -0400 Received: from vadimr.dell (vpn-200-236.tlv.redhat.com [10.35.200.236]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p9NFdsR4008413; Sun, 23 Oct 2011 11:39:59 -0400 From: Vadim Rozenfeld To: kvm@vger.kernel.org Date: Sun, 23 Oct 2011 17:39:48 +0200 Message-Id: <1319384389-1389-2-git-send-email-vrozenfe@redhat.com> In-Reply-To: <1319384389-1389-1-git-send-email-vrozenfe@redhat.com> References: <1319384389-1389-1-git-send-email-vrozenfe@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Jan Kiszka , qemu-devel@nongnu.org, Vadim Rozenfeld , Paolo Bonzini , Avi Kivity Subject: [Qemu-devel] [PATCH 1/2] [PATCH RFC v2 1/2] hyper-v: introduce Hyper-V support infrastructure. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org --- Makefile.target | 2 + target-i386/cpuid.c | 14 ++++++++++ target-i386/hyperv.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++ target-i386/hyperv.h | 37 ++++++++++++++++++++++++++++ 4 files changed, 118 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 325f26e..446fabc 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-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 1e8bcff..261c168 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..b2e57ad --- /dev/null +++ b/target-i386/hyperv.c @@ -0,0 +1,65 @@ +/* + * QEMU Hyper-V support + * + * Copyright Red Hat, Inc. 2011 + * + * Author: Vadim Rozenfeld + * + * 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..0d742f8 --- /dev/null +++ b/target-i386/hyperv.h @@ -0,0 +1,37 @@ +/* + * QEMU Hyper-V support + * + * Copyright Red Hat, Inc. 2011 + * + * Author: Vadim Rozenfeld + * + * 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 + +#ifndef HYPERV_SPINLOCK_NEVER_RETRY +#define HYPERV_SPINLOCK_NEVER_RETRY 0xFFFFFFFF +#endif + +#ifndef KVM_CPUID_SIGNATURE_NEXT +#define KVM_CPUID_SIGNATURE_NEXT 0x40000100 +#endif + +void hyperv_enable_vapic_recommended(bool val); +void hyperv_enable_relaxed_timing(bool val); +void hyperv_set_spinlock_retries(int val); + +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 */