From nobody Fri Nov 14 21:04: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=1760540596; cv=none; d=zohomail.com; s=zohoarc; b=IN8s3Nd9770xD8A/Na+O44onzJF6GxCx9bvhZK0AKbBQ/AxJ6tF2fzynEN/IKL2zVN5xEGYrDtS5kt1jXO1j/CcmT+nmL4pJk2AtIeZHA6lCDUIvfpYOCaeNhwzVoRk/CANFMrocFxkCzGxzCV6sckH0ZFfHLrk/K65Pbuxx45g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760540596; 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=Cc4fro7LMqaYMZ5I3F9f9KBUdUTKDXhLsBEoX+i+vMw=; b=FMxT5wUwJD1JDW3SWEQ5TwRy4BIXtyzIoBHWwwEEM04Iy7Jx9x7lKRpCFZ56UviX5dH7e2NmlK0zqKaKBq2d+Kw2yFNrhdIvB90thQR1pyQcW3QjB2uLsEu/AHqT9Sk9nmDq/g1m5SHNg9HFEgjwiKlK4P1giJMmEKDHC3RBpFk= 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 1760540596000575.1509494270476; Wed, 15 Oct 2025 08:03:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v92xP-0007ej-8D; Wed, 15 Oct 2025 10:58:27 -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 1v92xN-0007eO-KI for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:25 -0400 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v92xH-0000aB-9c for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:25 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id C78C7C050E; Wed, 15 Oct 2025 17:58:12 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id AwRFIp2FFSw0-oQDO0m51; Wed, 15 Oct 2025 17:58:12 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760540292; bh=Cc4fro7LMqaYMZ5I3F9f9KBUdUTKDXhLsBEoX+i+vMw=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=w2DFPtx0BKSIMZAjTZpImHwRd1AuhdEl10ceHDRmyf4qJaNmxBiVYAFA4uVn7tpaU 47ZbzMEvKjHpFPMAt+N2XNGWHOB9rPeqDz/eRxoA4FSXUPNGmWZJXa53HjK+vXjp5r ZX0gjcR1INpFf+5q0RngWfEYBvBSnARI+YgeBDp8= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.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, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Raphael Norwitz , "Gonglei (Arei)" , Zhenwei Pi , Jason Wang Subject: [PATCH v3 01/23] vhost-user: rework enabling vrings Date: Wed, 15 Oct 2025 17:57:45 +0300 Message-ID: <20251015145808.1112843-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015145808.1112843-1-vsementsov@yandex-team.ru> References: <20251015145808.1112843-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=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_DNSWL_LOW=-0.7, 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: 1760540598127154100 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: Daniil Tatianin 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