QEMU-4.1 supports 'Direct Mode' for Hyper-V synthetic timers (hv-stimer-direct CPU flag): Windows guests can request that timer expiration notifications are delivered as normal interrupts (and not VMBus messages). This is used by Hyper-V on KVM. Signed-off-by: Vitaly Kuznetsov <vkuznets@xxxxxxxxxx> --- src/qemu/qemu_command.c | 22 ++++++++++++++-- src/qemu/qemu_process.c | 39 +++++++++++++++++++++++++++-- tests/qemuxml2argvdata/hyperv.args | 4 +-- tests/qemuxml2argvdata/hyperv.xml | 4 ++- tests/qemuxml2xmloutdata/hyperv.xml | 4 ++- 5 files changed, 65 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 1cf165079f..12229e879e 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -7096,7 +7096,7 @@ qemuBuildCpuCommandLine(virCommandPtr cmd, int ret = -1; virBuffer cpu_buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER; - size_t i; + size_t i, j; if (def->cpu && (def->cpu->mode != VIR_CPU_MODE_CUSTOM || def->cpu->model)) { @@ -7158,7 +7158,6 @@ qemuBuildCpuCommandLine(virCommandPtr cmd, case VIR_DOMAIN_HYPERV_VPINDEX: case VIR_DOMAIN_HYPERV_RUNTIME: case VIR_DOMAIN_HYPERV_SYNIC: - case VIR_DOMAIN_HYPERV_STIMER: case VIR_DOMAIN_HYPERV_RESET: case VIR_DOMAIN_HYPERV_FREQUENCIES: case VIR_DOMAIN_HYPERV_REENLIGHTENMENT: @@ -7170,6 +7169,25 @@ qemuBuildCpuCommandLine(virCommandPtr cmd, virDomainHypervTypeToString(i)); break; + case VIR_DOMAIN_HYPERV_STIMER: + if (def->hyperv_features[i] == VIR_TRISTATE_SWITCH_ON) + virBufferAsprintf(&buf, ",hv_%s", + virDomainHypervTypeToString(i)); + for (j = 0; j < VIR_DOMAIN_HYPERV_STIMER_LAST; j++) { + switch ((virDomainHypervStimer) j) { + case VIR_DOMAIN_HYPERV_STIMER_DIRECT: + if (def->hyperv_stimer_features[j] == VIR_TRISTATE_SWITCH_ON) + virBufferAsprintf(&buf, ",hv_stimer_%s", + virDomainHypervStimerTypeToString(j)); + break; + + /* coverity[dead_error_begin] */ + case VIR_DOMAIN_HYPERV_STIMER_LAST: + break; + } + } + break; + case VIR_DOMAIN_HYPERV_SPINLOCKS: if (def->hyperv_features[i] == VIR_TRISTATE_SWITCH_ON) virBufferAsprintf(&buf, ",hv_spinlocks=0x%x", diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 75205bc121..0235cfd022 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4111,10 +4111,45 @@ qemuProcessVerifyHypervFeatures(virDomainDefPtr def, rc = virCPUDataCheckFeature(cpu, cpuFeature); VIR_FREE(cpuFeature); - if (rc < 0) + if (rc < 0) { return -1; - else if (rc == 1) + } else if (rc == 1) { + if ((i == VIR_DOMAIN_HYPERV_STIMER)) { + size_t j; + + for (j = 0; j < VIR_DOMAIN_HYPERV_STIMER_LAST; j++) { + switch ((virDomainHypervStimer) j) { + case VIR_DOMAIN_HYPERV_STIMER_DIRECT: + if (def->hyperv_stimer_features[j] != VIR_TRISTATE_SWITCH_ON) + continue; + + if (virAsprintf(&cpuFeature, "__kvm_hv_stimer_%s", + virDomainHypervStimerTypeToString(j)) < 0) + return -1; + + rc = virCPUDataCheckFeature(cpu, cpuFeature); + VIR_FREE(cpuFeature); + + if (rc < 0) + return -1; + else if (rc == 1) + continue; + + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("host doesn't support hyperv stimer '%s' feature"), + virDomainHypervStimerTypeToString(i)); + return -1; + + /* coverity[dead_error_begin] */ + case VIR_DOMAIN_HYPERV_STIMER_LAST: + break; + } + } + + } + continue; + } switch ((virDomainHyperv) i) { case VIR_DOMAIN_HYPERV_RELAXED: diff --git a/tests/qemuxml2argvdata/hyperv.args b/tests/qemuxml2argvdata/hyperv.args index c557b6d8fe..a8f47ebb21 100644 --- a/tests/qemuxml2argvdata/hyperv.args +++ b/tests/qemuxml2argvdata/hyperv.args @@ -12,8 +12,8 @@ QEMU_AUDIO_DRV=none \ -S \ -machine pc,accel=tcg,usb=off,dump-guest-core=off \ -cpu 'qemu32,hv_relaxed,hv_vapic,hv_spinlocks=0x2fff,hv_vpindex,hv_runtime,\ -hv_synic,hv_stimer,hv_reset,hv_vendor_id=KVM Hv,hv_frequencies,\ -hv_reenlightenment,hv_tlbflush,hv_ipi,hv_evmcs' \ +hv_synic,hv_stimer,hv_stimer_direct,hv_reset,hv_vendor_id=KVM Hv,\ +hv_frequencies,hv_reenlightenment,hv_tlbflush,hv_ipi,hv_evmcs' \ -m 214 \ -realtime mlock=off \ -smp 6,sockets=6,cores=1,threads=1 \ diff --git a/tests/qemuxml2argvdata/hyperv.xml b/tests/qemuxml2argvdata/hyperv.xml index c6feaed528..ae0f934f76 100644 --- a/tests/qemuxml2argvdata/hyperv.xml +++ b/tests/qemuxml2argvdata/hyperv.xml @@ -17,7 +17,9 @@ <vpindex state='on'/> <runtime state='on'/> <synic state='on'/> - <stimer state='on'/> + <stimer state='on'> + <direct state='on'/> + </stimer> <reset state='on'/> <vendor_id state='on' value='KVM Hv'/> <frequencies state='on'/> diff --git a/tests/qemuxml2xmloutdata/hyperv.xml b/tests/qemuxml2xmloutdata/hyperv.xml index 5510d3dfad..2e4b43d4c6 100644 --- a/tests/qemuxml2xmloutdata/hyperv.xml +++ b/tests/qemuxml2xmloutdata/hyperv.xml @@ -17,7 +17,9 @@ <vpindex state='on'/> <runtime state='on'/> <synic state='on'/> - <stimer state='on'/> + <stimer state='on'> + <direct state='on'/> + </stimer> <reset state='on'/> <vendor_id state='on' value='KVM Hv'/> <frequencies state='on'/> -- 2.20.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list