qemu/target/i386/kvm
donsheng 285cef5c39 target-i386: hyper-v: Correct kvm_hv_handle_exit return value
This bug fix addresses the incorrect return value of kvm_hv_handle_exit for
KVM_EXIT_HYPERV_SYNIC, which should be EXCP_INTERRUPT.

Handling of KVM_EXIT_HYPERV_SYNIC in QEMU needs to be synchronous.
This means that async_synic_update should run in the current QEMU vCPU
thread before returning to KVM, returning EXCP_INTERRUPT to guarantee this.
Returning 0 can cause async_synic_update to run asynchronously.

One problem (kvm-unit-tests's hyperv_synic test fails with timeout error)
caused by this bug:

When a guest VM writes to the HV_X64_MSR_SCONTROL MSR to enable Hyper-V SynIC,
a VM exit is triggered and processed by the kvm_hv_handle_exit function of the
QEMU vCPU. This function then calls the async_synic_update function to set
synic->sctl_enabled to true. A true value of synic->sctl_enabled is required
before creating SINT routes using the hyperv_sint_route_new() function.

If kvm_hv_handle_exit returns 0 for KVM_EXIT_HYPERV_SYNIC, the current QEMU
vCPU thread may return to KVM and enter the guest VM before running
async_synic_update. In such case, the hyperv_synic test’s subsequent call to
synic_ctl(HV_TEST_DEV_SINT_ROUTE_CREATE, ...) immediately after writing to
HV_X64_MSR_SCONTROL can cause QEMU’s hyperv_sint_route_new() function to return
prematurely (because synic->sctl_enabled is false).

If the SINT route is not created successfully, the SINT interrupt will not be
fired, resulting in a timeout error in the hyperv_synic test.

Fixes: 267e071bd6 (“hyperv: make overlay pages for SynIC”)
Suggested-by: Chao Gao <chao.gao@intel.com>
Signed-off-by: Dongsheng Zhang <dongsheng.x.zhang@intel.com>
Message-ID: <20240521200114.11588-1-dongsheng.x.zhang@intel.com>
Cc: qemu-stable@nongnu.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit 84d4b72854)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
2024-05-27 07:37:34 +03: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: hyper-v: Correct kvm_hv_handle_exit return value 2024-05-27 07:37:34 +03: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: i8254: require KVM_CAP_PIT2 and KVM_CAP_PIT_STATE2 2023-10-25 19:53:38 +02:00
kvm-cpu.c target/i386/kvm: Correct comment in kvm_cpu_realize() 2023-11-07 12:13:27 +01:00
kvm-cpu.h i386: split cpu accelerators from cpu.c, using AccelCPUClass 2021-05-10 15:41:49 -04:00
kvm.c vmbus: Print a warning when enabled without the recommended set of features 2024-03-08 14:18:56 +01:00
meson.build target/i386: Rename i386_softmmu_kvm_ss -> i386_kvm_ss 2023-10-07 19:02:59 +02:00
sev-stub.c Remove qemu-common.h include from most units 2022-04-06 14:31:55 +02:00
trace-events i386/xen: implement HVMOP_set_evtchn_upcall_vector 2023-03-01 08:22:50 +00:00
trace.h
xen-compat.h i386/xen: Implement HYPERVISOR_physdev_op 2023-03-01 09:08:26 +00:00
xen-emu.c qemu/main-loop: rename QEMU_IOTHREAD_LOCK_GUARD to BQL_LOCK_GUARD 2024-01-08 10:45:43 -05:00
xen-emu.h hw/xen: Support HVM_PARAM_CALLBACK_TYPE_GSI callback 2023-03-01 09:06:44 +00:00