From nobody Fri Nov 14 22:05:54 2025 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760225114; cv=none; d=zohomail.com; s=zohoarc; b=cARdajzfGs+1RNMbhEbMAWj+B3k+Ua5x9bAQyHCm+e8MCiNTQArwFWqDr9amsXCexxuJW821ANsZ7TeoZrkc6ob2dJ6VHJAWLwKyIpuLBcNwK08qxkJpEQutDZ1phhLGWvK8r7tCDVqusmz7CG85n+WMFHU7Jv/tc7KnKILRtdM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760225114; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=kPANk57eCGyW2xi6VXpwOdfF/zPec2fDl+4MdLGVlPk=; b=BEFt2zOhgvuOxBnLisc5VlRM42IItzOK5cW9CNSclrYt17ldfrWtww/6pzI62euPyri4bLoZg59q7vSmBh/cKKYYYN2db/sCl8tBYob534GhT1f6L48SrBP5DokwHroZCTsoCbMXAEYrm1Dbk9rwLBWddTxjFSXY0HlGKd81Ngc= 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 1760225114966458.87681687138695; Sat, 11 Oct 2025 16:25:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7iwl-00069y-7L; Sat, 11 Oct 2025 19:24:19 -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 1v7iwh-00068M-Mk for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:15 -0400 Received: from forwardcorp1a.mail.yandex.net ([178.154.239.72]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v7iwf-0000r4-HE for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:15 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:7394:0:640:5a8a:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 6570CC01DA; Sun, 12 Oct 2025 02:24:09 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a4b::1:3c]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 6OWMXt1FjqM0-e9wupjhW; Sun, 12 Oct 2025 02:24:08 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760225048; bh=kPANk57eCGyW2xi6VXpwOdfF/zPec2fDl+4MdLGVlPk=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=czwjZpPW/YZAZflH3sNu5+16EPdJx7rIHqUiRgXehc5IeFxSfrqoy/0K1cvKg73PC fIDOHAitjr3Pu53kK2SaY2adeO9r4h76f0fbg9VvZeZykOXkOLEaqafd417UKzrBpN ZkQtzzaTjTFGDiDpAliILNP02/u/HCVErSA6OzoA= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, raphael.s.norwitz@gmail.com, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, "Gonglei (Arei)" , Zhenwei Pi , Jason Wang Subject: [PATCH v2 01/23] vhost-user: rework enabling vrings Date: Sun, 12 Oct 2025 02:23:40 +0300 Message-ID: <20251011232404.561024-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251011232404.561024-1-vsementsov@yandex-team.ru> References: <20251011232404.561024-1-vsementsov@yandex-team.ru> 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=178.154.239.72; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760225119042154100 Content-Type: text/plain; charset="utf-8" We call the handler almost the same way in three places: - cryptodev-vhost.c - vhost_net.c - vhost.c The only difference, is that in vhost.c we don't try to call the handler for old vhost-user (when VHOST_USER_F_PROTOCOL_FEATURES is not supported). cryptodev-vhost and vhost_net code will just fail in this case. Probably they were developed only for newer vhost-user. Anyway, it doesn't seem correct to rely on this error path, if these devices want to check, that they don't communicate to old vhost-user protocol, they should do that earlier. Let's create the common helper, to call .vhost_set_vring_enable and use in all three places. For vhost-user let's just always skip enable/disable if it's unsupported. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Raphael Norwitz --- backends/cryptodev-vhost.c | 8 +------- hw/net/vhost_net.c | 7 +------ hw/virtio/vhost-user.c | 7 ++++++- hw/virtio/vhost.c | 21 --------------------- include/hw/virtio/vhost.h | 9 +++++++++ 5 files changed, 17 insertions(+), 35 deletions(-) diff --git a/backends/cryptodev-vhost.c b/backends/cryptodev-vhost.c index 943680a23a..abdfce33af 100644 --- a/backends/cryptodev-vhost.c +++ b/backends/cryptodev-vhost.c @@ -152,7 +152,6 @@ vhost_set_vring_enable(CryptoDevBackendClient *cc, { CryptoDevBackendVhost *crypto =3D cryptodev_get_vhost(cc, b, queue); - const VhostOps *vhost_ops; =20 cc->vring_enable =3D enable; =20 @@ -160,12 +159,7 @@ vhost_set_vring_enable(CryptoDevBackendClient *cc, return 0; } =20 - vhost_ops =3D crypto->dev.vhost_ops; - if (vhost_ops->vhost_set_vring_enable) { - return vhost_ops->vhost_set_vring_enable(&crypto->dev, enable); - } - - return 0; + return vhost_dev_set_vring_enable(&crypto->dev, enable); } =20 int cryptodev_vhost_start(VirtIODevice *dev, int total_queues) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index a8ee18a912..25e9f1fd24 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -587,7 +587,6 @@ VHostNetState *get_vhost_net(NetClientState *nc) int vhost_net_set_vring_enable(NetClientState *nc, int enable) { VHostNetState *net =3D get_vhost_net(nc); - const VhostOps *vhost_ops =3D net->dev.vhost_ops; =20 /* * vhost-vdpa network devices need to enable dataplane virtqueues after @@ -601,11 +600,7 @@ int vhost_net_set_vring_enable(NetClientState *nc, int= enable) =20 nc->vring_enable =3D enable; =20 - if (vhost_ops && vhost_ops->vhost_set_vring_enable) { - return vhost_ops->vhost_set_vring_enable(&net->dev, enable); - } - - return 0; + return vhost_dev_set_vring_enable(&net->dev, enable); } =20 int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 36c9c2e04d..f367ce06ce 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1235,7 +1235,12 @@ static int vhost_user_set_vring_enable(struct vhost_= dev *dev, int enable) int i; =20 if (!virtio_has_feature(dev->features, VHOST_USER_F_PROTOCOL_FEATURES)= ) { - return -EINVAL; + /* + * For vhost-user devices, if VHOST_USER_F_PROTOCOL_FEATURES has n= ot + * been negotiated, the rings start directly in the enabled state, + * and can't be disabled. + */ + return 0; } =20 for (i =3D 0; i < dev->nvqs; ++i) { diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 266a11514a..414a48a218 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -2013,27 +2013,6 @@ int vhost_dev_get_inflight(struct vhost_dev *dev, ui= nt16_t queue_size, return 0; } =20 -static int vhost_dev_set_vring_enable(struct vhost_dev *hdev, int enable) -{ - if (!hdev->vhost_ops->vhost_set_vring_enable) { - return 0; - } - - /* - * For vhost-user devices, if VHOST_USER_F_PROTOCOL_FEATURES has not - * been negotiated, the rings start directly in the enabled state, and - * .vhost_set_vring_enable callback will fail since - * VHOST_USER_SET_VRING_ENABLE is not supported. - */ - if (hdev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_USER && - !virtio_has_feature(hdev->backend_features, - VHOST_USER_F_PROTOCOL_FEATURES)) { - return 0; - } - - return hdev->vhost_ops->vhost_set_vring_enable(hdev, enable); -} - /* * Host notifiers must be enabled at this point. * diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 08bbb4dfe9..1ee639dd7e 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -215,6 +215,15 @@ static inline bool vhost_dev_is_started(struct vhost_d= ev *hdev) return hdev->started; } =20 +static inline int vhost_dev_set_vring_enable(struct vhost_dev *hdev, int e= nable) +{ + if (!hdev->vhost_ops->vhost_set_vring_enable) { + return 0; + } + + return hdev->vhost_ops->vhost_set_vring_enable(hdev, enable); +} + /** * vhost_dev_start() - start the vhost device * @hdev: common vhost_dev structure --=20 2.48.1