virtio-blk: set correct config size for the host driver
PATCH v2 1/1 virtio-blk: set correct config size for the host driver
Commit caa1ee43 "vhost-user-blk: add discard/write zeroes features support" introduced extra fields to existing struct virtio_blk_config, when migration was executed from older QEMU version to current head, it will break the migration. While here, set the correct config size when initializing the host driver, for now, discard/write zeroes are not supported by virtio-blk host driver, so set the config size as before, users can change config size when adding the new feature bits support.
--- hw/block/virtio-blk.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
hw/block/virtio-blk.c +6 -4
@@ -28,6 +28,9 @@#include "hw/virtio/virtio-bus.h" #include "hw/virtio/virtio-access.h" +#define VIRTIO_BLK_CFG_SIZE (offsetof(struct virtio_blk_config, num_queues) + \ + sizeof_field(struct virtio_blk_config, num_queues)) +static void virtio_blk_init_request (VirtIOBlock *s,VirtQueue *vq,VirtIOBlockReq *req) {
@@ -761,7 +764,7 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config) blkcfg.alignment_offset =0 ; blkcfg.wce =blk_enable_write_cache (s->blk);virtio_stw_p (vdev, &blkcfg.num_queues, s->conf.num_queues); -memcpy (config, &blkcfg,sizeof (struct virtio_blk_config )); +memcpy (config, &blkcfg,VIRTIO_BLK_CFG_SIZE ); }static void virtio_blk_set_config (VirtIODevice *vdev,const uint8_t *config)
@@ -769,7 +772,7 @@ static void virtio_blk_set_config(VirtIODevice *vdev, const uint8_t *config)VirtIOBlock *s =VIRTIO_BLK (vdev);struct virtio_blk_config blkcfg; -memcpy (&blkcfg, config,sizeof (blkcfg)); +memcpy (&blkcfg, config,VIRTIO_BLK_CFG_SIZE );aio_context_acquire (blk_get_aio_context (s->blk));blk_set_enable_write_cache (s->blk, blkcfg.wce !=0 );
@@ -952,8 +955,7 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp)return ; } -virtio_init (vdev,"virtio-blk" ,VIRTIO_ID_BLOCK , -sizeof (struct virtio_blk_config )); +virtio_init (vdev,"virtio-blk" ,VIRTIO_ID_BLOCK ,VIRTIO_BLK_CFG_SIZE ); s->blk = conf->conf.blk; s->rq =NULL ;
Signature · 1 line
1.9.3
Quoted 3 lines · On Tue, 12 Feb 2019 14:01:44 +0800 Changpeng Liu <[email protected]>…
Commit
caa1ee43"vhost-user-blk: add discard/write zeroes features support" introduced extra fields to existing structvirtio_blk_config, when migration was executed from older QEMU version to current head, it
A hint about the breakage is often a good practice, as it helps people to find the fix if they hit the issue.
Quoted 1 line
will break the migration. While here, set the correct config size
"While here" usually means that the corresponding change isn't strictly needed. I don't believe this is the case here since fixing the config size is precisely the goal of this patch.
Quoted 2 lines
when initializing the host driver, for now, discard/write zeroes are not supported by virtio-blk host driver, so set the config
As mentioned by Michael, there's no such thing as a "host driver". Just say virtio-blk.
Quoted 3 lines
size as before, users can change config size when adding the new feature bits support.
What about ?
Commit caa1ee43 "vhost-user-blk: add discard/write zeroes features support" added fields to struct virtio_blk_config. This changes the size of the config space and breaks migration from QEMU 3.1 and older:
qemu-system-ppc64: get_pci_config_device: Bad config data: i=0x10 read: 41 device: 1 cmask: ff wmask: 80 w1cmask:0
qemu-system-ppc64: Failed to load PCIDevice:config
qemu-system-ppc64: Failed to load virtio-blk:virtio
qemu-system-ppc64: error while loading state for instance 0x0 of device 'pci@800000020000000:01.0/virtio-blk'
qemu-system-ppc64: load of migration failed: Invalid argument
Since virtio-blk doesn't support the "discard" and "write zeroes" features, it shouldn't even expose the associated fields in the config space actually. Just include all fields up to num_queues to match QEMU 3.1 and older.
Quoted 2 lines
Signed-off-by Changpeng Liu <[email protected]>---
LGTM
Quoted 45 lines
hw/block/virtio-blk.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)hw/block/virtio-blk.c +6
-4@@ -28,6 +28,9 @@#include "hw/virtio/virtio-bus.h" #include "hw/virtio/virtio-access.h" +#define VIRTIO_BLK_CFG_SIZE (offsetof(struct virtio_blk_config, num_queues) + \ + sizeof_field(struct virtio_blk_config, num_queues)) +static void virtio_blk_init_request (VirtIOBlock *s,VirtQueue *vq,VirtIOBlockReq *req) {@@ -761,7 +764,7 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config) blkcfg.alignment_offset =0 ; blkcfg.wce =blk_enable_write_cache (s->blk);virtio_stw_p (vdev, &blkcfg.num_queues, s->conf.num_queues); -memcpy (config, &blkcfg,sizeof (struct virtio_blk_config )); +memcpy (config, &blkcfg,VIRTIO_BLK_CFG_SIZE ); }static void virtio_blk_set_config (VirtIODevice *vdev,const uint8_t *config)@@ -769,7 +772,7 @@ static void virtio_blk_set_config(VirtIODevice *vdev, const uint8_t *config)VirtIOBlock *s =VIRTIO_BLK (vdev);struct virtio_blk_config blkcfg; -memcpy (&blkcfg, config,sizeof (blkcfg)); +memcpy (&blkcfg, config,VIRTIO_BLK_CFG_SIZE );aio_context_acquire (blk_get_aio_context (s->blk));blk_set_enable_write_cache (s->blk, blkcfg.wce !=0 );@@ -952,8 +955,7 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp)return ; } -virtio_init (vdev,"virtio-blk" ,VIRTIO_ID_BLOCK , -sizeof (struct virtio_blk_config )); +virtio_init (vdev,"virtio-blk" ,VIRTIO_ID_BLOCK ,VIRTIO_BLK_CFG_SIZE ); s->blk = conf->conf.blk; s->rq =NULL ;
Quoted 10 lines · Changpeng Liu
Commit
caa1ee43"vhost-user-blk: add discard/write zeroes features support" introduced extra fields to existing structvirtio_blk_config, when migration was executed from older QEMU version to current head, it will break the migration. While here, set the correct config size when initializing the host driver, for now, discard/write zeroes are not supported by virtio-blk host driver, so set the config size as before, users can change config size when adding the new feature bits support.Signed-off-by Changpeng Liu <[email protected]>
Pls rewrite commit log as suggested in this thread and repost.
Quoted 9 lines
--- hw/block/virtio-blk.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)hw/block/virtio-blk.c +0
-0
hw/block/virtio-blk.c line 33
Quoted 6 lines
hw/block/virtio-blk.c +3
-0@@ -28,6 +28,9 @@#include "hw/virtio/virtio-bus.h" #include "hw/virtio/virtio-access.h" +#define VIRTIO_BLK_CFG_SIZE (offsetof(struct virtio_blk_config, num_queues) + \ + sizeof_field(struct virtio_blk_config, num_queues)) +
I would just do offsetof(max_discard_sectors)
with a comment "we don't support discard yet, hide associated config fields".
hw/block/virtio-blk.c static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config) · line 767
Quoted 9 lines
hw/block/virtio-blk.c +1
-1static void virtio_blk_init_request (VirtIOBlock *s,VirtQueue *vq,VirtIOBlockReq *req) {@@ -761,7 +764,7 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config) blkcfg.alignment_offset =0 ; blkcfg.wce =blk_enable_write_cache (s->blk);virtio_stw_p (vdev, &blkcfg.num_queues, s->conf.num_queues); -memcpy (config, &blkcfg,sizeof (struct virtio_blk_config )); +memcpy (config, &blkcfg,VIRTIO_BLK_CFG_SIZE );
Let's add QEMU_BUILD_BUG_ON(VIRTIO_BLK_CFG_SIZE <= sizeof(struct virtio_blk_config)) just for documentation purposes.
hw/block/virtio-blk.c static void virtio_blk_set_config(VirtIODevice *vdev, const uint8_t *config) · line 775
Quoted 9 lines
hw/block/virtio-blk.c +1
-1}static void virtio_blk_set_config (VirtIODevice *vdev,const uint8_t *config)@@ -769,7 +772,7 @@ static void virtio_blk_set_config(VirtIODevice *vdev, const uint8_t *config)VirtIOBlock *s =VIRTIO_BLK (vdev);struct virtio_blk_config blkcfg; -memcpy (&blkcfg, config,sizeof (blkcfg)); +memcpy (&blkcfg, config,VIRTIO_BLK_CFG_SIZE );
Here too, QEMU_BUILD_BUG_ON(VIRTIO_BLK_CFG_SIZE <= sizeof(blkcfg))
Quoted 15 lines
hw/block/virtio-blk.c +1
-2aio_context_acquire (blk_get_aio_context (s->blk));blk_set_enable_write_cache (s->blk, blkcfg.wce !=0 );@@ -952,8 +955,7 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp)return ; } -virtio_init (vdev,"virtio-blk" ,VIRTIO_ID_BLOCK , -sizeof (struct virtio_blk_config )); +virtio_init (vdev,"virtio-blk" ,VIRTIO_ID_BLOCK ,VIRTIO_BLK_CFG_SIZE ); s->blk = conf->conf.blk; s->rq =NULL ;Signature · 1 line
1.9.3
Quoted 20 lines
-----Original Message-----
From: Michael S. Tsirkin [mailto:[email protected]]
Sent: Tuesday, February 12, 2019 9:49 PM
To: Liu, Changpeng <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2] virtio-blk: set correct config size for the host driverQuoted 9 lines · Changpeng Liu
Commit
caa1ee43"vhost-user-blk: add discard/write zeroes features support" introduced extra fields to existing structvirtio_blk_config, when migration was executed from older QEMU version to current head, it will break the migration. While here, set the correct config size when initializing the host driver, for now, discard/write zeroes are not supported by virtio-blk host driver, so set the config size as before, users can change config size when adding the new feature bits support.
Quoted 5 lines
Quoted 1 line
Signed-off-by Changpeng Liu <[email protected]>Pls rewrite commit log as suggested in this thread and repost.
Thanks, repost a v3 patch to address the commit message and your following comments.
Quoted 67 lines
Quoted 10 lines
--- hw/block/virtio-blk.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)hw/block/virtio-blk.c +0
-0hw/block/virtio-blk.c line 31
Quoted 4 lines
hw/block/virtio-blk.c +1
-0@@ -28,6 +28,9 @@#include "hw/virtio/virtio-bus.h" #include "hw/virtio/virtio-access.h" +#define VIRTIO_BLK_CFG_SIZE (offsetof(struct virtio_blk_config, num_queues)+ \
hw/block/virtio-blk.c line 33
Quoted 2 lines
hw/block/virtio-blk.c +2
-0+ sizeof_field(struct virtio_blk_config, num_queues)) +I would just do
offsetof(max_discard_sectors)
with a comment "we don't support discard yet, hide associated config fields".hw/block/virtio-blk.c static void virtio_blk_update_config(VirtIODevice *vdev,
Quoted 4 lines
hw/block/virtio-blk.c +0
-0static void virtio_blk_init_request (VirtIOBlock *s,VirtQueue *vq,VirtIOBlockReq *req) {@@ -761,7 +764,7 @@ static void virtio_blk_update_config(VirtIODevice *vdev,
uint8_t*config)hw/block/virtio-blk.c static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config) · line 767
Quoted 5 lines
hw/block/virtio-blk.c +1
-1blkcfg.alignment_offset =0 ; blkcfg.wce =blk_enable_write_cache (s->blk);virtio_stw_p (vdev, &blkcfg.num_queues, s->conf.num_queues); -memcpy (config, &blkcfg,sizeof (struct virtio_blk_config )); +memcpy (config, &blkcfg,VIRTIO_BLK_CFG_SIZE );Let's add
QEMU_BUILD_BUG_ON(VIRTIO_BLK_CFG_SIZE <= sizeof(struct virtio_blk_config))just for documentation purposes.hw/block/virtio-blk.c static void virtio_blk_set_config(VirtIODevice *vdev,
Quoted 4 lines
hw/block/virtio-blk.c +0
-0}static void virtio_blk_set_config (VirtIODevice *vdev,const uint8_t *config)@@ -769,7 +772,7 @@ static void virtio_blk_set_config(VirtIODevice *vdev,const
uint8_t*config)hw/block/virtio-blk.c static void virtio_blk_set_config(VirtIODevice *vdev, const uint8_t *config) · line 775
Quoted 5 lines
hw/block/virtio-blk.c +1
-1VirtIOBlock *s =VIRTIO_BLK (vdev);struct virtio_blk_config blkcfg; -memcpy (&blkcfg, config,sizeof (blkcfg)); +memcpy (&blkcfg, config,VIRTIO_BLK_CFG_SIZE );Here too,
QEMU_BUILD_BUG_ON(VIRTIO_BLK_CFG_SIZE <= sizeof(blkcfg))hw/block/virtio-blk.c static void virtio_blk_device_realize(DeviceState *dev,
Quoted 4 lines
hw/block/virtio-blk.c +0
-0aio_context_acquire (blk_get_aio_context (s->blk));blk_set_enable_write_cache (s->blk, blkcfg.wce !=0 );@@ -952,8 +955,7 @@ static void virtio_blk_device_realize(DeviceState *dev,Error **errp)
Quoted 11 lines
hw/block/virtio-blk.c +1
-3return ; } -virtio_init (vdev,"virtio-blk" ,VIRTIO_ID_BLOCK , -sizeof (struct virtio_blk_config )); +virtio_init (vdev,"virtio-blk" ,VIRTIO_ID_BLOCK ,VIRTIO_BLK_CFG_SIZE ); s->blk = conf->conf.blk; s->rq =NULL ; --1.9.3