Blame SOURCES/0001-vhost-flush-IOTLB-cache-on-new-mem-table-handling.patch

dd2e6b
From af53db486792f3d864c9a30dc13ee12402994640 Mon Sep 17 00:00:00 2001
dd2e6b
From: Maxime Coquelin <maxime.coquelin@redhat.com>
dd2e6b
Date: Thu, 2 Aug 2018 19:21:22 +0200
dd2e6b
Subject: [PATCH] vhost: flush IOTLB cache on new mem table handling
dd2e6b
dd2e6b
IOTLB entries contain the host virtual address of the guest
dd2e6b
pages. When receiving a new VHOST_USER_SET_MEM_TABLE request,
dd2e6b
the previous regions get unmapped, so the IOTLB entries, if any,
dd2e6b
will be invalid. It does cause the vhost-user process to
dd2e6b
segfault.
dd2e6b
dd2e6b
This patch introduces a new function to flush the IOTLB cache,
dd2e6b
and call it as soon as the backend handles a VHOST_USER_SET_MEM
dd2e6b
request.
dd2e6b
dd2e6b
Fixes: 69c90e98f483 ("vhost: enable IOMMU support")
dd2e6b
Cc: stable@dpdk.org
dd2e6b
dd2e6b
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
dd2e6b
Reviewed-by: Tiwei Bie <tiwei.bie@intel.com>
dd2e6b
Reviewed-by: Jens Freimann <jfreimann@redhat.com>
dd2e6b
---
dd2e6b
 lib/librte_vhost/iotlb.c      | 10 ++++++++--
dd2e6b
 lib/librte_vhost/iotlb.h      |  2 +-
dd2e6b
 lib/librte_vhost/vhost_user.c |  5 +++++
dd2e6b
 3 files changed, 14 insertions(+), 3 deletions(-)
dd2e6b
dd2e6b
diff --git a/lib/librte_vhost/iotlb.c b/lib/librte_vhost/iotlb.c
dd2e6b
index c11ebcaac..c6354fef7 100644
dd2e6b
--- a/lib/librte_vhost/iotlb.c
dd2e6b
+++ b/lib/librte_vhost/iotlb.c
dd2e6b
@@ -303,6 +303,13 @@ vhost_user_iotlb_cache_find(struct vhost_virtqueue *vq, uint64_t iova,
dd2e6b
 	return vva;
dd2e6b
 }
dd2e6b
 
dd2e6b
+void
dd2e6b
+vhost_user_iotlb_flush_all(struct vhost_virtqueue *vq)
dd2e6b
+{
dd2e6b
+	vhost_user_iotlb_cache_remove_all(vq);
dd2e6b
+	vhost_user_iotlb_pending_remove_all(vq);
dd2e6b
+}
dd2e6b
+
dd2e6b
 int
dd2e6b
 vhost_user_iotlb_init(struct virtio_net *dev, int vq_index)
dd2e6b
 {
dd2e6b
@@ -315,8 +322,7 @@ vhost_user_iotlb_init(struct virtio_net *dev, int vq_index)
dd2e6b
 		 * The cache has already been initialized,
dd2e6b
 		 * just drop all cached and pending entries.
dd2e6b
 		 */
dd2e6b
-		vhost_user_iotlb_cache_remove_all(vq);
dd2e6b
-		vhost_user_iotlb_pending_remove_all(vq);
dd2e6b
+		vhost_user_iotlb_flush_all(vq);
dd2e6b
 	}
dd2e6b
 
dd2e6b
 #ifdef RTE_LIBRTE_VHOST_NUMA
dd2e6b
diff --git a/lib/librte_vhost/iotlb.h b/lib/librte_vhost/iotlb.h
dd2e6b
index e7083e37b..60b9e4c57 100644
dd2e6b
--- a/lib/librte_vhost/iotlb.h
dd2e6b
+++ b/lib/librte_vhost/iotlb.h
dd2e6b
@@ -73,7 +73,7 @@ void vhost_user_iotlb_pending_insert(struct vhost_virtqueue *vq, uint64_t iova,
dd2e6b
 						uint8_t perm);
dd2e6b
 void vhost_user_iotlb_pending_remove(struct vhost_virtqueue *vq, uint64_t iova,
dd2e6b
 						uint64_t size, uint8_t perm);
dd2e6b
-
dd2e6b
+void vhost_user_iotlb_flush_all(struct vhost_virtqueue *vq);
dd2e6b
 int vhost_user_iotlb_init(struct virtio_net *dev, int vq_index);
dd2e6b
 
dd2e6b
 #endif /* _VHOST_IOTLB_H_ */
dd2e6b
diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c
dd2e6b
index dc53ff712..a2d4c9ffc 100644
dd2e6b
--- a/lib/librte_vhost/vhost_user.c
dd2e6b
+++ b/lib/librte_vhost/vhost_user.c
dd2e6b
@@ -813,6 +813,11 @@ vhost_user_set_mem_table(struct virtio_net **pdev, struct VhostUserMsg *pmsg)
dd2e6b
 		dev->mem = NULL;
dd2e6b
 	}
dd2e6b
 
dd2e6b
+	/* Flush IOTLB cache as previous HVAs are now invalid */
dd2e6b
+	if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))
dd2e6b
+		for (i = 0; i < dev->nr_vring; i++)
dd2e6b
+			vhost_user_iotlb_flush_all(dev->virtqueue[i]);
dd2e6b
+
dd2e6b
 	dev->nr_guest_pages = 0;
dd2e6b
 	if (!dev->guest_pages) {
dd2e6b
 		dev->max_guest_pages = 8;
dd2e6b
-- 
dd2e6b
2.17.1
dd2e6b