Blame SOURCES/0001-vhost-retranslate-vring-addr-when-memory-table-chang.patch

343f6f
From 96935c61631fe2095246b5dce5c6fea960e34c87 Mon Sep 17 00:00:00 2001
343f6f
From: Maxime Coquelin <maxime.coquelin@redhat.com>
343f6f
Date: Thu, 16 Aug 2018 19:29:22 +0200
343f6f
Subject: [PATCH] vhost: retranslate vring addr when memory table changes
343f6f
343f6f
[ backported from upstream commit d5022533c20aed365d513663806a999459037015 ]
343f6f
343f6f
When the vhost-user master sends memory updates using
343f6f
VHOST_USER_SET_MEM request, the user backends unmap and then
343f6f
mmap again the memory regions in its address space.
343f6f
343f6f
If the ring addresses have already been translated, it needs to
343f6f
be translated again as they point to unmapped memory.
343f6f
343f6f
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
343f6f
---
343f6f
 lib/librte_vhost/vhost_user.c | 24 ++++++++++++++++++++++--
343f6f
 1 file changed, 22 insertions(+), 2 deletions(-)
343f6f
343f6f
diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c
343f6f
index 07c848c7c..0eb5e0d65 100644
343f6f
--- a/lib/librte_vhost/vhost_user.c
343f6f
+++ b/lib/librte_vhost/vhost_user.c
343f6f
@@ -622,8 +622,9 @@ dump_guest_pages(struct virtio_net *dev)
343f6f
 #endif
343f6f
 
343f6f
 static int
343f6f
-vhost_user_set_mem_table(struct virtio_net *dev, struct VhostUserMsg *pmsg)
343f6f
+vhost_user_set_mem_table(struct virtio_net **pdev, struct VhostUserMsg *pmsg)
343f6f
 {
343f6f
+	struct virtio_net *dev = *pdev;
343f6f
 	struct VhostUserMemory memory = pmsg->payload.memory;
343f6f
 	struct rte_vhost_mem_region *reg;
343f6f
 	void *mmap_addr;
343f6f
@@ -732,6 +733,25 @@ vhost_user_set_mem_table(struct virtio_n
343f6f
 			mmap_offset);
343f6f
 	}
343f6f
 
343f6f
+	for (i = 0; i < dev->nr_vring; i++) {
343f6f
+		struct vhost_virtqueue *vq = dev->virtqueue[i];
343f6f
+
343f6f
+		if (vq->desc || vq->avail || vq->used) {
343f6f
+			/*
343f6f
+			 * If the memory table got updated, the ring addresses
343f6f
+			 * need to be translated again as virtual addresses have
343f6f
+			 * changed.
343f6f
+			 */
343f6f
+			vring_invalidate(dev, vq);
343f6f
+
343f6f
+			dev = translate_ring_addresses(dev, i);
343f6f
+			if (!dev)
343f6f
+				return -1;
343f6f
+
343f6f
+			*pdev = dev;
343f6f
+		}
343f6f
+	}
343f6f
+
343f6f
 	dump_guest_pages(dev);
343f6f
 
343f6f
 	return 0;
343f6f
@@ -1390,7 +1410,7 @@ vhost_user_msg_handler(int vid, int fd)
343f6f
 		break;
343f6f
 
343f6f
 	case VHOST_USER_SET_MEM_TABLE:
343f6f
-		ret = vhost_user_set_mem_table(dev, &msg;;
343f6f
+		ret = vhost_user_set_mem_table(&dev, &msg;;
343f6f
 		break;
343f6f
 
343f6f
 	case VHOST_USER_SET_LOG_BASE:
343f6f
-- 
343f6f
2.17.1
343f6f