Skip to content

Commit

Permalink
kvm: Pass PCI device pointer to MSI routing functions
Browse files Browse the repository at this point in the history
In-kernel ITS emulation on ARM64 will require to supply requester IDs.
These IDs can now be retrieved from the device pointer using new
pci_requester_id() function.

This patch adds pci_dev pointer to KVM GSI routing functions and makes
callers passing it.

x86 architecture does not use requester IDs, but hw/i386/kvm/pci-assign.c
also made passing PCI device pointer instead of NULL for consistency with
the rest of the code.

Signed-off-by: Pavel Fedin <[email protected]>
Message-Id: <ce081423ba2394a4efc30f30708fca07656bc500.1444916432.git.p.fedin@samsung.com>
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
pfedin authored and bonzini committed Oct 19, 2015
1 parent a05f686 commit dc9f06c
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 25 deletions.
9 changes: 5 additions & 4 deletions hw/i386/kvm/pci-assign.c
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ static void assigned_dev_update_msi(PCIDevice *pci_dev)
MSIMessage msg = msi_get_message(pci_dev, 0);
int virq;

virq = kvm_irqchip_add_msi_route(kvm_state, msg);
virq = kvm_irqchip_add_msi_route(kvm_state, msg, pci_dev);
if (virq < 0) {
perror("assigned_dev_update_msi: kvm_irqchip_add_msi_route");
return;
Expand Down Expand Up @@ -1017,7 +1017,7 @@ static void assigned_dev_update_msi_msg(PCIDevice *pci_dev)
}

kvm_irqchip_update_msi_route(kvm_state, assigned_dev->msi_virq[0],
msi_get_message(pci_dev, 0));
msi_get_message(pci_dev, 0), pci_dev);
}

static bool assigned_dev_msix_masked(MSIXTableEntry *entry)
Expand Down Expand Up @@ -1083,7 +1083,7 @@ static int assigned_dev_update_msix_mmio(PCIDevice *pci_dev)

msg.address = entry->addr_lo | ((uint64_t)entry->addr_hi << 32);
msg.data = entry->data;
r = kvm_irqchip_add_msi_route(kvm_state, msg);
r = kvm_irqchip_add_msi_route(kvm_state, msg, pci_dev);
if (r < 0) {
return r;
}
Expand Down Expand Up @@ -1602,7 +1602,8 @@ static void assigned_dev_msix_mmio_write(void *opaque, hwaddr addr,
msg.data = entry->data;

ret = kvm_irqchip_update_msi_route(kvm_state,
adev->msi_virq[i], msg);
adev->msi_virq[i], msg,
pdev);
if (ret) {
error_report("Error updating irq routing entry (%d)", ret);
}
Expand Down
11 changes: 6 additions & 5 deletions hw/vfio/pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ static void vfio_add_kvm_msi_virq(VFIOPCIDevice *vdev, VFIOMSIVector *vector,
return;
}

virq = kvm_irqchip_add_msi_route(kvm_state, *msg);
virq = kvm_irqchip_add_msi_route(kvm_state, *msg, &vdev->pdev);
if (virq < 0) {
event_notifier_cleanup(&vector->kvm_interrupt);
return;
Expand All @@ -449,9 +449,10 @@ static void vfio_remove_kvm_msi_virq(VFIOMSIVector *vector)
event_notifier_cleanup(&vector->kvm_interrupt);
}

static void vfio_update_kvm_msi_virq(VFIOMSIVector *vector, MSIMessage msg)
static void vfio_update_kvm_msi_virq(VFIOMSIVector *vector, MSIMessage msg,
PCIDevice *pdev)
{
kvm_irqchip_update_msi_route(kvm_state, vector->virq, msg);
kvm_irqchip_update_msi_route(kvm_state, vector->virq, msg, pdev);
}

static int vfio_msix_vector_do_use(PCIDevice *pdev, unsigned int nr,
Expand Down Expand Up @@ -486,7 +487,7 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, unsigned int nr,
if (!msg) {
vfio_remove_kvm_msi_virq(vector);
} else {
vfio_update_kvm_msi_virq(vector, *msg);
vfio_update_kvm_msi_virq(vector, *msg, pdev);
}
} else {
vfio_add_kvm_msi_virq(vdev, vector, msg, true);
Expand Down Expand Up @@ -760,7 +761,7 @@ static void vfio_update_msi(VFIOPCIDevice *vdev)
}

msg = msi_get_message(&vdev->pdev, i);
vfio_update_kvm_msi_virq(vector, msg);
vfio_update_kvm_msi_virq(vector, msg, &vdev->pdev);
}
}

