From patchwork Mon Mar 5 16:11:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Kulasek X-Patchwork-Id: 35663 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 67D9156A1; Mon, 5 Mar 2018 17:12:01 +0100 (CET) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id 53781548B for ; Mon, 5 Mar 2018 17:11:59 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Mar 2018 08:11:59 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,427,1515484800"; d="scan'208";a="35616833" Received: from unknown (HELO Sent) ([10.103.102.195]) by fmsmga001.fm.intel.com with SMTP; 05 Mar 2018 08:11:56 -0800 Received: by Sent (sSMTP sendmail emulation); Mon, 05 Mar 2018 17:11:13 +0100 From: Tomasz Kulasek To: yliu@fridaylinux.org Cc: daniel.verkamp@intel.com, james.r.harris@intel.com, pawelx.wodkowski@intel.com, dev@dpdk.org, Dariusz Stojaczyk Date: Mon, 5 Mar 2018 17:11:08 +0100 Message-Id: <20180305161108.8232-1-tomaszx.kulasek@intel.com> X-Mailer: git-send-email 2.16.1 Subject: [dpdk-dev] [PATCH] vhost: stop device before updating public vring data X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" For now DPDK assumes that callfd, kickfd and last_idx are being set just once during vring initialization and device cannot be running while DPDK receives SET_VRING_KICK, SET_VRING_CALL and SET_VRING_BASE messages. However, that assumption is wrong. For Vhost SCSI messages might arrive at any point of time, possibly multiple times, one after another. QEMU issues SET_VRING_CALL once during device initialization, then again during device start. The second message will close previous callfd, which is still being used by the user-implementation of vhost device. This results in writing to invalid (closed) callfd. Other messages like SET_FEATURES, SET_VRING_ADDR etc also will change internal state of VQ or device. To prevent race condition device should also be stopped before updateing vring data. Signed-off-by: Dariusz Stojaczyk Signed-off-by: Pawel Wodkowski Signed-off-by: Tomasz Kulasek --- lib/librte_vhost/vhost_user.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 65ee33919..3895e6edd 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -172,6 +172,10 @@ vhost_user_set_features(struct virtio_net *dev, uint64_t features) 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->features = features; @@ -487,6 +491,12 @@ vhost_user_set_vring_addr(struct virtio_net **pdev, 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]; @@ -517,6 +527,12 @@ static int vhost_user_set_vring_base(struct virtio_net *dev, VhostUserMsg *msg) { + /* Remove from the data plane. */ + if (dev->flags & VIRTIO_DEV_RUNNING) { + dev->flags &= ~VIRTIO_DEV_RUNNING; + dev->notify_ops->destroy_device(dev->vid); + } + dev->virtqueue[msg->payload.state.index]->last_used_idx = msg->payload.state.num; dev->virtqueue[msg->payload.state.index]->last_avail_idx = @@ -796,6 +812,12 @@ vhost_user_set_vring_call(struct virtio_net *dev, struct VhostUserMsg *pmsg) struct vhost_vring_file file; struct vhost_virtqueue *vq; + /* Remove from the data plane. */ + if (dev->flags & VIRTIO_DEV_RUNNING) { + dev->flags &= ~VIRTIO_DEV_RUNNING; + dev->notify_ops->destroy_device(dev->vid); + } + file.index = pmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK; if (pmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK) file.fd = VIRTIO_INVALID_EVENTFD; @@ -818,6 +840,12 @@ vhost_user_set_vring_kick(struct virtio_net **pdev, struct VhostUserMsg *pmsg) struct vhost_virtqueue *vq; struct virtio_net *dev = *pdev; + /* Remove from the data plane. */ + if (dev->flags & VIRTIO_DEV_RUNNING) { + dev->flags &= ~VIRTIO_DEV_RUNNING; + dev->notify_ops->destroy_device(dev->vid); + } + file.index = pmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK; if (pmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK) file.fd = VIRTIO_INVALID_EVENTFD; @@ -959,6 +987,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; } @@ -981,6 +1015,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,