From patchwork Sat Jun 4 21:33:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 9154975 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0B8E260574 for ; Sat, 4 Jun 2016 21:38:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F161527F2B for ; Sat, 4 Jun 2016 21:38:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E5CAC28327; Sat, 4 Jun 2016 21:38:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8EEEE27F2B for ; Sat, 4 Jun 2016 21:38:45 +0000 (UTC) Received: from localhost ([::1]:34219 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9JHI-0001oM-Ms for patchwork-qemu-devel@patchwork.kernel.org; Sat, 04 Jun 2016 17:38:44 -0400 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DVeIoP6Q4eOIgvi8NY2GyPLttrITapCgvHBPx3GV7cg=; b=v0ypavDL+Fwqh8MEVq14fuIpVynfwD8dBGSmzmbYKgkFqG95rK7iZtmxZ3E35ZEkMu aaM9ogumacv7/vjXnjoa1IakgdWVUvZGvM+kB/JpaXTF4Oou4VOG103Zp/mBJvFZgu1L 6vG0jHVw0Y1SF2wlPpYoYg4I767kv4dNl18FDqptQA2bJ7MAyfYxOBI6hwAvBl0eThjz 8xJne8g90nLPp+IK6a48aafk/HRbp1MA+1WV+nKB4TOdZPJsfzWXzPVpulea1wNxnxMG xvEKobk0W1/6zcEZqBkOZ4fpFc99hP+e6xcPrTYqAmFu5rxliFpwSfHg31gGfJEUY7nC wbWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=DVeIoP6Q4eOIgvi8NY2GyPLttrITapCgvHBPx3GV7cg=; b=NaLpE7fBfO+tXOrehIEz0kdgE7XVQMsHmDW30dkgxFumsU0rA5E0JRD9KZhVjuaTYc kOjiavxhf2Wo4db1Q4Y+jPEoBRU7eoCYuypTJlDppE0MhQL8v4drknqLzK23yZePK3ub 50/UemNw7AYSrRWe6tgdjXJsOrL31epw/HmG7dAabaYog81UyI9EMmlLQplAZupAkf0f 53rVuvpNsC/gSXNsRYPEfh+cVrYekDxpdLL5zF4wp7Eu0dETQ1R/K1lNhUPC+AGQgsqa mxraJbbAhzQmgIoJf/mDhLLPn8n0lQgU7oqHTiptI9TTuk/q3DOFiXVW7WeW89IcY87F Z62w== X-Gm-Message-State: ALyK8tLpxKptyhEbuQd23myV4QmIMnxGekMivtziWudy8QORGvIbY4JNn8UXHlwlLHdrEA== X-Received: by 10.28.195.69 with SMTP id t66mr3384404wmf.95.1465076026020; Sat, 04 Jun 2016 14:33:46 -0700 (PDT) Received: from localhost (APoitiers-110-1-1-235.w193-248.abo.wanadoo.fr. [193.248.103.235]) by smtp.gmail.com with ESMTPSA id i190sm6219205wmf.10.2016.06.04.14.33.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 04 Jun 2016 14:33:45 -0700 (PDT) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Date: Sat, 4 Jun 2016 23:33:17 +0200 Message-Id: <1465076003-26291-9-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 2.7.4 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 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::244 Subject: [Qemu-devel] [RFC 08/14] vhost: make sure call fd has been received X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , kraxel@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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,