qemu/target/i386/kvm
Vitaly Kuznetsov d3177e2e43 target/i386: Make sure SynIC state is really updated before KVM_RUN
'hyperv_synic' test from KVM unittests was observed to be flaky on certain
hardware (hangs sometimes). Debugging shows that the problem happens in
hyperv_sint_route_new() when the test tries to set up a new SynIC
route. The function bails out on:

 if (!synic->sctl_enabled) {
         goto cleanup;
 }

but the test writes to HV_X64_MSR_SCONTROL just before it starts
establishing SINT routes. Further investigation shows that
synic_update() (called from async_synic_update()) happens after the SINT
setup attempt and not before. Apparently, the comment before
async_safe_run_on_cpu() in kvm_hv_handle_exit() does not correctly describe
the guarantees async_safe_run_on_cpu() gives. In particular, async worked
added to a CPU is actually processed from qemu_wait_io_event() which is not
always called before KVM_RUN, i.e. kvm_cpu_exec() checks whether an exit
request is pending for a CPU and if not, keeps running the vCPU until it
meets an exit it can't handle internally. Hyper-V specific MSR writes are
not automatically trigger an exit.

Fix the issue by simply raising an exit request for the vCPU where SynIC
update was queued. This is not a performance critical path as SynIC state
does not get updated so often (and async_safe_run_on_cpu() is a big hammer
anyways).

Reported-by: Jan Richter <jarichte@redhat.com>
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Link: https://lore.kernel.org/r/20240917160051.2637594-4-vkuznets@redhat.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2024-10-17 12:30:21 +02:00
..
hyperv-proto.h i386: Hyper-V Direct TLB flush hypercall 2022-05-25 21:26:35 +02:00
hyperv-stub.c vmbus: Print a warning when enabled without the recommended set of features 2024-03-08 14:18:56 +01:00
hyperv.c target/i386: Make sure SynIC state is really updated before KVM_RUN 2024-10-17 12:30:21 +02:00
hyperv.h vmbus: Print a warning when enabled without the recommended set of features 2024-03-08 14:18:56 +01:00
kvm_i386.h kvm/i386: make kvm_filter_msr() and related definitions private to kvm module 2024-10-02 12:58:46 +02:00
kvm-cpu.c target/i386: pass X86CPU to x86_cpu_get_supported_feature_word 2024-07-03 18:41:26 +02:00
kvm.c target/i386: Exclude 'hv-syndbg' from 'hv-passthrough' 2024-10-17 12:30:21 +02:00
meson.build Add support for RAPL MSRs in KVM/Qemu 2024-07-22 19:19:37 +02:00
trace-events i386/kvm: Add KVM_EXIT_HYPERCALL handling for KVM_HC_MAP_GPA_RANGE 2024-06-05 11:01:06 +02:00
trace.h
vmsr_energy.c kvm/i386: fix return values of is_host_cpu_intel() 2024-10-02 12:58:46 +02:00
vmsr_energy.h Add support for RAPL MSRs in KVM/Qemu 2024-07-22 19:19:37 +02:00
xen-compat.h i386/xen: Implement HYPERVISOR_physdev_op 2023-03-01 09:08:26 +00:00
xen-emu.c hw/i386/fw_cfg: Add etc/e820 to fw_cfg late 2024-07-03 18:14:06 -04:00
xen-emu.h hw/xen: Support HVM_PARAM_CALLBACK_TYPE_GSI callback 2023-03-01 09:06:44 +00:00