Expand Down
5 changes: 3 additions & 2 deletions hw/virtio/virtio-pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ static int kvm_virtio_pci_vq_vector_use(VirtIOPCIProxy *proxy,
int ret;

if (irqfd->users == 0) {
ret = kvm_irqchip_add_msi_route(kvm_state, msg);
ret = kvm_irqchip_add_msi_route(kvm_state, msg, &proxy->pci_dev);
if (ret < 0) {
return ret;
}
Expand Down Expand Up @@ -726,7 +726,8 @@ static int virtio_pci_vq_vector_unmask(VirtIOPCIProxy *proxy,
if (proxy->vector_irqfd) {
irqfd = &proxy->vector_irqfd[vector];
if (irqfd->msg.data != msg.data || irqfd->msg.address != msg.address) {
ret = kvm_irqchip_update_msi_route(kvm_state, irqfd->virq, msg);
ret = kvm_irqchip_update_msi_route(kvm_state, irqfd->virq, msg,
&proxy->pci_dev);
if (ret < 0) {
return ret;
}
Expand Down
7 changes: 4 additions & 3 deletions include/sysemu/kvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ int kvm_arch_on_sigbus(int code, void *addr);
void kvm_arch_init_irq_routing(KVMState *s);

int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route,
uint64_t address, uint32_t data);
uint64_t address, uint32_t data, PCIDevice *dev);

int kvm_arch_msi_data_to_gsi(uint32_t data);

Expand Down Expand Up @@ -451,8 +451,9 @@ static inline void cpu_clean_state(CPUState *cpu)
}
}

int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg);
int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg);
int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg, PCIDevice *dev);
int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg,
PCIDevice *dev);
void kvm_irqchip_release_virq(KVMState *s, int virq);

int kvm_irqchip_add_adapter_route(KVMState *s, AdapterInfo *adapter);
Expand Down
9 changes: 5 additions & 4 deletions kvm-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,7 @@ int kvm_irqchip_send_msi(KVMState *s, MSIMessage msg)
return kvm_set_irq(s, route->kroute.gsi, 1);
}

int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg)
int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg, PCIDevice *dev)
{
struct kvm_irq_routing_entry kroute = {};
int virq;
Expand All @@ -1213,7 +1213,7 @@ int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg)
kroute.u.msi.address_lo = (uint32_t)msg.address;
kroute.u.msi.address_hi = msg.address >> 32;
kroute.u.msi.data = le32_to_cpu(msg.data);
if (kvm_arch_fixup_msi_route(&kroute, msg.address, msg.data)) {
if (kvm_arch_fixup_msi_route(&kroute, msg.address, msg.data, dev)) {
kvm_irqchip_release_virq(s, virq);
return -EINVAL;
}
Expand All @@ -1224,7 +1224,8 @@ int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg)
return virq;
}

int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg)
int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg,
PCIDevice *dev)
{
struct kvm_irq_routing_entry kroute = {};

Expand All @@ -1242,7 +1243,7 @@ int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg)
kroute.u.msi.address_lo = (uint32_t)msg.address;
kroute.u.msi.address_hi = msg.address >> 32;
kroute.u.msi.data = le32_to_cpu(msg.data);
if (kvm_arch_fixup_msi_route(&kroute, msg.address, msg.data)) {
if (kvm_arch_fixup_msi_route(&kroute, msg.address, msg.data, dev)) {
return -EINVAL;
}

Expand Down
5 changes: 3 additions & 2 deletions kvm-stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ int kvm_on_sigbus(int code, void *addr)
}

#ifndef CONFIG_USER_ONLY
int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg)
int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg, PCIDevice *dev)
{
return -ENOSYS;
}
Expand All @@ -128,7 +128,8 @@ void kvm_irqchip_release_virq(KVMState *s, int virq)
{
}

int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg)
int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg,
PCIDevice *dev)
{
return -ENOSYS;
}
Expand Down
2 changes: 1 addition & 1 deletion target-arm/kvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ int kvm_arm_vgic_probe(void)
}

int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route,
uint64_t address, uint32_t data)
uint64_t address, uint32_t data, PCIDevice *dev)
{
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion target-i386/kvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2992,7 +2992,7 @@ int kvm_device_msix_deassign(KVMState *s, uint32_t dev_id)
}

int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route,
uint64_t address, uint32_t data)
uint64_t address, uint32_t data, PCIDevice *dev)
{
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion target-mips/kvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ int kvm_arch_get_registers(CPUState *cs)
}

int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route,
uint64_t address, uint32_t data)
uint64_t address, uint32_t data, PCIDevice *dev)
{
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion target-ppc/kvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2483,7 +2483,7 @@ void kvmppc_hash64_write_pte(CPUPPCState *env, target_ulong pte_index,
}

int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route,
uint64_t address, uint32_t data)
uint64_t address, uint32_t data, PCIDevice *dev)
{
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion target-s390x/kvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2208,7 +2208,7 @@ int kvm_s390_vcpu_interrupt_post_load(S390CPU *cpu)
}

int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route,
uint64_t address, uint32_t data)
uint64_t address, uint32_t data, PCIDevice *dev)
{
S390PCIBusDevice *pbdev;
uint32_t fid = data >> ZPCI_MSI_VEC_BITS;
Expand Down

0 comments on commit dc9f06c

Please sign in to comment.