patches for DPDK stable branches
 help / color / mirror / Atom feed
* [dpdk-stable] [PATCH] vhost: retranslate vring addr when memory table changes
@ 2018-08-16 17:29 Maxime Coquelin
  2018-08-16 17:55 ` Yongseok Koh
  0 siblings, 1 reply; 2+ messages in thread
From: Maxime Coquelin @ 2018-08-16 17:29 UTC (permalink / raw)
  To: yskoh, stable; +Cc: bluca, Maxime Coquelin

[ Backported from upstream commit d5022533c20aed365d513663806a999459037015 ]

When the vhost-user master sends memory updates using
VHOST_USER_SET_MEM request, the user backends unmap and then
mmap again the memory regions in its address space.

If the ring addresses have already been translated, it needs to
be translated again as they point to unmapped memory.

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---

Hi Yongseok,

This patch is already in upstream master since v18.05, but wasn't
backported to stable because it initially fixed a bug in a new
feature.

I have been reported of a crash in the vhost-user library that
this patch fixes, so we would need to backport this patch to
v17.11 LTS.

Thanks,
Maxime

 lib/librte_vhost/vhost_user.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c
index 07c848c7c..0eb5e0d65 100644
--- a/lib/librte_vhost/vhost_user.c
+++ b/lib/librte_vhost/vhost_user.c
@@ -623,8 +623,9 @@ vhost_memory_changed(struct VhostUserMemory *new,
 }
 
 static int
-vhost_user_set_mem_table(struct virtio_net *dev, struct VhostUserMsg *pmsg)
+vhost_user_set_mem_table(struct virtio_net **pdev, struct VhostUserMsg *pmsg)
 {
+	struct virtio_net *dev = *pdev;
 	struct VhostUserMemory memory = pmsg->payload.memory;
 	struct rte_vhost_mem_region *reg;
 	void *mmap_addr;
@@ -748,6 +749,25 @@ vhost_user_set_mem_table(struct virtio_net *dev, struct VhostUserMsg *pmsg)
 			mmap_offset);
 	}
 
+	for (i = 0; i < dev->nr_vring; i++) {
+		struct vhost_virtqueue *vq = dev->virtqueue[i];
+
+		if (vq->desc || vq->avail || vq->used) {
+			/*
+			 * If the memory table got updated, the ring addresses
+			 * need to be translated again as virtual addresses have
+			 * changed.
+			 */
+			vring_invalidate(dev, vq);
+
+			dev = translate_ring_addresses(dev, i);
+			if (!dev)
+				return -1;
+
+			*pdev = dev;
+		}
+	}
+
 	dump_guest_pages(dev);
 
 	return 0;
@@ -1409,7 +1429,7 @@ vhost_user_msg_handler(int vid, int fd)
 		break;
 
 	case VHOST_USER_SET_MEM_TABLE:
-		ret = vhost_user_set_mem_table(dev, &msg);
+		ret = vhost_user_set_mem_table(&dev, &msg);
 		break;
 
 	case VHOST_USER_SET_LOG_BASE:
-- 
2.17.1

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

* Re: [dpdk-stable] [PATCH] vhost: retranslate vring addr when memory table changes
  2018-08-16 17:29 [dpdk-stable] [PATCH] vhost: retranslate vring addr when memory table changes Maxime Coquelin
@ 2018-08-16 17:55 ` Yongseok Koh
  0 siblings, 0 replies; 2+ messages in thread
From: Yongseok Koh @ 2018-08-16 17:55 UTC (permalink / raw)
  To: Maxime Coquelin; +Cc: stable, bluca


> On Aug 16, 2018, at 10:29 AM, Maxime Coquelin <maxime.coquelin@redhat.com> wrote:
> 
> [ Backported from upstream commit d5022533c20aed365d513663806a999459037015 ]
> 
> When the vhost-user master sends memory updates using
> VHOST_USER_SET_MEM request, the user backends unmap and then
> mmap again the memory regions in its address space.
> 
> If the ring addresses have already been translated, it needs to
> be translated again as they point to unmapped memory.
> 
> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
> ---
> 
> Hi Yongseok,
> 
> This patch is already in upstream master since v18.05, but wasn't
> backported to stable because it initially fixed a bug in a new
> feature.
> 
> I have been reported of a crash in the vhost-user library that
> this patch fixes, so we would need to backport this patch to
> v17.11 LTS.

Many thanks.
Applied to stable/17.11

Yongseok

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

end of thread, other threads:[~2018-08-16 17:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-16 17:29 [dpdk-stable] [PATCH] vhost: retranslate vring addr when memory table changes Maxime Coquelin
2018-08-16 17:55 ` Yongseok Koh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).