Patchwork virtio-blk: fix cross-endian config space

login
register
mail settings
Submitter Paolo Bonzini
Date Nov. 15, 2011, 11:07 a.m.
Message ID <1321355273-6139-1-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/125745/
State New
Headers show

Comments

Paolo Bonzini - Nov. 15, 2011, 11:07 a.m.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/virtio-blk.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
Stefan Hajnoczi - Nov. 15, 2011, 12:17 p.m.
On Tue, Nov 15, 2011 at 12:07:53PM +0100, Paolo Bonzini wrote:
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  hw/virtio-blk.c |    6 +++---
>  1 files changed, 3 insertions(+), 3 deletions(-)

Works with existing x86 guests and does the right thing for big-endian
guests.

Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Kevin Wolf - Nov. 18, 2011, 12:51 p.m.
Am 15.11.2011 12:07, schrieb Paolo Bonzini:
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  hw/virtio-blk.c |    6 +++---
>  1 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
> index 01aeb28..4a15f0c 100644
> --- a/hw/virtio-blk.c
> +++ b/hw/virtio-blk.c
> @@ -481,14 +481,14 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
>      stq_raw(&blkcfg.capacity, capacity);
>      stl_raw(&blkcfg.seg_max, 128 - 2);
>      stw_raw(&blkcfg.cylinders, cylinders);
> +    stl_raw(&blkcfg.blk_size, s->conf->logical_block_size);
> +    stw_raw(&blkcfg.min_io_size, s->conf->min_io_size / blkcfg.blk_size);
> +    stw_raw(&blkcfg.opt_io_size, s->conf->opt_io_size / blkcfg.blk_size);

blkcfg.blk_size is in target endianness now, so you can't use it in the
calculation for min/opt_io_size any more.

Kevin

Patch

diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 01aeb28..4a15f0c 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -481,14 +481,14 @@  static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
     stq_raw(&blkcfg.capacity, capacity);
     stl_raw(&blkcfg.seg_max, 128 - 2);
     stw_raw(&blkcfg.cylinders, cylinders);
+    stl_raw(&blkcfg.blk_size, s->conf->logical_block_size);
+    stw_raw(&blkcfg.min_io_size, s->conf->min_io_size / blkcfg.blk_size);
+    stw_raw(&blkcfg.opt_io_size, s->conf->opt_io_size / blkcfg.blk_size);
     blkcfg.heads = heads;
     blkcfg.sectors = secs & ~s->sector_mask;
-    blkcfg.blk_size = s->conf->logical_block_size;
     blkcfg.size_max = 0;
     blkcfg.physical_block_exp = get_physical_block_exp(s->conf);
     blkcfg.alignment_offset = 0;
-    blkcfg.min_io_size = s->conf->min_io_size / blkcfg.blk_size;
-    blkcfg.opt_io_size = s->conf->opt_io_size / blkcfg.blk_size;
     memcpy(config, &blkcfg, sizeof(struct virtio_blk_config));
 }