From c1cfc10a592e1721fd17178db45ababd119569e4 Mon Sep 17 00:00:00 2001 From: Pawel Wodkowski Date: Mon, 22 Jan 2018 18:11:30 +0100 Subject: [PATCH] rte_vhost: stop device before messages that can change something Some messages like SET_FEATURES, SET_VRING_ADDR etc will change internal state of VQ or device. To prevent race vs thread polling those queues stop the device. Change-Id: I15caf9da0decbaa660e9773c93d45ff148e5e9a8 Signed-off-by: Pawel Wodkowski Reviewed-on: https://review.gerrithub.io/395739 Reviewed-by: Daniel Verkamp Reviewed-by: Dariusz Stojaczyk Tested-by: SPDK Automated Test System Reviewed-by: Jim Harris --- lib/vhost/rte_vhost/vhost_user.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/vhost/rte_vhost/vhost_user.c b/lib/vhost/rte_vhost/vhost_user.c index ef920f66d..47bfe494b 100644 --- a/lib/vhost/rte_vhost/vhost_user.c +++ b/lib/vhost/rte_vhost/vhost_user.c @@ -183,8 +183,12 @@ vhost_user_set_features(struct virtio_net *dev, uint64_t features) } if ((dev->flags & VIRTIO_DEV_RUNNING) && dev->negotiated_features != features) { - if (dev->notify_ops->features_changed) + if (dev->notify_ops->features_changed) { dev->notify_ops->features_changed(dev->vid, features); + } else { + dev->flags &= ~VIRTIO_DEV_RUNNING; + dev->notify_ops->destroy_device(dev->vid); + } } dev->negotiated_features = features; @@ -358,6 +362,12 @@ vhost_user_set_vring_addr(struct virtio_net *dev, VhostUserMsg *msg) if (dev->mem == NULL) return -1; + /* Remove from the data plane. */ + if (dev->flags & VIRTIO_DEV_RUNNING) { + dev->flags &= ~VIRTIO_DEV_RUNNING; + dev->notify_ops->destroy_device(dev->vid); + } + /* addr->index refers to the queue index. The txq 1, rxq is 0. */ vq = dev->virtqueue[msg->payload.addr.index]; @@ -831,6 +841,12 @@ vhost_user_set_protocol_features(struct virtio_net *dev, if (protocol_features & ~VHOST_USER_PROTOCOL_FEATURES) return; + /* Remove from the data plane. */ + if (dev->flags & VIRTIO_DEV_RUNNING) { + dev->flags &= ~VIRTIO_DEV_RUNNING; + dev->notify_ops->destroy_device(dev->vid); + } + dev->protocol_features = protocol_features; } @@ -853,6 +869,12 @@ vhost_user_set_log_base(struct virtio_net *dev, struct VhostUserMsg *msg) return -1; } + /* Remove from the data plane. */ + if (dev->flags & VIRTIO_DEV_RUNNING) { + dev->flags &= ~VIRTIO_DEV_RUNNING; + dev->notify_ops->destroy_device(dev->vid); + } + size = msg->payload.log.mmap_size; off = msg->payload.log.mmap_offset; RTE_LOG(INFO, VHOST_CONFIG,