From patchwork Thu Jun 10 19:27:15 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 105451 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o5AJRYm1024703 for ; Thu, 10 Jun 2010 19:27:34 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759500Ab0FJT1c (ORCPT ); Thu, 10 Jun 2010 15:27:32 -0400 Received: from qmta04.emeryville.ca.mail.comcast.net ([76.96.30.40]:34908 "EHLO qmta04.emeryville.ca.mail.comcast.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759128Ab0FJT1b (ORCPT ); Thu, 10 Jun 2010 15:27:31 -0400 Received: from omta05.emeryville.ca.mail.comcast.net ([76.96.30.43]) by qmta04.emeryville.ca.mail.comcast.net with comcast id UCoB1e0050vp7WLA4KTXlC; Thu, 10 Jun 2010 19:27:31 +0000 Received: from localhost.localdomain ([75.71.122.219]) by omta05.emeryville.ca.mail.comcast.net with comcast id UKTW1e00D4k7Kz78RKTWdB; Thu, 10 Jun 2010 19:27:31 +0000 From: Alex Williamson Subject: [PATCH] device-assignment: Cleanup on exit To: kvm@vger.kernel.org Date: Thu, 10 Jun 2010 13:27:15 -0600 Message-ID: <20100610192715.27230.23460.stgit@localhost.localdomain> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Thu, 10 Jun 2010 19:27:34 +0000 (UTC) diff --git a/hw/device-assignment.c b/hw/device-assignment.c index 2b963b5..d2c5fbb 100644 --- a/hw/device-assignment.c +++ b/hw/device-assignment.c @@ -60,6 +60,8 @@ static void assigned_dev_load_option_rom(AssignedDevice *dev); +static void assigned_dev_unregister_msix_mmio(AssignedDevice *dev); + static uint32_t guest_to_host_ioport(AssignedDevRegion *region, uint32_t addr) { return region->u.r_baseport + (addr - region->e_physbase); @@ -783,10 +785,14 @@ static void free_assigned_device(AssignedDevice *dev) fprintf(stderr, "Failed to unmap assigned device region: %s\n", strerror(errno)); + close(pci_region->resource_fd); } } } + if (dev->cap.available & ASSIGNED_DEVICE_CAP_MSIX) + assigned_dev_unregister_msix_mmio(dev); + if (dev->real_device.config_fd) { close(dev->real_device.config_fd); dev->real_device.config_fd = 0; @@ -1370,6 +1376,21 @@ static int assigned_dev_register_msix_mmio(AssignedDevice *dev) return 0; } +static void assigned_dev_unregister_msix_mmio(AssignedDevice *dev) +{ + if (!dev->msix_table_page) + return; + + cpu_unregister_io_memory(dev->mmio_index); + dev->mmio_index = 0; + + if (munmap(dev->msix_table_page, 0x1000) == -1) { + fprintf(stderr, "error unmapping msix_table_page! %s\n", + strerror(errno)); + } + dev->msix_table_page = NULL; +} + static int assigned_initfn(struct PCIDevice *pci_dev) { AssignedDevice *dev = DO_UPCAST(AssignedDevice, dev, pci_dev);