From nobody Thu Nov 14 16:30:53 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=1696278828; cv=none; d=zohomail.com; s=zohoarc; b=PUnbSth0L7tfivVUrvSBM53Dm96vQImuk1nunVmNvjiYn9uzWiYmV0bSmFtH7V12laO1ZhtPENs0bSnM/2uXvXB8t3FPd17GACYjAAtbqzwltTY+qkG3rt9RmSdFpI+gAI331F0VKtUsz/WQeMFSbAT2pO6iL57V+5e1PKIYr5s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696278828; 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=PFA/Prb6o6KEE5fPBsFRk33AjGqGuJPgq23VOAGuoEc=; b=H94hN3cfS1wmidIWw7TkCZ3tv/PtdibHgbogaQ8uMfdi+nhOI1W6D+wjJfHzgKgYt6FunwmLpNetYG8N32amKNFgf1er3ht7SusfYi5IR/W7O626qMKOcC0bACPmdAfI/QMdB9zt9n1BiYB9wk6Fg7hUGiZCXx63D7c28yhGCkc= 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 1696278828570456.4819008915026; Mon, 2 Oct 2023 13:33:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnPaz-0003UF-Lu; Mon, 02 Oct 2023 16:32:49 -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 1qnPax-0003Tf-3f for qemu-devel@nongnu.org; Mon, 02 Oct 2023 16:32:47 -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 1qnPav-0001Ut-Ch for qemu-devel@nongnu.org; Mon, 02 Oct 2023 16:32:46 -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-286-TJ9N5eUHO4i_jT2wUtAxJQ-1; Mon, 02 Oct 2023 16:32:42 -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 8D877811E7E; Mon, 2 Oct 2023 20:32:42 +0000 (UTC) Received: from lacos-laptop-9.usersys.redhat.com (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7AAF940C6EBF; Mon, 2 Oct 2023 20:32:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696278764; 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=PFA/Prb6o6KEE5fPBsFRk33AjGqGuJPgq23VOAGuoEc=; b=DnvFxC463IC6sN0XFrrUkDn71N4WO2SR2QnH1LUd0y8b+EKYcnKm8kVPSQGjHETTDOljoM 1M/tZE+3xfEycX/0AlryMJVdLzH1qqjDpKA5C/naBGpzpUrCoZjGWeM/npfivE0n/pMfdj 9cgObilDBeuTHtNdztUQyDH49gF1DM8= X-MC-Unique: TJ9N5eUHO4i_jT2wUtAxJQ-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 5/7] vhost-user: hoist "write_sync", "get_features", "get_u64" Date: Mon, 2 Oct 2023 22:32:19 +0200 Message-Id: <20231002203221.17241-6-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: 1696278829846100003 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 Tested-by: Albert Esteve Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Eugenio P=C3=A9rez --- Notes: v3: =20 - pick up R-b from Phil and Eugenio, T-b from Albert =20 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) {