From patchwork Tue Apr 25 14:39:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 9698337 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 E04176020A for ; Tue, 25 Apr 2017 14:39:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C5AC028484 for ; Tue, 25 Apr 2017 14:39:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BA70E2857D; Tue, 25 Apr 2017 14:39:34 +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 6C41028484 for ; Tue, 25 Apr 2017 14:39:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1947881AbdDYOjb (ORCPT ); Tue, 25 Apr 2017 10:39:31 -0400 Received: from foss.arm.com ([217.140.101.70]:42114 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1948168AbdDYOhd (ORCPT ); Tue, 25 Apr 2017 10:37:33 -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 5299716BA; Tue, 25 Apr 2017 07:37:33 -0700 (PDT) Received: from e104803-lin.lan (unknown [10.1.207.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2D2203F220; Tue, 25 Apr 2017 07:37:32 -0700 (PDT) From: Andre Przywara To: Will Deacon , Marc Zyngier Cc: Jean-Philippe Brucker , kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [kvmtool PATCH v10 06/15] PCI: Only allocate IRQ routing entry when available Date: Tue, 25 Apr 2017 15:39:23 +0100 Message-Id: <20170425143932.17235-7-andre.przywara@arm.com> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170425143932.17235-1-andre.przywara@arm.com> References: <20170425143932.17235-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 If we need to inject an MSI into the guest, we rely at the moment on a working GSI MSI routing functionality. However we can get away without IRQ routing, if the host supports MSI injection via the KVM_SIGNAL_MSI ioctl. So we try the GSI routing first, but if that fails due to a missing IRQ routing functionality, we fall back to KVM_SIGNAL_MSI (if that is supported). Signed-off-by: Andre Przywara --- virtio/pci.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/virtio/pci.c b/virtio/pci.c index e9f36c7..04176c1 100644 --- a/virtio/pci.c +++ b/virtio/pci.c @@ -193,8 +193,20 @@ static bool virtio_pci__specific_io_out(struct kvm *kvm, struct virtio_device *v gsi = irq__add_msix_route(kvm, &vpci->msix_table[vec].msg); - if (gsi >= 0) - vpci->config_gsi = gsi; + /* + * We don't need IRQ routing if we can use + * MSI injection via the KVM_SIGNAL_MSI ioctl. + */ + if (gsi == -ENXIO && + vpci->features & VIRTIO_PCI_F_SIGNAL_MSI) + break; + + if (gsi < 0) { + die("failed to configure MSIs"); + break; + } + + vpci->config_gsi = gsi; break; case VIRTIO_MSI_QUEUE_VECTOR: vec = ioport__read16(data); @@ -205,8 +217,19 @@ static bool virtio_pci__specific_io_out(struct kvm *kvm, struct virtio_device *v gsi = irq__add_msix_route(kvm, &vpci->msix_table[vec].msg); - if (gsi < 0) + /* + * We don't need IRQ routing if we can use + * MSI injection via the KVM_SIGNAL_MSI ioctl. + */ + if (gsi == -ENXIO && + vpci->features & VIRTIO_PCI_F_SIGNAL_MSI) break; + + if (gsi < 0) { + die("failed to configure MSIs"); + break; + } + vpci->gsis[vpci->queue_selector] = gsi; if (vdev->ops->notify_vq_gsi) vdev->ops->notify_vq_gsi(kvm, vpci->dev,