Skip to content

Commit b6909a6

Browse files
committed
KVM: arm/arm64: Support a vgic interrupt line level sample function
The GIC sometimes need to sample the physical line of a mapped interrupt. As we know this to be notoriously slow, provide a callback function for devices (such as the timer) which can do this much faster than talking to the distributor, for example by comparing a few in-memory values. Fall back to the good old method of poking the physical GIC if no callback is provided. Reviewed-by: Marc Zyngier <[email protected]> Reviewed-by: Eric Auger <[email protected]> Signed-off-by: Christoffer Dall <[email protected]>
1 parent e40cc57 commit b6909a6

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

include/kvm/arm_vgic.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,17 @@ struct vgic_irq {
130130
u8 priority;
131131
enum vgic_irq_config config; /* Level or edge */
132132

133+
/*
134+
* Callback function pointer to in-kernel devices that can tell us the
135+
* state of the input level of mapped level-triggered IRQ faster than
136+
* peaking into the physical GIC.
137+
*
138+
* Always called in non-preemptible section and the functions can use
139+
* kvm_arm_get_running_vcpu() to get the vcpu pointer for private
140+
* IRQs.
141+
*/
142+
bool (*get_input_level)(int vintid);
143+
133144
void *owner; /* Opaque pointer to reserve an interrupt
134145
for in-kernel devices. */
135146
};
@@ -331,7 +342,7 @@ void kvm_vgic_init_cpu_hardware(void);
331342
int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid,
332343
bool level, void *owner);
333344
int kvm_vgic_map_phys_irq(struct kvm_vcpu *vcpu, unsigned int host_irq,
334-
u32 vintid);
345+
u32 vintid, bool (*get_input_level)(int vindid));
335346
int kvm_vgic_unmap_phys_irq(struct kvm_vcpu *vcpu, unsigned int vintid);
336347
bool kvm_vgic_map_is_active(struct kvm_vcpu *vcpu, unsigned int vintid);
337348

virt/kvm/arm/arch_timer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,8 @@ int kvm_timer_enable(struct kvm_vcpu *vcpu)
834834
return -EINVAL;
835835
}
836836

837-
ret = kvm_vgic_map_phys_irq(vcpu, host_vtimer_irq, vtimer->irq.irq);
837+
ret = kvm_vgic_map_phys_irq(vcpu, host_vtimer_irq, vtimer->irq.irq,
838+
NULL);
838839
if (ret)
839840
return ret;
840841

virt/kvm/arm/vgic/vgic.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,15 @@ void vgic_put_irq(struct kvm *kvm, struct vgic_irq *irq)
144144
kfree(irq);
145145
}
146146

147-
/* Get the input level of a mapped IRQ directly from the physical GIC */
148147
bool vgic_get_phys_line_level(struct vgic_irq *irq)
149148
{
150149
bool line_level;
151150

152151
BUG_ON(!irq->hw);
153152

153+
if (irq->get_input_level)
154+
return irq->get_input_level(irq->intid);
155+
154156
WARN_ON(irq_get_irqchip_state(irq->host_irq,
155157
IRQCHIP_STATE_PENDING,
156158
&line_level));
@@ -436,7 +438,8 @@ int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid,
436438

437439
/* @irq->irq_lock must be held */
438440
static int kvm_vgic_map_irq(struct kvm_vcpu *vcpu, struct vgic_irq *irq,
439-
unsigned int host_irq)
441+
unsigned int host_irq,
442+
bool (*get_input_level)(int vindid))
440443
{
441444
struct irq_desc *desc;
442445
struct irq_data *data;
@@ -456,6 +459,7 @@ static int kvm_vgic_map_irq(struct kvm_vcpu *vcpu, struct vgic_irq *irq,
456459
irq->hw = true;
457460
irq->host_irq = host_irq;
458461
irq->hwintid = data->hwirq;
462+
irq->get_input_level = get_input_level;
459463
return 0;
460464
}
461465

@@ -464,10 +468,11 @@ static inline void kvm_vgic_unmap_irq(struct vgic_irq *irq)
464468
{
465469
irq->hw = false;
466470
irq->hwintid = 0;
471+
irq->get_input_level = NULL;
467472
}
468473

469474
int kvm_vgic_map_phys_irq(struct kvm_vcpu *vcpu, unsigned int host_irq,
470-
u32 vintid)
475+
u32 vintid, bool (*get_input_level)(int vindid))
471476
{
472477
struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, vintid);
473478
unsigned long flags;
@@ -476,7 +481,7 @@ int kvm_vgic_map_phys_irq(struct kvm_vcpu *vcpu, unsigned int host_irq,
476481
BUG_ON(!irq);
477482

478483
spin_lock_irqsave(&irq->irq_lock, flags);
479-
ret = kvm_vgic_map_irq(vcpu, irq, host_irq);
484+
ret = kvm_vgic_map_irq(vcpu, irq, host_irq, get_input_level);
480485
spin_unlock_irqrestore(&irq->irq_lock, flags);
481486
vgic_put_irq(vcpu->kvm, irq);
482487

0 commit comments

Comments
 (0)