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

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