OpenCloudOS-Kernel/arch/x86/kvm/vmx
Haitao Shan 7de33b0fc9 KVM: x86: Fix lapic timer interrupt lost after loading a snapshot.
commit 9cfec6d097c607e36199cf0cfbb8cf5acbd8e9b2 upstream.

When running android emulator (which is based on QEMU 2.12) on
certain Intel hosts with kernel version 6.3-rc1 or above, guest
will freeze after loading a snapshot. This is almost 100%
reproducible. By default, the android emulator will use snapshot
to speed up the next launching of the same android guest. So
this breaks the android emulator badly.

I tested QEMU 8.0.4 from Debian 12 with an Ubuntu 22.04 guest by
running command "loadvm" after "savevm". The same issue is
observed. At the same time, none of our AMD platforms is impacted.
More experiments show that loading the KVM module with
"enable_apicv=false" can workaround it.

The issue started to show up after commit 8e6ed96cdd ("KVM: x86:
fire timer when it is migrated and expired, and in oneshot mode").
However, as is pointed out by Sean Christopherson, it is introduced
by commit 967235d320 ("KVM: vmx: clear pending interrupts on
KVM_SET_LAPIC"). commit 8e6ed96cdd ("KVM: x86: fire timer when
it is migrated and expired, and in oneshot mode") just makes it
easier to hit the issue.

Having both commits, the oneshot lapic timer gets fired immediately
inside the KVM_SET_LAPIC call when loading the snapshot. On Intel
platforms with APIC virtualization and posted interrupt processing,
this eventually leads to setting the corresponding PIR bit. However,
the whole PIR bits get cleared later in the same KVM_SET_LAPIC call
by apicv_post_state_restore. This leads to timer interrupt lost.

The fix is to move vmx_apicv_post_state_restore to the beginning of
the KVM_SET_LAPIC call and rename to vmx_apicv_pre_state_restore.
What vmx_apicv_post_state_restore does is actually clearing any
former apicv state and this behavior is more suitable to carry out
in the beginning.

Fixes: 967235d320 ("KVM: vmx: clear pending interrupts on KVM_SET_LAPIC")
Cc: stable@vger.kernel.org
Suggested-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Haitao Shan <hshan@google.com>
Link: https://lore.kernel.org/r/20230913000215.478387-1-hshan@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-11-28 17:19:56 +00:00
..
capabilities.h KVM: VMX: Rename XSAVES control to follow KVM's preferred "ENABLE_XYZ" 2023-08-17 11:38:28 -07:00
hyperv.c KVM: VMX: Rename XSAVES control to follow KVM's preferred "ENABLE_XYZ" 2023-08-17 11:38:28 -07:00
hyperv.h KVM: VMX: Rename "KVM is using eVMCS" static key to match its wrapper 2023-03-14 10:28:58 -04:00
nested.c KVM: nVMX: Use KVM-governed feature framework to track "nested VMX enabled" 2023-08-17 11:40:55 -07:00
nested.h KVM: VMX: Rename XSAVES control to follow KVM's preferred "ENABLE_XYZ" 2023-08-17 11:38:28 -07:00
pmu_intel.c KVM: x86/pmu: Truncate counter value to allowed width on write 2023-09-25 14:30:44 -07:00
posted_intr.c x86/apic: Wrap IPI calls into helper functions 2023-08-09 12:00:55 -07:00
posted_intr.h KVM: VMX: enable IPI virtualization 2022-06-08 04:47:37 -04:00
run_flags.h KVM: VMX: Prevent guest RSB poisoning attacks with eIBRS 2022-06-27 10:34:00 +02:00
sgx.c KVM: VMX: Inject #GP, not #UD, if SGX2 ENCLS leafs are unsupported 2023-06-02 10:12:03 -07:00
sgx.h KVM: VMX: Enable SGX virtualization for SGX1, SGX2 and LC 2021-04-20 04:18:56 -04:00
vmcs.h KVM: VMX: Handle NMI VM-Exits in noinstr region 2023-01-24 10:36:41 -08:00
vmcs12.c KVM: x86: Unify pr_fmt to use module name for all KVM modules 2022-12-29 15:47:35 -05:00
vmcs12.h bug: introduce ASSERT_STRUCT_OFFSET 2022-11-09 12:31:16 -05:00
vmcs_shadow_fields.h KVM: Fix some out-dated function names in comment 2020-01-21 13:57:27 +01:00
vmenter.S KVM: VMX: Make VMREAD error path play nice with noinstr 2023-07-29 11:05:26 -04:00
vmx.c KVM: x86: Fix lapic timer interrupt lost after loading a snapshot. 2023-11-28 17:19:56 +00:00
vmx.h KVM: nVMX: Use KVM-governed feature framework to track "nested VMX enabled" 2023-08-17 11:40:55 -07:00
vmx_ops.h KVM: VMX: Use vmread_error() to report VM-Fail in "goto" path 2023-07-29 11:05:26 -04:00