From nobody Mon Feb 9 17:24:19 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=linux.alibaba.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1658153591914288.66330713246407; Mon, 18 Jul 2022 07:13:11 -0700 (PDT) Received: from localhost ([::1]:59360 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDRUk-00064R-Ra for importer@patchew.org; Mon, 18 Jul 2022 10:13:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37438) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDOpn-0007XE-Ta for qemu-devel@nongnu.org; Mon, 18 Jul 2022 07:22:43 -0400 Received: from out30-44.freemail.mail.aliyun.com ([115.124.30.44]:50907) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDOph-0000if-Og for qemu-devel@nongnu.org; Mon, 18 Jul 2022 07:22:43 -0400 Received: from localhost(mailfrom:kangjie.xu@linux.alibaba.com fp:SMTPD_---0VJjIA9J_1658143042) by smtp.aliyun-inc.com; Mon, 18 Jul 2022 19:17:22 +0800 X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R171e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=ay29a033018046060; MF=kangjie.xu@linux.alibaba.com; NM=1; PH=DS; RN=5; SR=0; TI=SMTPD_---0VJjIA9J_1658143042; From: Kangjie Xu To: qemu-devel@nongnu.org Cc: mst@redhat.com, jasowang@redhat.com, hengqi@linux.alibaba.com, xuanzhuo@linux.alibaba.com Subject: [PATCH 09/16] vhost-user: enable/disable a single vring Date: Mon, 18 Jul 2022 19:17:06 +0800 Message-Id: <46deff7d44ad806a4bfb9235e57b0d37d8cfa95c.1658141552.git.kangjie.xu@linux.alibaba.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=115.124.30.44; envelope-from=kangjie.xu@linux.alibaba.com; helo=out30-44.freemail.mail.aliyun.com X-Spam_score_int: -98 X-Spam_score: -9.9 X-Spam_bar: --------- X-Spam_report: (-9.9 / 5.0 requ) BAYES_00=-1.9, ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, UNPARSEABLE_RELAY=0.001, USER_IN_DEF_SPF_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 18 Jul 2022 09:49:04 -0400 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" X-ZM-MESSAGEID: 1658153593707100001 Content-Type: text/plain; charset="utf-8" Implement the vhost_set_single_vring_enable, which is to enable or disable a single vring. The parameter wait_for_reply is added to help for some cases such as vq reset. Meanwhile, vhost_user_set_vring_enable() is refactored. Signed-off-by: Kangjie Xu Signed-off-by: Xuan Zhuo --- hw/virtio/vhost-user.c | 55 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 75b8df21a4..5a80a415f0 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -267,6 +267,8 @@ struct scrub_regions { int fd_idx; }; =20 +static int enforce_reply(struct vhost_dev *dev, const VhostUserMsg *msg); + static bool ioeventfd_enabled(void) { return !kvm_enabled() || kvm_eventfds_enabled(); @@ -1198,6 +1200,49 @@ static int vhost_user_set_vring_base(struct vhost_de= v *dev, return vhost_set_vring(dev, VHOST_USER_SET_VRING_BASE, ring); } =20 + +static int vhost_user_set_single_vring_enable(struct vhost_dev *dev, + int index, + int enable, + bool wait_for_reply) +{ + int ret; + + if (index < dev->vq_index || index >=3D dev->vq_index + dev->nvqs) { + return -EINVAL; + } + + struct vhost_vring_state state =3D { + .index =3D index, + .num =3D enable, + }; + + VhostUserMsg msg =3D { + .hdr.request =3D VHOST_USER_SET_VRING_ENABLE, + .hdr.flags =3D VHOST_USER_VERSION, + .payload.state =3D state, + .hdr.size =3D sizeof(msg.payload.state), + }; + + bool reply_supported =3D virtio_has_feature(dev->protocol_features, + VHOST_USER_PROTOCOL_F_REPLY_= ACK); + + if (reply_supported && wait_for_reply) { + 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 ret; +} + static int vhost_user_set_vring_enable(struct vhost_dev *dev, int enable) { int i; @@ -1207,13 +1252,8 @@ static int vhost_user_set_vring_enable(struct vhost_= dev *dev, int enable) } =20 for (i =3D 0; i < dev->nvqs; ++i) { - int ret; - struct vhost_vring_state state =3D { - .index =3D dev->vq_index + i, - .num =3D enable, - }; - - ret =3D vhost_set_vring(dev, VHOST_USER_SET_VRING_ENABLE, &state); + int ret =3D vhost_user_set_single_vring_enable(dev, dev->vq_index = + i, + enable, false); if (ret < 0) { /* * Restoring the previous state is likely infeasible, as well = as @@ -2627,6 +2667,7 @@ const VhostOps user_ops =3D { .vhost_set_owner =3D vhost_user_set_owner, .vhost_reset_device =3D vhost_user_reset_device, .vhost_get_vq_index =3D vhost_user_get_vq_index, + .vhost_set_single_vring_enable =3D vhost_user_set_single_vring_ena= ble, .vhost_set_vring_enable =3D vhost_user_set_vring_enable, .vhost_requires_shm_log =3D vhost_user_requires_shm_log, .vhost_migration_done =3D vhost_user_migration_done, --=20 2.32.0