Commit 15daa58e authored by Sean Christopherson's avatar Sean Christopherson
Browse files

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: default avatarSean Christopherson <seanjc@google.com>
parent cc63f918
Loading
Loading
Loading
Loading
+18 −12
Original line number Diff line number Diff line
@@ -1474,24 +1474,30 @@ void kvm_apic_set_eoi_accelerated(struct kvm_vcpu *vcpu, int vector)
}
EXPORT_SYMBOL_GPL(kvm_apic_set_eoi_accelerated);

void kvm_apic_send_ipi(struct kvm_lapic *apic, u32 icr_low, u32 icr_high)
static void kvm_icr_to_lapic_irq(struct kvm_lapic *apic, u32 icr_low,
				 u32 icr_high, struct kvm_lapic_irq *irq)
{
	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;
	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;
		irq->dest_id = icr_high;
	else
		irq.dest_id = GET_XAPIC_DEST_FIELD(icr_high);
		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_icr_to_lapic_irq(apic, icr_low, icr_high, &irq);

	trace_kvm_apic_ipi(icr_low, irq.dest_id);