From nobody Thu Nov 13 22:10:27 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582708301; cv=none; d=zohomail.com; s=zohoarc; b=gGGOqnctJC1rSqiMX9DoHJh774XEy0P7eebJRLt4NoA6fTOQDmuVFok33YGPztTcfiGNfgNYH4E+CZ/8O7cLRy7TYkYw6tDq0zyzQO1doI7jGLfoyL/JU0PX4+D2MdYcFIzrVbJmlr1tNf3Q48XRqx0c5Lei/XfaDFdLTQ7xPMQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582708301; h=Content-Type: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; bh=PaVZ83rgHHJzvD04uhNEPYZywTa4yNbe9G1r2BQHUDs=; b=P6mXuZ7JiXRZ57vbyjmotcJWje8T2dcDSkt59e225B9yCmJN/DCmRjLFO+vphs6J8U5LKc8cTj2Sb0uaDGeWAiPWn16QNKn+KAm29QcctS7wFGXxN4ftvX1b9mGsT2sEBzl1HWw+VcQLzjKqXCrGhyHkj0YFJ+r8DaajlTJ6Hms= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582708301851506.61558322119583; Wed, 26 Feb 2020 01:11:41 -0800 (PST) Received: from localhost ([::1]:40574 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6sjE-00055k-LY for importer@patchew.org; Wed, 26 Feb 2020 04:11:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59406) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6sfT-0006bN-Nn for qemu-devel@nongnu.org; Wed, 26 Feb 2020 04:07:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6sfS-00011A-9K for qemu-devel@nongnu.org; Wed, 26 Feb 2020 04:07:47 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:30404 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6sfS-00010b-2C for qemu-devel@nongnu.org; Wed, 26 Feb 2020 04:07:46 -0500 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-400-r6AZ2QiCPKWqw__n5n0g8w-1; Wed, 26 Feb 2020 04:07:41 -0500 Received: by mail-wr1-f70.google.com with SMTP id p5so1167702wrj.17 for ; Wed, 26 Feb 2020 01:07:41 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id p17sm11274wre.89.2020.02.26.01.07.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2020 01:07:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582708065; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PaVZ83rgHHJzvD04uhNEPYZywTa4yNbe9G1r2BQHUDs=; b=YuVT3SUlUmhZOL8MYQykCeru4fzRscdu1XWIPtkT7RAwg5W4Tp3mDG/7npcqZ2yQrOh7wS Yd1EGEMH5oGn8V1q3JNpHr6MW2CNjjx5rTPZMrzQV4tpXyRdZVa7lzJMUAzNoOwalCtAY4 kf2/n54SRyjuq5BeQn5ss2Cl/NSUccE= X-MC-Unique: r6AZ2QiCPKWqw__n5n0g8w-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=BEIFZp6ZV6EMxNZvhYr+RG8aqKLzp8+FfOWRj9nMRTw=; b=FTpgsMPqFKvDV+9pDqDDt5uUXEMa9fqfl7A/VjeX81xVAxYBZ8kDvNYiexgO9Gg2cl yAnbn5v5dEjOaO5a2rFjuabnY9qmKvAIaV2aNFZW1Y1ypSW8RcJ90xlGnTvgbMsJlahO wkuoE85DfrJR7kkpRySEtkEcl0Q3JJd3IwF7HdTfYQanbGLEaRfoyVy/0rhi7KIw/75M HpNMtlPl/KPbbqgK5/uxDrIcJxO0gyf32VfBvZolo9MnE3DbdT1wSAg8TAOsM8Iex57g pB0L+Pky/68dsDvbL9SQb7Q8ppJlSCIFcP4oICqzCB0Aj23yEZtvlpXntMWxjw+Q2jZo 80GA== X-Gm-Message-State: APjAAAWmfYR7VldMZvzDmHwd+0aBMycYCB6bnC0jLlVXW9E4nSOSA76C sphKaibCWaFU9VCT5PZO996X0LhGAMiwBWREkw//UQZae4xppVW7WWsBi9h1DjnfgmifbOAzwMW egkJ95h75bQEpDcg= X-Received: by 2002:adf:e644:: with SMTP id b4mr4206266wrn.110.1582708060139; Wed, 26 Feb 2020 01:07:40 -0800 (PST) X-Google-Smtp-Source: APXvYqww5iB5V2WczINd8OkK7tVEKvKlKcNuqwVytB3smY32PXkVbyDVpmoUhxrLeC79wCj4BazXLg== X-Received: by 2002:adf:e644:: with SMTP id b4mr4206241wrn.110.1582708059907; Wed, 26 Feb 2020 01:07:39 -0800 (PST) Date: Wed, 26 Feb 2020 04:07:38 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL v2 25/30] libvhost-user: handle NOFD flag in call/kick/err better Message-ID: <20200226090010.708934-26-mst@redhat.com> References: <20200226090010.708934-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200226090010.708934-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 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: Peter Maydell , Stefan Hajnoczi , Gerd Hoffmann , Johannes Berg , =?utf-8?Q?Marc-Andr=C3=A9?= Lureau Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Johannes Berg The code here is odd, for example will it print out invalid file descriptor numbers that were never sent in the message. Clean that up a bit so it's actually possible to implement a device that uses polling. Signed-off-by: Johannes Berg Message-Id: <20200123081708.7817-5-johannes@sipsolutions.net> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- contrib/libvhost-user/libvhost-user.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/contrib/libvhost-user/libvhost-user.c b/contrib/libvhost-user/= libvhost-user.c index 533d55d82a..3abc9689e5 100644 --- a/contrib/libvhost-user/libvhost-user.c +++ b/contrib/libvhost-user/libvhost-user.c @@ -948,6 +948,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); @@ -955,8 +956,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; @@ -1053,6 +1058,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 @@ -1066,8 +1072,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) { @@ -1147,6 +1153,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 @@ -1159,14 +1166,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; } @@ -1175,6 +1182,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 @@ -1187,7 +1195,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; } --=20 MST