[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250401161106.790710-21-pbonzini@redhat.com>
Date: Tue, 1 Apr 2025 18:10:57 +0200
From: Paolo Bonzini <pbonzini@...hat.com>
To: linux-kernel@...r.kernel.org,
kvm@...r.kernel.org
Cc: roy.hopkins@...e.com,
seanjc@...gle.com,
thomas.lendacky@....com,
ashish.kalra@....com,
michael.roth@....com,
jroedel@...e.de,
nsaenz@...zon.com,
anelkz@...zon.de,
James.Bottomley@...senPartnership.com
Subject: [PATCH 20/29] KVM: x86: add planes support for interrupt delivery
Plumb the destination plane into struct kvm_lapic_irq and propagate it
everywhere. The in-kernel IOAPIC only targets plane 0.
Signed-off-by: Paolo Bonzini <pbonzini@...hat.com>
---
arch/x86/include/asm/kvm_host.h | 1 +
arch/x86/kvm/hyperv.c | 1 +
arch/x86/kvm/ioapic.c | 4 ++--
arch/x86/kvm/irq_comm.c | 14 +++++++++++---
arch/x86/kvm/lapic.c | 8 ++++----
arch/x86/kvm/x86.c | 8 +++++---
arch/x86/kvm/xen.c | 1 +
7 files changed, 25 insertions(+), 12 deletions(-)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index f832352cf4d3..283d8a4b5b14 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -1661,6 +1661,7 @@ struct kvm_lapic_irq {
u16 delivery_mode;
u16 dest_mode;
bool level;
+ u8 plane;
u16 trig_mode;
u32 shorthand;
u32 dest_id;
diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index a522b467be48..cd1ff31038d2 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -491,6 +491,7 @@ static int synic_set_irq(struct kvm_vcpu_hv_synic *synic, u32 sint)
irq.delivery_mode = APIC_DM_FIXED;
irq.vector = vector;
irq.level = 1;
+ irq.plane = vcpu->plane;
ret = kvm_irq_delivery_to_apic(vcpu->kvm, vcpu->arch.apic, &irq, NULL);
trace_kvm_hv_synic_set_irq(vcpu->vcpu_id, sint, irq.vector, ret);
diff --git a/arch/x86/kvm/ioapic.c b/arch/x86/kvm/ioapic.c
index 995eb5054360..c538867afceb 100644
--- a/arch/x86/kvm/ioapic.c
+++ b/arch/x86/kvm/ioapic.c
@@ -402,7 +402,7 @@ static void ioapic_write_indirect(struct kvm_ioapic *ioapic, u32 val)
ioapic_service(ioapic, index, false);
}
if (e->fields.delivery_mode == APIC_DM_FIXED) {
- struct kvm_lapic_irq irq;
+ struct kvm_lapic_irq irq = { 0 };
irq.vector = e->fields.vector;
irq.delivery_mode = e->fields.delivery_mode << 8;
@@ -442,7 +442,7 @@ static void ioapic_write_indirect(struct kvm_ioapic *ioapic, u32 val)
static int ioapic_service(struct kvm_ioapic *ioapic, int irq, bool line_status)
{
union kvm_ioapic_redirect_entry *entry = &ioapic->redirtbl[irq];
- struct kvm_lapic_irq irqe;
+ struct kvm_lapic_irq irqe = { 0 };
int ret;
if (entry->fields.mask ||
diff --git a/arch/x86/kvm/irq_comm.c b/arch/x86/kvm/irq_comm.c
index 8136695f7b96..94f9db50384e 100644
--- a/arch/x86/kvm/irq_comm.c
+++ b/arch/x86/kvm/irq_comm.c
@@ -48,6 +48,7 @@ int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
struct kvm_lapic_irq *irq, struct dest_map *dest_map)
{
int r = -1;
+ struct kvm_plane *plane = kvm->planes[irq->plane];
struct kvm_vcpu *vcpu, *lowest = NULL;
unsigned long i, dest_vcpu_bitmap[BITS_TO_LONGS(KVM_MAX_VCPUS)];
unsigned int dest_vcpus = 0;
@@ -63,7 +64,7 @@ int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
memset(dest_vcpu_bitmap, 0, sizeof(dest_vcpu_bitmap));
- kvm_for_each_vcpu(i, vcpu, kvm) {
+ kvm_for_each_plane_vcpu(i, vcpu, plane) {
if (!kvm_apic_present(vcpu))
continue;
@@ -92,7 +93,7 @@ int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
int idx = kvm_vector_to_index(irq->vector, dest_vcpus,
dest_vcpu_bitmap, KVM_MAX_VCPUS);
- lowest = kvm_get_vcpu(kvm, idx);
+ lowest = kvm_get_plane_vcpu(plane, idx);
}
if (lowest)
@@ -119,13 +120,20 @@ void kvm_set_msi_irq(struct kvm *kvm, struct kvm_kernel_irq_routing_entry *e,
irq->msi_redir_hint = msg.arch_addr_lo.redirect_hint;
irq->level = 1;
irq->shorthand = APIC_DEST_NOSHORT;
+ irq->plane = e->msi.plane;
}
EXPORT_SYMBOL_GPL(kvm_set_msi_irq);
static inline bool kvm_msi_route_invalid(struct kvm *kvm,
struct kvm_kernel_irq_routing_entry *e)
{
- return kvm->arch.x2apic_format && (e->msi.address_hi & 0xff);
+ if (kvm->arch.x2apic_format && (e->msi.address_hi & 0xff))
+ return true;
+
+ if (!kvm->planes[e->msi.plane])
+ return true;
+
+ return false;
}
int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e,
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 6ed5f5b4f878..16a0e2387f2c 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -1223,14 +1223,13 @@ static inline bool kvm_apic_map_get_dest_lapic(struct kvm_plane *plane,
}
*bitmap = (lowest >= 0) ? 1 << lowest : 0;
-
return true;
}
bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm, struct kvm_lapic *src,
struct kvm_lapic_irq *irq, int *r, struct dest_map *dest_map)
{
- struct kvm_plane *plane = kvm->planes[0];
+ struct kvm_plane *plane = kvm->planes[irq->plane];
struct kvm_apic_map *map;
unsigned long bitmap;
struct kvm_lapic **dst = NULL;
@@ -1286,7 +1285,7 @@ bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm, struct kvm_lapic *src,
bool kvm_intr_is_single_vcpu_fast(struct kvm *kvm, struct kvm_lapic_irq *irq,
struct kvm_vcpu **dest_vcpu)
{
- struct kvm_plane *plane = kvm->planes[0];
+ struct kvm_plane *plane = kvm->planes[irq->plane];
struct kvm_apic_map *map;
unsigned long bitmap;
struct kvm_lapic **dst = NULL;
@@ -1422,7 +1421,7 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,
void kvm_bitmap_or_dest_vcpus(struct kvm *kvm, struct kvm_lapic_irq *irq,
unsigned long *vcpu_bitmap)
{
- struct kvm_plane *plane = kvm->planes[0];
+ struct kvm_plane *plane = kvm->planes[irq->plane];
struct kvm_lapic **dest_vcpu = NULL;
struct kvm_lapic *src = NULL;
struct kvm_apic_map *map;
@@ -1544,6 +1543,7 @@ void kvm_apic_send_ipi(struct kvm_lapic *apic, u32 icr_low, u32 icr_high)
irq.trig_mode = icr_low & APIC_INT_LEVELTRIG;
irq.shorthand = icr_low & APIC_SHORT_MASK;
irq.msi_redir_hint = false;
+ irq.plane = apic->vcpu->plane;
if (apic_x2apic_mode(apic))
irq.dest_id = icr_high;
else
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 19e3bb33bf7d..ce8e623052a7 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -9949,7 +9949,7 @@ static int kvm_pv_clock_pairing(struct kvm_vcpu *vcpu, gpa_t paddr,
*
* @apicid - apicid of vcpu to be kicked.
*/
-static void kvm_pv_kick_cpu_op(struct kvm *kvm, int apicid)
+static void kvm_pv_kick_cpu_op(struct kvm *kvm, unsigned plane_id, int apicid)
{
/*
* All other fields are unused for APIC_DM_REMRD, but may be consumed by
@@ -9960,6 +9960,7 @@ static void kvm_pv_kick_cpu_op(struct kvm *kvm, int apicid)
.dest_mode = APIC_DEST_PHYSICAL,
.shorthand = APIC_DEST_NOSHORT,
.dest_id = apicid,
+ .plane = plane_id,
};
kvm_irq_delivery_to_apic(kvm, NULL, &lapic_irq, NULL);
@@ -10092,7 +10093,7 @@ int ____kvm_emulate_hypercall(struct kvm_vcpu *vcpu, int cpl,
if (!guest_pv_has(vcpu, KVM_FEATURE_PV_UNHALT))
break;
- kvm_pv_kick_cpu_op(vcpu->kvm, a1);
+ kvm_pv_kick_cpu_op(vcpu->kvm, vcpu->plane, a1);
kvm_sched_yield(vcpu, a1);
ret = 0;
break;
@@ -13559,7 +13560,8 @@ void kvm_arch_async_page_present(struct kvm_vcpu *vcpu,
{
struct kvm_lapic_irq irq = {
.delivery_mode = APIC_DM_FIXED,
- .vector = vcpu->arch.apf.vec
+ .vector = vcpu->arch.apf.vec,
+ .plane = vcpu->plane,
};
if (work->wakeup_all)
diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c
index 7449be30d701..ac9c69f2190b 100644
--- a/arch/x86/kvm/xen.c
+++ b/arch/x86/kvm/xen.c
@@ -625,6 +625,7 @@ void kvm_xen_inject_vcpu_vector(struct kvm_vcpu *v)
irq.shorthand = APIC_DEST_NOSHORT;
irq.delivery_mode = APIC_DM_FIXED;
irq.level = 1;
+ irq.plane = v->plane;
kvm_irq_delivery_to_apic(v->kvm, NULL, &irq, NULL);
}
--
2.49.0
Powered by blists - more mailing lists