On 14/12/2023 16:56, David Woodhouse wrote:
From: David Woodhouse <dwmw@xxxxxxxxxxxx> 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 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. We lose edges. Specifically, when the local APIC is *disabled*, delivering the MSI will fail. Xen checks the vcpu_info->evtchn_upcall_pending flag when enabling the local APIC for a vCPU and injects the vector immediately if so. Since userspace doesn't get to notice when the guest enables a local APIC which is emulated in KVM, KVM needs to do the same. 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@xxxxxxxxxxxx> --- v2: • Add Fixes: tag. arch/x86/kvm/lapic.c | 5 ++++- arch/x86/kvm/xen.c | 2 +- arch/x86/kvm/xen.h | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-)
Reviewed-by: Paul Durrant <paul@xxxxxxx>