All of lore.kernel.org
 help / color / mirror / Atom feed
From: Raphael Norwitz <raphael.norwitz@nutanix.com>
To: Daniil Tatianin <d-tatianin@yandex-team.ru>
Cc: "qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
	"yc-core@yandex-team.ru" <yc-core@yandex-team.ru>,
	"mst@redhat.com" <mst@redhat.com>,
	"stefanha@redhat.com" <stefanha@redhat.com>,
	Raphael Norwitz <raphael.norwitz@nutanix.com>,
	"kwolf@redhat.com" <kwolf@redhat.com>,
	"qemu-block@nongnu.org" <qemu-block@nongnu.org>,
	"jasowang@redhat.com" <jasowang@redhat.com>
Subject: Re: [PATCH v2 8/8] vhost-user-blk: dynamically resize config space based on features
Date: Fri, 2 Sep 2022 17:59:01 +0000	[thread overview]
Message-ID: <20220902175901.GH5363@raphael-debian-dev> (raw)
In-Reply-To: <20220826143248.580939-9-d-tatianin@yandex-team.ru>

On Fri, Aug 26, 2022 at 05:32:48PM +0300, Daniil Tatianin wrote:
> 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 features enabled")
> 
> It's currently impossible to migrate from an older VM with
> vhost-user-blk (with disable-legacy=off) because of errors like this:
> 
> qemu-system-x86_64: get_pci_config_device: Bad config data: i=0x10 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 '0000: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).
>

With the relevant meson.build and MAINTAINERS bits rebased here:

Reviewed-by: Raphael Norwitz <raphael.norwitz@nutanix.com>


> Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru>
> ---
>  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 *vdev, uint8_t *config)
>      /* Our num_queues overrides the device backend */
>      virtio_stw_p(vdev, &s->blkcfg.num_queues, s->num_queues);
>  
> -    memcpy(config, &s->blkcfg, sizeof(struct virtio_blk_config));
> +    memcpy(config, &s->blkcfg, vdev->config_len);
>  }
>  
>  static void vhost_user_blk_set_config(VirtIODevice *vdev, const uint8_t *config)
> @@ -92,12 +93,12 @@ static int vhost_user_blk_handle_config_change(struct vhost_dev *dev)
>  {
>      int ret;
>      struct virtio_blk_config blkcfg;
> +    VirtIODevice *vdev = dev->vdev;
>      VHostUserBlk *s = VHOST_USER_BLK(dev->vdev);
>      Error *local_err = NULL;
>  
>      ret = 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 vhost_dev *dev)
>      /* valid for resize only */
>      if (blkcfg.capacity != s->blkcfg.capacity) {
>          s->blkcfg.capacity = blkcfg.capacity;
> -        memcpy(dev->vdev->config, &s->blkcfg, sizeof(struct virtio_blk_config));
> +        memcpy(dev->vdev->config, &s->blkcfg, vdev->config_len);
>          virtio_notify_config(dev->vdev);
>      }
>  
> @@ -442,7 +443,7 @@ static int vhost_user_blk_realize_connect(VHostUserBlk *s, Error **errp)
>      assert(s->connected);
>  
>      ret = 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 = VIRTIO_DEVICE(dev);
>      VHostUserBlk *s = VHOST_USER_BLK(vdev);
> +    size_t config_size;
>      int retries;
>      int i, ret;
>  
> @@ -487,8 +489,9 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp)
>          return;
>      }
>  
> -    virtio_init(vdev, VIRTIO_ID_BLOCK,
> -                sizeof(struct virtio_blk_config));
> +    config_size = virtio_get_config_size(&virtio_blk_cfg_size_params,
> +                                         vdev->host_features);
> +    virtio_init(vdev, VIRTIO_ID_BLOCK, config_size);
>  
>      s->virtqs = g_new(VirtQueue *, s->num_queues);
>      for (i = 0; i < s->num_queues; i++) {
> -- 
> 2.25.1
> 

  reply	other threads:[~2022-09-02 18:26 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-26 14:32 [PATCH v2 0/8] vhost-user-blk: dynamically resize config space based on features Daniil Tatianin
2022-08-26 14:32 ` [PATCH v2 1/8] virtio: introduce VirtIOConfigSizeParams & virtio_get_config_size Daniil Tatianin
2022-09-02 17:52   ` Raphael Norwitz
2022-09-02 22:12     ` Daniil Tatianin
2022-09-04 22:40       ` Raphael Norwitz
2022-08-26 14:32 ` [PATCH v2 2/8] virtio-blk: utilize " Daniil Tatianin
2022-09-02 17:52   ` Raphael Norwitz
2022-08-26 14:32 ` [PATCH v2 3/8] virtio-net: " Daniil Tatianin
2022-09-02 17:54   ` Raphael Norwitz
2022-09-02 22:24     ` Daniil Tatianin
2022-08-26 14:32 ` [PATCH v2 4/8] virtio: remove the virtio_feature_get_config_size helper Daniil Tatianin
2022-09-02 17:55   ` Raphael Norwitz
2022-08-26 14:32 ` [PATCH v2 5/8] virtio-blk: move config size params to virtio-blk-common Daniil Tatianin
2022-09-02 17:57   ` Raphael Norwitz
2022-09-02 22:15     ` Daniil Tatianin
2022-08-26 14:32 ` [PATCH v2 6/8] vhost-user-blk: make it possible to disable write-zeroes/discard Daniil Tatianin
2022-09-02 17:57   ` Raphael Norwitz
2022-08-26 14:32 ` [PATCH v2 7/8] vhost-user-blk: make 'config_wce' part of 'host_features' Daniil Tatianin
2022-09-02 17:58   ` Raphael Norwitz
2022-08-26 14:32 ` [PATCH v2 8/8] vhost-user-blk: dynamically resize config space based on features Daniil Tatianin
2022-09-02 17:59   ` Raphael Norwitz [this message]
     [not found] ` <292621662027678@mail.yandex-team.ru>
2022-09-02  3:40   ` [PATCH v2 0/8] " Raphael Norwitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220902175901.GH5363@raphael-debian-dev \
    --to=raphael.norwitz@nutanix.com \
    --cc=d-tatianin@yandex-team.ru \
    --cc=jasowang@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=yc-core@yandex-team.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.