From: andre.przywara@arm.com (Andre Przywara)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v8 14/16] extend GSI IRQ routing to take a device ID
Date: Fri, 4 Nov 2016 17:32:01 +0000 [thread overview]
Message-ID: <20161104173203.21168-15-andre.przywara@arm.com> (raw)
In-Reply-To: <20161104173203.21168-1-andre.przywara@arm.com>
For ITS emulation we need the device ID along with the MSI payload
and doorbell address to identify an MSI, so we need to put it in the
GSI IRQ routing table too.
There is a per-VM capability by which the kernel signals the need for
a device ID, so check this and put the device ID into the routing
table if needed.
For PCI devices we take the bus/device/function triplet and and that
to the routing setup call.
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
hw/pci-shmem.c | 3 ++-
include/kvm/irq.h | 2 +-
irq.c | 24 ++++++++++++++++++++++--
virtio/pci.c | 6 ++++--
4 files changed, 29 insertions(+), 6 deletions(-)
diff --git a/hw/pci-shmem.c b/hw/pci-shmem.c
index 7ce98cb..512b5b0 100644
--- a/hw/pci-shmem.c
+++ b/hw/pci-shmem.c
@@ -135,7 +135,8 @@ int pci_shmem__get_local_irqfd(struct kvm *kvm)
return fd;
if (pci_shmem_pci_device.msix.ctrl & cpu_to_le16(PCI_MSIX_FLAGS_ENABLE)) {
- gsi = irq__add_msix_route(kvm, &msix_table[0].msg);
+ gsi = irq__add_msix_route(kvm, &msix_table[0].msg,
+ pci_shmem_device.dev_num << 3);
if (gsi < 0)
return gsi;
} else {
diff --git a/include/kvm/irq.h b/include/kvm/irq.h
index f35eb7e..ee059e3 100644
--- a/include/kvm/irq.h
+++ b/include/kvm/irq.h
@@ -20,7 +20,7 @@ int irq__init(struct kvm *kvm);
int irq__exit(struct kvm *kvm);
int irq__allocate_routing_entry(void);
-int irq__add_msix_route(struct kvm *kvm, struct msi_msg *msg);
+int irq__add_msix_route(struct kvm *kvm, struct msi_msg *msg, u32 device_id);
void irq__update_msix_route(struct kvm *kvm, u32 gsi, struct msi_msg *msg);
#endif
diff --git a/irq.c b/irq.c
index 895e5eb..4c2721a 100644
--- a/irq.c
+++ b/irq.c
@@ -66,7 +66,21 @@ static bool check_for_irq_routing(struct kvm *kvm)
return has_irq_routing > 0;
}
-int irq__add_msix_route(struct kvm *kvm, struct msi_msg *msg)
+static bool check_for_msi_devid(struct kvm *kvm)
+{
+ static int needs_devid = 0;
+
+ if (needs_devid == 0) {
+ if (kvm__supports_vm_extension(kvm, KVM_CAP_MSI_DEVID))
+ needs_devid = 1;
+ else
+ needs_devid = -1;
+ }
+
+ return needs_devid > 0;
+}
+
+int irq__add_msix_route(struct kvm *kvm, struct msi_msg *msg, u32 device_id)
{
int r;
@@ -77,7 +91,7 @@ int irq__add_msix_route(struct kvm *kvm, struct msi_msg *msg)
if (r)
return r;
- irq_routing->entries[irq_routing->nr++] =
+ irq_routing->entries[irq_routing->nr] =
(struct kvm_irq_routing_entry) {
.gsi = next_gsi,
.type = KVM_IRQ_ROUTING_MSI,
@@ -86,6 +100,12 @@ int irq__add_msix_route(struct kvm *kvm, struct msi_msg *msg)
.u.msi.data = msg->data,
};
+ if (check_for_msi_devid(kvm)) {
+ irq_routing->entries[irq_routing->nr].flags = KVM_MSI_VALID_DEVID;
+ irq_routing->entries[irq_routing->nr].u.msi.devid = device_id;
+ }
+ irq_routing->nr++;
+
r = ioctl(kvm->vm_fd, KVM_SET_GSI_ROUTING, irq_routing);
if (r)
return r;
diff --git a/virtio/pci.c b/virtio/pci.c
index e9f81f7..da9a555 100644
--- a/virtio/pci.c
+++ b/virtio/pci.c
@@ -192,7 +192,8 @@ static bool virtio_pci__specific_io_out(struct kvm *kvm, struct virtio_device *v
break;
gsi = irq__add_msix_route(kvm,
- &vpci->msix_table[vec].msg);
+ &vpci->msix_table[vec].msg,
+ vpci->dev_hdr.dev_num << 3);
if (gsi >= 0) {
vpci->config_gsi = gsi;
break;
@@ -210,7 +211,8 @@ static bool virtio_pci__specific_io_out(struct kvm *kvm, struct virtio_device *v
break;
gsi = irq__add_msix_route(kvm,
- &vpci->msix_table[vec].msg);
+ &vpci->msix_table[vec].msg,
+ vpci->dev_hdr.dev_num << 3);
if (gsi < 0) {
if (gsi == -ENXIO &&
vpci->features & VIRTIO_PCI_F_SIGNAL_MSI)
--
2.9.0
next prev parent reply other threads:[~2016-11-04 17:32 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-04 17:31 [PATCH v8 00/16] kvmtool: arm: ITS emulation and GSI routing support Andre Przywara
2016-11-04 17:31 ` [PATCH v8 01/16] FDT: introduce global phandle allocation Andre Przywara
2016-12-09 11:55 ` Marc Zyngier
2016-12-19 18:43 ` Andre Przywara
2016-12-20 9:43 ` Andrew Jones
2016-12-09 12:03 ` Marc Zyngier
2016-12-19 18:43 ` Andre Przywara
2017-02-01 16:44 ` André Przywara
2017-02-01 17:13 ` Marc Zyngier
2017-02-02 16:31 ` Andre Przywara
2016-11-04 17:31 ` [PATCH v8 02/16] arm: use new phandle allocation functions Andre Przywara
2016-12-09 13:26 ` Marc Zyngier
2016-11-04 17:31 ` [PATCH v8 03/16] irq: move IRQ routing into irq.c Andre Przywara
2016-12-09 14:41 ` Marc Zyngier
2016-11-04 17:31 ` [PATCH v8 04/16] MSI-X: update GSI routing after changed MSI-X configuration Andre Przywara
2016-12-09 17:13 ` Marc Zyngier
2016-12-19 18:44 ` Andre Przywara
2016-11-04 17:31 ` [PATCH v8 05/16] virtio: fix endianness check for vhost support Andre Przywara
2016-11-04 17:31 ` [PATCH v8 06/16] PCI: Only allocate IRQ routing entry when available Andre Przywara
2016-11-04 17:31 ` [PATCH v8 07/16] update public Linux headers for GICv3 ITS emulation Andre Przywara
2016-11-04 17:31 ` [PATCH v8 08/16] arm: gic: allow 32-bit compilation Andre Przywara
2016-11-04 17:31 ` [PATCH v8 09/16] arm: allow creation of an MSI register frame region Andre Przywara
2016-11-04 17:31 ` [PATCH v8 10/16] arm: FDT: create MSI controller DT node Andre Przywara
2016-11-04 17:31 ` [PATCH v8 11/16] add kvm__check_vm_capability Andre Przywara
2016-11-04 17:31 ` [PATCH v8 12/16] PCI: inject PCI device ID on MSI injection Andre Przywara
2016-11-04 17:32 ` [PATCH v8 13/16] arm: setup SPI IRQ routing tables Andre Przywara
2016-11-04 17:32 ` Andre Przywara [this message]
2016-11-04 17:32 ` [PATCH v8 15/16] arm64: enable GICv3-ITS emulation Andre Przywara
2016-11-04 17:32 ` [PATCH v8 16/16] arm: add support for vGICv3 and vITS Andre Przywara
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161104173203.21168-15-andre.przywara@arm.com \
--to=andre.przywara@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox