From nobody Mon Apr 6 10:48:12 2026 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=1774864425; cv=none; d=zohomail.com; s=zohoarc; b=FJQ3lkZby0n/QZtx7Q0EQdUYhMhxuFjAcxvPcTiSmfhBuzNacTkcW3AMEwlyFAYKiwBDoBAygBuYZGPZs21bupDhExp4OuNqBHchmEkqyn1JdZLnVOUZdC2cNhM89/zcGqANZ9tjKK/X49XLmck21InnHtaHOfmR68wBkZdhqvY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774864425; 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=Hh5LG4Doo1WyRSeiFJBSkiaSBS0yCBvqInUEe434a44=; b=fRvseiZv4jejDVC+8P7Twh6pzF9TXFRy0pk/jX5prKoZcUkyjxFDaLcrInYyQOSmu4x6vduZ539nM7tDraeh7mjeM/WS9TKVDwB84pAmQgJNOUBc3qj7bHhkJ0whZ4iLcwYu0HXjsAYT+GiPDOI6YotOlPfVN6I1gfJzDowp7RU= 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 1774864425350324.0161974175993; Mon, 30 Mar 2026 02:53:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w79Ip-0005P8-2Z; Mon, 30 Mar 2026 05:52:59 -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 1w79Id-0005N7-3f; Mon, 30 Mar 2026 05:52:48 -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 1w79IZ-00064W-3x; Mon, 30 Mar 2026 05:52:46 -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:3530:0:640:eca4:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 9989EC0203; Mon, 30 Mar 2026 12:52:41 +0300 (MSK) Received: from dtalexundeer-nx.yandex-team.ru (unknown [2a02:6bf:8080:78d::1:13]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id QqVNFG1Af4Y0-5AOJ86sv; Mon, 30 Mar 2026 12:52:40 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1774864360; bh=Hh5LG4Doo1WyRSeiFJBSkiaSBS0yCBvqInUEe434a44=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=LRYxjwiMbBzC7+zDw44jqlEVvTVB+c0ttr229s8mU327X7ixmhIVuTrqLEJCWBxNz yy9sUmLKw/Q2lo8DBvyfs5owDPIiq1Ehbm8m/6MWqLYuvhz15/FYnpp1Jrno1mEr+z /Y3jybaki2fs06GZ1lg1SEmWrkIh6RYT+4tRBWdY= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Alexandr Moshkov To: qemu-devel@nongnu.org Cc: "Gonglei (Arei)" , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Milan Zamazal , Raphael Norwitz , Paolo Bonzini , Jason Wang , qemu-block@nongnu.org, Fam Zheng , zhenwei pi , Hanna Reitz , virtio-fs@lists.linux.dev, Pierrick Bouvier , Stefano Garzarella , "Michael S. Tsirkin" , "yc-core@yandex-team.ru" , Kevin Wolf , Stefan Hajnoczi , Alexandr Moshkov , Vladimir Sementsov-Ogievskiy Subject: [PATCH v3 5/5] vhost-user: add skip_drain param to GET_VRING_BASE Date: Mon, 30 Mar 2026 14:52:26 +0500 Message-Id: <20260330095226.158386-6-dtalexundeer@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260330095226.158386-1-dtalexundeer@yandex-team.ru> References: <20260330095226.158386-1-dtalexundeer@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=dtalexundeer@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: qemu development 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: 1774864428737154100 Content-Type: text/plain; charset="utf-8" In case of migration of QEMU from the new version (where the inllight-migration parameter is present), to the old one (where it is absent) there is no way to disable this feature on the backend during runtime. This commit slightly changes the semantics of the protocol feature VHOST_USER_PROTOCOL_F_GET_VRING_BASE_INFLIGHT. Enabling this feature adds a new parameter for GET_VRING_BASE, which allows to control the drain in-flight requests on the backend. Thus, QEMU will be able to turn this feature on GET_VRING_BASE off and on anytime. In vhost-user-blk use inflight_migration param to enable skip_drain to suspend in-flight I/O requests, and then migrate them throught inflight subsection. Also now QEMU will always try to setup VHOST_USER_PROTOCOL_F_GET_VRING_BASE_INFLIGHT protocol featrue with backend. This will allow to use skip_drain parameter on GET_VRING_BASE message. Reviewed-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Alexandr Moshkov --- docs/interop/vhost-user.rst | 6 ++---- hw/block/vhost-user-blk.c | 30 ++++++++++++++++++++++++------ hw/virtio/vhost-user.c | 3 +-- hw/virtio/vhost.c | 1 + include/hw/virtio/vhost-user.h | 1 - 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/docs/interop/vhost-user.rst b/docs/interop/vhost-user.rst index bfa75ff9a3..63efc87264 100644 --- a/docs/interop/vhost-user.rst +++ b/docs/interop/vhost-user.rst @@ -1255,14 +1255,12 @@ Front-end message types *suspended*, see :ref:`Suspended device state `. =20 - The request payload's *num* field is currently reserved and must be - set to 0. - By default, the back-end must complete all inflight I/O requests for the specified vring before stopping it. =20 If the ``VHOST_USER_PROTOCOL_F_GET_VRING_BASE_INFLIGHT`` protocol - feature has been negotiated, the back-end may suspend in-flight I/O + feature has been negotiated, using request payload's *num* field, + when *num* is set to 1, QEMU can tell the back-end to suspend in-flight = I/O requests and record them as described in :ref:`Inflight I/O tracking ` instead of completing them before stopping the v= ring. How to suspend an in-flight request depends on the implementation of the= back-end diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index a3ecd83f54..522e9d34b5 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -134,10 +134,7 @@ static bool vhost_user_blk_inflight_needed(void *opaqu= e) { struct VHostUserBlk *s =3D opaque; =20 - bool inflight_migration =3D virtio_has_feature(s->dev.protocol_feature= s, - VHOST_USER_PROTOCOL_F_GET_VRING_BASE_INFLIG= HT); - - return inflight_migration; + return s->inflight_migration; } =20 =20 @@ -232,11 +229,14 @@ static int vhost_user_blk_stop(VirtIODevice *vdev) return 0; } =20 + bool skip_drain =3D vhost_user_blk_inflight_needed(s) && + runstate_check(RUN_STATE_FINISH_MIGRATE); + force_stop =3D s->skip_get_vring_base_on_force_shutdown && qemu_force_shutdown_requested(); =20 ret =3D force_stop ? vhost_dev_force_stop(&s->dev, vdev, true) : - vhost_dev_stop(&s->dev, vdev, true, false); + vhost_dev_stop(&s->dev, vdev, true, skip_drain); =20 if (k->set_guest_notifiers(qbus->parent, s->dev.nvqs, false) < 0) { error_report("vhost guest notifier cleanup failed: %d", ret); @@ -364,7 +364,6 @@ static int vhost_user_blk_connect(DeviceState *dev, Err= or **errp) vhost_dev_set_config_notifier(&s->dev, &blk_ops); =20 s->vhost_user.supports_config =3D true; - s->vhost_user.supports_inflight_migration =3D s->inflight_migration; ret =3D vhost_dev_init(&s->dev, &s->vhost_user, VHOST_BACKEND_TYPE_USE= R, 0, errp); if (ret < 0) { @@ -580,10 +579,29 @@ static struct vhost_dev *vhost_user_blk_get_vhost(Vir= tIODevice *vdev) return &s->dev; } =20 +static bool vhost_user_blk_pre_save(void *opaque, Error **errp) +{ + VHostUserBlk *s =3D VHOST_USER_BLK(opaque); + + bool inflight_migration_enabled =3D virtio_has_feature( + s->dev.protocol_features, + VHOST_USER_PROTOCOL_F_GET_VRING_BASE_INFLIGHT); + if (vhost_user_blk_inflight_needed(s) && !inflight_migration_enabled) { + error_setg(errp, "can't migrate vhost-user-blk device: " + "backend doesn't support " + "VHOST_USER_PROTOCOL_F_GET_VRING_BASE_INFLIGHT " + "protocol feature"); + return false; + } + + return true; +} + static const VMStateDescription vmstate_vhost_user_blk_inflight =3D { .name =3D "vhost-user-blk/inflight", .version_id =3D 1, .needed =3D vhost_user_blk_inflight_needed, + .pre_save_errp =3D vhost_user_blk_pre_save, .fields =3D (const VMStateField[]) { VMSTATE_VHOST_INFLIGHT_REGION(inflight, VHostUserBlk), VMSTATE_END_OF_LIST() diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index bb8f8eab77..ed95ec7523 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -2225,8 +2225,7 @@ static int vhost_user_backend_init(struct vhost_dev *= dev, void *opaque, } } =20 - if (!u->user->supports_inflight_migration || - !virtio_has_feature(protocol_features, + if (!virtio_has_feature(protocol_features, VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) { protocol_features &=3D ~(1ULL << VHOST_USER_PROTOCOL_F_GET_VRING_BASE_INFLIG= HT); diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index ac4d6fca73..54e4ce2660 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1398,6 +1398,7 @@ static int do_vhost_virtqueue_stop(struct vhost_dev *= dev, int vhost_vq_index =3D dev->vhost_ops->vhost_get_vq_index(dev, idx); struct vhost_vring_state state =3D { .index =3D vhost_vq_index, + .num =3D skip_drain, }; int r =3D 0; =20 diff --git a/include/hw/virtio/vhost-user.h b/include/hw/virtio/vhost-user.h index 53fe996686..c95bad5ddc 100644 --- a/include/hw/virtio/vhost-user.h +++ b/include/hw/virtio/vhost-user.h @@ -69,7 +69,6 @@ typedef struct VhostUserState { GPtrArray *notifiers; int memory_slots; bool supports_config; - bool supports_inflight_migration; } VhostUserState; =20 /** --=20 2.34.1