From nobody Mon Feb 9 04:08:52 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=yandex-team.ru Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1633360434455438.8070464555468; Mon, 4 Oct 2021 08:13:54 -0700 (PDT) Received: from localhost ([::1]:41202 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mXPf7-0006BY-CL for importer@patchew.org; Mon, 04 Oct 2021 11:13:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33652) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mXPZM-0006bV-Ah; Mon, 04 Oct 2021 11:07:56 -0400 Received: from forwardcorp1j.mail.yandex.net ([2a02:6b8:0:1619::183]:34830) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mXPZH-0003zW-9q; Mon, 04 Oct 2021 11:07:56 -0400 Received: from myt5-23f0be3aa648.qloud-c.yandex.net (myt5-23f0be3aa648.qloud-c.yandex.net [IPv6:2a02:6b8:c12:3e29:0:640:23f0:be3a]) by forwardcorp1j.mail.yandex.net (Yandex) with ESMTP id 7C14E2E1A55; Mon, 4 Oct 2021 18:07:42 +0300 (MSK) Received: from myt6-76f0a6db1a7e.qloud-c.yandex.net (2a02:6b8:c12:422d:0:640:76f0:a6db [2a02:6b8:c12:422d:0:640:76f0:a6db]) by myt5-23f0be3aa648.qloud-c.yandex.net (mxbackcorp/Yandex) with ESMTP id 9onb2P5kB8-7gt4gK1b; Mon, 04 Oct 2021 18:07:42 +0300 Received: from den-plotnikov-w.yandex-team.ru (2a02:6b8:b081:8009::1:11 [2a02:6b8:b081:8009::1:11]) by myt6-76f0a6db1a7e.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPS id AnWxZOr920-7f0aPOMn; Mon, 04 Oct 2021 18:07:42 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) Precedence: bulk DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1633360062; bh=NUkgCkrI/qClBYJz68V2MGeBe90XZE+fc7O4XdL6a90=; h=Message-Id:References:Date:Subject:To:From:In-Reply-To:Cc; b=oiybj6r6m4EHTWBdIesD3v7wFeS4WvM9IIh24hiPcW0N89L465tQNKwaMnpRCTZD2 4GedI03u/25r4c9nFspm2gxesjBBdFpUmC8bZagdabkXWShyRD12dr8LrMpqNxGzK5 pJdJXM0sBRSl/WzUd+WNQHB1LGFX0ZcwmdsHwxpQ= Authentication-Results: myt5-23f0be3aa648.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Denis Plotnikov To: qemu-devel@nongnu.org Subject: [PATCH v0 1/2] vhost-user-blk: add a new vhost-user-virtio-blk type Date: Mon, 4 Oct 2021 18:07:30 +0300 Message-Id: <20211004150731.191270-2-den-plotnikov@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211004150731.191270-1-den-plotnikov@yandex-team.ru> References: <20211004150731.191270-1-den-plotnikov@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:0:1619::183; envelope-from=den-plotnikov@yandex-team.ru; helo=forwardcorp1j.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_DNSWL_NONE=-0.0001, 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.23 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, mst@redhat.com, yc-core@yandex-team.ru, qemu-block@nongnu.org, raphael.norwitz@nutanix.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1633360436277100001 Content-Type: text/plain; charset="utf-8" The main reason of adding a new type is to make cross-device live migration between "virtio-blk" and "vhost-user-blk" devices possible in both directio= ns. It might be useful for the cases when a slow block layer should be replaced with a more performant one on running VM without stopping, i.e. with very l= ow downtime comparable with the one on migration. It's possible to achive that for two reasons: 1.The VMStates of "virtio-blk" and "vhost-user-blk" are almost the same. They consist of the identical VMSTATE_VIRTIO_DEVICE and differs from each other in the values of migration service fields only. 2.The device driver used in the guest is the same: virtio-blk The new type uses virtio-blk VMState instead of vhost-user-blk specific VMstate, also it implements migration save/load callbacks to be compatible with migration stream produced by "virtio-blk" device. Adding the new vhost-user-blk type instead of modifying the existing one is convenent. It ease to differ the new virtio-blk-compatible vhost-user-blk device from the existing non-compatible one using qemu machinery without any other modifiactions. That gives all the variety of qemu device related constraints out of box. Signed-off-by: Denis Plotnikov --- hw/block/vhost-user-blk.c | 63 ++++++++++++++++++++++++++++++ include/hw/virtio/vhost-user-blk.h | 2 + 2 files changed, 65 insertions(+) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index ba13cb87e520..877fe54e891f 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -30,6 +30,7 @@ #include "hw/virtio/virtio-access.h" #include "sysemu/sysemu.h" #include "sysemu/runstate.h" +#include "migration/qemu-file-types.h" =20 #define REALIZE_CONNECTION_RETRIES 3 =20 @@ -612,9 +613,71 @@ static const TypeInfo vhost_user_blk_info =3D { .class_init =3D vhost_user_blk_class_init, }; =20 +/* + * this is the same as vmstate_virtio_blk + * we use it to allow virtio-blk <-> vhost-user-virtio-blk migration + */ +static const VMStateDescription vmstate_vhost_user_virtio_blk =3D { + .name =3D "virtio-blk", + .minimum_version_id =3D 2, + .version_id =3D 2, + .fields =3D (VMStateField[]) { + VMSTATE_VIRTIO_DEVICE, + VMSTATE_END_OF_LIST() + }, +}; + +static void vhost_user_virtio_blk_save(VirtIODevice *vdev, QEMUFile *f) +{ + /* + * put a zero byte in the stream to be compatible with virtio-blk + */ + qemu_put_sbyte(f, 0); +} + +static int vhost_user_virtio_blk_load(VirtIODevice *vdev, QEMUFile *f, + int version_id) +{ + if (qemu_get_sbyte(f)) { + /* + * on virtio-blk -> vhost-user-virtio-blk migration we don't expect + * to get any infilght requests in the migration stream because + * we can't load them yet. + * TODO: consider putting those inflight requests to inflight regi= on + */ + error_report("%s: can't load in-flight requests", + TYPE_VHOST_USER_VIRTIO_BLK); + return -EINVAL; + } + + return 0; +} + +static void vhost_user_virtio_blk_class_init(ObjectClass *klass, void *dat= a) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_CLASS(klass); + + /* override vmstate of vhost_user_blk */ + dc->vmsd =3D &vmstate_vhost_user_virtio_blk; + + /* adding callbacks to be compatible with virtio-blk migration stream = */ + vdc->save =3D vhost_user_virtio_blk_save; + vdc->load =3D vhost_user_virtio_blk_load; +} + +static const TypeInfo vhost_user_virtio_blk_info =3D { + .name =3D TYPE_VHOST_USER_VIRTIO_BLK, + .parent =3D TYPE_VHOST_USER_BLK, + .instance_size =3D sizeof(VHostUserBlk), + /* instance_init is the same as in parent type */ + .class_init =3D vhost_user_virtio_blk_class_init, +}; + static void virtio_register_types(void) { type_register_static(&vhost_user_blk_info); + type_register_static(&vhost_user_virtio_blk_info); } =20 type_init(virtio_register_types) diff --git a/include/hw/virtio/vhost-user-blk.h b/include/hw/virtio/vhost-u= ser-blk.h index 7c91f15040eb..d81f18d22596 100644 --- a/include/hw/virtio/vhost-user-blk.h +++ b/include/hw/virtio/vhost-user-blk.h @@ -23,6 +23,8 @@ #include "qom/object.h" =20 #define TYPE_VHOST_USER_BLK "vhost-user-blk" +#define TYPE_VHOST_USER_VIRTIO_BLK "vhost-user-virtio-blk" + OBJECT_DECLARE_SIMPLE_TYPE(VHostUserBlk, VHOST_USER_BLK) =20 #define VHOST_USER_BLK_AUTO_NUM_QUEUES UINT16_MAX --=20 2.25.1 From nobody Mon Feb 9 04:08:52 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=yandex-team.ru Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1633360322674399.14131589114606; Mon, 4 Oct 2021 08:12:02 -0700 (PDT) Received: from localhost ([::1]:35436 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mXPdJ-00025a-Gb for importer@patchew.org; Mon, 04 Oct 2021 11:12:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33646) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mXPZL-0006aJ-RZ; Mon, 04 Oct 2021 11:07:55 -0400 Received: from forwardcorp1o.mail.yandex.net ([95.108.205.193]:50956) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mXPZH-0003zz-BB; Mon, 04 Oct 2021 11:07:55 -0400 Received: from myt5-23f0be3aa648.qloud-c.yandex.net (myt5-23f0be3aa648.qloud-c.yandex.net [IPv6:2a02:6b8:c12:3e29:0:640:23f0:be3a]) by forwardcorp1o.mail.yandex.net (Yandex) with ESMTP id 69D5E2E0A28; Mon, 4 Oct 2021 18:07:43 +0300 (MSK) Received: from myt6-76f0a6db1a7e.qloud-c.yandex.net (2a02:6b8:c12:422d:0:640:76f0:a6db [2a02:6b8:c12:422d:0:640:76f0:a6db]) by myt5-23f0be3aa648.qloud-c.yandex.net (mxbackcorp/Yandex) with ESMTP id UbWJuImLp9-7gt8LOaA; Mon, 04 Oct 2021 18:07:43 +0300 Received: from den-plotnikov-w.yandex-team.ru (2a02:6b8:b081:8009::1:11 [2a02:6b8:b081:8009::1:11]) by myt6-76f0a6db1a7e.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPS id AnWxZOr920-7g0a0w3j; Mon, 04 Oct 2021 18:07:42 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) Precedence: bulk DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1633360063; bh=+uHd/9XSz/fGL4Gdt06LdRMN09AiVnaVecGnUykUMRM=; h=Message-Id:References:Date:Subject:To:From:In-Reply-To:Cc; b=FIdmwKQ1fZenzVMYzVlIv6HVdcgt0CpIrG3Xgp5wAkVwAwg6Y4U3tZyZMCHam7OE1 kr1b8yg7YCzgJ+xSJx3o3W/8HQq/rotxl6rRAueLuaBO0ej1ePM5f2az6HYqSUU4v9 LjVLgNH4XFIX/P6tsYzP7O3offYAQLnxDVz1IKhw= Authentication-Results: myt5-23f0be3aa648.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Denis Plotnikov To: qemu-devel@nongnu.org Subject: [PATCH v0 2/2] vhost-user-blk-pci: add new pci device type to support vhost-user-virtio-blk Date: Mon, 4 Oct 2021 18:07:31 +0300 Message-Id: <20211004150731.191270-3-den-plotnikov@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211004150731.191270-1-den-plotnikov@yandex-team.ru> References: <20211004150731.191270-1-den-plotnikov@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=95.108.205.193; envelope-from=den-plotnikov@yandex-team.ru; helo=forwardcorp1o.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.23 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, mst@redhat.com, yc-core@yandex-team.ru, qemu-block@nongnu.org, raphael.norwitz@nutanix.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1633360323228100003 Content-Type: text/plain; charset="utf-8" To allow the recently added vhost-user-virtio-blk work via virtio-pci. This patch refactors the vhost-user-blk-pci object model to reuse the existing code. Signed-off-by: Denis Plotnikov --- hw/virtio/vhost-user-blk-pci.c | 43 +++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/hw/virtio/vhost-user-blk-pci.c b/hw/virtio/vhost-user-blk-pci.c index 33b404d8a225..2f68296af22f 100644 --- a/hw/virtio/vhost-user-blk-pci.c +++ b/hw/virtio/vhost-user-blk-pci.c @@ -34,10 +34,18 @@ typedef struct VHostUserBlkPCI VHostUserBlkPCI; /* * vhost-user-blk-pci: This extends VirtioPCIProxy. */ +#define TYPE_VHOST_USER_BLK_PCI_ABSTRACT "vhost-user-blk-pci-abstract-base" +#define VHOST_USER_BLK_PCI_ABSTRACT(obj) \ + OBJECT_CHECK(VHostUserBlkPCI, (obj), TYPE_VHOST_USER_BLK_PCI_ABSTR= ACT) + #define TYPE_VHOST_USER_BLK_PCI "vhost-user-blk-pci-base" DECLARE_INSTANCE_CHECKER(VHostUserBlkPCI, VHOST_USER_BLK_PCI, TYPE_VHOST_USER_BLK_PCI) =20 +#define TYPE_VHOST_USER_VIRTIO_BLK_PCI "vhost-user-virtio-blk-pci-base" +#define VHOST_USER_VIRTIO_BLK_PCI(obj) \ + OBJECT_CHECK(VHostUserBlkPCI, (obj), TYPE_VHOST_USER_VIRTIO_BLK_PC= I) + struct VHostUserBlkPCI { VirtIOPCIProxy parent_obj; VHostUserBlk vdev; @@ -52,7 +60,7 @@ static Property vhost_user_blk_pci_properties[] =3D { =20 static void vhost_user_blk_pci_realize(VirtIOPCIProxy *vpci_dev, Error **e= rrp) { - VHostUserBlkPCI *dev =3D VHOST_USER_BLK_PCI(vpci_dev); + VHostUserBlkPCI *dev =3D VHOST_USER_BLK_PCI_ABSTRACT(vpci_dev); DeviceState *vdev =3D DEVICE(&dev->vdev); =20 if (dev->vdev.num_queues =3D=3D VHOST_USER_BLK_AUTO_NUM_QUEUES) { @@ -66,7 +74,8 @@ static void vhost_user_blk_pci_realize(VirtIOPCIProxy *vp= ci_dev, Error **errp) qdev_realize(vdev, BUS(&vpci_dev->bus), errp); } =20 -static void vhost_user_blk_pci_class_init(ObjectClass *klass, void *data) +static void vhost_user_blk_pci_abstract_class_init(ObjectClass *klass, + void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); VirtioPCIClass *k =3D VIRTIO_PCI_CLASS(klass); @@ -81,6 +90,12 @@ static void vhost_user_blk_pci_class_init(ObjectClass *k= lass, void *data) pcidev_k->class_id =3D PCI_CLASS_STORAGE_SCSI; } =20 +static const VirtioPCIDeviceTypeInfo vhost_user_blk_pci_abstract_info =3D { + .base_name =3D TYPE_VHOST_USER_BLK_PCI_ABSTRACT, + .instance_size =3D sizeof(VHostUserBlkPCI), + .class_init =3D vhost_user_blk_pci_abstract_class_init, +}; + static void vhost_user_blk_pci_instance_init(Object *obj) { VHostUserBlkPCI *dev =3D VHOST_USER_BLK_PCI(obj); @@ -92,18 +107,40 @@ static void vhost_user_blk_pci_instance_init(Object *o= bj) } =20 static const VirtioPCIDeviceTypeInfo vhost_user_blk_pci_info =3D { + .parent =3D TYPE_VHOST_USER_BLK_PCI_ABSTRACT, .base_name =3D TYPE_VHOST_USER_BLK_PCI, .generic_name =3D "vhost-user-blk-pci", .transitional_name =3D "vhost-user-blk-pci-transitional", .non_transitional_name =3D "vhost-user-blk-pci-non-transitional", .instance_size =3D sizeof(VHostUserBlkPCI), .instance_init =3D vhost_user_blk_pci_instance_init, - .class_init =3D vhost_user_blk_pci_class_init, +}; + +static void vhost_user_virtio_blk_pci_instance_init(Object *obj) +{ + VHostUserBlkPCI *dev =3D VHOST_USER_VIRTIO_BLK_PCI(obj); + + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), + TYPE_VHOST_USER_VIRTIO_BLK); + object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev), + "bootindex"); +} + +static const VirtioPCIDeviceTypeInfo vhost_user_virtio_blk_pci_info =3D { + .parent =3D TYPE_VHOST_USER_BLK_PCI_ABSTRACT, + .base_name =3D TYPE_VHOST_USER_VIRTIO_BLK_PCI, + .generic_name =3D "vhost-user-virtio-blk-pci", + .transitional_name =3D "vhost-user-virtio-blk-pci-transitional", + .non_transitional_name =3D "vhost-user-virtio-blk-pci-non-transition= al", + .instance_size =3D sizeof(VHostUserBlkPCI), + .instance_init =3D vhost_user_virtio_blk_pci_instance_init, }; =20 static void vhost_user_blk_pci_register(void) { + virtio_pci_types_register(&vhost_user_blk_pci_abstract_info); virtio_pci_types_register(&vhost_user_blk_pci_info); + virtio_pci_types_register(&vhost_user_virtio_blk_pci_info); } =20 type_init(vhost_user_blk_pci_register) --=20 2.25.1