From patchwork Fri Dec 6 20:48:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 298277 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 76A442C00A7 for ; Sat, 7 Dec 2013 08:24:12 +1100 (EST) Received: from localhost ([::1]:33410 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vp2MH-0008T9-92 for incoming@patchwork.ozlabs.org; Fri, 06 Dec 2013 15:50:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38273) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vp2Kh-0006RB-4j for qemu-devel@nongnu.org; Fri, 06 Dec 2013 15:49:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vp2Kc-0008Ag-3B for qemu-devel@nongnu.org; Fri, 06 Dec 2013 15:49:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:16359) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vp2KQ-00089I-Sh; Fri, 06 Dec 2013 15:48:51 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rB6KmnWY003989 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 6 Dec 2013 15:48:49 -0500 Received: from bling.home (ovpn-113-87.phx2.redhat.com [10.3.113.87]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id rB6KmmQ7005279; Fri, 6 Dec 2013 15:48:48 -0500 To: aliguori@amazon.com From: Alex Williamson Date: Fri, 06 Dec 2013 13:48:48 -0700 Message-ID: <20131206204848.16731.62459.stgit@bling.home> In-Reply-To: <20131206204715.16731.12627.stgit@bling.home> References: <20131206204715.16731.12627.stgit@bling.home> User-Agent: StGit/0.16 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-stable@nongnu.org Subject: [Qemu-devel] [PULL 5/5] vfio-pci: Release all MSI-X vectors when disabled X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@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 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); }