public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] vhost-vdpa: cleanup memory maps when closing vdpa fds
@ 2023-01-31 14:53 Longpeng(Mike)
  2023-02-14  1:53 ` Longpeng (Mike, Cloud Infrastructure Service Product Dept.)
  2023-02-14  6:16 ` Jason Wang
  0 siblings, 2 replies; 11+ messages in thread
From: Longpeng(Mike) @ 2023-01-31 14:53 UTC (permalink / raw)
  To: mst, jasowang
  Cc: arei.gonglei, yechuan, huangzhichao, virtualization, linux-kernel,
	kvm, Longpeng

From: Longpeng <longpeng2@huawei.com>

We must cleanup all memory maps when closing the vdpa fds, otherwise
some critical resources (e.g. memory, iommu map) will leaked if the
userspace exits unexpectedly (e.g. kill -9).

Signed-off-by: Longpeng <longpeng2@huawei.com>
---
 drivers/vhost/vdpa.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index a527eeeac637..37477cffa5aa 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -823,6 +823,18 @@ static void vhost_vdpa_unmap(struct vhost_vdpa *v,
 		vhost_vdpa_remove_as(v, asid);
 }
 
+static void vhost_vdpa_clean_map(struct vhost_vdpa *v)
+{
+	struct vhost_vdpa_as *as;
+	u32 asid;
+
+	for (asid = 0; asid < v->vdpa->nas; asid++) {
+		as = asid_to_as(v, asid);
+		if (as)
+			vhost_vdpa_unmap(v, &as->iotlb, 0ULL, 0ULL - 1);
+	}
+}
+
 static int vhost_vdpa_va_map(struct vhost_vdpa *v,
 			     struct vhost_iotlb *iotlb,
 			     u64 iova, u64 size, u64 uaddr, u32 perm)
@@ -1247,6 +1259,7 @@ static int vhost_vdpa_release(struct inode *inode, struct file *filep)
 	vhost_vdpa_clean_irq(v);
 	vhost_vdpa_reset(v);
 	vhost_dev_stop(&v->vdev);
+	vhost_vdpa_clean_map(v);
 	vhost_vdpa_free_domain(v);
 	vhost_vdpa_config_put(v);
 	vhost_vdpa_cleanup(v);
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2023-03-10  8:40 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-31 14:53 [PATCH] vhost-vdpa: cleanup memory maps when closing vdpa fds Longpeng(Mike)
2023-02-14  1:53 ` Longpeng (Mike, Cloud Infrastructure Service Product Dept.)
2023-02-14  6:16 ` Jason Wang
2023-02-14  6:27   ` Longpeng (Mike, Cloud Infrastructure Service Product Dept.)
2023-02-15  2:00     ` Jason Wang
2023-02-15  2:49       ` Longpeng (Mike, Cloud Infrastructure Service Product Dept.)
2023-02-15  2:56         ` Jason Wang
2023-02-15  5:15           ` Longpeng (Mike, Cloud Infrastructure Service Product Dept.)
2023-02-15 11:45             ` Michael S. Tsirkin
2023-02-17  5:58             ` Jason Wang
2023-03-10  8:37             ` Michael S. Tsirkin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox