{"id":2225299,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2225299/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260420200339.708640-2-vsementsov@yandex-team.ru/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/1.2/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260420200339.708640-2-vsementsov@yandex-team.ru>","list_archive_url":null,"date":"2026-04-20T20:03:16","name":"[v6,01/22] vhost-user: rework enabling vrings","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"0367c6f7ffbf27ee97f04cf7165a41a3f86bcbc0","submitter":{"id":84116,"url":"http://patchwork.ozlabs.org/api/1.2/people/84116/?format=json","name":"Vladimir Sementsov-Ogievskiy","email":"vsementsov@yandex-team.ru"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260420200339.708640-2-vsementsov@yandex-team.ru/mbox/","series":[{"id":500672,"url":"http://patchwork.ozlabs.org/api/1.2/series/500672/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=500672","date":"2026-04-20T20:03:18","name":"vhost refactoring and fixes","version":6,"mbox":"http://patchwork.ozlabs.org/series/500672/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2225299/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2225299/checks/","tags":{},"related":[],"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=yandex-team.ru header.i=@yandex-team.ru\n header.a=rsa-sha256 header.s=default header.b=lYZu89zo;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists1p.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)","mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net;\n dkim=pass header.i=@yandex-team.ru"],"Received":["from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fzxKh66whz1yD4\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 21 Apr 2026 06:04:56 +1000 (AEST)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists1p.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wEuqy-0001Zs-15; Mon, 20 Apr 2026 16:04:20 -0400","from eggs.gnu.org ([2001:470:142:3::10])\n by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <vsementsov@yandex-team.ru>)\n id 1wEuqf-0001K8-2n\n for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:03 -0400","from forwardcorp1d.mail.yandex.net ([178.154.239.200])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <vsementsov@yandex-team.ru>)\n id 1wEuqX-0001k3-Gf\n for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:03:56 -0400","from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net\n (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net\n [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0])\n by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 82F9780676;\n Mon, 20 Apr 2026 23:03:47 +0300 (MSK)","from vsementsov-lin (unknown [2a02:6bf:8080:54b::1:34])\n by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA\n id f3YMX10K1Sw0-TnnmZKyo; Mon, 20 Apr 2026 23:03:46 +0300"],"Precedence":"bulk","X-Yandex-Fwd":"1","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru;\n s=default; t=1776715426;\n bh=52WD3FWkb0j8c8h/V6OhMQSzRC7zRqnFb8vo6zNsGZg=;\n h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From;\n b=lYZu89zoESSoM73r3pjAG/uovZAQo2PlEpfAq+cDIC2A8J7SHnMH3dg1YHk6B2ONP\n d94fZToDPSyl/fja2FBMe9xhyi6jcBeh9OE2757N/MgPD7TFN2m3vvKFM8BLRpDHJx\n dBVKgIt+XiVY7HMRSEf3Ow3g8DXIu2BgwoejC9j0=","From":"Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>","To":"mst@redhat.com","Cc":"sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org,\n vsementsov@yandex-team.ru, yc-core@yandex-team.ru,\n d-tatianin@yandex-team.ru, Raphael Norwitz <raphael.s.norwitz@gmail.com>,\n \"Gonglei (Arei)\" <arei.gonglei@huawei.com>,\n zhenwei pi <zhenwei.pi@linux.dev>, Jason Wang <jasowang@redhat.com>","Subject":"[PATCH v6 01/22] vhost-user: rework enabling vrings","Date":"Mon, 20 Apr 2026 23:03:16 +0300","Message-ID":"<20260420200339.708640-2-vsementsov@yandex-team.ru>","X-Mailer":"git-send-email 2.52.0","In-Reply-To":"<20260420200339.708640-1-vsementsov@yandex-team.ru>","References":"<20260420200339.708640-1-vsementsov@yandex-team.ru>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Received-SPF":"pass client-ip=178.154.239.200;\n envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net","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, DKIM_SIGNED=0.1,\n DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001,\n 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","List-Id":"qemu development <qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<https://lists.nongnu.org/archive/html/qemu-devel>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"},"content":"We call the handler almost the same way in three places:\n\n - cryptodev-vhost.c\n - vhost_net.c\n - vhost.c\n\nThe only difference, is that in vhost.c we don't try to call the handler\nfor old vhost-user (when VHOST_USER_F_PROTOCOL_FEATURES is not supported).\n\ncryptodev-vhost and vhost_net code will just fail in this case. Probably\nthey were developed only for newer vhost-user. Anyway, it doesn't seem\ncorrect to rely on this error path, if these devices want to check,\nthat they don't communicate to old vhost-user protocol, they should\ndo that earlier.\n\nLet's create the common helper, to call .vhost_set_vring_enable and\nuse in all three places. For vhost-user let's just always skip\nenable/disable if it's unsupported.\n\nSigned-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>\nReviewed-by: Daniil Tatianin <d-tatianin@yandex-team.ru>\nReviewed-by: Raphael Norwitz <raphael.s.norwitz@gmail.com>\n---\n backends/cryptodev-vhost.c |  8 +-------\n hw/net/vhost_net.c         |  7 +------\n hw/virtio/vhost-user.c     |  7 ++++++-\n hw/virtio/vhost.c          | 21 ---------------------\n include/hw/virtio/vhost.h  |  9 +++++++++\n 5 files changed, 17 insertions(+), 35 deletions(-)","diff":"diff --git a/backends/cryptodev-vhost.c b/backends/cryptodev-vhost.c\nindex 943680a23af..abdfce33afc 100644\n--- a/backends/cryptodev-vhost.c\n+++ b/backends/cryptodev-vhost.c\n@@ -152,7 +152,6 @@ vhost_set_vring_enable(CryptoDevBackendClient *cc,\n {\n     CryptoDevBackendVhost *crypto =\n                        cryptodev_get_vhost(cc, b, queue);\n-    const VhostOps *vhost_ops;\n \n     cc->vring_enable = enable;\n \n@@ -160,12 +159,7 @@ vhost_set_vring_enable(CryptoDevBackendClient *cc,\n         return 0;\n     }\n \n-    vhost_ops = crypto->dev.vhost_ops;\n-    if (vhost_ops->vhost_set_vring_enable) {\n-        return vhost_ops->vhost_set_vring_enable(&crypto->dev, enable);\n-    }\n-\n-    return 0;\n+    return vhost_dev_set_vring_enable(&crypto->dev, enable);\n }\n \n int cryptodev_vhost_start(VirtIODevice *dev, int total_queues)\ndiff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c\nindex a8ee18a9126..25e9f1fd244 100644\n--- a/hw/net/vhost_net.c\n+++ b/hw/net/vhost_net.c\n@@ -587,7 +587,6 @@ VHostNetState *get_vhost_net(NetClientState *nc)\n int vhost_net_set_vring_enable(NetClientState *nc, int enable)\n {\n     VHostNetState *net = get_vhost_net(nc);\n-    const VhostOps *vhost_ops = net->dev.vhost_ops;\n \n     /*\n      * vhost-vdpa network devices need to enable dataplane virtqueues after\n@@ -601,11 +600,7 @@ int vhost_net_set_vring_enable(NetClientState *nc, int enable)\n \n     nc->vring_enable = enable;\n \n-    if (vhost_ops && vhost_ops->vhost_set_vring_enable) {\n-        return vhost_ops->vhost_set_vring_enable(&net->dev, enable);\n-    }\n-\n-    return 0;\n+    return vhost_dev_set_vring_enable(&net->dev, enable);\n }\n \n int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu)\ndiff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c\nindex a8907cca74e..13c73e7b178 100644\n--- a/hw/virtio/vhost-user.c\n+++ b/hw/virtio/vhost-user.c\n@@ -1230,7 +1230,12 @@ static int vhost_user_set_vring_enable(struct vhost_dev *dev, int enable)\n     int i;\n \n     if (!virtio_has_feature(dev->features, VHOST_USER_F_PROTOCOL_FEATURES)) {\n-        return -EINVAL;\n+        /*\n+         * For vhost-user devices, if VHOST_USER_F_PROTOCOL_FEATURES has not\n+         * been negotiated, the rings start directly in the enabled state,\n+         * and can't be disabled.\n+         */\n+        return 0;\n     }\n \n     for (i = 0; i < dev->nvqs; ++i) {\ndiff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c\nindex b9dc4ed13ba..b89797df95e 100644\n--- a/hw/virtio/vhost.c\n+++ b/hw/virtio/vhost.c\n@@ -2078,27 +2078,6 @@ int vhost_dev_get_inflight(struct vhost_dev *dev, uint16_t queue_size,\n     return 0;\n }\n \n-static int vhost_dev_set_vring_enable(struct vhost_dev *hdev, int enable)\n-{\n-    if (!hdev->vhost_ops->vhost_set_vring_enable) {\n-        return 0;\n-    }\n-\n-    /*\n-     * For vhost-user devices, if VHOST_USER_F_PROTOCOL_FEATURES has not\n-     * been negotiated, the rings start directly in the enabled state, and\n-     * .vhost_set_vring_enable callback will fail since\n-     * VHOST_USER_SET_VRING_ENABLE is not supported.\n-     */\n-    if (hdev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_USER &&\n-        !virtio_has_feature(hdev->backend_features,\n-                            VHOST_USER_F_PROTOCOL_FEATURES)) {\n-        return 0;\n-    }\n-\n-    return hdev->vhost_ops->vhost_set_vring_enable(hdev, enable);\n-}\n-\n /*\n  * Host notifiers must be enabled at this point.\n  *\ndiff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h\nindex 89817bd8486..3dfec5e15cc 100644\n--- a/include/hw/virtio/vhost.h\n+++ b/include/hw/virtio/vhost.h\n@@ -215,6 +215,15 @@ static inline bool vhost_dev_is_started(struct vhost_dev *hdev)\n     return hdev->started;\n }\n \n+static inline int vhost_dev_set_vring_enable(struct vhost_dev *hdev, int enable)\n+{\n+    if (!hdev->vhost_ops->vhost_set_vring_enable) {\n+        return 0;\n+    }\n+\n+    return hdev->vhost_ops->vhost_set_vring_enable(hdev, enable);\n+}\n+\n /**\n  * vhost_dev_start() - start the vhost device\n  * @hdev: common vhost_dev structure\n","prefixes":["v6","01/22"]}