[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[qemu-xen stable-4.16] vfio: Fix memory leak of hostwin



commit 8c2d5911debfd00a7e8b3d8989c23e892c872043
Author:     Peng Liang <liangpeng10@xxxxxxxxxx>
AuthorDate: Wed Nov 17 09:47:39 2021 +0800
Commit:     Michael Roth <michael.roth@xxxxxxx>
CommitDate: Tue Dec 14 14:49:55 2021 -0600

    vfio: Fix memory leak of hostwin
    
    hostwin is allocated and added to hostwin_list in vfio_host_win_add, but
    it is only deleted from hostwin_list in vfio_host_win_del, which causes
    a memory leak.  Also, freeing all elements in hostwin_list is missing in
    vfio_disconnect_container.
    
    Fix: 2e4109de8e58 ("vfio/spapr: Create DMA window dynamically (SPAPR IOMMU 
v2)")
    CC: qemu-stable@xxxxxxxxxx
    Signed-off-by: Peng Liang <liangpeng10@xxxxxxxxxx>
    Link: 
https://lore.kernel.org/r/20211117014739.1839263-1-liangpeng10@xxxxxxxxxx
    Signed-off-by: Alex Williamson <alex.williamson@xxxxxxxxxx>
    (cherry picked from commit f3bc3a73c908df15966e66f88d5a633bd42fd029)
    Signed-off-by: Michael Roth <michael.roth@xxxxxxx>
---
 hw/vfio/common.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 8728d4d5c2..af37346aca 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -551,6 +551,7 @@ static int vfio_host_win_del(VFIOContainer *container, 
hwaddr min_iova,
     QLIST_FOREACH(hostwin, &container->hostwin_list, hostwin_next) {
         if (hostwin->min_iova == min_iova && hostwin->max_iova == max_iova) {
             QLIST_REMOVE(hostwin, hostwin_next);
+            g_free(hostwin);
             return 0;
         }
     }
@@ -2230,6 +2231,7 @@ static void vfio_disconnect_container(VFIOGroup *group)
     if (QLIST_EMPTY(&container->group_list)) {
         VFIOAddressSpace *space = container->space;
         VFIOGuestIOMMU *giommu, *tmp;
+        VFIOHostDMAWindow *hostwin, *next;
 
         QLIST_REMOVE(container, next);
 
@@ -2240,6 +2242,12 @@ static void vfio_disconnect_container(VFIOGroup *group)
             g_free(giommu);
         }
 
+        QLIST_FOREACH_SAFE(hostwin, &container->hostwin_list, hostwin_next,
+                           next) {
+            QLIST_REMOVE(hostwin, hostwin_next);
+            g_free(hostwin);
+        }
+
         trace_vfio_disconnect_container(container->fd);
         close(container->fd);
         g_free(container);
--
generated by git-patchbot for /home/xen/git/qemu-xen.git#stable-4.16



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.