[QEMU PATCH] i386/kvm: add support for Direct Mode for Hyper-V synthetic timers
From: Vitaly Kuznetsov
Date: Tue Nov 13 2018 - 10:22:40 EST
Signed-off-by: Vitaly Kuznetsov <vkuznets@xxxxxxxxxx>
---
linux-headers/linux/kvm.h | 1 +
target/i386/cpu.c | 1 +
target/i386/cpu.h | 1 +
target/i386/hyperv-proto.h | 1 +
target/i386/kvm.c | 11 +++++++++++
5 files changed, 15 insertions(+)
diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
index f11a7eb49c..43fb240b60 100644
--- a/linux-headers/linux/kvm.h
+++ b/linux-headers/linux/kvm.h
@@ -965,6 +965,7 @@ struct kvm_ppc_resize_hpt {
#define KVM_CAP_COALESCED_PIO 162
#define KVM_CAP_HYPERV_ENLIGHTENED_VMCS 163
#define KVM_CAP_EXCEPTION_PAYLOAD 164
+#define KVM_CAP_HYPERV_STIMER_DIRECT 166
#ifdef KVM_CAP_IRQ_ROUTING
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index af7e9f09cc..cd42fb81dd 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -5733,6 +5733,7 @@ static Property x86_cpu_properties[] = {
DEFINE_PROP_BOOL("hv-reenlightenment", X86CPU, hyperv_reenlightenment, false),
DEFINE_PROP_BOOL("hv-tlbflush", X86CPU, hyperv_tlbflush, false),
DEFINE_PROP_BOOL("hv-ipi", X86CPU, hyperv_ipi, false),
+ DEFINE_PROP_BOOL("hv-stimer-direct", X86CPU, hyperv_stimer_direct, false),
DEFINE_PROP_BOOL("check", X86CPU, check_cpuid, true),
DEFINE_PROP_BOOL("enforce", X86CPU, enforce_cpuid, false),
DEFINE_PROP_BOOL("kvm", X86CPU, expose_kvm, true),
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index ad0e0b4534..a3d7cac8be 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -1392,6 +1392,7 @@ struct X86CPU {
bool hyperv_reenlightenment;
bool hyperv_tlbflush;
bool hyperv_ipi;
+ bool hyperv_stimer_direct;
bool check_cpuid;
bool enforce_cpuid;
bool expose_kvm;
diff --git a/target/i386/hyperv-proto.h b/target/i386/hyperv-proto.h
index 8c572cd7c2..4543112cf5 100644
--- a/target/i386/hyperv-proto.h
+++ b/target/i386/hyperv-proto.h
@@ -48,6 +48,7 @@
#define HV_GUEST_IDLE_STATE_AVAILABLE (1u << 5)
#define HV_FREQUENCY_MSRS_AVAILABLE (1u << 8)
#define HV_GUEST_CRASH_MSR_AVAILABLE (1u << 10)
+#define HV_STIMER_DIRECT_MODE_AVAILABLE (1u << 19)
/*
* HV_CPUID_ENLIGHTMENT_INFO.EAX bits
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
index 796a049a0d..f12321e0f7 100644
--- a/target/i386/kvm.c
+++ b/target/i386/kvm.c
@@ -797,6 +797,17 @@ static int hyperv_handle_properties(CPUState *cs)
}
env->features[FEAT_HYPERV_EAX] |= HV_SYNTIMERS_AVAILABLE;
}
+ if (cpu->hyperv_stimer_direct) {
+ if (kvm_check_extension(cs->kvm_state,
+ KVM_CAP_HYPERV_STIMER_DIRECT) <= 0) {
+ fprintf(stderr, "Hyper-V timers direct mode "
+ "(requested by 'hv-stimer-direct' cpu flag) "
+ " is not supported by kernel\n");
+ return -ENOSYS;
+ }
+ env->features[FEAT_HYPERV_EDX] |= HV_STIMER_DIRECT_MODE_AVAILABLE;
+ }
+
return 0;
}
--
2.17.2