mirror of https://github.com/xemu-project/xemu.git
hyper-v: introduce Hyper-V support infrastructure.
[Jan: fix build with CONFIG_USER_ONLY] Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
This commit is contained in:
parent
8c4ec5c026
commit
28f52cc04d
|
@ -199,6 +199,8 @@ obj-$(CONFIG_NO_KVM) += kvm-stub.o
|
||||||
obj-y += memory.o savevm.o
|
obj-y += memory.o savevm.o
|
||||||
LIBS+=-lz
|
LIBS+=-lz
|
||||||
|
|
||||||
|
obj-i386-y +=hyperv.o
|
||||||
|
|
||||||
QEMU_CFLAGS += $(VNC_TLS_CFLAGS)
|
QEMU_CFLAGS += $(VNC_TLS_CFLAGS)
|
||||||
QEMU_CFLAGS += $(VNC_SASL_CFLAGS)
|
QEMU_CFLAGS += $(VNC_SASL_CFLAGS)
|
||||||
QEMU_CFLAGS += $(VNC_JPEG_CFLAGS)
|
QEMU_CFLAGS += $(VNC_JPEG_CFLAGS)
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
#include "qemu-option.h"
|
#include "qemu-option.h"
|
||||||
#include "qemu-config.h"
|
#include "qemu-config.h"
|
||||||
|
|
||||||
|
#include "hyperv.h"
|
||||||
|
|
||||||
/* feature flags taken from "Intel Processor Identification and the CPUID
|
/* feature flags taken from "Intel Processor Identification and the CPUID
|
||||||
* Instruction" and AMD's "CPUID Specification". In cases of disagreement
|
* Instruction" and AMD's "CPUID Specification". In cases of disagreement
|
||||||
* between feature naming conventions, aliases may be added.
|
* 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;
|
goto error;
|
||||||
}
|
}
|
||||||
x86_cpu_def->tsc_khz = tsc_freq / 1000;
|
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 {
|
} else {
|
||||||
fprintf(stderr, "unrecognized feature %s\n", featurestr);
|
fprintf(stderr, "unrecognized feature %s\n", featurestr);
|
||||||
goto error;
|
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;
|
check_cpuid = 1;
|
||||||
} else if (!strcmp(featurestr, "enforce")) {
|
} else if (!strcmp(featurestr, "enforce")) {
|
||||||
check_cpuid = enforce_cpuid = 1;
|
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 {
|
} else {
|
||||||
fprintf(stderr, "feature string `%s' not in format (+feature|-feature|feature=xyz)\n", featurestr);
|
fprintf(stderr, "feature string `%s' not in format (+feature|-feature|feature=xyz)\n", featurestr);
|
||||||
goto error;
|
goto error;
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -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 */
|
Loading…
Reference in New Issue