KVM: x86: Add kvm_icr_to_lapic_irq() helper to allow for fastpath IPIs

Extract the code for converting an ICR message into a kvm_lapic_irq
structure into a local helper so that a fast-only IPI path can share the
conversion logic.

No functional change intended.

Link: https://lore.kernel.org/r/20250805190526.1453366-3-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
This commit is contained in:
Sean Christopherson 2025-08-05 12:05:10 -07:00
parent cc63f918a2
commit 15daa58e78

View File

@ -1474,24 +1474,30 @@ void kvm_apic_set_eoi_accelerated(struct kvm_vcpu *vcpu, int vector)
}
EXPORT_SYMBOL_GPL(kvm_apic_set_eoi_accelerated);
static void kvm_icr_to_lapic_irq(struct kvm_lapic *apic, u32 icr_low,
u32 icr_high, struct kvm_lapic_irq *irq)
{
/* KVM has no delay and should always clear the BUSY/PENDING flag. */
WARN_ON_ONCE(icr_low & APIC_ICR_BUSY);
irq->vector = icr_low & APIC_VECTOR_MASK;
irq->delivery_mode = icr_low & APIC_MODE_MASK;
irq->dest_mode = icr_low & APIC_DEST_MASK;
irq->level = (icr_low & APIC_INT_ASSERT) != 0;
irq->trig_mode = icr_low & APIC_INT_LEVELTRIG;
irq->shorthand = icr_low & APIC_SHORT_MASK;
irq->msi_redir_hint = false;
if (apic_x2apic_mode(apic))
irq->dest_id = icr_high;
else
irq->dest_id = GET_XAPIC_DEST_FIELD(icr_high);
}
void kvm_apic_send_ipi(struct kvm_lapic *apic, u32 icr_low, u32 icr_high)
{
struct kvm_lapic_irq irq;
/* KVM has no delay and should always clear the BUSY/PENDING flag. */
WARN_ON_ONCE(icr_low & APIC_ICR_BUSY);
irq.vector = icr_low & APIC_VECTOR_MASK;
irq.delivery_mode = icr_low & APIC_MODE_MASK;
irq.dest_mode = icr_low & APIC_DEST_MASK;
irq.level = (icr_low & APIC_INT_ASSERT) != 0;
irq.trig_mode = icr_low & APIC_INT_LEVELTRIG;
irq.shorthand = icr_low & APIC_SHORT_MASK;
irq.msi_redir_hint = false;
if (apic_x2apic_mode(apic))
irq.dest_id = icr_high;
else
irq.dest_id = GET_XAPIC_DEST_FIELD(icr_high);
kvm_icr_to_lapic_irq(apic, icr_low, icr_high, &irq);
trace_kvm_apic_ipi(icr_low, irq.dest_id);