Received: from eggs.gnu.org ([2001:4830:134:3::10]:44763) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9JCX-0005ys-76 for qemu-devel@nongnu.org; Sat, 04 Jun 2016 17:33:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b9JCV-0005rq-8L for qemu-devel@nongnu.org; Sat, 04 Jun 2016 17:33:48 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:36174) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9JCU-0005rk-Jp for qemu-devel@nongnu.org; Sat, 04 Jun 2016 17:33:47 -0400 Received: by mail-wm0-x244.google.com with SMTP id m124so6198161wme.3 for ; Sat, 04 Jun 2016 14:33:46 -0700 (PDT) Sender: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= From: marcandre.lureau@redhat.com Date: Sat, 4 Jun 2016 23:33:17 +0200 Message-Id: <1465076003-26291-9-git-send-email-marcandre.lureau@redhat.com> In-Reply-To: <1465076003-26291-1-git-send-email-marcandre.lureau@redhat.com> References: <1465076003-26291-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [RFC 08/14] vhost: make sure call fd has been received List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kraxel@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= From: Marc-André Lureau vhost switches between masked notifier and guest notifier when unmasking. virtio_pci_vq_vector_unmask() checks if there was pending notification, but at the time it is checked, vhost-user backend doesn't guarantee that the switch happened yet, so it may lose some events. To solve this vhost-user race, I introduced an extra "sync" call (waiting for a reply). One may want to make all/many vhost-user replies mandatories by adding a new capability instead. Signed-off-by: Marc-André Lureau --- hw/virtio/vhost.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 4400718..692c38f 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1181,6 +1181,7 @@ void vhost_virtqueue_mask(struct vhost_dev *hdev, VirtIODevice *vdev, int n, struct VirtQueue *vvq = virtio_get_queue(vdev, n); int r, index = n - hdev->vq_index; struct vhost_vring_file file; + uint64_t features; if (mask) { assert(vdev->use_guest_notifier_mask); @@ -1192,6 +1193,10 @@ void vhost_virtqueue_mask(struct vhost_dev *hdev, VirtIODevice *vdev, int n, file.index = hdev->vhost_ops->vhost_get_vq_index(hdev, n); r = hdev->vhost_ops->vhost_set_vring_call(hdev, &file); assert(r >= 0); + + /* silly sync call to make sure the call fd has been received */ + r = hdev->vhost_ops->vhost_get_features(hdev, &features); + assert(r >= 0); } uint64_t vhost_get_features(struct vhost_dev *hdev, const int *feature_bits, -- 2.7.4