]> www.infradead.org Git - users/dwmw2/linux.git/commit
KVM: x86/xen: Inject vCPU upcall vector when local APIC is enabled
authorDavid Woodhouse <dwmw@amazon.co.uk>
Wed, 25 Oct 2023 21:53:45 +0000 (22:53 +0100)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Tue, 23 Jan 2024 15:03:08 +0000 (15:03 +0000)
commit96aee1721d5ecb5d3664f582595f0ff536e6525b
tree40503b0eba510636a034cef83ead889fa759c4a6
parenteb798515c766ae869bc0a1d68ac7374c28be3c4f
KVM: x86/xen: Inject vCPU upcall vector when local APIC is enabled

Linux guests since commit b1c3497e604d ("x86/xen: Add support for
HVMOP_set_evtchn_upcall_vector") in v6.0 onwards will use the per-vCPU
upcall vector when it's advertised in the Xen CPUID leaves.

This upcall is injected through the guest's local APIC as an MSI, unlike
the older system vector which was merely injected by the hypervisor any
time the CPU was able to receive an interrupt and the upcall_pending
flags is set in its vcpu_info.

Effectively, that makes the per-CPU upcall edge triggered instead of
level triggered, which results in the upcall being lost if the MSI is
delivered when the local APIC is *disabled*.

Xen checks the vcpu_info->evtchn_upcall_pending flag when the local APIC
for a vCPU is software enabled (in fact, on any write to the SPIV
register which doesn't disable the APIC). Do the same in KVM since KVM
doesn't provide a way for userspace to intervene and trap accesses to
the SPIV register of a local APIC emulated by KVM.

Astute reviewers may note that kvm_xen_inject_vcpu_vector() function has
a WARN_ON_ONCE() in the case where kvm_irq_delivery_to_apic_fast() fails
and returns false. In the case where the MSI is not delivered due to the
local APIC being disabled, kvm_irq_delivery_to_apic_fast() still returns
true but the value in *r is zero. So the WARN_ON_ONCE() remains correct,
as that case should still never happen.

Fixes: fde0451be8fb3 ("KVM: x86/xen: Support per-vCPU event channel upcall via local APIC")
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: Paul Durrant <paul@xen.org>
Cc: stable@vger.kernel.org
arch/x86/kvm/lapic.c
arch/x86/kvm/xen.c
arch/x86/kvm/xen.h