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 <pawelx.wodkowski@intel.com>
Reviewed-on: https://review.gerrithub.io/395739
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Pawel Wodkowski 2018-01-22 18:11:30 +01:00 committed by Jim Harris
parent 29181903ce
commit c1cfc10a59

View File

@ -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,