From: Roman Kagan Date: Thu, 28 May 2020 22:55:09 +0000 (+0300) Subject: virtio-blk: store opt_io_size with correct size X-Git-Tag: v5.1.0-rc0~64^2~13 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6abee2608563599f783bf1305a8322ee7b447815;p=thirdparty%2Fqemu.git virtio-blk: store opt_io_size with correct size The width of opt_io_size in virtio_blk_config is 32bit. However, it's written with virtio_stw_p; this may result in value truncation, and on big-endian systems with legacy virtio in completely bogus readings in the guest. Use the appropriate accessor to store it. Signed-off-by: Roman Kagan Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Kevin Wolf Message-Id: <20200528225516.1676602-2-rvkagan@yandex-team.ru> Signed-off-by: Kevin Wolf --- diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 8882a1d1d42..6938a75aa52 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -930,7 +930,7 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config) virtio_stw_p(vdev, &blkcfg.geometry.cylinders, conf->cyls); virtio_stl_p(vdev, &blkcfg.blk_size, blk_size); virtio_stw_p(vdev, &blkcfg.min_io_size, conf->min_io_size / blk_size); - virtio_stw_p(vdev, &blkcfg.opt_io_size, conf->opt_io_size / blk_size); + virtio_stl_p(vdev, &blkcfg.opt_io_size, conf->opt_io_size / blk_size); blkcfg.geometry.heads = conf->heads; /* * We must ensure that the block device capacity is a multiple of