KVM: x86: Move "KVM no-APIC vCPU" key management into local APIC code
authorSean Christopherson <seanjc@google.com>
Fri, 9 Feb 2024 22:20:46 +0000 (14:20 -0800)
committerSean Christopherson <seanjc@google.com>
Fri, 23 Feb 2024 00:24:09 +0000 (16:24 -0800)
commita78d9046696b88079a5696bccec4e4e439a3f2a2
treee97fcb2825dacf56674e1b9024632e1ef6fc0857
parent0ec3d6d1f169baa7fc512ae4b78d17e7c94b7763
KVM: x86: Move "KVM no-APIC vCPU" key management into local APIC code

Move incrementing and decrementing of kvm_has_noapic_vcpu into
kvm_create_lapic() and kvm_free_lapic() respectively to fix a benign bug
where KVM fails to decrement the count if vCPU creation ultimately fails,
e.g. due to a memory allocation failing.

Note, the bug is benign as kvm_has_noapic_vcpu is used purely to optimize
lapic_in_kernel() checks, and that optimization is quite dubious.  That,
and practically speaking no setup that cares at all about performance runs
with a userspace local APIC.

Reported-by: Li RongQing <lirongqing@baidu.com>
Cc: Maxim Levitsky <mlevitsk@redhat.com>
Reviewed-by: Xu Yilun <yilun.xu@linux.intel.com>
Link: https://lore.kernel.org/r/20240209222047.394389-2-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/lapic.c
arch/x86/kvm/x86.c