From nobody Tue May 7 12:40:19 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=1567772103; cv=none; d=zoho.com; s=zohoarc; b=G6U9RyqHFwgmGnv+pRwVp+WNz/W7aOLIZFss/teAjBGR/ji5DMoZm4cL1OApx0ZVwjKuBHDztGlQTASAVE7/06/noSwvkJUkObDmyQfvg+ItFmonkVku1NF76BN82DtgyRL8bV+X6QILx6ifIGbyB3N0j9J74YGIfyOPnP3cy2Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567772103; 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=zGrVbTTxETASWt/CcXb2AhqQGnTepPrnooVl7rSXj6Y=; b=SQgibR+ZWPaIKnz3OxlGaKI/Nqp9ll4jmjJAKwZfyub7IJRya8nObnqYcbSLKhiRLHuZC3a0fX+4Vp1p5yusrtndEHx3w1fhFKoNzKbrzedGvRobvogZNtFYXcTv2gyOvG/hO4PJU/07R85mrMFuNtGzt4fPyBAhvj9umCuVwTA= 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 1567772103100795.1997663741623; Fri, 6 Sep 2019 05:15:03 -0700 (PDT) Received: from localhost ([::1]:55476 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i6D8h-00043o-79 for importer@patchew.org; Fri, 06 Sep 2019 08:14:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46527) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i6D7p-0003eu-Ob for qemu-devel@nongnu.org; Fri, 06 Sep 2019 08:14:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i6D7o-0003QB-6v for qemu-devel@nongnu.org; Fri, 06 Sep 2019 08:14:01 -0400 Received: from s3.sipsolutions.net ([2a01:4f8:191:4433::2]:47380 helo=sipsolutions.net) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i6D7o-0003PQ-0f for qemu-devel@nongnu.org; Fri, 06 Sep 2019 08:14:00 -0400 Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.92.1) (envelope-from ) id 1i6D7k-0006HC-Qy; Fri, 06 Sep 2019 14:13:56 +0200 From: Johannes Berg To: qemu-devel@nongnu.org Date: Fri, 6 Sep 2019 15:13:50 +0300 Message-Id: <20190906121350.29202-1-johannes@sipsolutions.net> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190902121233.13382-1-johannes@sipsolutions.net> References: <20190902121233.13382-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] libvhost-user: implement VHOST_USER_PROTOCOL_F_KICK_CALL_MSGS 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 Signed-off-by: Johannes Berg --- contrib/libvhost-user/libvhost-user.c | 61 +++++++++++++++++++++++---- contrib/libvhost-user/libvhost-user.h | 3 ++ 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/contrib/libvhost-user/libvhost-user.c b/contrib/libvhost-user/= libvhost-user.c index fba291c13db4..550f6416a211 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 @@ -920,6 +921,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 +929,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 +1031,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 +1045,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 +1123,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 VHOST_USER_VRING_NOFD_MASK; =20 DPRINT("u64: 0x%016"PRIx64"\n", vmsg->payload.u64); =20 @@ -1128,14 +1136,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; } @@ -1169,7 +1177,8 @@ vu_get_protocol_features_exec(VuDev *dev, VhostUserMs= g *vmsg) 1ULL << VHOST_USER_PROTOCOL_F_SLAVE_REQ | 1ULL << VHOST_USER_PROTOCOL_F_HOST_NOTIFIER | 1ULL << VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD | - 1ULL << VHOST_USER_PROTOCOL_F_REPLY_ACK; + 1ULL << VHOST_USER_PROTOCOL_F_REPLY_ACK | + 1ULL << VHOST_USER_PROTOCOL_F_KICK_CALL_MSGS; =20 if (have_userfault()) { features |=3D 1ULL << VHOST_USER_PROTOCOL_F_PAGEFAULT; @@ -1456,6 +1465,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 +1566,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 +2040,21 @@ vu_queue_notify(VuDev *dev, VuVirtq *vq) return; } =20 + if (vu_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_KICK_CALL_MSGS)= && + 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 dev->vq - 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..392dea306bb9 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_KICK_CALL_MSGS =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,7 @@ 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_MAX } VhostUserSlaveRequest; =20 --=20 2.23.0