diff mbox

[2/3,RESEND] kvm: qemu: fix leak of ioperm data

Message ID 715D42877B251141A38726ABF5CABF2C01957E5A51@pdsmsx503.ccr.corp.intel.com (mailing list archive)
State Accepted, archived
Headers show

Commit Message

Han, Weidong Feb. 6, 2009, 8:58 a.m. UTC
implement kvm_remove_ioperm_data to free ioperm data, and call it
in free_assigned_device to avoid leak.

Signed-off-by: Weidong Han <weidong.han@intel.com>
---
 qemu/hw/device-assignment.c |    2 ++
 qemu/qemu-kvm.c             |   17 +++++++++++++++++
 qemu/qemu-kvm.h             |    1 +
 3 files changed, 20 insertions(+), 0 deletions(-)

Comments

Mark McLoughlin Feb. 6, 2009, 10:16 a.m. UTC | #1
On Fri, 2009-02-06 at 16:58 +0800, Han, Weidong wrote:
> implement kvm_remove_ioperm_data to free ioperm data, and call it
> in free_assigned_device to avoid leak.
> 
> Signed-off-by: Weidong Han <weidong.han@intel.com>

Acked-by: Mark McLoughlin <markmc@redhat.com>

Cheers,
Mark.

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/qemu/hw/device-assignment.c b/qemu/hw/device-assignment.c
index 5003611..82ff00a 100644
--- a/qemu/hw/device-assignment.c
+++ b/qemu/hw/device-assignment.c
@@ -457,6 +457,8 @@  void free_assigned_device(AssignedDevInfo *adev)
             if (!pci_region->valid || !(pci_region->type & IORESOURCE_MEM))
                 continue;
 
+            kvm_remove_ioperm_data(region->u.r_baseport, region->r_size);
+
             if (region->u.r_virtbase) {
                 int ret = munmap(region->u.r_virtbase,
                                  (pci_region->size + 0xFFF) & 0xFFFFF000);
diff --git a/qemu/qemu-kvm.c b/qemu/qemu-kvm.c
index 5ff63ad..f14237e 100644
--- a/qemu/qemu-kvm.c
+++ b/qemu/qemu-kvm.c
@@ -1329,6 +1329,23 @@  void kvm_add_ioperm_data(struct ioperm_data *data)
     LIST_INSERT_HEAD(&ioperm_head, data, entries);
 }
 
+void kvm_remove_ioperm_data(unsigned long start_port, unsigned long num)
+{
+    struct ioperm_data *data;
+
+    data = LIST_FIRST(&ioperm_head);
+    while (data) {
+        struct ioperm_data *next = LIST_NEXT(data, entries);
+
+        if (data->start_port == start_port && data->num == num) {
+            LIST_REMOVE(data, entries);
+            qemu_free(data);
+        }
+
+        data = next;
+    }
+}
+
 void kvm_ioperm(CPUState *env, void *data)
 {
     if (kvm_enabled() && qemu_system_ready)
diff --git a/qemu/qemu-kvm.h b/qemu/qemu-kvm.h
index 042dd93..e7acd2e 100644
--- a/qemu/qemu-kvm.h
+++ b/qemu/qemu-kvm.h
@@ -127,6 +127,7 @@  struct ioperm_data;
 
 void kvm_ioperm(CPUState *env, void *data);
 void kvm_add_ioperm_data(struct ioperm_data *data);
+void kvm_remove_ioperm_data(unsigned long start_port, unsigned long num);
 void kvm_arch_do_ioperm(void *_data);
 #endif