Skip to content

Commit b452cb5

Browse files
committed
KVM: arm/arm64: Remove the IRQ field from struct irq_phys_map
The communication of a Linux IRQ number from outside the VGIC to the vgic was a leftover from the day when the vgic code cared about how a particular device injects virtual interrupts mapped to a physical interrupt. We can safely remove this notion, leaving all physical IRQ handling to be done in the device driver (the arch timer in this case), which makes room for a saner API for the new VGIC. Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org> Signed-off-by: Andre Przywara <andre.przywara@arm.com> Reviewed-by: Eric Auger <eric.auger@linaro.org>
1 parent 63306c2 commit b452cb5

3 files changed

Lines changed: 28 additions & 26 deletions

File tree

‎include/kvm/arm_vgic.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ struct vgic_io_device {
158158
struct irq_phys_map {
159159
u32 virt_irq;
160160
u32 phys_irq;
161-
u32 irq;
162161
};
163162

164163
struct irq_phys_map_entry {
@@ -346,7 +345,7 @@ int kvm_vgic_inject_mapped_irq(struct kvm *kvm, int cpuid,
346345
void vgic_v3_dispatch_sgi(struct kvm_vcpu *vcpu, u64 reg);
347346
int kvm_vgic_vcpu_pending_irq(struct kvm_vcpu *vcpu);
348347
struct irq_phys_map *kvm_vgic_map_phys_irq(struct kvm_vcpu *vcpu,
349-
int virt_irq, int irq);
348+
int virt_irq, int phys_irq);
350349
int kvm_vgic_unmap_phys_irq(struct kvm_vcpu *vcpu, unsigned int virt_irq);
351350
bool kvm_vgic_map_is_active(struct kvm_vcpu *vcpu, unsigned int virt_irq);
352351

‎virt/kvm/arm/arch_timer.c‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/kvm.h>
2121
#include <linux/kvm_host.h>
2222
#include <linux/interrupt.h>
23+
#include <linux/irq.h>
2324

2425
#include <clocksource/arm_arch_timer.h>
2526
#include <asm/arch_timer.h>
@@ -300,7 +301,7 @@ void kvm_timer_flush_hwstate(struct kvm_vcpu *vcpu)
300301
if (timer->active_cleared_last && !phys_active)
301302
return;
302303

303-
ret = irq_set_irqchip_state(timer->map->irq,
304+
ret = irq_set_irqchip_state(host_vtimer_irq,
304305
IRQCHIP_STATE_ACTIVE,
305306
phys_active);
306307
WARN_ON(ret);
@@ -333,6 +334,9 @@ int kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu,
333334
{
334335
struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu;
335336
struct irq_phys_map *map;
337+
struct irq_desc *desc;
338+
struct irq_data *data;
339+
int phys_irq;
336340

337341
/*
338342
* The vcpu timer irq number cannot be determined in
@@ -351,11 +355,26 @@ int kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu,
351355
timer->cntv_ctl = 0;
352356
kvm_timer_update_state(vcpu);
353357

358+
/*
359+
* Find the physical IRQ number corresponding to the host_vtimer_irq
360+
*/
361+
desc = irq_to_desc(host_vtimer_irq);
362+
if (!desc) {
363+
kvm_err("%s: no interrupt descriptor\n", __func__);
364+
return -EINVAL;
365+
}
366+
367+
data = irq_desc_get_irq_data(desc);
368+
while (data->parent_data)
369+
data = data->parent_data;
370+
371+
phys_irq = data->hwirq;
372+
354373
/*
355374
* Tell the VGIC that the virtual interrupt is tied to a
356375
* physical interrupt. We do that once per VCPU.
357376
*/
358-
map = kvm_vgic_map_phys_irq(vcpu, irq->irq, host_vtimer_irq);
377+
map = kvm_vgic_map_phys_irq(vcpu, irq->irq, phys_irq);
359378
if (WARN_ON(IS_ERR(map)))
360379
return PTR_ERR(map);
361380

‎virt/kvm/arm/vgic.c‎

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,38 +1711,24 @@ static struct list_head *vgic_get_irq_phys_map_list(struct kvm_vcpu *vcpu,
17111711
/**
17121712
* kvm_vgic_map_phys_irq - map a virtual IRQ to a physical IRQ
17131713
* @vcpu: The VCPU pointer
1714-
* @virt_irq: The virtual irq number
1715-
* @irq: The Linux IRQ number
1714+
* @virt_irq: The virtual IRQ number for the guest
1715+
* @phys_irq: The hardware IRQ number of the host
17161716
*
17171717
* Establish a mapping between a guest visible irq (@virt_irq) and a
1718-
* Linux irq (@irq). On injection, @virt_irq will be associated with
1719-
* the physical interrupt represented by @irq. This mapping can be
1718+
* hardware irq (@phys_irq). On injection, @virt_irq will be associated with
1719+
* the physical interrupt represented by @phys_irq. This mapping can be
17201720
* established multiple times as long as the parameters are the same.
17211721
*
17221722
* Returns a valid pointer on success, and an error pointer otherwise
17231723
*/
17241724
struct irq_phys_map *kvm_vgic_map_phys_irq(struct kvm_vcpu *vcpu,
1725-
int virt_irq, int irq)
1725+
int virt_irq, int phys_irq)
17261726
{
17271727
struct vgic_dist *dist = &vcpu->kvm->arch.vgic;
17281728
struct list_head *root = vgic_get_irq_phys_map_list(vcpu, virt_irq);
17291729
struct irq_phys_map *map;
17301730
struct irq_phys_map_entry *entry;
1731-
struct irq_desc *desc;
1732-
struct irq_data *data;
1733-
int phys_irq;
17341731

1735-
desc = irq_to_desc(irq);
1736-
if (!desc) {
1737-
kvm_err("%s: no interrupt descriptor\n", __func__);
1738-
return ERR_PTR(-EINVAL);
1739-
}
1740-
1741-
data = irq_desc_get_irq_data(desc);
1742-
while (data->parent_data)
1743-
data = data->parent_data;
1744-
1745-
phys_irq = data->hwirq;
17461732

17471733
/* Create a new mapping */
17481734
entry = kzalloc(sizeof(*entry), GFP_KERNEL);
@@ -1755,8 +1741,7 @@ struct irq_phys_map *kvm_vgic_map_phys_irq(struct kvm_vcpu *vcpu,
17551741
map = vgic_irq_map_search(vcpu, virt_irq);
17561742
if (map) {
17571743
/* Make sure this mapping matches */
1758-
if (map->phys_irq != phys_irq ||
1759-
map->irq != irq)
1744+
if (map->phys_irq != phys_irq)
17601745
map = ERR_PTR(-EINVAL);
17611746

17621747
/* Found an existing, valid mapping */
@@ -1766,7 +1751,6 @@ struct irq_phys_map *kvm_vgic_map_phys_irq(struct kvm_vcpu *vcpu,
17661751
map = &entry->map;
17671752
map->virt_irq = virt_irq;
17681753
map->phys_irq = phys_irq;
1769-
map->irq = irq;
17701754

17711755
list_add_tail_rcu(&entry->entry, root);
17721756

0 commit comments

Comments
 (0)