vdpasim: fix memory leak when freeing IOTLBs
authorJason Wang <jasowang@redhat.com>
Tue, 13 Dec 2022 09:07:17 +0000 (17:07 +0800)
committerMichael S. Tsirkin <mst@redhat.com>
Wed, 28 Dec 2022 10:28:11 +0000 (05:28 -0500)
After commit bda324fd037a ("vdpasim: control virtqueue support"),
vdpasim->iommu became an array of IOTLB, so we should clean the
mappings of each free one by one instead of just deleting the ranges
in the first IOTLB which may leak maps.

Fixes: bda324fd037a ("vdpasim: control virtqueue support")
Cc: Gautam Dawar <gautam.dawar@xilinx.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
Message-Id: <20221213090717.61529-1-jasowang@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Gautam Dawar <gautam.dawar@amd.com>
drivers/vdpa/vdpa_sim/vdpa_sim.c

index b20689f8fe89cbe1b4d245ae3a0f82e2297a5029..cb88891b44a8c4218c244b39333cbcfa8faee8df 100644 (file)
@@ -689,7 +689,9 @@ static void vdpasim_free(struct vdpa_device *vdpa)
        }
 
        kvfree(vdpasim->buffer);
-       vhost_iotlb_free(vdpasim->iommu);
+       for (i = 0; i < vdpasim->dev_attr.nas; i++)
+               vhost_iotlb_reset(&vdpasim->iommu[i]);
+       kfree(vdpasim->iommu);
        kfree(vdpasim->vqs);
        kfree(vdpasim->config);
 }