From nobody Wed Feb 11 02:14:27 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=1661526241; cv=none; d=zohomail.com; s=zohoarc; b=Uyfjl5moO13AhvskBG48sSuGHzIrYDMGEtSbaDKv6lPoZuljZazium4fvhXoy50zl3WAzQJiCbm67iiCZ8BBofM6cHm8AKif9GF7mXZJ+G8rCK3eGe6P0WFWdh2jwkyyAXG4WYJOEDvl4blaADdzpq3JqsxnHdpVBS5vTdQqSV8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661526241; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jXiXxAHhxmj/hJLYBXAZVWU0LYyvY8VgGKiX7Bv4ipo=; b=eHY6+a5mWB2fyn2ndATYssq1WxPfucIR0ALjKEPzVmK4kVa5AlNNwS9RSarG8gcc3NQiWSXlQIjuhv7hn1AD8zH+1UUUxaRpQ5kbs9aOm+0KvayOYNwD+ybQpV76Ycgfa04bHaL2MqCkLQgPzEN+U/WR1m6IaFeURab2+M/hw1o= 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 1661526241401230.70982634703262; Fri, 26 Aug 2022 08:04:01 -0700 (PDT) Received: from localhost ([::1]:48392 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oRasJ-0002m6-6j for importer@patchew.org; Fri, 26 Aug 2022 11:03:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52460) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oRaOh-0004G7-Jp; Fri, 26 Aug 2022 10:33:24 -0400 Received: from forwardcorp1p.mail.yandex.net ([2a02:6b8:0:1472:2741:0:8b6:217]:48202) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oRaOe-0007BV-Is; Fri, 26 Aug 2022 10:33:23 -0400 Received: from iva4-f06c35e68a0a.qloud-c.yandex.net (iva4-f06c35e68a0a.qloud-c.yandex.net [IPv6:2a02:6b8:c0c:152e:0:640:f06c:35e6]) by forwardcorp1p.mail.yandex.net (Yandex) with ESMTP id 2776B2E14B3; Fri, 26 Aug 2022 17:33:13 +0300 (MSK) Received: from d-tatianin-nix.yandex-team.ru (unknown [2a02:6b8:b081:b581::1:d]) by iva4-f06c35e68a0a.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 7Ht2PirWaX-XCOqxXUD; Fri, 26 Aug 2022 17:33:12 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1661524392; bh=jXiXxAHhxmj/hJLYBXAZVWU0LYyvY8VgGKiX7Bv4ipo=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=PvgkOlqcaRfcDkPCVqFyQezK0cgPmg2VIw5PSKsZdsvCZW7zhZf4v1J7IuJljt82e zR++kEyWES84IWQkFSfRCDx7o0ZLmteeLEkAzg6oaEn3P9pYjmkf+ePVSQsYo28Abh mW9brsEP8XwOHEyg71OXSmuNUVeCaLb7lN6wWIMo= Authentication-Results: iva4-f06c35e68a0a.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Daniil Tatianin To: qemu-devel@nongnu.org Cc: yc-core@yandex-team.ru, mst@redhat.com, stefanha@redhat.com, raphael.norwitz@nutanix.com, kwolf@redhat.com, qemu-block@nongnu.org, jasowang@redhat.com, d-tatianin@yandex-team.ru Subject: [PATCH v2 8/8] vhost-user-blk: dynamically resize config space based on features Date: Fri, 26 Aug 2022 17:32:48 +0300 Message-Id: <20220826143248.580939-9-d-tatianin@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220826143248.580939-1-d-tatianin@yandex-team.ru> References: <20220826143248.580939-1-d-tatianin@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:1472:2741:0:8b6:217; envelope-from=d-tatianin@yandex-team.ru; helo=forwardcorp1p.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1661526243149100001 Content-Type: text/plain; charset="utf-8" Make vhost-user-blk backwards compatible when migrating from older VMs running with modern features turned off, the same way it was done for virtio-blk in 20764be0421c ("virtio-blk: set config size depending on the f= eatures enabled") It's currently impossible to migrate from an older VM with vhost-user-blk (with disable-legacy=3Doff) because of errors like this: qemu-system-x86_64: get_pci_config_device: Bad config data: i=3D0x10 read: = 41 device: 1 cmask: ff wmask: 80 w1cmask:0 qemu-system-x86_64: Failed to load PCIDevice:config qemu-system-x86_64: Failed to load virtio-blk:virtio qemu-system-x86_64: error while loading state for instance 0x0 of device '0= 000:00:05.0:00.0:02.0/virtio-blk' qemu-system-x86_64: load of migration failed: Invalid argument This is caused by the newer (destination) VM requiring a bigger BAR0 alignment because it has to cover a bigger configuration space, which isn't actually needed since those additional config fields are not active (write-zeroes/discard). Signed-off-by: Daniil Tatianin Reviewed-by: Raphael Norwitz --- hw/block/vhost-user-blk.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 0d916edefa..8dd063eb96 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -23,6 +23,7 @@ #include "hw/qdev-core.h" #include "hw/qdev-properties.h" #include "hw/qdev-properties-system.h" +#include "hw/virtio/virtio-blk-common.h" #include "hw/virtio/vhost.h" #include "hw/virtio/vhost-user-blk.h" #include "hw/virtio/virtio.h" @@ -63,7 +64,7 @@ static void vhost_user_blk_update_config(VirtIODevice *vd= ev, uint8_t *config) /* Our num_queues overrides the device backend */ virtio_stw_p(vdev, &s->blkcfg.num_queues, s->num_queues); =20 - memcpy(config, &s->blkcfg, sizeof(struct virtio_blk_config)); + memcpy(config, &s->blkcfg, vdev->config_len); } =20 static void vhost_user_blk_set_config(VirtIODevice *vdev, const uint8_t *c= onfig) @@ -92,12 +93,12 @@ static int vhost_user_blk_handle_config_change(struct v= host_dev *dev) { int ret; struct virtio_blk_config blkcfg; + VirtIODevice *vdev =3D dev->vdev; VHostUserBlk *s =3D VHOST_USER_BLK(dev->vdev); Error *local_err =3D NULL; =20 ret =3D vhost_dev_get_config(dev, (uint8_t *)&blkcfg, - sizeof(struct virtio_blk_config), - &local_err); + vdev->config_len, &local_err); if (ret < 0) { error_report_err(local_err); return ret; @@ -106,7 +107,7 @@ static int vhost_user_blk_handle_config_change(struct v= host_dev *dev) /* valid for resize only */ if (blkcfg.capacity !=3D s->blkcfg.capacity) { s->blkcfg.capacity =3D blkcfg.capacity; - memcpy(dev->vdev->config, &s->blkcfg, sizeof(struct virtio_blk_con= fig)); + memcpy(dev->vdev->config, &s->blkcfg, vdev->config_len); virtio_notify_config(dev->vdev); } =20 @@ -442,7 +443,7 @@ static int vhost_user_blk_realize_connect(VHostUserBlk = *s, Error **errp) assert(s->connected); =20 ret =3D vhost_dev_get_config(&s->dev, (uint8_t *)&s->blkcfg, - sizeof(struct virtio_blk_config), errp); + s->parent_obj.config_len, errp); if (ret < 0) { qemu_chr_fe_disconnect(&s->chardev); vhost_dev_cleanup(&s->dev); @@ -457,6 +458,7 @@ static void vhost_user_blk_device_realize(DeviceState *= dev, Error **errp) ERRP_GUARD(); VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); VHostUserBlk *s =3D VHOST_USER_BLK(vdev); + size_t config_size; int retries; int i, ret; =20 @@ -487,8 +489,9 @@ static void vhost_user_blk_device_realize(DeviceState *= dev, Error **errp) return; } =20 - virtio_init(vdev, VIRTIO_ID_BLOCK, - sizeof(struct virtio_blk_config)); + config_size =3D virtio_get_config_size(&virtio_blk_cfg_size_params, + vdev->host_features); + virtio_init(vdev, VIRTIO_ID_BLOCK, config_size); =20 s->virtqs =3D g_new(VirtQueue *, s->num_queues); for (i =3D 0; i < s->num_queues; i++) { --=20 2.25.1