From nobody Mon May 20 22:46:38 2024 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=1662449738; cv=none; d=zohomail.com; s=zohoarc; b=PLZETlYXw42FFSDfFdEv02osBOaC8Dv1H66hX0tSpRLe6eAuLci+Kw2sFe/IZDesA3Cp0zYbUHqMeekFXXHpYXIrkGfEmfzUZqysuspZG6IoJefem/ffu4FVeLt+JPb8eFMAT5Y/S08MBZc6l//o1LVpweLjx167DJVQFodEr9Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662449738; 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=KNrFvrgdy1NLNEup9+sDAaS59t6E16z0cqN39qUBNac=; b=YiTUgk7p0/t+ceouKhlOKi18fTAMsAYAgW885ZBoTGvOHRWf1MO1yqi43bguosaVZh5OOmQ2Tf/HijUUZkd1xnYfneVgVQYYhrpjCr1XuIAMZcssEc8jwNpi4SA+eHacVWQLOuK5ag0lmbMHxy1NfWsWaXJigNWFIMv7d923oZs= 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 1662449738403840.9333330829505; Tue, 6 Sep 2022 00:35:38 -0700 (PDT) Received: from localhost ([::1]:48408 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVT7R-0005y7-02 for importer@patchew.org; Tue, 06 Sep 2022 03:35:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39098) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVT3Y-0003Is-0z; Tue, 06 Sep 2022 03:31:36 -0400 Received: from forwardcorp1o.mail.yandex.net ([2a02:6b8:0:1a2d::193]:43740) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVT3S-0002xN-BR; Tue, 06 Sep 2022 03:31:35 -0400 Received: from vla1-81430ab5870b.qloud-c.yandex.net (vla1-81430ab5870b.qloud-c.yandex.net [IPv6:2a02:6b8:c0d:35a1:0:640:8143:ab5]) by forwardcorp1o.mail.yandex.net (Yandex) with ESMTP id F18FF2E0F42; Tue, 6 Sep 2022 10:31:17 +0300 (MSK) Received: from d-tatianin-nix.yandex.net (unknown [2a02:6b8:0:419:d8d0:8d85:2aad:ab5b]) by vla1-81430ab5870b.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id WefwVQnsrp-VGXi6Avj; Tue, 06 Sep 2022 10:31:16 +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=1662449476; bh=KNrFvrgdy1NLNEup9+sDAaS59t6E16z0cqN39qUBNac=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=xZZ2bBNlYnCt0xJ1ttSE3NyiWeCLYdIISK+50vWvWRt1pjTiEDtEzLlkrXOQBqIFe 9lWU4ScDY5PMrLl1p4Uj4JUzhW9BUx7/jW435vnpH9nv5a4YCSuiZeXs5ifRr3sCi5 U9Z3/w9byLx0tST9dVI1Mshs2xkXL9sxXR3qjfIc= Authentication-Results: vla1-81430ab5870b.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 v3 1/5] virtio: introduce VirtIOConfigSizeParams & virtio_get_config_size Date: Tue, 6 Sep 2022 10:31:07 +0300 Message-Id: <20220906073111.353245-2-d-tatianin@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220906073111.353245-1-d-tatianin@yandex-team.ru> References: <20220906073111.353245-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:1a2d::193; envelope-from=d-tatianin@yandex-team.ru; helo=forwardcorp1o.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: 1662449741056100001 Content-Type: text/plain; charset="utf-8" This is the first step towards moving all device config size calculation logic into the virtio core code. In particular, this adds a struct that contains all the necessary information for common virtio code to be able to calculate the final config size for a device. This is expected to be used with the new virtio_get_config_size helper, which calculates the final length based on the provided host features. This builds on top of already existing code like VirtIOFeature and virtio_feature_get_config_size(), but adds additional fields, as well as sanity checking so that device-specifc code doesn't have to duplicate it. An example usage would be: static const VirtIOFeature dev_features[] =3D { {.flags =3D 1ULL << FEATURE_1_BIT, .end =3D endof(struct virtio_dev_config, feature_1)}, {.flags =3D 1ULL << FEATURE_2_BIT, .end =3D endof(struct virtio_dev_config, feature_2)}, {} }; static const VirtIOConfigSizeParams dev_cfg_size_params =3D { .min_size =3D DEV_BASE_CONFIG_SIZE, .max_size =3D sizeof(struct virtio_dev_config), .feature_sizes =3D dev_features }; // code inside my_dev_device_realize() size_t config_size =3D virtio_get_config_size(&dev_cfg_size_params, host_features); virtio_init(vdev, VIRTIO_ID_MYDEV, config_size); Currently every device is expected to write its own boilerplate from the example above in device_realize(), however, the next step of this transition is moving VirtIOConfigSizeParams into VirtioDeviceClass, so that it can be done automatically by the virtio initialization code. All of the users of virtio_feature_get_config_size have been converted to use virtio_get_config_size so it's no longer needed and is removed with this commit. Signed-off-by: Daniil Tatianin Reviewed-by: Raphael Norwitz --- hw/block/virtio-blk.c | 16 +++++++--------- hw/net/virtio-net.c | 9 +++++++-- hw/virtio/virtio.c | 10 ++++++---- include/hw/virtio/virtio.h | 10 ++++++++-- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index e9ba752f6b..10c47c2934 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -49,13 +49,11 @@ static const VirtIOFeature feature_sizes[] =3D { {} }; =20 -static void virtio_blk_set_config_size(VirtIOBlock *s, uint64_t host_featu= res) -{ - s->config_size =3D MAX(VIRTIO_BLK_CFG_SIZE, - virtio_feature_get_config_size(feature_sizes, host_features)); - - assert(s->config_size <=3D sizeof(struct virtio_blk_config)); -} +static const VirtIOConfigSizeParams cfg_size_params =3D { + .min_size =3D VIRTIO_BLK_CFG_SIZE, + .max_size =3D sizeof(struct virtio_blk_config), + .feature_sizes =3D feature_sizes +}; =20 static void virtio_blk_init_request(VirtIOBlock *s, VirtQueue *vq, VirtIOBlockReq *req) @@ -1204,8 +1202,8 @@ static void virtio_blk_device_realize(DeviceState *de= v, Error **errp) return; } =20 - virtio_blk_set_config_size(s, s->host_features); - + s->config_size =3D virtio_get_config_size(&cfg_size_params, + s->host_features); virtio_init(vdev, VIRTIO_ID_BLOCK, s->config_size); =20 s->blk =3D conf->conf.blk; diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index dd0d056fde..78b003a158 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -106,6 +106,12 @@ static const VirtIOFeature feature_sizes[] =3D { {} }; =20 +static const VirtIOConfigSizeParams cfg_size_params =3D { + .min_size =3D endof(struct virtio_net_config, mac), + .max_size =3D sizeof(struct virtio_net_config), + .feature_sizes =3D feature_sizes +}; + static VirtIONetQueue *virtio_net_get_subqueue(NetClientState *nc) { VirtIONet *n =3D qemu_get_nic_opaque(nc); @@ -3246,8 +3252,7 @@ static void virtio_net_set_config_size(VirtIONet *n, = uint64_t host_features) { virtio_add_feature(&host_features, VIRTIO_NET_F_MAC); =20 - n->config_size =3D virtio_feature_get_config_size(feature_sizes, - host_features); + n->config_size =3D virtio_get_config_size(&cfg_size_params, host_featu= res); } =20 void virtio_net_set_netclient_name(VirtIONet *n, const char *name, diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 5d607aeaa0..c0bf8dd6fd 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -2999,11 +2999,12 @@ int virtio_set_features(VirtIODevice *vdev, uint64_= t val) return ret; } =20 -size_t virtio_feature_get_config_size(const VirtIOFeature *feature_sizes, - uint64_t host_features) +size_t virtio_get_config_size(const VirtIOConfigSizeParams *params, + uint64_t host_features) { - size_t config_size =3D 0; - int i; + size_t config_size =3D params->min_size; + const VirtIOFeature *feature_sizes =3D params->feature_sizes; + size_t i; =20 for (i =3D 0; feature_sizes[i].flags !=3D 0; i++) { if (host_features & feature_sizes[i].flags) { @@ -3011,6 +3012,7 @@ size_t virtio_feature_get_config_size(const VirtIOFea= ture *feature_sizes, } } =20 + assert(config_size <=3D params->max_size); return config_size; } =20 diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index db1c0ddf6b..f3ff6710d5 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -44,8 +44,14 @@ typedef struct VirtIOFeature { size_t end; } VirtIOFeature; =20 -size_t virtio_feature_get_config_size(const VirtIOFeature *features, - uint64_t host_features); +typedef struct VirtIOConfigSizeParams { + size_t min_size; + size_t max_size; + const VirtIOFeature *feature_sizes; +} VirtIOConfigSizeParams; + +size_t virtio_get_config_size(const VirtIOConfigSizeParams *params, + uint64_t host_features); =20 typedef struct VirtQueue VirtQueue; =20 --=20 2.25.1 From nobody Mon May 20 22:46:38 2024 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=1662449757; cv=none; d=zohomail.com; s=zohoarc; b=S5+bzlQZrV1vbPBRgX73wPIhG0pkxKsCtNQs0rYH6zhNqFnLf/cYjdw50bFzPEvgER81R5dIR0L1iFGQ8T8y3BJXZ/pb5OqnB7hdvI77ci5AkpBqjjFmbQuhJKUe2eCvxh9s6FiozxuQ8S8khENTuLC5YTJGOBHVh31OacBpRqM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662449757; 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=kV6D4xcVx1KDmrv9tcmp6vQ/S6NIeJj51U/GwK/y4nk=; b=MB4Hs9NozqcHQKRWR647BdfIaNCKgX1odsrXPLWtwK6iC7xbF503kbG4XJh2GTFqrBT4pwCvKuZ5lB24aP7y/zlUYf9HZIeJKYCBLXLYOuVy6J/W7AmDuI0zozoulrNfV3iRO4bvFR67/UNvvCxvbuBqLylZtzvR7aDcyLkHEDw= 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 1662449757406856.8336470187294; Tue, 6 Sep 2022 00:35:57 -0700 (PDT) Received: from localhost ([::1]:36960 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVT7k-0006Sa-9S for importer@patchew.org; Tue, 06 Sep 2022 03:35:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43354) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVT3Y-0003IW-Mk; Tue, 06 Sep 2022 03:31:36 -0400 Received: from forwardcorp1p.mail.yandex.net ([77.88.29.217]:49702) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVT3S-0002xT-AE; Tue, 06 Sep 2022 03:31:34 -0400 Received: from vla1-81430ab5870b.qloud-c.yandex.net (vla1-81430ab5870b.qloud-c.yandex.net [IPv6:2a02:6b8:c0d:35a1:0:640:8143:ab5]) by forwardcorp1p.mail.yandex.net (Yandex) with ESMTP id 0A14C2E1227; Tue, 6 Sep 2022 10:31:19 +0300 (MSK) Received: from d-tatianin-nix.yandex.net (unknown [2a02:6b8:0:419:d8d0:8d85:2aad:ab5b]) by vla1-81430ab5870b.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id WefwVQnsrp-VIXi5FIV; Tue, 06 Sep 2022 10:31:18 +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=1662449478; bh=kV6D4xcVx1KDmrv9tcmp6vQ/S6NIeJj51U/GwK/y4nk=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=kUJcBa1DigWNzGxP+w8CRU2KWt/Fbi3SySLzRMrrvo+LJEYVxQEqWd3h0VwdZWxft 7dia27hCGgwWhWE8cnQc4e7sZlmUI6EYY8t3jVIoy5ToMO17FQWWLHtDReVzf2f4/m +ESYIeew69R6yGpt7BzSuTYsi9MvkeDWrLw/dShk= Authentication-Results: vla1-81430ab5870b.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 v3 2/5] virtio-blk: move config size params to virtio-blk-common Date: Tue, 6 Sep 2022 10:31:08 +0300 Message-Id: <20220906073111.353245-3-d-tatianin@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220906073111.353245-1-d-tatianin@yandex-team.ru> References: <20220906073111.353245-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=77.88.29.217; envelope-from=d-tatianin@yandex-team.ru; helo=forwardcorp1p.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, 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: 1662449759223100001 Content-Type: text/plain; charset="utf-8" This way we can reuse it for other virtio-blk devices, e.g vhost-user-blk, which currently does not control its config space size dynamically. Signed-off-by: Daniil Tatianin Reviewed-by: Raphael Norwitz --- MAINTAINERS | 2 ++ hw/block/meson.build | 2 +- hw/block/virtio-blk-common.c | 39 +++++++++++++++++++++++++++ hw/block/virtio-blk.c | 24 ++--------------- include/hw/virtio/virtio-blk-common.h | 20 ++++++++++++++ 5 files changed, 64 insertions(+), 23 deletions(-) create mode 100644 hw/block/virtio-blk-common.c create mode 100644 include/hw/virtio/virtio-blk-common.h diff --git a/MAINTAINERS b/MAINTAINERS index 5ce4227ff6..2858577c5b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2030,8 +2030,10 @@ virtio-blk M: Stefan Hajnoczi L: qemu-block@nongnu.org S: Supported +F: hw/block/virtio-blk-common.c F: hw/block/virtio-blk.c F: hw/block/dataplane/* +F: include/hw/virtio/virtio-blk-common.h F: tests/qtest/virtio-blk-test.c T: git https://github.com/stefanha/qemu.git block =20 diff --git a/hw/block/meson.build b/hw/block/meson.build index 2389326112..8ee1f1f850 100644 --- a/hw/block/meson.build +++ b/hw/block/meson.build @@ -16,7 +16,7 @@ softmmu_ss.add(when: 'CONFIG_SWIM', if_true: files('swim.= c')) softmmu_ss.add(when: 'CONFIG_XEN', if_true: files('xen-block.c')) softmmu_ss.add(when: 'CONFIG_TC58128', if_true: files('tc58128.c')) =20 -specific_ss.add(when: 'CONFIG_VIRTIO_BLK', if_true: files('virtio-blk.c')) +specific_ss.add(when: 'CONFIG_VIRTIO_BLK', if_true: files('virtio-blk.c', = 'virtio-blk-common.c')) specific_ss.add(when: 'CONFIG_VHOST_USER_BLK', if_true: files('vhost-user-= blk.c')) =20 subdir('dataplane') diff --git a/hw/block/virtio-blk-common.c b/hw/block/virtio-blk-common.c new file mode 100644 index 0000000000..ac52d7c176 --- /dev/null +++ b/hw/block/virtio-blk-common.c @@ -0,0 +1,39 @@ +/* + * Virtio Block Device common helpers + * + * Copyright IBM, Corp. 2007 + * + * Authors: + * Anthony Liguori + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" + +#include "standard-headers/linux/virtio_blk.h" +#include "hw/virtio/virtio.h" +#include "hw/virtio/virtio-blk-common.h" + +/* Config size before the discard support (hide associated config fields) = */ +#define VIRTIO_BLK_CFG_SIZE offsetof(struct virtio_blk_config, \ + max_discard_sectors) + +/* + * Starting from the discard feature, we can use this array to properly + * set the config size depending on the features enabled. + */ +static const VirtIOFeature feature_sizes[] =3D { + {.flags =3D 1ULL << VIRTIO_BLK_F_DISCARD, + .end =3D endof(struct virtio_blk_config, discard_sector_alignment)}, + {.flags =3D 1ULL << VIRTIO_BLK_F_WRITE_ZEROES, + .end =3D endof(struct virtio_blk_config, write_zeroes_may_unmap)}, + {} +}; + +const VirtIOConfigSizeParams virtio_blk_cfg_size_params =3D { + .min_size =3D VIRTIO_BLK_CFG_SIZE, + .max_size =3D sizeof(struct virtio_blk_config), + .feature_sizes =3D feature_sizes +}; diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 10c47c2934..8131ec2dbc 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -32,29 +32,9 @@ #include "hw/virtio/virtio-bus.h" #include "migration/qemu-file-types.h" #include "hw/virtio/virtio-access.h" +#include "hw/virtio/virtio-blk-common.h" #include "qemu/coroutine.h" =20 -/* Config size before the discard support (hide associated config fields) = */ -#define VIRTIO_BLK_CFG_SIZE offsetof(struct virtio_blk_config, \ - max_discard_sectors) -/* - * Starting from the discard feature, we can use this array to properly - * set the config size depending on the features enabled. - */ -static const VirtIOFeature feature_sizes[] =3D { - {.flags =3D 1ULL << VIRTIO_BLK_F_DISCARD, - .end =3D endof(struct virtio_blk_config, discard_sector_alignment)}, - {.flags =3D 1ULL << VIRTIO_BLK_F_WRITE_ZEROES, - .end =3D endof(struct virtio_blk_config, write_zeroes_may_unmap)}, - {} -}; - -static const VirtIOConfigSizeParams cfg_size_params =3D { - .min_size =3D VIRTIO_BLK_CFG_SIZE, - .max_size =3D sizeof(struct virtio_blk_config), - .feature_sizes =3D feature_sizes -}; - static void virtio_blk_init_request(VirtIOBlock *s, VirtQueue *vq, VirtIOBlockReq *req) { @@ -1202,7 +1182,7 @@ static void virtio_blk_device_realize(DeviceState *de= v, Error **errp) return; } =20 - s->config_size =3D virtio_get_config_size(&cfg_size_params, + s->config_size =3D virtio_get_config_size(&virtio_blk_cfg_size_params, s->host_features); virtio_init(vdev, VIRTIO_ID_BLOCK, s->config_size); =20 diff --git a/include/hw/virtio/virtio-blk-common.h b/include/hw/virtio/virt= io-blk-common.h new file mode 100644 index 0000000000..31daada3e3 --- /dev/null +++ b/include/hw/virtio/virtio-blk-common.h @@ -0,0 +1,20 @@ +/* + * Virtio Block Device common helpers + * + * Copyright IBM, Corp. 2007 + * + * Authors: + * Anthony Liguori + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + */ + +#ifndef VIRTIO_BLK_COMMON_H +#define VIRTIO_BLK_COMMON_H + +#include "hw/virtio/virtio.h" + +extern const VirtIOConfigSizeParams virtio_blk_cfg_size_params; + +#endif --=20 2.25.1 From nobody Mon May 20 22:46:38 2024 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=1662449963; cv=none; d=zohomail.com; s=zohoarc; b=dwhcYGeF0h7bXU2/ka2y+7KQ1Y0ezsndpxYyaL2+Em0Njf3aUXPAQRdIUw1Daq0aEAtpIWTV2eIjlE8YX3xLm0O9O2IqpZOaiLF5jyqeguwk2R05+x4YJRi98L3Rdecffjbe77g6LH3NZT31pWeyjLw/xo58LrCo+rJpLFTO8JY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662449963; 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=CSW1A7UJsUY4+uHeXma7o5wMMCuBXH41Ny7gH8yaeGs=; b=jkprxhvMqNtgeO/G5PLkhYgbWxu8vZkW1eihn4srO7DpMp7SabQvL+3ZKc0WHbnf/IvQ2xxiqPTjoQp61DzwhRhKd0Ij/IMfxRhM/Z8b1tRZWrNk/SCNG4dnPwbPPZSV0sUV0KoqVUMCrNawOzBxAduvQ/+JH6YpTYokBFh2RTc= 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 166244996372925.59033504707861; Tue, 6 Sep 2022 00:39:23 -0700 (PDT) Received: from localhost ([::1]:50420 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVTB4-00021p-Ek for importer@patchew.org; Tue, 06 Sep 2022 03:39:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43356) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVT3Y-0003Iq-MM; Tue, 06 Sep 2022 03:31:36 -0400 Received: from forwardcorp1p.mail.yandex.net ([77.88.29.217]:49704) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVT3U-0002xU-6u; Tue, 06 Sep 2022 03:31:35 -0400 Received: from vla1-81430ab5870b.qloud-c.yandex.net (vla1-81430ab5870b.qloud-c.yandex.net [IPv6:2a02:6b8:c0d:35a1:0:640:8143:ab5]) by forwardcorp1p.mail.yandex.net (Yandex) with ESMTP id E4A5C2E0B44; Tue, 6 Sep 2022 10:31:19 +0300 (MSK) Received: from d-tatianin-nix.yandex.net (unknown [2a02:6b8:0:419:d8d0:8d85:2aad:ab5b]) by vla1-81430ab5870b.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id WefwVQnsrp-VJXiuDjk; Tue, 06 Sep 2022 10:31:19 +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=1662449479; bh=CSW1A7UJsUY4+uHeXma7o5wMMCuBXH41Ny7gH8yaeGs=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=uB0iiSMGmjpA2xEzve//WUrUGhmK+w6/ewUSvRR9Sh7V8ZLNcrh47pSOoOxiKr/8v SBgCRk1s/v72Q7+wD0crQwC7YFbNjnTiPfOnNILr5URBK2992N+iDoYu6pnb4/SNg/ 3ErAdDZqsvTQTOO2sc5GdpXggKdOQXBqh/4ok47s= Authentication-Results: vla1-81430ab5870b.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 v3 3/5] vhost-user-blk: make it possible to disable write-zeroes/discard Date: Tue, 6 Sep 2022 10:31:09 +0300 Message-Id: <20220906073111.353245-4-d-tatianin@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220906073111.353245-1-d-tatianin@yandex-team.ru> References: <20220906073111.353245-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=77.88.29.217; envelope-from=d-tatianin@yandex-team.ru; helo=forwardcorp1p.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, 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: 1662449965230100001 Content-Type: text/plain; charset="utf-8" It is useful to have the ability to disable these features for compatibility with older VMs that don't have these implemented. Signed-off-by: Daniil Tatianin Reviewed-by: Raphael Norwitz --- hw/block/vhost-user-blk.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 9117222456..4c9727e08c 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -259,8 +259,6 @@ static uint64_t vhost_user_blk_get_features(VirtIODevic= e *vdev, virtio_add_feature(&features, VIRTIO_BLK_F_BLK_SIZE); virtio_add_feature(&features, VIRTIO_BLK_F_FLUSH); virtio_add_feature(&features, VIRTIO_BLK_F_RO); - virtio_add_feature(&features, VIRTIO_BLK_F_DISCARD); - virtio_add_feature(&features, VIRTIO_BLK_F_WRITE_ZEROES); =20 if (s->config_wce) { virtio_add_feature(&features, VIRTIO_BLK_F_CONFIG_WCE); @@ -592,6 +590,10 @@ static Property vhost_user_blk_properties[] =3D { VHOST_USER_BLK_AUTO_NUM_QUEUES), DEFINE_PROP_UINT32("queue-size", VHostUserBlk, queue_size, 128), DEFINE_PROP_BIT("config-wce", VHostUserBlk, config_wce, 0, true), + DEFINE_PROP_BIT64("discard", VHostUserBlk, parent_obj.host_features, + VIRTIO_BLK_F_DISCARD, true), + DEFINE_PROP_BIT64("write-zeroes", VHostUserBlk, parent_obj.host_featur= es, + VIRTIO_BLK_F_WRITE_ZEROES, true), DEFINE_PROP_END_OF_LIST(), }; =20 --=20 2.25.1 From nobody Mon May 20 22:46:38 2024 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=1662449964; cv=none; d=zohomail.com; s=zohoarc; b=WYbpN6EXqU/1YI7GWsj1KjWVCC41PciVjGLU+eWMwuuyU7EpDU4qL+xGHn8kGAGvgKVJekqFI3dsizPbn9RgLQSulFk4Tsqi2sxDuq02UNMQW03hV4CigfIhHjJKXkwz1Bl+ipol81VHSlVHdxXCoOiDgQIOZBhZATrRDu3m2ZA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662449964; 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=DE9Z90+5ZAssORhEqBwU4+fbkaVeRy6PPYdJcRCDwrE=; b=Zu6AQ3esxRPcfECiU/2iL/w8602BKD6tdPMPeH4HpUQG6pnu7LQ1NODQqCc4H7i1IM69YTLlVpb8qoPetZyZFOAyEQa70fFPLirWHg3xfNeVRxNdAXCEC51jlPQw6P3tZ99TrApKftpXuaF3o2V4nuYtASrAjVfV51lwFX99HAw= 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 1662449964317257.051276532672; Tue, 6 Sep 2022 00:39:24 -0700 (PDT) Received: from localhost ([::1]:50422 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVTB4-00022u-3g for importer@patchew.org; Tue, 06 Sep 2022 03:39:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39096) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVT3Y-0003Ir-Mn; Tue, 06 Sep 2022 03:31:36 -0400 Received: from forwardcorp1j.mail.yandex.net ([2a02:6b8:0:1619::183]:54206) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVT3U-0002xh-6s; Tue, 06 Sep 2022 03:31:35 -0400 Received: from vla1-81430ab5870b.qloud-c.yandex.net (vla1-81430ab5870b.qloud-c.yandex.net [IPv6:2a02:6b8:c0d:35a1:0:640:8143:ab5]) by forwardcorp1j.mail.yandex.net (Yandex) with ESMTP id DB5612E2DCD; Tue, 6 Sep 2022 10:31:20 +0300 (MSK) Received: from d-tatianin-nix.yandex.net (unknown [2a02:6b8:0:419:d8d0:8d85:2aad:ab5b]) by vla1-81430ab5870b.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id WefwVQnsrp-VKXiX48U; Tue, 06 Sep 2022 10:31:20 +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=1662449480; bh=DE9Z90+5ZAssORhEqBwU4+fbkaVeRy6PPYdJcRCDwrE=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=k0pf9MdX+5YZYR5UOmzYSKA9wnBP5zPqQ/UDUzkJ4EuUoatGmtbqJLGw9l7aVi0Di HDa5DnjrMM0QqA+eHnLyg+YXpehg0gYa8sskYrAeaZt2dFnMC/BMqNrz3WBRbZpt/z shvEDoW7ICxQVVzrQgEM6i33i2RiiBSAWLAqmLY4= Authentication-Results: vla1-81430ab5870b.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 v3 4/5] vhost-user-blk: make 'config_wce' part of 'host_features' Date: Tue, 6 Sep 2022 10:31:10 +0300 Message-Id: <20220906073111.353245-5-d-tatianin@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220906073111.353245-1-d-tatianin@yandex-team.ru> References: <20220906073111.353245-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:1619::183; envelope-from=d-tatianin@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, 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: 1662449965233100002 Content-Type: text/plain; charset="utf-8" No reason to have this be a separate field. This also makes it more akin to what the virtio-blk device does. Signed-off-by: Daniil Tatianin Reviewed-by: Raphael Norwitz --- hw/block/vhost-user-blk.c | 6 ++---- include/hw/virtio/vhost-user-blk.h | 1 - 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 4c9727e08c..0d916edefa 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -260,9 +260,6 @@ static uint64_t vhost_user_blk_get_features(VirtIODevic= e *vdev, virtio_add_feature(&features, VIRTIO_BLK_F_FLUSH); virtio_add_feature(&features, VIRTIO_BLK_F_RO); =20 - if (s->config_wce) { - virtio_add_feature(&features, VIRTIO_BLK_F_CONFIG_WCE); - } if (s->num_queues > 1) { virtio_add_feature(&features, VIRTIO_BLK_F_MQ); } @@ -589,7 +586,8 @@ static Property vhost_user_blk_properties[] =3D { DEFINE_PROP_UINT16("num-queues", VHostUserBlk, num_queues, VHOST_USER_BLK_AUTO_NUM_QUEUES), DEFINE_PROP_UINT32("queue-size", VHostUserBlk, queue_size, 128), - DEFINE_PROP_BIT("config-wce", VHostUserBlk, config_wce, 0, true), + DEFINE_PROP_BIT64("config-wce", VHostUserBlk, parent_obj.host_features, + VIRTIO_BLK_F_CONFIG_WCE, true), DEFINE_PROP_BIT64("discard", VHostUserBlk, parent_obj.host_features, VIRTIO_BLK_F_DISCARD, true), DEFINE_PROP_BIT64("write-zeroes", VHostUserBlk, parent_obj.host_featur= es, diff --git a/include/hw/virtio/vhost-user-blk.h b/include/hw/virtio/vhost-u= ser-blk.h index 7c91f15040..ea085ee1ed 100644 --- a/include/hw/virtio/vhost-user-blk.h +++ b/include/hw/virtio/vhost-user-blk.h @@ -34,7 +34,6 @@ struct VHostUserBlk { struct virtio_blk_config blkcfg; uint16_t num_queues; uint32_t queue_size; - uint32_t config_wce; struct vhost_dev dev; struct vhost_inflight *inflight; VhostUserState vhost_user; --=20 2.25.1 From nobody Mon May 20 22:46:38 2024 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=1662449748; cv=none; d=zohomail.com; s=zohoarc; b=iMDlDxRs14d86eAqeN9Jm6/CAcKRST3Q3/jvmVQ/UjruEXb9DJRLzBEsJ8pfBjzwHrZgwRSfeXqs0FuG0NNft+bieD4uMNW+q6FE4RtLpe93aP7ZuKx0DGOpCGbq6NMpDIuXq+kzXODDneVg2tgL/CcD08odWLwxJLjxfm8D4W8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662449748; h=Content-Type: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=0D0HHr/ucF+3QHpLGClIrwqsInvbQHeZacJYLryFmA4=; b=enhV26n0HlpG++h3S6+v/iNZJqichA+IuU8H3g0r+AswX/wwUv2AtGfBnBQ3ShQeVSoryWd2uzK80U9FUj5uJEWfEw3ohLEHO9j7WkDboE4vlF/ttIVsZjLkaWY1LYucl7OeKYpv1nyz5og0A7IPCnkHoxtkYvTG2X6Ckuaf1pw= 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 1662449748517966.0303155217799; Tue, 6 Sep 2022 00:35:48 -0700 (PDT) Received: from localhost ([::1]:36958 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVT7b-0006P1-G5 for importer@patchew.org; Tue, 06 Sep 2022 03:35:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39100) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVT3Y-0003It-ML; Tue, 06 Sep 2022 03:31:36 -0400 Received: from forwardcorp1j.mail.yandex.net ([5.45.199.163]:47716) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVT3U-0002xm-7J; Tue, 06 Sep 2022 03:31:35 -0400 Received: from vla1-81430ab5870b.qloud-c.yandex.net (vla1-81430ab5870b.qloud-c.yandex.net [IPv6:2a02:6b8:c0d:35a1:0:640:8143:ab5]) by forwardcorp1j.mail.yandex.net (Yandex) with ESMTP id C99B62E2DF4; Tue, 6 Sep 2022 10:31:21 +0300 (MSK) Received: from d-tatianin-nix.yandex.net (unknown [2a02:6b8:0:419:d8d0:8d85:2aad:ab5b]) by vla1-81430ab5870b.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id WefwVQnsrp-VKXinvwg; Tue, 06 Sep 2022 10:31:20 +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=1662449480; bh=0D0HHr/ucF+3QHpLGClIrwqsInvbQHeZacJYLryFmA4=; h=Cc:Message-Id:References:Date:In-Reply-To:Subject:To:From; b=Mc6DO25biJ419BEw1oyo05Ys2kuRgcQgX3jo58XJn1HuB/WoZn5/eSVvjLxCspLyS 0GT81tlbCYlM435uYnXo7JmuSheyGP8soVFZaAnIXK13q3RExznVix+3uDtMtFPrxf wrPPJ5d7ZwGFpxiGIaWK0b0vlhwVVgPKpFJ8w838= Authentication-Results: vla1-81430ab5870b.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 v3 5/5] vhost-user-blk: dynamically resize config space based on features Date: Tue, 6 Sep 2022 10:31:11 +0300 Message-Id: <20220906073111.353245-6-d-tatianin@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220906073111.353245-1-d-tatianin@yandex-team.ru> References: <20220906073111.353245-1-d-tatianin@yandex-team.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=5.45.199.163; envelope-from=d-tatianin@yandex-team.ru; helo=forwardcorp1j.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, 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: 1662449749608100001 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 --- MAINTAINERS | 2 ++ hw/block/meson.build | 2 +- hw/block/vhost-user-blk.c | 17 ++++++++++------- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index 2858577c5b..a7d3914735 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2273,11 +2273,13 @@ S: Maintained F: contrib/vhost-user-blk/ F: contrib/vhost-user-scsi/ F: hw/block/vhost-user-blk.c +F: hw/block/virtio-blk-common.c F: hw/scsi/vhost-user-scsi.c F: hw/virtio/vhost-user-blk-pci.c F: hw/virtio/vhost-user-scsi-pci.c F: include/hw/virtio/vhost-user-blk.h F: include/hw/virtio/vhost-user-scsi.h +F: include/hw/virtio/virtio-blk-common.h =20 vhost-user-gpu M: Marc-Andr=C3=A9 Lureau diff --git a/hw/block/meson.build b/hw/block/meson.build index 8ee1f1f850..1908abd45c 100644 --- a/hw/block/meson.build +++ b/hw/block/meson.build @@ -17,6 +17,6 @@ softmmu_ss.add(when: 'CONFIG_XEN', if_true: files('xen-bl= ock.c')) softmmu_ss.add(when: 'CONFIG_TC58128', if_true: files('tc58128.c')) =20 specific_ss.add(when: 'CONFIG_VIRTIO_BLK', if_true: files('virtio-blk.c', = 'virtio-blk-common.c')) -specific_ss.add(when: 'CONFIG_VHOST_USER_BLK', if_true: files('vhost-user-= blk.c')) +specific_ss.add(when: 'CONFIG_VHOST_USER_BLK', if_true: files('vhost-user-= blk.c', 'virtio-blk-common.c')) =20 subdir('dataplane') 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