Skip to content

Commit ef1820b

Browse files
author
Marc Zyngier
committed
KVM: arm64: GICv4.1: Add direct injection capability to SGI registers
Most of the GICv3 emulation code that deals with SGIs now has to be aware of the v4.1 capabilities in order to benefit from it. Add such support, keyed on the interrupt having the hw flag set and being a SGI. Signed-off-by: Marc Zyngier <maz@kernel.org> Reviewed-by: Zenghui Yu <yuzenghui@huawei.com> Reviewed-by: Eric Auger <eric.auger@redhat.com> Link: https://lore.kernel.org/r/20200304203330.4967-19-maz@kernel.org
1 parent 9879b79 commit ef1820b

2 files changed

Lines changed: 107 additions & 8 deletions

File tree

‎virt/kvm/arm/vgic/vgic-mmio-v3.c‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/irqchip/arm-gic-v3.h>
77
#include <linux/kvm.h>
88
#include <linux/kvm_host.h>
9+
#include <linux/interrupt.h>
910
#include <kvm/iodev.h>
1011
#include <kvm/arm_vgic.h>
1112

@@ -257,8 +258,18 @@ static unsigned long vgic_v3_uaccess_read_pending(struct kvm_vcpu *vcpu,
257258
*/
258259
for (i = 0; i < len * 8; i++) {
259260
struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, intid + i);
261+
bool state = irq->pending_latch;
260262

261-
if (irq->pending_latch)
263+
if (irq->hw && vgic_irq_is_sgi(irq->intid)) {
264+
int err;
265+
266+
err = irq_get_irqchip_state(irq->host_irq,
267+
IRQCHIP_STATE_PENDING,
268+
&state);
269+
WARN_ON(err);
270+
}
271+
272+
if (state)
262273
value |= (1U << i);
263274

264275
vgic_put_irq(vcpu->kvm, irq);
@@ -942,8 +953,18 @@ void vgic_v3_dispatch_sgi(struct kvm_vcpu *vcpu, u64 reg, bool allow_group1)
942953
* generate interrupts of either group.
943954
*/
944955
if (!irq->group || allow_group1) {
945-
irq->pending_latch = true;
946-
vgic_queue_irq_unlock(vcpu->kvm, irq, flags);
956+
if (!irq->hw) {
957+
irq->pending_latch = true;
958+
vgic_queue_irq_unlock(vcpu->kvm, irq, flags);
959+
} else {
960+
/* HW SGI? Ask the GIC to inject it */
961+
int err;
962+
err = irq_set_irqchip_state(irq->host_irq,
963+
IRQCHIP_STATE_PENDING,
964+
true);
965+
WARN_RATELIMIT(err, "IRQ %d", irq->host_irq);
966+
raw_spin_unlock_irqrestore(&irq->irq_lock, flags);
967+
}
947968
} else {
948969
raw_spin_unlock_irqrestore(&irq->irq_lock, flags);
949970
}

‎virt/kvm/arm/vgic/vgic-mmio.c‎

Lines changed: 83 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include <linux/bitops.h>
77
#include <linux/bsearch.h>
8+
#include <linux/interrupt.h>
9+
#include <linux/irq.h>
810
#include <linux/kvm.h>
911
#include <linux/kvm_host.h>
1012
#include <kvm/iodev.h>
@@ -59,6 +61,11 @@ unsigned long vgic_mmio_read_group(struct kvm_vcpu *vcpu,
5961
return value;
6062
}
6163

64+
static void vgic_update_vsgi(struct vgic_irq *irq)
65+
{
66+
WARN_ON(its_prop_update_vsgi(irq->host_irq, irq->priority, irq->group));
67+
}
68+
6269
void vgic_mmio_write_group(struct kvm_vcpu *vcpu, gpa_t addr,
6370
unsigned int len, unsigned long val)
6471
{
@@ -71,7 +78,12 @@ void vgic_mmio_write_group(struct kvm_vcpu *vcpu, gpa_t addr,
7178

7279
raw_spin_lock_irqsave(&irq->irq_lock, flags);
7380
irq->group = !!(val & BIT(i));
74-
vgic_queue_irq_unlock(vcpu->kvm, irq, flags);
81+
if (irq->hw && vgic_irq_is_sgi(irq->intid)) {
82+
vgic_update_vsgi(irq);
83+
raw_spin_unlock_irqrestore(&irq->irq_lock, flags);
84+
} else {
85+
vgic_queue_irq_unlock(vcpu->kvm, irq, flags);
86+
}
7587

7688
vgic_put_irq(vcpu->kvm, irq);
7789
}
@@ -113,7 +125,21 @@ void vgic_mmio_write_senable(struct kvm_vcpu *vcpu,
113125
struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, intid + i);
114126

115127
raw_spin_lock_irqsave(&irq->irq_lock, flags);
116-
if (vgic_irq_is_mapped_level(irq)) {
128+
if (irq->hw && vgic_irq_is_sgi(irq->intid)) {
129+
if (!irq->enabled) {
130+
struct irq_data *data;
131+
132+
irq->enabled = true;
133+
data = &irq_to_desc(irq->host_irq)->irq_data;
134+
while (irqd_irq_disabled(data))
135+
enable_irq(irq->host_irq);
136+
}
137+
138+
raw_spin_unlock_irqrestore(&irq->irq_lock, flags);
139+
vgic_put_irq(vcpu->kvm, irq);
140+
141+
continue;
142+
} else if (vgic_irq_is_mapped_level(irq)) {
117143
bool was_high = irq->line_level;
118144

119145
/*
@@ -148,6 +174,8 @@ void vgic_mmio_write_cenable(struct kvm_vcpu *vcpu,
148174
struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, intid + i);
149175

150176
raw_spin_lock_irqsave(&irq->irq_lock, flags);
177+
if (irq->hw && vgic_irq_is_sgi(irq->intid) && irq->enabled)
178+
disable_irq_nosync(irq->host_irq);
151179

152180
irq->enabled = false;
153181

@@ -167,10 +195,22 @@ unsigned long vgic_mmio_read_pending(struct kvm_vcpu *vcpu,
167195
for (i = 0; i < len * 8; i++) {
168196
struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, intid + i);
169197
unsigned long flags;
198+
bool val;
170199

171200
raw_spin_lock_irqsave(&irq->irq_lock, flags);
172-
if (irq_is_pending(irq))
173-
value |= (1U << i);
201+
if (irq->hw && vgic_irq_is_sgi(irq->intid)) {
202+
int err;
203+
204+
val = false;
205+
err = irq_get_irqchip_state(irq->host_irq,
206+
IRQCHIP_STATE_PENDING,
207+
&val);
208+
WARN_RATELIMIT(err, "IRQ %d", irq->host_irq);
209+
} else {
210+
val = irq_is_pending(irq);
211+
}
212+
213+
value |= ((u32)val << i);
174214
raw_spin_unlock_irqrestore(&irq->irq_lock, flags);
175215

176216
vgic_put_irq(vcpu->kvm, irq);
@@ -215,6 +255,21 @@ void vgic_mmio_write_spending(struct kvm_vcpu *vcpu,
215255
}
216256

217257
raw_spin_lock_irqsave(&irq->irq_lock, flags);
258+
259+
if (irq->hw && vgic_irq_is_sgi(irq->intid)) {
260+
/* HW SGI? Ask the GIC to inject it */
261+
int err;
262+
err = irq_set_irqchip_state(irq->host_irq,
263+
IRQCHIP_STATE_PENDING,
264+
true);
265+
WARN_RATELIMIT(err, "IRQ %d", irq->host_irq);
266+
267+
raw_spin_unlock_irqrestore(&irq->irq_lock, flags);
268+
vgic_put_irq(vcpu->kvm, irq);
269+
270+
continue;
271+
}
272+
218273
if (irq->hw)
219274
vgic_hw_irq_spending(vcpu, irq, is_uaccess);
220275
else
@@ -269,6 +324,20 @@ void vgic_mmio_write_cpending(struct kvm_vcpu *vcpu,
269324

270325
raw_spin_lock_irqsave(&irq->irq_lock, flags);
271326

327+
if (irq->hw && vgic_irq_is_sgi(irq->intid)) {
328+
/* HW SGI? Ask the GIC to clear its pending bit */
329+
int err;
330+
err = irq_set_irqchip_state(irq->host_irq,
331+
IRQCHIP_STATE_PENDING,
332+
false);
333+
WARN_RATELIMIT(err, "IRQ %d", irq->host_irq);
334+
335+
raw_spin_unlock_irqrestore(&irq->irq_lock, flags);
336+
vgic_put_irq(vcpu->kvm, irq);
337+
338+
continue;
339+
}
340+
272341
if (irq->hw)
273342
vgic_hw_irq_cpending(vcpu, irq, is_uaccess);
274343
else
@@ -318,8 +387,15 @@ static void vgic_mmio_change_active(struct kvm_vcpu *vcpu, struct vgic_irq *irq,
318387

319388
raw_spin_lock_irqsave(&irq->irq_lock, flags);
320389

321-
if (irq->hw) {
390+
if (irq->hw && !vgic_irq_is_sgi(irq->intid)) {
322391
vgic_hw_irq_change_active(vcpu, irq, active, !requester_vcpu);
392+
} else if (irq->hw && vgic_irq_is_sgi(irq->intid)) {
393+
/*
394+
* GICv4.1 VSGI feature doesn't track an active state,
395+
* so let's not kid ourselves, there is nothing we can
396+
* do here.
397+
*/
398+
irq->active = false;
323399
} else {
324400
u32 model = vcpu->kvm->arch.vgic.vgic_model;
325401
u8 active_source;
@@ -493,6 +569,8 @@ void vgic_mmio_write_priority(struct kvm_vcpu *vcpu,
493569
raw_spin_lock_irqsave(&irq->irq_lock, flags);
494570
/* Narrow the priority range to what we actually support */
495571
irq->priority = (val >> (i * 8)) & GENMASK(7, 8 - VGIC_PRI_BITS);
572+
if (irq->hw && vgic_irq_is_sgi(irq->intid))
573+
vgic_update_vsgi(irq);
496574
raw_spin_unlock_irqrestore(&irq->irq_lock, flags);
497575

498576
vgic_put_irq(vcpu->kvm, irq);

0 commit comments

Comments
 (0)