Skip to content

Commit c6ccd30

Browse files
author
Christoffer Dall
committed
KVM: arm/arm64: Introduce an allocator for in-kernel irq lines
Having multiple devices being able to signal the same interrupt line is very confusing and almost certainly guarantees a configuration error. Therefore, introduce a very simple allocator which allows a device to claim an interrupt line from the vgic for a given VM. Signed-off-by: Christoffer Dall <cdall@linaro.org> Acked-by: Marc Zyngier <marc.zyngier@arm.com>
1 parent 99a1db7 commit c6ccd30

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

‎include/kvm/arm_vgic.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ struct vgic_irq {
121121
u8 source; /* GICv2 SGIs only */
122122
u8 priority;
123123
enum vgic_irq_config config; /* Level or edge */
124+
125+
void *owner; /* Opaque pointer to reserve an interrupt
126+
for in-kernel devices. */
124127
};
125128

126129
struct vgic_register_region;
@@ -340,4 +343,6 @@ int kvm_send_userspace_msi(struct kvm *kvm, struct kvm_msi *msi);
340343
*/
341344
int kvm_vgic_setup_default_irq_routing(struct kvm *kvm);
342345

346+
int kvm_vgic_set_owner(struct kvm_vcpu *vcpu, unsigned int intid, void *owner);
347+
343348
#endif /* __KVM_ARM_VGIC_H */

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,39 @@ int kvm_vgic_unmap_phys_irq(struct kvm_vcpu *vcpu, unsigned int virt_irq)
434434
return 0;
435435
}
436436

437+
/**
438+
* kvm_vgic_set_owner - Set the owner of an interrupt for a VM
439+
*
440+
* @vcpu: Pointer to the VCPU (used for PPIs)
441+
* @intid: The virtual INTID identifying the interrupt (PPI or SPI)
442+
* @owner: Opaque pointer to the owner
443+
*
444+
* Returns 0 if intid is not already used by another in-kernel device and the
445+
* owner is set, otherwise returns an error code.
446+
*/
447+
int kvm_vgic_set_owner(struct kvm_vcpu *vcpu, unsigned int intid, void *owner)
448+
{
449+
struct vgic_irq *irq;
450+
int ret = 0;
451+
452+
if (!vgic_initialized(vcpu->kvm))
453+
return -EAGAIN;
454+
455+
/* SGIs and LPIs cannot be wired up to any device */
456+
if (!irq_is_ppi(intid) && !vgic_valid_spi(vcpu->kvm, intid))
457+
return -EINVAL;
458+
459+
irq = vgic_get_irq(vcpu->kvm, vcpu, intid);
460+
spin_lock(&irq->irq_lock);
461+
if (irq->owner && irq->owner != owner)
462+
ret = -EEXIST;
463+
else
464+
irq->owner = owner;
465+
spin_unlock(&irq->irq_lock);
466+
467+
return ret;
468+
}
469+
437470
/**
438471
* vgic_prune_ap_list - Remove non-relevant interrupts from the list
439472
*

0 commit comments

Comments
 (0)