qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Aurelien Jarno <aurelien@aurel32.net>
To: qemu-devel@nongnu.org
Cc: Anthony Liguori <aliguori@us.ibm.com>
Subject: Re: [Qemu-devel] [PATCH 2/2] virtio-blk: fix cross-endianness targets
Date: Tue, 25 Jan 2011 09:07:44 +0100	[thread overview]
Message-ID: <20110125080744.GF23331@hall.aurel32.net> (raw)
In-Reply-To: <1295119664-25920-2-git-send-email-aurelien@aurel32.net>

On Sat, Jan 15, 2011 at 08:27:44PM +0100, Aurelien Jarno wrote:
> virtio-blk doesn't work on cross-endian configuration, as endianness is
> not handled correctly.
> 
> This patch adds missing endianness conversions to make virtio-blk
> working. Tested on the following configurations:
> - i386 guest on x86_64 host
> - ppc guest on x86_64 host
> - i386 guest on mips host
> - ppc guest on mips host
> 
> Cc: Anthony Liguori <aliguori@us.ibm.com>
> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
> ---
>  hw/virtio-blk.c |   40 +++++++++++++++++++++++++---------------
>  1 files changed, 25 insertions(+), 15 deletions(-)
> 
> diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
> index f62ccd1..9f2a9c0 100644
> --- a/hw/virtio-blk.c
> +++ b/hw/virtio-blk.c
> @@ -55,7 +55,7 @@ static void virtio_blk_req_complete(VirtIOBlockReq *req, int status)
>  
>      trace_virtio_blk_req_complete(req, status);
>  
> -    req->in->status = status;
> +    stb_p(&req->in->status, status);
>      virtqueue_push(s->vq, &req->elem, req->qiov.size + sizeof(*req->in));
>      virtio_notify(&s->vdev, s->vq);
>  
> @@ -94,7 +94,7 @@ static void virtio_blk_rw_complete(void *opaque, int ret)
>      trace_virtio_blk_rw_complete(req, ret);
>  
>      if (ret) {
> -        int is_read = !(req->out->type & VIRTIO_BLK_T_OUT);
> +        int is_read = !(ldl_p(&req->out->type) & VIRTIO_BLK_T_OUT);
>          if (virtio_blk_handle_rw_error(req, -ret, is_read))
>              return;
>      }
> @@ -223,10 +223,10 @@ static void virtio_blk_handle_scsi(VirtIOBlockReq *req)
>          status = VIRTIO_BLK_S_OK;
>      }
>  
> -    req->scsi->errors = hdr.status;
> -    req->scsi->residual = hdr.resid;
> -    req->scsi->sense_len = hdr.sb_len_wr;
> -    req->scsi->data_len = hdr.dxfer_len;
> +    stl_p(&req->scsi->errors, hdr.status);
> +    stl_p(&req->scsi->residual, hdr.resid);
> +    stl_p(&req->scsi->sense_len, hdr.sb_len_wr);
> +    stl_p(&req->scsi->data_len, hdr.dxfer_len);
>  
>      virtio_blk_req_complete(req, status);
>  }
> @@ -280,10 +280,13 @@ static void virtio_blk_handle_flush(VirtIOBlockReq *req, MultiReqBuffer *mrb)
>  static void virtio_blk_handle_write(VirtIOBlockReq *req, MultiReqBuffer *mrb)
>  {
>      BlockRequest *blkreq;
> +    uint64_t sector;
>  
> -    trace_virtio_blk_handle_write(req, req->out->sector, req->qiov.size / 512);
> +    sector = ldq_p(&req->out->sector);
>  
> -    if (req->out->sector & req->dev->sector_mask) {
> +    trace_virtio_blk_handle_write(req, sector, req->qiov.size / 512);
> +
> +    if (sector & req->dev->sector_mask) {
>          virtio_blk_rw_complete(req, -EIO);
>          return;
>      }
> @@ -293,7 +296,7 @@ static void virtio_blk_handle_write(VirtIOBlockReq *req, MultiReqBuffer *mrb)
>      }
>  
>      blkreq = &mrb->blkreq[mrb->num_writes];
> -    blkreq->sector = req->out->sector;
> +    blkreq->sector = sector;
>      blkreq->nb_sectors = req->qiov.size / BDRV_SECTOR_SIZE;
>      blkreq->qiov = &req->qiov;
>      blkreq->cb = virtio_blk_rw_complete;
> @@ -306,13 +309,16 @@ static void virtio_blk_handle_write(VirtIOBlockReq *req, MultiReqBuffer *mrb)
>  static void virtio_blk_handle_read(VirtIOBlockReq *req)
>  {
>      BlockDriverAIOCB *acb;
> +    uint64_t sector;
> +
> +    sector = ldq_p(&req->out->sector);
>  
> -    if (req->out->sector & req->dev->sector_mask) {
> +    if (sector & req->dev->sector_mask) {
>          virtio_blk_rw_complete(req, -EIO);
>          return;
>      }
>  
> -    acb = bdrv_aio_readv(req->dev->bs, req->out->sector, &req->qiov,
> +    acb = bdrv_aio_readv(req->dev->bs, sector, &req->qiov,
>                           req->qiov.size / BDRV_SECTOR_SIZE,
>                           virtio_blk_rw_complete, req);
>      if (!acb) {
> @@ -323,6 +329,8 @@ static void virtio_blk_handle_read(VirtIOBlockReq *req)
>  static void virtio_blk_handle_request(VirtIOBlockReq *req,
>      MultiReqBuffer *mrb)
>  {
> +    uint32_t type;
> +
>      if (req->elem.out_num < 1 || req->elem.in_num < 1) {
>          error_report("virtio-blk missing headers");
>          exit(1);
> @@ -337,17 +345,19 @@ static void virtio_blk_handle_request(VirtIOBlockReq *req,
>      req->out = (void *)req->elem.out_sg[0].iov_base;
>      req->in = (void *)req->elem.in_sg[req->elem.in_num - 1].iov_base;
>  
> -    if (req->out->type & VIRTIO_BLK_T_FLUSH) {
> +    type = ldl_p(&req->out->type);
> +
> +    if (type & VIRTIO_BLK_T_FLUSH) {
>          virtio_blk_handle_flush(req, mrb);
> -    } else if (req->out->type & VIRTIO_BLK_T_SCSI_CMD) {
> +    } else if (type & VIRTIO_BLK_T_SCSI_CMD) {
>          virtio_blk_handle_scsi(req);
> -    } else if (req->out->type & VIRTIO_BLK_T_GET_ID) {
> +    } else if (type & VIRTIO_BLK_T_GET_ID) {
>          VirtIOBlock *s = req->dev;
>  
>          memcpy(req->elem.in_sg[0].iov_base, s->sn,
>                 MIN(req->elem.in_sg[0].iov_len, sizeof(s->sn)));
>          virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
> -    } else if (req->out->type & VIRTIO_BLK_T_OUT) {
> +    } else if (type & VIRTIO_BLK_T_OUT) {
>          qemu_iovec_init_external(&req->qiov, &req->elem.out_sg[1],
>                                   req->elem.out_num - 1);
>          virtio_blk_handle_write(req, mrb);
> -- 
> 1.7.2.3
> 

Ping?

-- 
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
aurelien@aurel32.net                 http://www.aurel32.net

  reply	other threads:[~2011-01-25  8:08 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-15 19:27 [Qemu-devel] [PATCH 1/2] virtio-net: fix cross-endianness support Aurelien Jarno
2011-01-15 19:27 ` [Qemu-devel] [PATCH 2/2] virtio-blk: fix cross-endianness targets Aurelien Jarno
2011-01-25  8:07   ` Aurelien Jarno [this message]
2011-01-25  9:58   ` Stefan Hajnoczi
2011-01-25  8:07 ` [Qemu-devel] [PATCH 1/2] virtio-net: fix cross-endianness support Aurelien Jarno
2011-02-28  8:43 ` Liu Yu-B13201
2011-03-03 19:16   ` Aurelien Jarno
2011-03-03 19:50     ` Stefan Hajnoczi
2011-03-03 20:51       ` Aurelien Jarno
2011-03-03 21:42         ` [Qemu-devel] [PATCH] virtio-net: Fix lduw_p() pointer argument of wrong size Stefan Hajnoczi
2011-03-03 22:45           ` [Qemu-devel] " Aurelien Jarno
2011-03-04  6:41             ` [Qemu-devel] " Liu Yu-B13201

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=20110125080744.GF23331@hall.aurel32.net \
    --to=aurelien@aurel32.net \
    --cc=aliguori@us.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).