linux-stable/arch/x86
Haitao Shan b1f3291804 KVM: x86: Fix lapic timer interrupt lost after loading a snapshot.
commit 9cfec6d097 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:15:00 +00:00
..
boot x86/sev: Check for user-space IOIO pointing to kernel space 2023-10-25 12:16:10 +02:00
coco x86/tdx: Zero out the missing RSI in TDX_HYPERCALL macro 2023-11-20 11:56:59 +01:00
configs arch/*/configs/*defconfig: Replace AUTOFS4_FS by AUTOFS_FS 2023-07-29 14:08:22 -07:00
crypto crypto: x86/sha - load modules based on CPU features 2023-11-28 17:14:59 +00:00
entry x86/mm: Fix VDSO and VVAR placement on 5-level paging machines 2023-08-09 13:38:48 -07:00
events perf/x86/lbr: Filter vsyscall addresses 2023-10-19 23:11:05 +02:00
hyperv hyperv-fixes for 6.5-rc5 2023-08-04 17:16:14 -07:00
ia32
include KVM: x86: Fix lapic timer interrupt lost after loading a snapshot. 2023-11-28 17:15:00 +00:00
kernel x86/cpu/hygon: Fix the CPU topology evaluation for real 2023-11-28 17:14:59 +00:00
kvm KVM: x86: Fix lapic timer interrupt lost after loading a snapshot. 2023-11-28 17:15:00 +00:00
lib iov_iter, x86: Be consistent about the __user tag on copy_mc_to_user() 2023-11-20 11:56:42 +01:00
math-emu
mm x86/mm: Drop the 4 MB restriction on minimal NUMA node memory size 2023-11-28 17:14:41 +00:00
net bpf, x86: initialize the variable "first_off" in save_args() 2023-11-20 11:57:26 +01:00
pci x86/PCI: Avoid PME from D3hot/D3cold for AMD Rembrandt and Phoenix USB4 2023-11-28 17:14:59 +00:00
platform A single regression fix for x86: 2023-07-01 11:40:01 -07:00
power
purgatory x86/purgatory: Remove LTO flags 2023-09-23 11:14:33 +02:00
ras
realmode
tools
um
video drm changes for 6.5-rc1: 2023-06-29 11:00:17 -07:00
virt/vmx/tdx
xen xen: branch for v6.5-rc2 2023-07-13 13:39:36 -07:00
.gitignore
Kbuild
Kconfig efi/x86: Ensure that EFI_RUNTIME_MAP is enabled for kexec 2023-10-06 13:16:10 +02:00
Kconfig.assembler
Kconfig.cpu
Kconfig.debug
Makefile
Makefile.postlink
Makefile.um
Makefile_32.cpu