DPDK patches and discussions
 help / color / mirror / Atom feed
From: Tiwei Bie <tiwei.bie@intel.com>
To: dev@dpdk.org, maxime.coquelin@redhat.com, zhihong.wang@intel.com
Cc: lvyilong.lyl@alibaba-inc.com, yinan.wang@intel.com,
	xnhp0320@icloud.com, stable@dpdk.org
Subject: [dpdk-dev] [PATCH 2/3] vhost: fix vring addr handling during live migration
Date: Mon, 19 Aug 2019 19:34:56 +0800	[thread overview]
Message-ID: <20190819113457.15569-3-tiwei.bie@intel.com> (raw)
In-Reply-To: <20190819113457.15569-1-tiwei.bie@intel.com>

When live migration starts, QEMU will set ring addrs again for
each virtqueue. In this case, we should try to translate ring
addrs after we invalidating the ring, otherwise virtqueues can
be enabled with the addrs untranslated. Besides, also leverage
the access_ok flag in non-IOMMU case to prevent the data path
accessing invalidated virtqueues.

Fixes: 5a4933e56be4 ("vhost: postpone ring address translations at kick time only")
Cc: stable@dpdk.org

Reported-by: Yilong Lv <lvyilong.lyl@alibaba-inc.com>
Signed-off-by: Tiwei Bie <tiwei.bie@intel.com>
---
 lib/librte_vhost/vhost.c      |  3 +--
 lib/librte_vhost/vhost_user.c | 12 ++++++++++--
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c
index 981837b5d..77be16069 100644
--- a/lib/librte_vhost/vhost.c
+++ b/lib/librte_vhost/vhost.c
@@ -358,7 +358,7 @@ vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq)
 {
 
 	if (!(dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM)))
-		goto out;
+		return -1;
 
 	if (vq_is_packed(dev)) {
 		if (vring_translate_packed(dev, vq) < 0)
@@ -367,7 +367,6 @@ vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq)
 		if (vring_translate_split(dev, vq) < 0)
 			return -1;
 	}
-out:
 	vq->access_ok = 1;
 
 	return 0;
diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c
index ea43ab139..381250cbc 100644
--- a/lib/librte_vhost/vhost_user.c
+++ b/lib/librte_vhost/vhost_user.c
@@ -622,6 +622,7 @@ translate_ring_addresses(struct virtio_net *dev, int vq_index)
 			return dev;
 		}
 
+		vq->access_ok = 1;
 		return dev;
 	}
 
@@ -680,6 +681,7 @@ translate_ring_addresses(struct virtio_net *dev, int vq_index)
 	}
 
 	vq->log_guest_addr = addr->log_guest_addr;
+	vq->access_ok = 1;
 
 	VHOST_LOG_DEBUG(VHOST_CONFIG, "(%d) mapped address desc: %p\n",
 			dev->vid, vq->desc);
@@ -704,6 +706,7 @@ vhost_user_set_vring_addr(struct virtio_net **pdev, struct VhostUserMsg *msg,
 	struct virtio_net *dev = *pdev;
 	struct vhost_virtqueue *vq;
 	struct vhost_vring_addr *addr = &msg->payload.addr;
+	bool access_ok;
 
 	if (dev->mem == NULL)
 		return RTE_VHOST_MSG_RESULT_ERR;
@@ -711,6 +714,8 @@ vhost_user_set_vring_addr(struct virtio_net **pdev, struct VhostUserMsg *msg,
 	/* addr->index refers to the queue index. The txq 1, rxq is 0. */
 	vq = dev->virtqueue[msg->payload.addr.index];
 
+	access_ok = vq->access_ok;
+
 	/*
 	 * Rings addresses should not be interpreted as long as the ring is not
 	 * started and enabled
@@ -719,8 +724,9 @@ vhost_user_set_vring_addr(struct virtio_net **pdev, struct VhostUserMsg *msg,
 
 	vring_invalidate(dev, vq);
 
-	if (vq->enabled && (dev->features &
-				(1ULL << VHOST_USER_F_PROTOCOL_FEATURES))) {
+	if ((vq->enabled && (dev->features &
+				(1ULL << VHOST_USER_F_PROTOCOL_FEATURES))) ||
+			access_ok) {
 		dev = translate_ring_addresses(dev, msg->payload.addr.index);
 		if (!dev)
 			return RTE_VHOST_MSG_RESULT_ERR;
@@ -1325,6 +1331,8 @@ vhost_user_get_vring_base(struct virtio_net **pdev,
 	msg->size = sizeof(msg->payload.state);
 	msg->fd_num = 0;
 
+	vring_invalidate(dev, vq);
+
 	return RTE_VHOST_MSG_RESULT_REPLY;
 }
 
-- 
2.17.1


  parent reply	other threads:[~2019-08-19 11:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-19 11:34 [dpdk-dev] [PATCH 0/3] Some fixes for vhost Tiwei Bie
2019-08-19 11:34 ` [dpdk-dev] [PATCH 1/3] vhost: do not realloc device and queues during running Tiwei Bie
2019-09-18 13:30   ` Maxime Coquelin
2019-08-19 11:34 ` Tiwei Bie [this message]
2019-09-27  7:54   ` [dpdk-dev] [PATCH 2/3] vhost: fix vring addr handling during live migration Maxime Coquelin
2019-08-19 11:34 ` [dpdk-dev] [PATCH 3/3] vhost: protect vring access done by application Tiwei Bie
2019-09-27  8:25   ` Maxime Coquelin
2019-09-27  9:48 ` [dpdk-dev] [PATCH 0/3] Some fixes for vhost Maxime Coquelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190819113457.15569-3-tiwei.bie@intel.com \
    --to=tiwei.bie@intel.com \
    --cc=dev@dpdk.org \
    --cc=lvyilong.lyl@alibaba-inc.com \
    --cc=maxime.coquelin@redhat.com \
    --cc=stable@dpdk.org \
    --cc=xnhp0320@icloud.com \
    --cc=yinan.wang@intel.com \
    --cc=zhihong.wang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).