Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 340e01248478ba8b78a6d4d1809b1eff > files > 315

kvm-83-270.el5_11.src.rpm

From a798429af80d3419d418fd989017090c696e7fd8 Mon Sep 17 00:00:00 2001
From: Amos Kong <akong@redhat.com>
Date: Mon, 19 Dec 2011 13:25:20 +0100
Subject: [PATCH 2/3] device-assignment: Cleanup on exit

RH-Author: Amos Kong <akong@redhat.com>
Message-id: <20111219132520.7612.4601.stgit@dhcp-8-167.nay.redhat.com>
Patchwork-id: 35882
O-Subject: [RHEL5.9 KVM PATCH 2/2] device-assignment: Cleanup on exit
Bugzilla: 761350
RH-Acked-by: Alex Williamson <alex.williamson@redhat.com>
RH-Acked-by: Avi Kivity <avi@redhat.com>
RH-Acked-by: Xiao Wang <jasowang@redhat.com>

Bugzilla: 761350
Upstream: applied
Test status: Tested in my local machine

close() the resource fd when we're done with it.  Unregister and munmap the
anonymous memory for the MSIX table.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

Manually cherry-picked from 909bfdba8ba01d7f3b36c3e72d965f189df83bf2

Signed-off-by: Amos Kong <akong@redhat.com>
---
 qemu/hw/device-assignment.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)

Signed-off-by: Michal Novotny <minovotn@redhat.com>
---
 qemu/hw/device-assignment.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/qemu/hw/device-assignment.c b/qemu/hw/device-assignment.c
index ab33e75..5874a75 100644
--- a/qemu/hw/device-assignment.c
+++ b/qemu/hw/device-assignment.c
@@ -56,6 +56,8 @@
 #define DEBUG(fmt, ...) do { } while(0)
 #endif
 
+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);
@@ -576,6 +578,8 @@ static void free_assigned_device(AssignedDevInfo *adev)
             }
             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);
@@ -1101,6 +1105,22 @@ 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;
+}
+
+
 struct PCIDevice *init_assigned_device(AssignedDevInfo *adev, PCIBus *bus)
 {
     int r;
-- 
1.7.7.6