From nobody Thu Apr 18 02:49:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1568209649; cv=none; d=zoho.com; s=zohoarc; b=e6XUaSzyqdfby1Y0d0ZDvf9I53A0QXvw3LXoBwe+sG210G3g8xvhaD1C9o+XRgAs90eojfEgv4h1b6gZo1Zr9yQZWVU+XNSV6M77yyf69Lk8dyENjCU/t7psA3CXFUks14LS63QyNQ5gDLgNuXXabrPoMaH/6MIU2dHunTmN4zo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568209649; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=lML0CqxGv//+6KlxHm6m1KKoTVChNzlZoJh3V3Kg8Xk=; b=H2R8jU/g6jUZuKa24Qlo0Tb6Cp7NGJmkx6xNBaA8rqRjN/XX28rAePjxM/e6uXNbsFSWmMzDmfT3myui3DitkcC/jcuUW8K6d0bWwXer836rcDwOnF//8VorYQSbNsOa34jssoC4sOa8G7CiOa05K8JeqKFPZXxxqB4/b0o22fE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15682096494021000.4411208588309; Wed, 11 Sep 2019 06:47:29 -0700 (PDT) Received: from localhost ([::1]:51240 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i82xs-0004ZV-MJ for importer@patchew.org; Wed, 11 Sep 2019 09:47:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34921) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i82wP-0003gz-DI for qemu-devel@nongnu.org; Wed, 11 Sep 2019 09:45:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i82wN-0008UU-L8 for qemu-devel@nongnu.org; Wed, 11 Sep 2019 09:45:49 -0400 Received: from s3.sipsolutions.net ([2a01:4f8:191:4433::2]:57026 helo=sipsolutions.net) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i82wN-0008TT-CE for qemu-devel@nongnu.org; Wed, 11 Sep 2019 09:45:47 -0400 Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1i82wK-0000VV-MV; Wed, 11 Sep 2019 15:45:44 +0200 From: Johannes Berg To: qemu-devel@nongnu.org Date: Wed, 11 Sep 2019 15:45:38 +0200 Message-Id: <20190911134539.25650-2-johannes@sipsolutions.net> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190911134539.25650-1-johannes@sipsolutions.net> References: <20190911134539.25650-1-johannes@sipsolutions.net> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a01:4f8:191:4433::2 Subject: [Qemu-devel] [RFC v2 1/2] docs: vhost-user: add in-band kick/call messages X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Johannes Berg , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Johannes Berg For good reason, vhost-user is currently built asynchronously, that way better performance can be obtained. However, for certain use cases such as simulation, this is problematic. Consider an event-based simulation in which both the device and CPU have scheduled according to a simulation "calendar". Now, consider the CPU sending I/O to the device, over a vring in the vhost-user protocol. In this case, the CPU must wait for the vring interrupt to have been processed by the device, so that the device is able to put an entry onto the simulation calendar to obtain time to handle the interrupt. Note that this doesn't mean the I/O is actually done at this time, it just means that the handling of it is scheduled before the CPU can continue running. This cannot be done with the asynchronous eventfd based vring kick and call design. Extend the protocol slightly, so that a message can be used for kick and call instead, if VHOST_USER_PROTOCOL_F_IN_BAND_NOTIFICATIONS is negotiated. This in itself doesn't guarantee synchronisation, but both sides can also negotiate VHOST_USER_PROTOCOL_F_REPLY_ACK and thus get a reply to this message by setting the need_reply flag, and ensure synchronisation this way. To really use it in both directions, VHOST_USER_PROTOCOL_F_SLAVE_REQ is also needed. Since it is used for simulation purposes and too many messages on the socket can lock up the virtual machine, document that this should only be used together with the mentioned features. Signed-off-by: Johannes Berg --- docs/interop/vhost-user.rst | 113 ++++++++++++++++++++++++++++++------ 1 file changed, 96 insertions(+), 17 deletions(-) diff --git a/docs/interop/vhost-user.rst b/docs/interop/vhost-user.rst index 7827b710aa0a..c4396eabf9e9 100644 --- a/docs/interop/vhost-user.rst +++ b/docs/interop/vhost-user.rst @@ -2,6 +2,7 @@ Vhost-user Protocol =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D :Copyright: 2014 Virtual Open Systems Sarl. +:Copyright: 2019 Intel Corporation :Licence: This work is licensed under the terms of the GNU GPL, version 2 or later. See the COPYING file in the top-level directory. @@ -279,6 +280,9 @@ If *master* is unable to send the full message or recei= ves a wrong reply it will close the connection. An optional reconnection mechanism can be implemented. =20 +If *slave* detects some error such as incompatible features, it may also +close the connection. This should only happen in exceptional circumstances. + Any protocol extensions are gated by protocol feature bits, which allows full backwards compatibility on both master and slave. As older slaves don't support negotiating protocol features, a feature @@ -315,7 +319,8 @@ it until ring is started, or after it has been stopped. =20 Client must start ring upon receiving a kick (that is, detecting that file descriptor is readable) on the descriptor specified by -``VHOST_USER_SET_VRING_KICK``, and stop ring upon receiving +``VHOST_USER_SET_VRING_KICK`` (or receiving the in-band message +``VHOST_USER_VRING_KICK`` if negotiated) and stop ring upon receiving ``VHOST_USER_GET_VRING_BASE``. =20 While processing the rings (whether they are enabled or not), client @@ -767,24 +772,48 @@ When reconnecting: #. Resubmit inflight ``DescStatePacked`` entries in order of their counter value =20 +In-band notifications +--------------------- + +In some limited situations (e.g. for simulation) it is desirable to +have the kick, call and error (if used) signals done via in-band +messages instead of asynchronous eventfd notifications. This can be +done by negotiating the ``VHOST_USER_PROTOCOL_F_IN_BAND_NOTIFICATIONS`` +protocol feature. + +Note that due to the fact that too many messages on the sockets can +cause the sending application(s) to block, it is not advised to use +this feature unless absolutely necessary. It is also considered an +error to negotiate this feature without also negotiating +``VHOST_USER_PROTOCOL_F_SLAVE_REQ`` and ``VHOST_USER_PROTOCOL_F_REPLY_ACK`= `, +the former is necessary for getting a message channel from the slave +to the master, while the latter needs to be used with the in-band +notification messages to block until they are processed, both to avoid +blocking later and for proper processing (at least in the simulation +use case.) As it has no other way of signalling this error, the slave +should close the connection as a response to a +``VHOST_USER_SET_PROTOCOL_FEATURES`` message that sets the in-band +notifications feature flag without the other two. + Protocol features ----------------- =20 .. code:: c =20 - #define VHOST_USER_PROTOCOL_F_MQ 0 - #define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1 - #define VHOST_USER_PROTOCOL_F_RARP 2 - #define VHOST_USER_PROTOCOL_F_REPLY_ACK 3 - #define VHOST_USER_PROTOCOL_F_MTU 4 - #define VHOST_USER_PROTOCOL_F_SLAVE_REQ 5 - #define VHOST_USER_PROTOCOL_F_CROSS_ENDIAN 6 - #define VHOST_USER_PROTOCOL_F_CRYPTO_SESSION 7 - #define VHOST_USER_PROTOCOL_F_PAGEFAULT 8 - #define VHOST_USER_PROTOCOL_F_CONFIG 9 - #define VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD 10 - #define VHOST_USER_PROTOCOL_F_HOST_NOTIFIER 11 - #define VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD 12 + #define VHOST_USER_PROTOCOL_F_MQ 0 + #define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1 + #define VHOST_USER_PROTOCOL_F_RARP 2 + #define VHOST_USER_PROTOCOL_F_REPLY_ACK 3 + #define VHOST_USER_PROTOCOL_F_MTU 4 + #define VHOST_USER_PROTOCOL_F_SLAVE_REQ 5 + #define VHOST_USER_PROTOCOL_F_CROSS_ENDIAN 6 + #define VHOST_USER_PROTOCOL_F_CRYPTO_SESSION 7 + #define VHOST_USER_PROTOCOL_F_PAGEFAULT 8 + #define VHOST_USER_PROTOCOL_F_CONFIG 9 + #define VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD 10 + #define VHOST_USER_PROTOCOL_F_HOST_NOTIFIER 11 + #define VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD 12 + #define VHOST_USER_PROTOCOL_F_IN_BAND_NOTIFICATIONS 13 =20 Master message types -------------------- @@ -946,7 +975,9 @@ Master message types Bits (0-7) of the payload contain the vring index. Bit 8 is the invalid FD flag. This flag is set when there is no file descriptor in the ancillary data. This signals that polling should be used - instead of waiting for a kick. + instead of waiting for the call. however, if the protocol feature + ``VHOST_USER_PROTOCOL_F_IN_BAND_NOTIFICATIONS`` has been negotiated + it instead means the updates should be done using the messages. =20 ``VHOST_USER_SET_VRING_CALL`` :id: 13 @@ -959,7 +990,9 @@ Master message types Bits (0-7) of the payload contain the vring index. Bit 8 is the invalid FD flag. This flag is set when there is no file descriptor in the ancillary data. This signals that polling will be used - instead of waiting for the call. + instead of waiting for the call; however, if the protocol feature + ``VHOST_USER_PROTOCOL_F_IN_BAND_NOTIFICATIONS`` has been negotiated + it instead means the updates should be done using the messages. =20 ``VHOST_USER_SET_VRING_ERR`` :id: 14 @@ -971,7 +1004,11 @@ Master message types =20 Bits (0-7) of the payload contain the vring index. Bit 8 is the invalid FD flag. This flag is set when there is no file descriptor - in the ancillary data. + in the ancillary data. If the protocol features + ``VHOST_USER_PROTOCOL_F_IN_BAND_NOTIFICATIONS`` and + ``VHOST_USER_PROTOCOL_F_SLAVE_REQ`` have been negotiated the invalid + FD flag will be used to indicate that updates should be done using + the ``VHOST_USER_SLAVE_ message. =20 ``VHOST_USER_GET_QUEUE_NUM`` :id: 17 @@ -1190,6 +1227,20 @@ Master message types ancillary data. The GPU protocol is used to inform the master of rendering state and updates. See vhost-user-gpu.rst for details. =20 +``VHOST_USER_VRING_KICK`` + :id: 34 + :equivalent ioctl: N/A + :slave payload: vring state description + :master payload: N/A + + When the ``VHOST_USER_PROTOCOL_F_IN_BAND_NOTIFICATIONS`` protocol + feature has been successfully negotiated, this message may be + submitted by the master to indicate that a buffer was added to + the vring instead of signalling it using the vring's event FD or + having the slave rely on polling. + + The state.num field is currently reserved and must be set to 0. + Slave message types ------------------- =20 @@ -1246,6 +1297,34 @@ Slave message types ``VHOST_USER_PROTOCOL_F_HOST_NOTIFIER`` protocol feature has been successfully negotiated. =20 +``VHOST_USER_SLAVE_VRING_CALL`` + :id: 4 + :equivalent ioctl: N/A + :slave payload: vring state description + :master payload: N/A + + When the ``VHOST_USER_PROTOCOL_F_IN_BAND_NOTIFICATIONS`` protocol + feature has been successfully negotiated, this message may be + submitted by the slave to indicate that a buffer was used from + the vring instead of signalling this using the vring's kick FD or + having the master relying on polling. + + The state.num field is currently reserved and must be set to 0. + +``VHOST_USER_SLAVE_VRING_ERR`` + :id: 5 + :equivalent ioctl: N/A + :slave payload: vring state description + :master payload: N/A + + When the ``VHOST_USER_PROTOCOL_F_IN_BAND_NOTIFICATIONS`` protocol + feature has been successfully negotiated, this message may be + submitted by the slave to indicate that an error occurred on the + specific vring, instead of signalling the error FD set by the + master via ``VHOST_USER_SET_VRING_ERR``. + + The state.num field is currently reserved and must be set to 0. + .. _reply_ack: =20 VHOST_USER_PROTOCOL_F_REPLY_ACK --=20 2.20.1 From nobody Thu Apr 18 02:49:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1568209773; cv=none; d=zoho.com; s=zohoarc; b=Ab04QbN7UsTThnKkCBApAeLbz0Tm+qGaiQTmnru7vL1U4lPBNVQV+19NDHtyaM4wXJwpMTtUyFPv9N6h2EJTY1D/cZ92Grq2R05Z/OWYGlcG+fMV1xPFzukI+1ubXEvjPHqcSDWUgbW5ncujut8db3u0kJeshbXQbF6zMKT/4J4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568209773; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=v/IB/AAFW4b1C3sXMpnaQuw3v8WkgayFHJYtK3mGy+I=; b=hvUcmC11ll3f3JhgViopBPy93/botJ/aGz5YM1BStWTI7TZkinfnCmMMCNKrqn8GAGM7hI5RzC749it5jZjF4lXZds983kL3ApmBtgCx4nGdcv7MgAm5OGBLvUPRuRD4yiUFH3YPlMRDLFnYS496EHqZe8okbeyCfEE8Cjg3cjg= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568209773261468.45747612461366; Wed, 11 Sep 2019 06:49:33 -0700 (PDT) Received: from localhost ([::1]:51277 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i82zx-0006ee-1w for importer@patchew.org; Wed, 11 Sep 2019 09:49:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34917) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i82wP-0003gv-8S for qemu-devel@nongnu.org; Wed, 11 Sep 2019 09:45:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i82wN-0008UL-J3 for qemu-devel@nongnu.org; Wed, 11 Sep 2019 09:45:49 -0400 Received: from s3.sipsolutions.net ([2a01:4f8:191:4433::2]:57028 helo=sipsolutions.net) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i82wN-0008TW-At for qemu-devel@nongnu.org; Wed, 11 Sep 2019 09:45:47 -0400 Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1i82wK-0000VV-Vh; Wed, 11 Sep 2019 15:45:45 +0200 From: Johannes Berg To: qemu-devel@nongnu.org Date: Wed, 11 Sep 2019 15:45:39 +0200 Message-Id: <20190911134539.25650-3-johannes@sipsolutions.net> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190911134539.25650-1-johannes@sipsolutions.net> References: <20190911134539.25650-1-johannes@sipsolutions.net> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a01:4f8:191:4433::2 Subject: [Qemu-devel] [RFC v2 2/2] libvhost-user: implement in-band notifications X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Johannes Berg , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Johannes Berg Add support for VHOST_USER_PROTOCOL_F_IN_BAND_NOTIFICATIONS, but as it's not desired by default, don't enable it unless the device implementation opts in by returning it from its protocol features callback. Note that I updated vu_set_vring_err_exec(), but didn't add any sending of the VHOST_USER_SLAVE_VRING_ERR message as there's no write to the err_fd today either. Signed-off-by: Johannes Berg --- contrib/libvhost-user/libvhost-user.c | 94 ++++++++++++++++++++++++--- contrib/libvhost-user/libvhost-user.h | 4 ++ 2 files changed, 89 insertions(+), 9 deletions(-) diff --git a/contrib/libvhost-user/libvhost-user.c b/contrib/libvhost-user/= libvhost-user.c index f1677da21201..6367ddeb17fb 100644 --- a/contrib/libvhost-user/libvhost-user.c +++ b/contrib/libvhost-user/libvhost-user.c @@ -136,6 +136,7 @@ vu_request_to_string(unsigned int req) REQ(VHOST_USER_GET_INFLIGHT_FD), REQ(VHOST_USER_SET_INFLIGHT_FD), REQ(VHOST_USER_GPU_SET_SOCKET), + REQ(VHOST_USER_VRING_KICK), REQ(VHOST_USER_MAX), }; #undef REQ @@ -163,7 +164,10 @@ vu_panic(VuDev *dev, const char *msg, ...) dev->panic(dev, buf); free(buf); =20 - /* FIXME: find a way to call virtio_error? */ + /* + * FIXME: + * find a way to call virtio_error, or perhaps close the connection? + */ } =20 /* Translate guest physical address to our virtual address. */ @@ -920,6 +924,7 @@ static bool vu_check_queue_msg_file(VuDev *dev, VhostUserMsg *vmsg) { int index =3D vmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK; + bool nofd =3D vmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK; =20 if (index >=3D dev->max_queues) { vmsg_close_fds(vmsg); @@ -927,8 +932,12 @@ vu_check_queue_msg_file(VuDev *dev, VhostUserMsg *vmsg) return false; } =20 - if (vmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK || - vmsg->fd_num !=3D 1) { + if (nofd) { + vmsg_close_fds(vmsg); + return true; + } + + if (vmsg->fd_num !=3D 1) { vmsg_close_fds(vmsg); vu_panic(dev, "Invalid fds in request: %d", vmsg->request); return false; @@ -1025,6 +1034,7 @@ static bool vu_set_vring_kick_exec(VuDev *dev, VhostUserMsg *vmsg) { int index =3D vmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK; + bool nofd =3D vmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK; =20 DPRINT("u64: 0x%016"PRIx64"\n", vmsg->payload.u64); =20 @@ -1038,8 +1048,8 @@ vu_set_vring_kick_exec(VuDev *dev, VhostUserMsg *vmsg) dev->vq[index].kick_fd =3D -1; } =20 - dev->vq[index].kick_fd =3D vmsg->fds[0]; - DPRINT("Got kick_fd: %d for vq: %d\n", vmsg->fds[0], index); + dev->vq[index].kick_fd =3D nofd ? -1 : vmsg->fds[0]; + DPRINT("Got kick_fd: %d for vq: %d\n", dev->vq[index].kick_fd, index); =20 dev->vq[index].started =3D true; if (dev->iface->queue_set_started) { @@ -1116,6 +1126,7 @@ static bool vu_set_vring_call_exec(VuDev *dev, VhostUserMsg *vmsg) { int index =3D vmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK; + bool nofd =3D vmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK; =20 DPRINT("u64: 0x%016"PRIx64"\n", vmsg->payload.u64); =20 @@ -1128,14 +1139,14 @@ vu_set_vring_call_exec(VuDev *dev, VhostUserMsg *vm= sg) dev->vq[index].call_fd =3D -1; } =20 - dev->vq[index].call_fd =3D vmsg->fds[0]; + dev->vq[index].call_fd =3D nofd ? -1 : vmsg->fds[0]; =20 /* in case of I/O hang after reconnecting */ - if (eventfd_write(vmsg->fds[0], 1)) { + if (dev->vq[index].call_fd !=3D -1 && eventfd_write(vmsg->fds[0], 1)) { return -1; } =20 - DPRINT("Got call_fd: %d for vq: %d\n", vmsg->fds[0], index); + DPRINT("Got call_fd: %d for vq: %d\n", dev->vq[index].call_fd, index); =20 return false; } @@ -1144,6 +1155,7 @@ static bool vu_set_vring_err_exec(VuDev *dev, VhostUserMsg *vmsg) { int index =3D vmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK; + bool nofd =3D vmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK; =20 DPRINT("u64: 0x%016"PRIx64"\n", vmsg->payload.u64); =20 @@ -1156,7 +1168,7 @@ vu_set_vring_err_exec(VuDev *dev, VhostUserMsg *vmsg) dev->vq[index].err_fd =3D -1; } =20 - dev->vq[index].err_fd =3D vmsg->fds[0]; + dev->vq[index].err_fd =3D nofd ? -1 : vmsg->fds[0]; =20 return false; } @@ -1164,6 +1176,14 @@ vu_set_vring_err_exec(VuDev *dev, VhostUserMsg *vmsg) static bool vu_get_protocol_features_exec(VuDev *dev, VhostUserMsg *vmsg) { + /* + * Note that we support, but intentionally do not set, + * VHOST_USER_PROTOCOL_F_IN_BAND_NOTIFICATIONS. This means that + * a device implementation can return it in its callback + * (get_protocol_features) if it wants to use this for + * simulation, but it is otherwise not desirable (if even + * implemented by the master.) + */ uint64_t features =3D 1ULL << VHOST_USER_PROTOCOL_F_MQ | 1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD | 1ULL << VHOST_USER_PROTOCOL_F_SLAVE_REQ | @@ -1196,6 +1216,25 @@ vu_set_protocol_features_exec(VuDev *dev, VhostUserM= sg *vmsg) =20 dev->protocol_features =3D vmsg->payload.u64; =20 + if (vu_has_protocol_feature(dev, + VHOST_USER_PROTOCOL_F_IN_BAND_NOTIFICATION= S) && + (!vu_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_SLAVE_REQ) || + !vu_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_REPLY_ACK))) { + /* + * The use case for using messages for kick/call is simulation, to= make + * the kick and call synchronous. To actually get that behaviour, = both + * of the other features are required. + * Theoretically, one could use only kick messages, or do them wit= hout + * having F_REPLY_ACK, but too many (possibly pending) messages on= the + * socket will eventually cause the master to hang, to avoid this = in + * scenarios where not desired enforce that the settings are in a = way + * that actually enables the simulation case. + */ + vu_panic(dev, + "F_IN_BAND_NOTIFICATIONS requires F_SLAVE_REQ && F_REPLY_= ACK"); + return false; + } + if (dev->iface->set_protocol_features) { dev->iface->set_protocol_features(dev, features); } @@ -1456,6 +1495,25 @@ vu_set_inflight_fd(VuDev *dev, VhostUserMsg *vmsg) return false; } =20 +static bool +vu_handle_vring_kick(VuDev *dev, VhostUserMsg *vmsg) +{ + unsigned int index =3D vmsg->payload.state.index; + + if (index >=3D dev->max_queues) { + vu_panic(dev, "Invalid queue index: %u", index); + return false; + } + + DPRINT("Got kick message: handler:%p idx:%d\n", + dev->vq[index].handler, index); + if (dev->vq[index].handler) { + dev->vq[index].handler(dev, index); + } + + return false; +} + static bool vu_process_message(VuDev *dev, VhostUserMsg *vmsg) { @@ -1538,6 +1596,8 @@ vu_process_message(VuDev *dev, VhostUserMsg *vmsg) return vu_get_inflight_fd(dev, vmsg); case VHOST_USER_SET_INFLIGHT_FD: return vu_set_inflight_fd(dev, vmsg); + case VHOST_USER_VRING_KICK: + return vu_handle_vring_kick(dev, vmsg); default: vmsg_close_fds(vmsg); vu_panic(dev, "Unhandled request: %d", vmsg->request); @@ -2010,6 +2070,22 @@ vu_queue_notify(VuDev *dev, VuVirtq *vq) return; } =20 + if (vu_has_protocol_feature(dev, + VHOST_USER_PROTOCOL_F_IN_BAND_NOTIFICATION= S) && + vu_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_SLAVE_REQ)) { + VhostUserMsg vmsg =3D { + .request =3D VHOST_USER_SLAVE_VRING_CALL, + .flags =3D VHOST_USER_VERSION, + .size =3D sizeof(vmsg.payload.state), + .payload.state =3D { + .index =3D vq - dev->vq, + }, + }; + + vu_message_write(dev, dev->slave_fd, &vmsg); + return; + } + if (eventfd_write(vq->call_fd, 1) < 0) { vu_panic(dev, "Error writing eventfd: %s", strerror(errno)); } diff --git a/contrib/libvhost-user/libvhost-user.h b/contrib/libvhost-user/= libvhost-user.h index 46b600799b2e..a22dc4733849 100644 --- a/contrib/libvhost-user/libvhost-user.h +++ b/contrib/libvhost-user/libvhost-user.h @@ -53,6 +53,7 @@ enum VhostUserProtocolFeature { VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD =3D 10, VHOST_USER_PROTOCOL_F_HOST_NOTIFIER =3D 11, VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD =3D 12, + VHOST_USER_PROTOCOL_F_IN_BAND_NOTIFICATIONS =3D 13, =20 VHOST_USER_PROTOCOL_F_MAX }; @@ -94,6 +95,7 @@ typedef enum VhostUserRequest { VHOST_USER_GET_INFLIGHT_FD =3D 31, VHOST_USER_SET_INFLIGHT_FD =3D 32, VHOST_USER_GPU_SET_SOCKET =3D 33, + VHOST_USER_VRING_KICK =3D 34, VHOST_USER_MAX } VhostUserRequest; =20 @@ -102,6 +104,8 @@ typedef enum VhostUserSlaveRequest { VHOST_USER_SLAVE_IOTLB_MSG =3D 1, VHOST_USER_SLAVE_CONFIG_CHANGE_MSG =3D 2, VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG =3D 3, + VHOST_USER_SLAVE_VRING_CALL =3D 4, + VHOST_USER_SLAVE_VRING_ERR =3D 5, VHOST_USER_SLAVE_MAX } VhostUserSlaveRequest; =20 --=20 2.20.1