From nobody Thu Nov 14 16:45:39 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=1696278851; cv=none; d=zohomail.com; s=zohoarc; b=KJoarFz3s50BmMxBuvLBB6IW6TtXAjLhU7ppNTHAvP8W2tjax1SkguF2HEnW/3FfgODFHqz25fIOVJBCZF3l4Zpq0ngT/aWsFDEeRyPEjvysW4I948zLXeKAwJdLBQJ76i/7+XNETvA37VyAVkMH1M9oDx1nv4Yx+/8YlFDFua8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696278851; 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=0nYH5tmHEHaZsrcQqH9kYvHwI5zmEvvxHuX9nbtNjjc=; b=mstZSOnXcafdlgUHtgRwxpzycBhO0NUEDblLIaJdosNhnJSsuOI8M+ZKGsbKyT2r1qcCfBJs1pH0jkSLPKs6CKKospMzaDDUJ66S/YN5dkNEkn5O31JGqOsdgIdJKONlLmTCQL3TYPkT3j1kxyxoCEnubMYGfim9ZT3FbLJYU7M= 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 1696278851656899.0242286577806; Mon, 2 Oct 2023 13:34:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnPb0-0003UL-9W; Mon, 02 Oct 2023 16:32:50 -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 1qnPaz-0003U7-8J for qemu-devel@nongnu.org; Mon, 02 Oct 2023 16:32:49 -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 1qnPax-0001VS-M3 for qemu-devel@nongnu.org; Mon, 02 Oct 2023 16:32:49 -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-386-vVKI9Q89OCuKwNlecfAj4A-1; Mon, 02 Oct 2023 16:32:45 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 077B0101A590; Mon, 2 Oct 2023 20:32:45 +0000 (UTC) Received: from lacos-laptop-9.usersys.redhat.com (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id EA35D40C6EBF; Mon, 2 Oct 2023 20:32:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696278767; 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=0nYH5tmHEHaZsrcQqH9kYvHwI5zmEvvxHuX9nbtNjjc=; b=PlEQaCwPD3fKfswNiV7BqRotZ5vV5gB/io282AjwetvotjYlQxava3/tmhDsSoPqs+iE/0 NvrwX6jRrMfuEWnQW8wCgMmJqablV4SjXi4Tm7IniuN2qcHY9Dwp7UzMBSRkjiDacf3RcV dvSQwMaXiRqLLzz1g1t6TuK6r9oWAew= X-MC-Unique: vVKI9Q89OCuKwNlecfAj4A-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 v3 6/7] vhost-user: allow "vhost_set_vring" to wait for a reply Date: Mon, 2 Oct 2023 22:32:20 +0200 Message-Id: <20231002203221.17241-7-lersek@redhat.com> In-Reply-To: <20231002203221.17241-1-lersek@redhat.com> References: <20231002203221.17241-1-lersek@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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_H3=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: 1696278852554100001 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 Tested-by: Albert Esteve Reviewed-by: Eugenio P=C3=A9rez --- Notes: v3: =20 - pick up R-b from Eugenio, T-b from Albert =20 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