From patchwork Wed Jul 20 17:04:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 9240033 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1BEBA60574 for ; Wed, 20 Jul 2016 17:04:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0593027D76 for ; Wed, 20 Jul 2016 17:04:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ECD4827D9B; Wed, 20 Jul 2016 17:04:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 82F5027D29 for ; Wed, 20 Jul 2016 17:04:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754871AbcGTREc (ORCPT ); Wed, 20 Jul 2016 13:04:32 -0400 Received: from foss.arm.com ([217.140.101.70]:43656 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754403AbcGTREH (ORCPT ); Wed, 20 Jul 2016 13:04:07 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DCF7ABF3; Wed, 20 Jul 2016 10:05:17 -0700 (PDT) Received: from e104803-lin.lan (unknown [10.1.207.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3510B3F387; Wed, 20 Jul 2016 10:04:06 -0700 (PDT) From: Andre Przywara To: Will Deacon , Marc Zyngier Cc: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v7 13/15] extend GSI IRQ routing to take a device ID Date: Wed, 20 Jul 2016 18:04:33 +0100 Message-Id: <20160720170435.28090-14-andre.przywara@arm.com> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160720170435.28090-1-andre.przywara@arm.com> References: <20160720170435.28090-1-andre.przywara@arm.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 4386a70..587b91d 100644 --- a/irq.c +++ b/irq.c @@ -62,7 +62,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; @@ -73,7 +87,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, @@ -82,6 +96,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)