Skip to contentSkip to conversation

vdpasim: fix memory leak when freeing IOTLBs

PATCH In review Jason Wang 2 participants 2 messages Dec 13, 2022 virtio core

lore
Share & tools
lore

Jason Wang

author
#0 lore raw

PATCH 1/1 vdpasim: fix memory leak when freeing IOTLBs

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 <[email protected]>
---
 drivers/vdpa/vdpa_sim/vdpa_sim.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/vdpa/vdpa_sim/vdpa_sim.c +3 -1
index b071f0d842fb..9668dc477843 100644
@@ -690,7 +690,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);
 }
Signature · 6 lines
2.25.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Reviewed-by on v1 1/1
#1 lore raw
Quoted 31 lines · Jason Wang

CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.

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 <[email protected]>
---
  drivers/vdpa/vdpa_sim/vdpa_sim.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/vdpa/vdpa_sim/vdpa_sim.c +3 -2
index b071f0d842fb..9668dc477843 100644
@@ -690,7 +690,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);
  }
--
Quoted 2 lines

2.25.1

Looks good to me.