From: Alex Williamson Subject: [PULL 5/5] vfio-pci: Release all MSI-X vectors when disabled Date: Fri, 06 Dec 2013 13:48:48 -0700 Message-ID: <20131206204848.16731.62459.stgit@bling.home> References: <20131206204715.16731.12627.stgit@bling.home> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-stable@nongnu.org To: aliguori@amazon.com Return-path: Received: from mx1.redhat.com ([209.132.183.28]:55595 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758322Ab3LFUsv (ORCPT ); Fri, 6 Dec 2013 15:48:51 -0500 In-Reply-To: <20131206204715.16731.12627.stgit@bling.home> Sender: kvm-owner@vger.kernel.org List-ID: 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 f367537..9aecaa8 100644 --- a/hw/misc/vfio.c +++ b/hw/misc/vfio.c @@ -905,8 +905,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); }