From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50546) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VjdX0-0007vt-O9 for qemu-devel@nongnu.org; Thu, 21 Nov 2013 18:19:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VjdWv-0007TI-Nd for qemu-devel@nongnu.org; Thu, 21 Nov 2013 18:19:30 -0500 From: Alex Williamson Date: Thu, 21 Nov 2013 16:19:23 -0700 Message-ID: <20131121231843.16252.53408.stgit@bling.home> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH] vfio-pci: Release all MSI-X vectors when disabled List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: alex.williamson@redhat.com, qemu-devel@nongnu.org Cc: bsd@redhat.com, qemu-stable@nongnu.org We were relying on msix_unset_vector_notifiers() to release all the vectors when we disable MSI-X, but this only happens when MSI-X is still enabled on the device. Perform further cleanup by releasing any remaining vectors listed as in-use after this call. This caused a leak of IRQ routes on hotplug depending on how the guest OS prepared the device for removal. Signed-off-by: Alex Williamson Cc: qemu-stable@nongnu.org --- hw/misc/vfio.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c index f7f8a19..355b018 100644 --- a/hw/misc/vfio.c +++ b/hw/misc/vfio.c @@ -878,8 +878,20 @@ static void vfio_disable_msi_common(VFIODevice *vdev) static void vfio_disable_msix(VFIODevice *vdev) { + int i; + msix_unset_vector_notifiers(&vdev->pdev); + /* + * MSI-X will only release vectors if MSI-X is still enabled on the + * device, check through the rest and release it ourselves if necessary. + */ + for (i = 0; i < vdev->nr_vectors; i++) { + if (vdev->msi_vectors[i].use) { + vfio_msix_vector_release(&vdev->pdev, i); + } + } + if (vdev->nr_vectors) { vfio_disable_irqindex(vdev, VFIO_PCI_MSIX_IRQ_INDEX); }