Skip to content

Commit

Permalink
vhost: fix vring address handling during live migration
Browse files Browse the repository at this point in the history
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: 5a4933e ("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>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
  • Loading branch information
Tiwei Bie authored and Ferruh Yigit committed Oct 7, 2019
1 parent 37f7c1b commit 72d002b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 1 addition & 2 deletions lib/librte_vhost/vhost.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down
12 changes: 10 additions & 2 deletions lib/librte_vhost/vhost_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ translate_ring_addresses(struct virtio_net *dev, int vq_index)
return dev;
}

vq->access_ok = 1;
return dev;
}

Expand Down Expand Up @@ -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);
Expand All @@ -704,13 +706,16 @@ 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;

/* 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
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 72d002b

Please sign in to comment.