vhost-user-blk: dynamically resize config space based on features
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 20764be042
("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).
Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru>
Reviewed-by: Raphael Norwitz <raphael.norwitz@nutanix.com>
Message-Id: <20220906073111.353245-6-d-tatianin@yandex-team.ru>
Reviewed-by: Raphael Norwitz <raphael.norwitz@nutanix.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
parent
f1c25f295d
commit
8edd56735b
@ -2281,11 +2281,13 @@ S: Maintained
|
|||||||
F: contrib/vhost-user-blk/
|
F: contrib/vhost-user-blk/
|
||||||
F: contrib/vhost-user-scsi/
|
F: contrib/vhost-user-scsi/
|
||||||
F: hw/block/vhost-user-blk.c
|
F: hw/block/vhost-user-blk.c
|
||||||
|
F: hw/block/virtio-blk-common.c
|
||||||
F: hw/scsi/vhost-user-scsi.c
|
F: hw/scsi/vhost-user-scsi.c
|
||||||
F: hw/virtio/vhost-user-blk-pci.c
|
F: hw/virtio/vhost-user-blk-pci.c
|
||||||
F: hw/virtio/vhost-user-scsi-pci.c
|
F: hw/virtio/vhost-user-scsi-pci.c
|
||||||
F: include/hw/virtio/vhost-user-blk.h
|
F: include/hw/virtio/vhost-user-blk.h
|
||||||
F: include/hw/virtio/vhost-user-scsi.h
|
F: include/hw/virtio/vhost-user-scsi.h
|
||||||
|
F: include/hw/virtio/virtio-blk-common.h
|
||||||
|
|
||||||
vhost-user-gpu
|
vhost-user-gpu
|
||||||
M: Marc-André Lureau <marcandre.lureau@redhat.com>
|
M: Marc-André Lureau <marcandre.lureau@redhat.com>
|
||||||
|
@ -17,6 +17,6 @@ softmmu_ss.add(when: 'CONFIG_XEN', if_true: files('xen-block.c'))
|
|||||||
softmmu_ss.add(when: 'CONFIG_TC58128', if_true: files('tc58128.c'))
|
softmmu_ss.add(when: 'CONFIG_TC58128', if_true: files('tc58128.c'))
|
||||||
|
|
||||||
specific_ss.add(when: 'CONFIG_VIRTIO_BLK', if_true: files('virtio-blk.c', 'virtio-blk-common.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'))
|
specific_ss.add(when: 'CONFIG_VHOST_USER_BLK', if_true: files('vhost-user-blk.c', 'virtio-blk-common.c'))
|
||||||
|
|
||||||
subdir('dataplane')
|
subdir('dataplane')
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "hw/qdev-core.h"
|
#include "hw/qdev-core.h"
|
||||||
#include "hw/qdev-properties.h"
|
#include "hw/qdev-properties.h"
|
||||||
#include "hw/qdev-properties-system.h"
|
#include "hw/qdev-properties-system.h"
|
||||||
|
#include "hw/virtio/virtio-blk-common.h"
|
||||||
#include "hw/virtio/vhost.h"
|
#include "hw/virtio/vhost.h"
|
||||||
#include "hw/virtio/vhost-user-blk.h"
|
#include "hw/virtio/vhost-user-blk.h"
|
||||||
#include "hw/virtio/virtio.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 */
|
/* Our num_queues overrides the device backend */
|
||||||
virtio_stw_p(vdev, &s->blkcfg.num_queues, s->num_queues);
|
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)
|
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;
|
int ret;
|
||||||
struct virtio_blk_config blkcfg;
|
struct virtio_blk_config blkcfg;
|
||||||
|
VirtIODevice *vdev = dev->vdev;
|
||||||
VHostUserBlk *s = VHOST_USER_BLK(dev->vdev);
|
VHostUserBlk *s = VHOST_USER_BLK(dev->vdev);
|
||||||
Error *local_err = NULL;
|
Error *local_err = NULL;
|
||||||
|
|
||||||
ret = vhost_dev_get_config(dev, (uint8_t *)&blkcfg,
|
ret = vhost_dev_get_config(dev, (uint8_t *)&blkcfg,
|
||||||
sizeof(struct virtio_blk_config),
|
vdev->config_len, &local_err);
|
||||||
&local_err);
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
error_report_err(local_err);
|
error_report_err(local_err);
|
||||||
return ret;
|
return ret;
|
||||||
@ -106,7 +107,7 @@ static int vhost_user_blk_handle_config_change(struct vhost_dev *dev)
|
|||||||
/* valid for resize only */
|
/* valid for resize only */
|
||||||
if (blkcfg.capacity != s->blkcfg.capacity) {
|
if (blkcfg.capacity != s->blkcfg.capacity) {
|
||||||
s->blkcfg.capacity = 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);
|
virtio_notify_config(dev->vdev);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -448,7 +449,7 @@ static int vhost_user_blk_realize_connect(VHostUserBlk *s, Error **errp)
|
|||||||
assert(s->connected);
|
assert(s->connected);
|
||||||
|
|
||||||
ret = vhost_dev_get_config(&s->dev, (uint8_t *)&s->blkcfg,
|
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) {
|
if (ret < 0) {
|
||||||
qemu_chr_fe_disconnect(&s->chardev);
|
qemu_chr_fe_disconnect(&s->chardev);
|
||||||
vhost_dev_cleanup(&s->dev);
|
vhost_dev_cleanup(&s->dev);
|
||||||
@ -463,6 +464,7 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp)
|
|||||||
ERRP_GUARD();
|
ERRP_GUARD();
|
||||||
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
|
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
|
||||||
VHostUserBlk *s = VHOST_USER_BLK(vdev);
|
VHostUserBlk *s = VHOST_USER_BLK(vdev);
|
||||||
|
size_t config_size;
|
||||||
int retries;
|
int retries;
|
||||||
int i, ret;
|
int i, ret;
|
||||||
|
|
||||||
@ -493,8 +495,9 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtio_init(vdev, VIRTIO_ID_BLOCK,
|
config_size = virtio_get_config_size(&virtio_blk_cfg_size_params,
|
||||||
sizeof(struct virtio_blk_config));
|
vdev->host_features);
|
||||||
|
virtio_init(vdev, VIRTIO_ID_BLOCK, config_size);
|
||||||
|
|
||||||
s->virtqs = g_new(VirtQueue *, s->num_queues);
|
s->virtqs = g_new(VirtQueue *, s->num_queues);
|
||||||
for (i = 0; i < s->num_queues; i++) {
|
for (i = 0; i < s->num_queues; i++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user