From nobody Wed May 15 11:15:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1693402881; cv=none; d=zohomail.com; s=zohoarc; b=JUj0vSG2bCqP5C1XgBpJzbdNZVhyQ65hUFpch3pL50zwipnSzQCS43E0OUk9gNeIinybVSSSSU5DmI/cmfzIRJr8ZxfzgV92TDDzzRFsvGCvpORTtH/zL5neTRvAvlQUvj3pi734rk9vo3qIU/LUdle5uzDdr3ubjrYJKA46TE8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693402881; 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; bh=dAiBNQ4x0WuXIAu2+bbjdgMkz3IXssOxBpt9Y4diNsM=; b=DHE/LDHRV7Kg8WEHbFgtkUr1W7LUmms5jvCnJddcGytkze5fUmvGmIsaShAY27qdJLtXiZJvVVn01CPgR7yvLTJuirqktetCe47OD8I6K63w7vRgVlnM2PlI3L+YpHZrFYmJZxeOMTr99z1usAVu1rbC1KQFMOHqWv825tFev1g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1693402881428709.6786789243188; Wed, 30 Aug 2023 06:41:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qbLRS-0008EU-OX; Wed, 30 Aug 2023 09:41:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qbLRR-0008CU-5V for qemu-devel@nongnu.org; Wed, 30 Aug 2023 09:41:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qbLRP-0007pB-2X for qemu-devel@nongnu.org; Wed, 30 Aug 2023 09:41:04 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-380-yrsOX4YBPh-OB3VpgXhx8A-1; Wed, 30 Aug 2023 09:41:00 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8532A185A793; Wed, 30 Aug 2023 13:41:00 +0000 (UTC) Received: from lacos-laptop-9.usersys.redhat.com (unknown [10.39.192.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 15DE5112131B; Wed, 30 Aug 2023 13:40:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693402862; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dAiBNQ4x0WuXIAu2+bbjdgMkz3IXssOxBpt9Y4diNsM=; b=HkFY3XJzetBkGqqmiIxByLI5d5CnLyH9ApwJ7bReKcxCxJLy5BO1TLLNe+CTKmBo2Al4Xd 0l8JBYRLzfbWHW1EbS6+IZaEKJWnm2s9Opo5XChgow4e2aFOgU3cBHptBoSynaQKkekPUJ +sOfkM93fdqqChIN1YRmDV4wYAB/O/Y= X-MC-Unique: yrsOX4YBPh-OB3VpgXhx8A-1 From: Laszlo Ersek To: qemu-devel@nongnu.org, lersek@redhat.com Cc: "Michael S. Tsirkin" , Eugenio Perez Martin , German Maglione , Liu Jiang , Sergio Lopez Pascual , Stefano Garzarella Subject: [PATCH v2 1/7] vhost-user: strip superfluous whitespace Date: Wed, 30 Aug 2023 15:40:49 +0200 Message-Id: <20230830134055.106812-2-lersek@redhat.com> In-Reply-To: <20230830134055.106812-1-lersek@redhat.com> References: <20230830134055.106812-1-lersek@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=lersek@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1693402883363100003 Content-Type: text/plain; charset="utf-8" Cc: "Michael S. Tsirkin" (supporter:vhost) Cc: Eugenio Perez Martin Cc: German Maglione Cc: Liu Jiang Cc: Sergio Lopez Pascual Cc: Stefano Garzarella Signed-off-by: Laszlo Ersek Reviewed-by: Stefano Garzarella Reviewed-by: Eugenio P=C3=A9rez Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Albert Esteve --- Notes: v2: =20 - pick up Stefano's R-b hw/virtio/vhost-user.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 8dcf049d422b..b4b677c1ce66 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -398,7 +398,7 @@ static int vhost_user_write(struct vhost_dev *dev, Vhos= tUserMsg *msg, * operations such as configuring device memory mappings or issuing de= vice * resets, which affect the whole device instead of individual VQs, * vhost-user messages should only be sent once. - *=20 + * * Devices with multiple vhost_devs are given an associated dev->vq_in= dex * so per_device requests are only sent if vq_index is 0. */ From nobody Wed May 15 11:15:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1693402936; cv=none; d=zohomail.com; s=zohoarc; b=hB6Uluo8m9kQMASudYkaHbCxr18a41dAFyNajIJEcSHjMAQ/G808FGe9b8ikxn1gZMxuE7rPpoYp+4oa/n3iXjb4paIvapo7edoAynEwhKgzPz+Qv2ToTkylVWvX+HO7bG6ihYj/cTY6h4Wr1vorVpu3eaNslnanlMTA3RuIMmQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693402936; 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; bh=wJDfKVz3ZSjlOPy51MrtUNVWCe8oOZ/2jLJFlKPoeW8=; b=lchTGdNWK3UMhpMVJHcit0U3jPfh8bxo285umYc/dM7fEAIA4LUXG6AeFTppzloW4MQAPHv65hwu7IcuVBgSXrkdZx0CoNbggLR6Vk/0MXpBRoWR4fZKZZ9W9crI1m1iBlBg2f7V+qx4igHKrI7nzwwXDPiZxT0z8FUAlXfT3Hw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1693402936507874.5314085282788; Wed, 30 Aug 2023 06:42:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qbLRX-0008K8-MV; Wed, 30 Aug 2023 09:41:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qbLRW-0008Js-To for qemu-devel@nongnu.org; Wed, 30 Aug 2023 09:41:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qbLRU-0007pm-Px for qemu-devel@nongnu.org; Wed, 30 Aug 2023 09:41:10 -0400 Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-609-x5zfKEFcOf26CNCKaMCGgw-1; Wed, 30 Aug 2023 09:41:04 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 12B1D3C0E236; Wed, 30 Aug 2023 13:41:04 +0000 (UTC) Received: from lacos-laptop-9.usersys.redhat.com (unknown [10.39.192.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 99A77112131B; Wed, 30 Aug 2023 13:41:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693402867; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wJDfKVz3ZSjlOPy51MrtUNVWCe8oOZ/2jLJFlKPoeW8=; b=O2clGFAjlcTgqd1a7A4mXwCHDs4kAsJ7avYiIrk0OUvttxrsdV1VajUR2/YzkOm8hwdDMa CdtJJaan67ncsyGGDkabuVB+YFXtFobR4DyRzTh0S2V4IkKLDLPhhFnk6VgEuoHWfrWo4M gHYcmkj0jjU4g3tgoubSVbAzE7vS95c= X-MC-Unique: x5zfKEFcOf26CNCKaMCGgw-1 From: Laszlo Ersek To: qemu-devel@nongnu.org, lersek@redhat.com Cc: "Michael S. Tsirkin" , Eugenio Perez Martin , German Maglione , Liu Jiang , Sergio Lopez Pascual , Stefano Garzarella Subject: [PATCH v2 2/7] vhost-user: tighten "reply_supported" scope in "set_vring_addr" Date: Wed, 30 Aug 2023 15:40:50 +0200 Message-Id: <20230830134055.106812-3-lersek@redhat.com> In-Reply-To: <20230830134055.106812-1-lersek@redhat.com> References: <20230830134055.106812-1-lersek@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=lersek@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1693402938776100003 Content-Type: text/plain; charset="utf-8" In the vhost_user_set_vring_addr() function, we calculate "reply_supported" unconditionally, even though we'll only need it if "wait_for_reply" is also true. Restrict the scope of "reply_supported" to the minimum. This is purely refactoring -- no observable change. Cc: "Michael S. Tsirkin" (supporter:vhost) Cc: Eugenio Perez Martin Cc: German Maglione Cc: Liu Jiang Cc: Sergio Lopez Pascual Cc: Stefano Garzarella Signed-off-by: Laszlo Ersek Reviewed-by: Stefano Garzarella Reviewed-by: Eugenio P=C3=A9rez Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- Notes: v2: =20 - pick up Stefano's R-b hw/virtio/vhost-user.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index b4b677c1ce66..64eac317bfb2 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1331,17 +1331,18 @@ static int vhost_user_set_vring_addr(struct vhost_d= ev *dev, .hdr.size =3D sizeof(msg.payload.addr), }; =20 - bool reply_supported =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_REPLY_= ACK); - /* * wait for a reply if logging is enabled to make sure * backend is actually logging changes */ bool wait_for_reply =3D addr->flags & (1 << VHOST_VRING_F_LOG); =20 - if (reply_supported && wait_for_reply) { - msg.hdr.flags |=3D VHOST_USER_NEED_REPLY_MASK; + if (wait_for_reply) { + bool reply_supported =3D virtio_has_feature(dev->protocol_features, + VHOST_USER_PROTOCOL_F_REPLY_ACK); + if (reply_supported) { + msg.hdr.flags |=3D VHOST_USER_NEED_REPLY_MASK; + } } =20 ret =3D vhost_user_write(dev, &msg, NULL, 0); From nobody Wed May 15 11:15:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1693402972; cv=none; d=zohomail.com; s=zohoarc; b=RLMvIJLc817oQodDQZYuhdx8zQCGQO/R4sjJzlTKhlUja/LTN67fiQ9xkzIS2ioRO7IOQA2izXc/sdM8Ie3/io7St4lBYdSMDr6ROJW+klcoDnQQj+7jx3DVGCG3iRPmf2ljK/NVmq80zG7U7+OibTvZl4rj13yTIpv+uFMI7fA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693402972; 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=VV7U8QDr6Rz38uDSt16RgP+Uap8nAfM694Y5zrxRJBc=; b=X5E7WTkeTp4kiz6elnfhckjhU3Jbxj7ZiutoxoQHTU4bxtrBfMfUHC2G9DlrmIFUcYj37I2IESN3WNTylh6bUIjoGpuNjdCVGWmnrWMVma2FA8gsM8UTQNKDesPft4x1kBYImSBD4l9CLjVkCuKtO/z8xvM9pmNVQ/vEC3Zs6gY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1693402972972253.5038647566514; Wed, 30 Aug 2023 06:42:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qbLRZ-0008Kc-8g; Wed, 30 Aug 2023 09:41:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qbLRX-0008Ju-1p for qemu-devel@nongnu.org; Wed, 30 Aug 2023 09:41:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qbLRU-0007pn-Q1 for qemu-devel@nongnu.org; Wed, 30 Aug 2023 09:41:10 -0400 Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-223-DN5pIU8oP3GtZJX9Fq6QKA-1; Wed, 30 Aug 2023 09:41:06 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C0C6A3C0E200; Wed, 30 Aug 2023 13:41:05 +0000 (UTC) Received: from lacos-laptop-9.usersys.redhat.com (unknown [10.39.192.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 536F2112131B; Wed, 30 Aug 2023 13:41:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693402867; 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=VV7U8QDr6Rz38uDSt16RgP+Uap8nAfM694Y5zrxRJBc=; b=Z4gaS4DhOA5n7Vmxo9R32LjlxbZXaYISVEAFOa8U4R+KkZ2BVioXJ3SSSMpdzH4i1AE6k1 AJGp76rA2/fgav8+ZikXv+USwpArsuAfB7tZrTAiB4ZN4RfeRKaAjqGvwUd3k85/eO+S0b 0BVifZpCoImOcBszrpLvo1AdTIAj3Wg= X-MC-Unique: DN5pIU8oP3GtZJX9Fq6QKA-1 From: Laszlo Ersek To: qemu-devel@nongnu.org, lersek@redhat.com Cc: "Michael S. Tsirkin" , Eugenio Perez Martin , German Maglione , Liu Jiang , Sergio Lopez Pascual , Stefano Garzarella Subject: [PATCH v2 3/7] vhost-user: factor out "vhost_user_write_sync" Date: Wed, 30 Aug 2023 15:40:51 +0200 Message-Id: <20230830134055.106812-4-lersek@redhat.com> In-Reply-To: <20230830134055.106812-1-lersek@redhat.com> References: <20230830134055.106812-1-lersek@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=lersek@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1693402973627100001 Content-Type: text/plain; charset="utf-8" The tails of the "vhost_user_set_vring_addr" and "vhost_user_set_u64" functions are now byte-for-byte identical. Factor the common tail out to a new function called "vhost_user_write_sync". This is purely refactoring -- no observable change. Cc: "Michael S. Tsirkin" (supporter:vhost) Cc: Eugenio Perez Martin Cc: German Maglione Cc: Liu Jiang Cc: Sergio Lopez Pascual Cc: Stefano Garzarella Signed-off-by: Laszlo Ersek Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefano Garzarella Reviewed-by: Eugenio P=C3=A9rez --- Notes: v2: =20 - pick up R-b's from Phil and Stefano =20 - rename "vhost_user_write_msg" to "vhost_user_write_sync" (in code and commit message) [Stefano] hw/virtio/vhost-user.c | 66 +++++++++----------- 1 file changed, 28 insertions(+), 38 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 64eac317bfb2..1476b36f0a6e 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1320,10 +1320,35 @@ static int enforce_reply(struct vhost_dev *dev, return vhost_user_get_features(dev, &dummy); } =20 +/* Note: "msg->hdr.flags" may be modified. */ +static int vhost_user_write_sync(struct vhost_dev *dev, VhostUserMsg *msg, + bool wait_for_reply) +{ + int ret; + + if (wait_for_reply) { + bool reply_supported =3D virtio_has_feature(dev->protocol_features, + VHOST_USER_PROTOCOL_F_REPLY_ACK); + if (reply_supported) { + msg->hdr.flags |=3D VHOST_USER_NEED_REPLY_MASK; + } + } + + ret =3D vhost_user_write(dev, msg, NULL, 0); + if (ret < 0) { + return ret; + } + + if (wait_for_reply) { + return enforce_reply(dev, msg); + } + + return 0; +} + static int vhost_user_set_vring_addr(struct vhost_dev *dev, struct vhost_vring_addr *addr) { - int ret; VhostUserMsg msg =3D { .hdr.request =3D VHOST_USER_SET_VRING_ADDR, .hdr.flags =3D VHOST_USER_VERSION, @@ -1337,24 +1362,7 @@ static int vhost_user_set_vring_addr(struct vhost_de= v *dev, */ bool wait_for_reply =3D addr->flags & (1 << VHOST_VRING_F_LOG); =20 - if (wait_for_reply) { - bool reply_supported =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_REPLY_ACK); - if (reply_supported) { - msg.hdr.flags |=3D VHOST_USER_NEED_REPLY_MASK; - } - } - - ret =3D vhost_user_write(dev, &msg, NULL, 0); - if (ret < 0) { - return ret; - } - - if (wait_for_reply) { - return enforce_reply(dev, &msg); - } - - return 0; + return vhost_user_write_sync(dev, &msg, wait_for_reply); } =20 static int vhost_user_set_u64(struct vhost_dev *dev, int request, uint64_t= u64, @@ -1366,26 +1374,8 @@ static int vhost_user_set_u64(struct vhost_dev *dev,= int request, uint64_t u64, .payload.u64 =3D u64, .hdr.size =3D sizeof(msg.payload.u64), }; - int ret; =20 - if (wait_for_reply) { - bool reply_supported =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_REPLY_ACK); - if (reply_supported) { - msg.hdr.flags |=3D VHOST_USER_NEED_REPLY_MASK; - } - } - - ret =3D vhost_user_write(dev, &msg, NULL, 0); - if (ret < 0) { - return ret; - } - - if (wait_for_reply) { - return enforce_reply(dev, &msg); - } - - return 0; + return vhost_user_write_sync(dev, &msg, wait_for_reply); } =20 static int vhost_user_set_status(struct vhost_dev *dev, uint8_t status) From nobody Wed May 15 11:15:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1693402886; cv=none; d=zohomail.com; s=zohoarc; b=ZaWmlsz855VrqjjUzEy9VyVRaWSOs15liooh6P5C5bTecHW2VLMvJLhTUudBQFQVuub79lD6WRyhk4o8qRi4+3S7GyetIfsdaDGeMc9BNMwnab7CsaJFsMBDGSLpZvug2GmlJefEYUmp650t+1fJ6dkSXd8xzwPV9W/lLVCHRm8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693402886; 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=vyNsvknF0VUozRK/KR9gJLKDhInaHr02cFO6Hr+TxQQ=; b=QARsDizT/ha9kA00XbdNbDc8xI+UC59I6ZizKMOoGAZQu+XIkHfeQj6UdoHC2CYXvrdG5Lq3NZG+pmiVJDeqb8xUYSZmrB0zLhx3YoR01y2h5XlZapDitIHWr2qfqsF/zBrEageSG+6T/9OnsAlcXCjIibr6Qqb/LBW+FrjmkXo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1693402886477205.61837968162342; Wed, 30 Aug 2023 06:41:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qbLRa-0008Kt-E8; Wed, 30 Aug 2023 09:41:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qbLRY-0008KV-TA for qemu-devel@nongnu.org; Wed, 30 Aug 2023 09:41:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qbLRV-0007q5-To for qemu-devel@nongnu.org; Wed, 30 Aug 2023 09:41:12 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-672-ugp_6j1cO_G1lXXfbJTkAQ-1; Wed, 30 Aug 2023 09:41:08 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7B6E185CBED; Wed, 30 Aug 2023 13:41:07 +0000 (UTC) Received: from lacos-laptop-9.usersys.redhat.com (unknown [10.39.192.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0DD4C1121315; Wed, 30 Aug 2023 13:41:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693402869; 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=vyNsvknF0VUozRK/KR9gJLKDhInaHr02cFO6Hr+TxQQ=; b=OGxjVnxPsLQ/QqbfiZM+VInGInwG+Hk62+6WnodcenTScdEG9OrtQJiLVFWXS0cBRBs7hq mvJKeWj5jvGndN76qhVqEwAQ6+KK8dMedadO+r/McTZt8VpLM6kLmTceLhK5V2O9FzNp3M NedB9/R9zi0JcWu2PDX75Y9DjS0hF7Q= X-MC-Unique: ugp_6j1cO_G1lXXfbJTkAQ-1 From: Laszlo Ersek To: qemu-devel@nongnu.org, lersek@redhat.com Cc: "Michael S. Tsirkin" , Eugenio Perez Martin , German Maglione , Liu Jiang , Sergio Lopez Pascual , Stefano Garzarella Subject: [PATCH v2 4/7] vhost-user: flatten "enforce_reply" into "vhost_user_write_sync" Date: Wed, 30 Aug 2023 15:40:52 +0200 Message-Id: <20230830134055.106812-5-lersek@redhat.com> In-Reply-To: <20230830134055.106812-1-lersek@redhat.com> References: <20230830134055.106812-1-lersek@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=lersek@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1693402887482100001 Content-Type: text/plain; charset="utf-8" At this point, only "vhost_user_write_sync" calls "enforce_reply"; embed the latter into the former. This is purely refactoring -- no observable change. Cc: "Michael S. Tsirkin" (supporter:vhost) Cc: Eugenio Perez Martin Cc: German Maglione Cc: Liu Jiang Cc: Sergio Lopez Pascual Cc: Stefano Garzarella Signed-off-by: Laszlo Ersek Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefano Garzarella Reviewed-by: Eugenio P=C3=A9rez --- Notes: v2: =20 - pick up R-b's from Phil and Stefano =20 - rename "vhost_user_write_msg" to "vhost_user_write_sync" (in code context and commit message) [Stefano] hw/virtio/vhost-user.c | 32 ++++++++------------ 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 1476b36f0a6e..4129ba72e408 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1302,24 +1302,6 @@ static int vhost_user_get_features(struct vhost_dev = *dev, uint64_t *features) return 0; } =20 -static int enforce_reply(struct vhost_dev *dev, - const VhostUserMsg *msg) -{ - uint64_t dummy; - - if (msg->hdr.flags & VHOST_USER_NEED_REPLY_MASK) { - return process_message_reply(dev, msg); - } - - /* - * We need to wait for a reply but the backend does not - * support replies for the command we just sent. - * Send VHOST_USER_GET_FEATURES which makes all backends - * send a reply. - */ - return vhost_user_get_features(dev, &dummy); -} - /* Note: "msg->hdr.flags" may be modified. */ static int vhost_user_write_sync(struct vhost_dev *dev, VhostUserMsg *msg, bool wait_for_reply) @@ -1340,7 +1322,19 @@ static int vhost_user_write_sync(struct vhost_dev *d= ev, VhostUserMsg *msg, } =20 if (wait_for_reply) { - return enforce_reply(dev, msg); + uint64_t dummy; + + if (msg->hdr.flags & VHOST_USER_NEED_REPLY_MASK) { + return process_message_reply(dev, msg); + } + + /* + * We need to wait for a reply but the backend does not + * support replies for the command we just sent. + * Send VHOST_USER_GET_FEATURES which makes all backends + * send a reply. + */ + return vhost_user_get_features(dev, &dummy); } =20 return 0; From nobody Wed May 15 11:15:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1693402968; cv=none; d=zohomail.com; s=zohoarc; b=MyEaZXfWlfuUD1n4DoJG9hqzkUBvvAXL8swkC5mpiwWIXFh4N/Bht5pukC1yZcYmJdDUizMU6pgR82LluIEgZ49zbZrISWnShIAg/DnxVEWYtMNtIDXbV1RG+PQSaVZlLasX5roIQyRs35WMAa7pxQp3Wi+44qD3NpTPNrM1dKw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693402968; 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; bh=hdg2AXLJyYkUGlf43V8yNJfwFgAiEVunkQBxiPcgiYI=; b=S9IrsxsXk91LMqYN1v212mzAugrWcEVMhco1vJStzcenjR9mexs/RU9NTGV4cpQmlR7vC/6Zt33+2uzM+1eZW211OGbYGaIUwWmCKl0v+GG0eOcV9VsrSYLO8YJm9Nt0sIMfC88PdiNfJzkKM8LuoaUJUuVs9aEMV/s43zY2cy4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1693402968679671.6372930934292; Wed, 30 Aug 2023 06:42:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qbLRc-0008Li-4K; Wed, 30 Aug 2023 09:41:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qbLRa-0008L9-RV for qemu-devel@nongnu.org; Wed, 30 Aug 2023 09:41:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qbLRY-0007qV-Aq for qemu-devel@nongnu.org; Wed, 30 Aug 2023 09:41:14 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-449-d5n4xXCMOwewTHCRMS3Ydw-1; Wed, 30 Aug 2023 09:41:09 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 35C20800FF5; Wed, 30 Aug 2023 13:41:09 +0000 (UTC) Received: from lacos-laptop-9.usersys.redhat.com (unknown [10.39.192.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC69A1121315; Wed, 30 Aug 2023 13:41:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693402871; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hdg2AXLJyYkUGlf43V8yNJfwFgAiEVunkQBxiPcgiYI=; b=NRfrT4Fy5TtHGp/higixXnzw4ttFoOzst+rG+AcepchYWKAIgpLVicMEM3ShKRxIVrg7lG C93n8+FbXjdFtJjWD5Swnnb3ON3EFlr48E0CfZRXqAtNFOXM0grP+hM4T9H/fuvx2YcqKL tL4Wj4dGjtTWDojakzx1llsT1mx/dro= X-MC-Unique: d5n4xXCMOwewTHCRMS3Ydw-1 From: Laszlo Ersek To: qemu-devel@nongnu.org, lersek@redhat.com Cc: "Michael S. Tsirkin" , Eugenio Perez Martin , German Maglione , Liu Jiang , Sergio Lopez Pascual , Stefano Garzarella Subject: [PATCH v2 5/7] vhost-user: hoist "write_sync", "get_features", "get_u64" Date: Wed, 30 Aug 2023 15:40:53 +0200 Message-Id: <20230830134055.106812-6-lersek@redhat.com> In-Reply-To: <20230830134055.106812-1-lersek@redhat.com> References: <20230830134055.106812-1-lersek@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=lersek@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1693402970975100003 Content-Type: text/plain; charset="utf-8" In order to avoid a forward-declaration for "vhost_user_write_sync" in a subsequent patch, hoist "vhost_user_write_sync" -> "vhost_user_get_features" -> "vhost_user_get_u64" just above "vhost_set_vring". This is purely code movement -- no observable change. Cc: "Michael S. Tsirkin" (supporter:vhost) Cc: Eugenio Perez Martin Cc: German Maglione Cc: Liu Jiang Cc: Sergio Lopez Pascual Cc: Stefano Garzarella Signed-off-by: Laszlo Ersek Reviewed-by: Stefano Garzarella Reviewed-by: Eugenio P=C3=A9rez Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- Notes: v2: =20 - pick up R-b from Stefano =20 - rename "vhost_user_write_msg" to "vhost_user_write_sync" (in code and commit message) [Stefano] hw/virtio/vhost-user.c | 170 ++++++++++---------- 1 file changed, 85 insertions(+), 85 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 4129ba72e408..c79b6f77cdca 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1083,6 +1083,91 @@ static int vhost_user_set_vring_endian(struct vhost_= dev *dev, return vhost_user_write(dev, &msg, NULL, 0); } =20 +static int vhost_user_get_u64(struct vhost_dev *dev, int request, uint64_t= *u64) +{ + int ret; + VhostUserMsg msg =3D { + .hdr.request =3D request, + .hdr.flags =3D VHOST_USER_VERSION, + }; + + if (vhost_user_per_device_request(request) && dev->vq_index !=3D 0) { + return 0; + } + + ret =3D vhost_user_write(dev, &msg, NULL, 0); + if (ret < 0) { + return ret; + } + + ret =3D vhost_user_read(dev, &msg); + if (ret < 0) { + return ret; + } + + if (msg.hdr.request !=3D request) { + error_report("Received unexpected msg type. Expected %d received %= d", + request, msg.hdr.request); + return -EPROTO; + } + + if (msg.hdr.size !=3D sizeof(msg.payload.u64)) { + error_report("Received bad msg size."); + return -EPROTO; + } + + *u64 =3D msg.payload.u64; + + return 0; +} + +static int vhost_user_get_features(struct vhost_dev *dev, uint64_t *featur= es) +{ + if (vhost_user_get_u64(dev, VHOST_USER_GET_FEATURES, features) < 0) { + return -EPROTO; + } + + return 0; +} + +/* Note: "msg->hdr.flags" may be modified. */ +static int vhost_user_write_sync(struct vhost_dev *dev, VhostUserMsg *msg, + bool wait_for_reply) +{ + int ret; + + if (wait_for_reply) { + bool reply_supported =3D virtio_has_feature(dev->protocol_features, + VHOST_USER_PROTOCOL_F_REPLY_ACK); + if (reply_supported) { + msg->hdr.flags |=3D VHOST_USER_NEED_REPLY_MASK; + } + } + + ret =3D vhost_user_write(dev, msg, NULL, 0); + if (ret < 0) { + return ret; + } + + if (wait_for_reply) { + uint64_t dummy; + + if (msg->hdr.flags & VHOST_USER_NEED_REPLY_MASK) { + return process_message_reply(dev, msg); + } + + /* + * We need to wait for a reply but the backend does not + * support replies for the command we just sent. + * Send VHOST_USER_GET_FEATURES which makes all backends + * send a reply. + */ + return vhost_user_get_features(dev, &dummy); + } + + return 0; +} + static int vhost_set_vring(struct vhost_dev *dev, unsigned long int request, struct vhost_vring_state *ring) @@ -1255,91 +1340,6 @@ static int vhost_user_set_vring_err(struct vhost_dev= *dev, return vhost_set_vring_file(dev, VHOST_USER_SET_VRING_ERR, file); } =20 -static int vhost_user_get_u64(struct vhost_dev *dev, int request, uint64_t= *u64) -{ - int ret; - VhostUserMsg msg =3D { - .hdr.request =3D request, - .hdr.flags =3D VHOST_USER_VERSION, - }; - - if (vhost_user_per_device_request(request) && dev->vq_index !=3D 0) { - return 0; - } - - ret =3D vhost_user_write(dev, &msg, NULL, 0); - if (ret < 0) { - return ret; - } - - ret =3D vhost_user_read(dev, &msg); - if (ret < 0) { - return ret; - } - - if (msg.hdr.request !=3D request) { - error_report("Received unexpected msg type. Expected %d received %= d", - request, msg.hdr.request); - return -EPROTO; - } - - if (msg.hdr.size !=3D sizeof(msg.payload.u64)) { - error_report("Received bad msg size."); - return -EPROTO; - } - - *u64 =3D msg.payload.u64; - - return 0; -} - -static int vhost_user_get_features(struct vhost_dev *dev, uint64_t *featur= es) -{ - if (vhost_user_get_u64(dev, VHOST_USER_GET_FEATURES, features) < 0) { - return -EPROTO; - } - - return 0; -} - -/* Note: "msg->hdr.flags" may be modified. */ -static int vhost_user_write_sync(struct vhost_dev *dev, VhostUserMsg *msg, - bool wait_for_reply) -{ - int ret; - - if (wait_for_reply) { - bool reply_supported =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_REPLY_ACK); - if (reply_supported) { - msg->hdr.flags |=3D VHOST_USER_NEED_REPLY_MASK; - } - } - - ret =3D vhost_user_write(dev, msg, NULL, 0); - if (ret < 0) { - return ret; - } - - if (wait_for_reply) { - uint64_t dummy; - - if (msg->hdr.flags & VHOST_USER_NEED_REPLY_MASK) { - return process_message_reply(dev, msg); - } - - /* - * We need to wait for a reply but the backend does not - * support replies for the command we just sent. - * Send VHOST_USER_GET_FEATURES which makes all backends - * send a reply. - */ - return vhost_user_get_features(dev, &dummy); - } - - return 0; -} - static int vhost_user_set_vring_addr(struct vhost_dev *dev, struct vhost_vring_addr *addr) { From nobody Wed May 15 11:15:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1693402912; cv=none; d=zohomail.com; s=zohoarc; b=UiaduO+Zf/DK2OsaVsfOSl+ySK+F6+OPAHEfidmacFVujfq3QnSZmNBvobKOKxsr9f8WaNmaIEjjIcOkIO26tDGNxFtYgFcJHtN9iaSjNbWwk8orDuT4uf/GNdTcFEjfeHBqBATrUa8w/DgmYl6OQ6MUtHpplvR3FuMfiHj1DDA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693402912; 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=5p0b5nURlJHXpHEozQMcDhYqdVz2TuCbLq5C4WviENA=; b=lyNa9HU64a5yHpX8vaogWzdW6Lkm+LtXNkMEuv4ZFGkRJFpMti5vCLla0af3unLUe0wJmP0WDeW9Tj4iuCUjnAt2YLGwuzKywhFUv1OcFLwd74BU43dLXAEqUJpVRsMm2AXd34Eo6pXmCgmccp2mRrL9+e3ZuWRSRFyv+zMB7zc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1693402912299678.0030485461398; Wed, 30 Aug 2023 06:41:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qbLRd-0008M5-NU; Wed, 30 Aug 2023 09:41:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qbLRb-0008LM-LZ for qemu-devel@nongnu.org; Wed, 30 Aug 2023 09:41:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qbLRZ-0007qi-FO for qemu-devel@nongnu.org; Wed, 30 Aug 2023 09:41:15 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-399-Qyio8eOdO06T4jcctT7alw-1; Wed, 30 Aug 2023 09:41:11 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E3391185A793; Wed, 30 Aug 2023 13:41:10 +0000 (UTC) Received: from lacos-laptop-9.usersys.redhat.com (unknown [10.39.192.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 76FFA1121315; Wed, 30 Aug 2023 13:41:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693402872; 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=5p0b5nURlJHXpHEozQMcDhYqdVz2TuCbLq5C4WviENA=; b=JlDWY/PKOnC5r7ub1g46Yxo222T9WyIRRMiQwKJh1duCsnBfwtj9Wnd+koQq1GbcxgjBXo sb+ULqg2IoR53S23zJqQkPIQIw+1Q7jRfZUUFtRnG8t/Yr4Eg1Q/CyTBgOnYdRtpqy/0TH NjaDlTcLIzSPmerINbDLtgyj4Lzy+Ds= X-MC-Unique: Qyio8eOdO06T4jcctT7alw-1 From: Laszlo Ersek To: qemu-devel@nongnu.org, lersek@redhat.com Cc: "Michael S. Tsirkin" , Eugenio Perez Martin , German Maglione , Liu Jiang , Sergio Lopez Pascual , Stefano Garzarella Subject: [PATCH v2 6/7] vhost-user: allow "vhost_set_vring" to wait for a reply Date: Wed, 30 Aug 2023 15:40:54 +0200 Message-Id: <20230830134055.106812-7-lersek@redhat.com> In-Reply-To: <20230830134055.106812-1-lersek@redhat.com> References: <20230830134055.106812-1-lersek@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=lersek@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1693402914008100001 Content-Type: text/plain; charset="utf-8" The "vhost_set_vring" function already centralizes the common parts of "vhost_user_set_vring_num", "vhost_user_set_vring_base" and "vhost_user_set_vring_enable". We'll want to allow some of those callers to wait for a reply. Therefore, rebase "vhost_set_vring" from just "vhost_user_write" to "vhost_user_write_sync", exposing the "wait_for_reply" parameter. This is purely refactoring -- there is no observable change. That's because: - all three callers pass in "false" for "wait_for_reply", which disables all logic in "vhost_user_write_sync" except the call to "vhost_user_write"; - the fds=3DNULL and fd_num=3D0 arguments of the original "vhost_user_write" call inside "vhost_set_vring" are hard-coded within "vhost_user_write_sync". Cc: "Michael S. Tsirkin" (supporter:vhost) Cc: Eugenio Perez Martin Cc: German Maglione Cc: Liu Jiang Cc: Sergio Lopez Pascual Cc: Stefano Garzarella Signed-off-by: Laszlo Ersek Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefano Garzarella Reviewed-by: Eugenio P=C3=A9rez --- Notes: v2: =20 - pick up R-b's from Phil and Stefano =20 - rename "vhost_user_write_msg" to "vhost_user_write_sync" (in code and commit message) [Stefano] hw/virtio/vhost-user.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index c79b6f77cdca..18e15a9bb359 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1170,7 +1170,8 @@ static int vhost_user_write_sync(struct vhost_dev *de= v, VhostUserMsg *msg, =20 static int vhost_set_vring(struct vhost_dev *dev, unsigned long int request, - struct vhost_vring_state *ring) + struct vhost_vring_state *ring, + bool wait_for_reply) { VhostUserMsg msg =3D { .hdr.request =3D request, @@ -1179,13 +1180,13 @@ static int vhost_set_vring(struct vhost_dev *dev, .hdr.size =3D sizeof(msg.payload.state), }; =20 - return vhost_user_write(dev, &msg, NULL, 0); + return vhost_user_write_sync(dev, &msg, wait_for_reply); } =20 static int vhost_user_set_vring_num(struct vhost_dev *dev, struct vhost_vring_state *ring) { - return vhost_set_vring(dev, VHOST_USER_SET_VRING_NUM, ring); + return vhost_set_vring(dev, VHOST_USER_SET_VRING_NUM, ring, false); } =20 static void vhost_user_host_notifier_free(VhostUserHostNotifier *n) @@ -1216,7 +1217,7 @@ static void vhost_user_host_notifier_remove(VhostUser= HostNotifier *n, static int vhost_user_set_vring_base(struct vhost_dev *dev, struct vhost_vring_state *ring) { - return vhost_set_vring(dev, VHOST_USER_SET_VRING_BASE, ring); + return vhost_set_vring(dev, VHOST_USER_SET_VRING_BASE, ring, false); } =20 static int vhost_user_set_vring_enable(struct vhost_dev *dev, int enable) @@ -1234,7 +1235,7 @@ static int vhost_user_set_vring_enable(struct vhost_d= ev *dev, int enable) .num =3D enable, }; =20 - ret =3D vhost_set_vring(dev, VHOST_USER_SET_VRING_ENABLE, &state); + ret =3D vhost_set_vring(dev, VHOST_USER_SET_VRING_ENABLE, &state, = false); if (ret < 0) { /* * Restoring the previous state is likely infeasible, as well = as From nobody Wed May 15 11:15:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1693402930; cv=none; d=zohomail.com; s=zohoarc; b=lH2qjqfaTvyARANiRSBIUp0t50CPJx6kv1F0JqzvKKsHuQKge5S8y6qxZJHfkCk2eK1BlsFhDrUprh4fsL87CEGWDyczgwqzRs+77mptLkf/P9Qmum8Jts1v8RUJgp9KkYdAdRDvUZjE2kmPE6qwPA5IZLQ2aujE8DNEHEb+Fhk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693402930; 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=cIIbtPgIuBYjxguUdrFg1fGOqTlujoHCpeldVMchkuU=; b=CymrqAPTG85SaLp37Gkp4QM1T82Dd92B1GO+anI7TRhrMV4grHGSCLrFRMqs7QOCXpIcWXhfCWfxDhyJ6ADTuTiG5uSe08SHVZXPEfHi94YW75QAavq63/iWc8/UIPLlHdERs/rUzRtavPE056yqmqQTbhEUTiVj+3SO/NngPRM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 169340293000222.612671541993222; Wed, 30 Aug 2023 06:42:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qbLRi-0000Kh-Er; Wed, 30 Aug 2023 09:41:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qbLRg-0008VQ-8c for qemu-devel@nongnu.org; Wed, 30 Aug 2023 09:41:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qbLRd-0007rH-CT for qemu-devel@nongnu.org; Wed, 30 Aug 2023 09:41:19 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-219-23IrlZ3WMCSHY6xMeLOloA-1; Wed, 30 Aug 2023 09:41:13 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9DDF1185A7A3; Wed, 30 Aug 2023 13:41:12 +0000 (UTC) Received: from lacos-laptop-9.usersys.redhat.com (unknown [10.39.192.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 302EF1121315; Wed, 30 Aug 2023 13:41:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693402876; 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=cIIbtPgIuBYjxguUdrFg1fGOqTlujoHCpeldVMchkuU=; b=anmxXDVLnf2SBjUvvBNlgobjQtrhKoJtIQ2Zb8mw3/tD86CcGl866t6FuMMs0d6mOLz306 skjeUJEOCwhlKJq6WqevrOvdrGp6iygYRe8jweykGu2FBss49fFHHNXhuFFFmgszcJ2IX1 ihRIiMRaqFiUQEvkwoZe46E8WaDg+u0= X-MC-Unique: 23IrlZ3WMCSHY6xMeLOloA-1 From: Laszlo Ersek To: qemu-devel@nongnu.org, lersek@redhat.com Cc: "Michael S. Tsirkin" , Eugenio Perez Martin , German Maglione , Liu Jiang , Sergio Lopez Pascual , Stefano Garzarella Subject: [PATCH v2 7/7] vhost-user: call VHOST_USER_SET_VRING_ENABLE synchronously Date: Wed, 30 Aug 2023 15:40:55 +0200 Message-Id: <20230830134055.106812-8-lersek@redhat.com> In-Reply-To: <20230830134055.106812-1-lersek@redhat.com> References: <20230830134055.106812-1-lersek@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=lersek@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1693402930853100003 Content-Type: text/plain; charset="utf-8" (1) The virtio-1.2 specification writes: > 3 General Initialization And Device Operation > 3.1 Device Initialization > 3.1.1 Driver Requirements: Device Initialization > > [...] > > 7. Perform device-specific setup, including discovery of virtqueues for > the device, optional per-bus setup, reading and possibly writing the > device=E2=80=99s virtio configuration space, and population of virtque= ues. > > 8. Set the DRIVER_OK status bit. At this point the device is =E2=80=9Cliv= e=E2=80=9D. and > 4 Virtio Transport Options > 4.1 Virtio Over PCI Bus > 4.1.4 Virtio Structure PCI Capabilities > 4.1.4.3 Common configuration structure layout > 4.1.4.3.2 Driver Requirements: Common configuration structure layout > > [...] > > The driver MUST configure the other virtqueue fields before enabling the > virtqueue with queue_enable. > > [...] (The same statements are present in virtio-1.0 identically, at .) These together mean that the following sub-sequence of steps is valid for a virtio-1.0 guest driver: (1.1) set "queue_enable" for the needed queues as the final part of device initialization step (7), (1.2) set DRIVER_OK in step (8), (1.3) immediately start sending virtio requests to the device. (2) When vhost-user is enabled, and the VHOST_USER_F_PROTOCOL_FEATURES special virtio feature is negotiated, then virtio rings start in disabled state, according to . In this case, explicit VHOST_USER_SET_VRING_ENABLE messages are needed for enabling vrings. Therefore setting "queue_enable" from the guest (1.1) is a *control plane* operation, which travels from the guest through QEMU to the vhost-user backend, using a unix domain socket. Whereas sending a virtio request (1.3) is a *data plane* operation, which evades QEMU -- it travels from guest to the vhost-user backend via eventfd. This means that steps (1.1) and (1.3) travel through different channels, and their relative order can be reversed, as perceived by the vhost-user backend. That's exactly what happens when OVMF's virtiofs driver (VirtioFsDxe) runs against the Rust-language virtiofsd version 1.7.2. (Which uses version 0.10.1 of the vhost-user-backend crate, and version 0.8.1 of the vhost crate.) Namely, when VirtioFsDxe binds a virtiofs device, it goes through the device initialization steps (i.e., control plane operations), and immediately sends a FUSE_INIT request too (i.e., performs a data plane operation). In the Rust-language virtiofsd, this creates a race between two components that run *concurrently*, i.e., in different threads or processes: - Control plane, handling vhost-user protocol messages: The "VhostUserSlaveReqHandlerMut::set_vring_enable" method [crates/vhost-user-backend/src/handler.rs] handles VHOST_USER_SET_VRING_ENABLE messages, and updates each vring's "enabled" flag according to the message processed. - Data plane, handling virtio / FUSE requests: The "VringEpollHandler::handle_event" method [crates/vhost-user-backend/src/event_loop.rs] handles the incoming virtio / FUSE request, consuming the virtio kick at the same time. If the vring's "enabled" flag is set, the virtio / FUSE request is processed genuinely. If the vring's "enabled" flag is clear, then the virtio / FUSE request is discarded. Note that OVMF enables the queue *first*, and sends FUSE_INIT *second*. However, if the data plane processor in virtiofsd wins the race, then it sees the FUSE_INIT *before* the control plane processor took notice of VHOST_USER_SET_VRING_ENABLE and green-lit the queue for the data plane processor. Therefore the latter drops FUSE_INIT on the floor, and goes back to waiting for further virtio / FUSE requests with epoll_wait. Meanwhile OVMF is stuck waiting for the FUSET_INIT response -- a deadlock. The deadlock is not deterministic. OVMF hangs infrequently during first boot. However, OVMF hangs almost certainly during reboots from the UEFI shell. The race can be "reliably masked" by inserting a very small delay -- a single debug message -- at the top of "VringEpollHandler::handle_event", i.e., just before the data plane processor checks the "enabled" field of the vring. That delay suffices for the control plane processor to act upon VHOST_USER_SET_VRING_ENABLE. We can deterministically prevent the race in QEMU, by blocking OVMF inside step (1.1) -- i.e., in the write to the "queue_enable" register -- until VHOST_USER_SET_VRING_ENABLE actually *completes*. That way OVMF's VCPU cannot advance to the FUSE_INIT submission before virtiofsd's control plane processor takes notice of the queue being enabled. Wait for VHOST_USER_SET_VRING_ENABLE completion by: - setting the NEED_REPLY flag on VHOST_USER_SET_VRING_ENABLE, and waiting for the reply, if the VHOST_USER_PROTOCOL_F_REPLY_ACK vhost-user feature has been negotiated, or - performing a separate VHOST_USER_GET_FEATURES *exchange*, which requires a backend response regardless of VHOST_USER_PROTOCOL_F_REPLY_ACK. Cc: "Michael S. Tsirkin" (supporter:vhost) Cc: Eugenio Perez Martin Cc: German Maglione Cc: Liu Jiang Cc: Sergio Lopez Pascual Cc: Stefano Garzarella Signed-off-by: Laszlo Ersek Reviewed-by: Stefano Garzarella Acked-by: Eugenio P=C3=A9rez Reviewed-by: Eugenio P=C3=A9rez --- Notes: v2: =20 - pick up R-b from Stefano =20 - update virtio spec reference from 1.0 to 1.2 (also keep the 1.0 ref) in the commit message; re-check the quotes / section headers [Stefano] =20 - summarize commit message in code comment [Stefano] hw/virtio/vhost-user.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 18e15a9bb359..41842eb023b5 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1235,7 +1235,21 @@ static int vhost_user_set_vring_enable(struct vhost_= dev *dev, int enable) .num =3D enable, }; =20 - ret =3D vhost_set_vring(dev, VHOST_USER_SET_VRING_ENABLE, &state, = false); + /* + * SET_VRING_ENABLE travels from guest to QEMU to vhost-user backe= nd / + * control plane thread via unix domain socket. Virtio requests tr= avel + * from guest to vhost-user backend / data plane thread via eventf= d. + * Even if the guest enables the ring first, and pushes its first = virtio + * request second (conforming to the virtio spec), the data plane = thread + * in the backend may see the virtio request before the control pl= ane + * thread sees the queue enablement. This causes (in fact, require= s) the + * data plane thread to discard the virtio request (it arrived on a + * seemingly disabled queue). To prevent this out-of-order deliver= y, + * don't let the guest proceed to pushing the virtio request until= the + * backend control plane acknowledges enabling the queue -- IOW, p= ass + * wait_for_reply=3Dtrue below. + */ + ret =3D vhost_set_vring(dev, VHOST_USER_SET_VRING_ENABLE, &state, = true); if (ret < 0) { /* * Restoring the previous state is likely infeasible, as well = as