qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 3/3] dataplane: handle misaligned virtio-blk requests
Date: Fri, 11 Jan 2013 15:38:07 +0100	[thread overview]
Message-ID: <20130111143807.GA2310@stefanha-thinkpad.muc.redhat.com> (raw)
In-Reply-To: <50F0080C.9010908@redhat.com>

On Fri, Jan 11, 2013 at 01:39:40PM +0100, Kevin Wolf wrote:
> Am 10.01.2013 17:48, schrieb Stefan Hajnoczi:
> > O_DIRECT on Linux has alignment requirements on I/O buffers and
> > misaligned requests result in -EINVAL.  The Linux virtio_blk guest
> > driver usually submits aligned requests so I forgot to handle misaligned
> > requests.
> > 
> > It turns out that virtio-win guest drivers submit misaligned requests.
> > Handle them using a bounce buffer that meets alignment requirements.
> > 
> > Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> > ---
> >  hw/dataplane/virtio-blk.c | 36 ++++++++++++++++++++++++++++++++++++
> >  1 file changed, 36 insertions(+)
> > 
> > diff --git a/hw/dataplane/virtio-blk.c b/hw/dataplane/virtio-blk.c
> > index a6696b8..991ab5f 100644
> > --- a/hw/dataplane/virtio-blk.c
> > +++ b/hw/dataplane/virtio-blk.c
> > @@ -34,6 +34,8 @@ typedef struct {
> >      struct iocb iocb;               /* Linux AIO control block */
> >      QEMUIOVector *inhdr;            /* iovecs for virtio_blk_inhdr */
> >      unsigned int head;              /* vring descriptor index */
> > +    void *bounce_buffer;            /* used if guest buffers are unaligned */
> > +    QEMUIOVector *read_qiov;        /* for read completion /w bounce buffer */
> >  } VirtIOBlockRequest;
> >  
> >  struct VirtIOBlockDataPlane {
> > @@ -89,6 +91,15 @@ static void complete_request(struct iocb *iocb, ssize_t ret, void *opaque)
> >  
> >      trace_virtio_blk_data_plane_complete_request(s, req->head, ret);
> >  
> > +    if (req->read_qiov) {
> > +        assert(req->bounce_buffer);
> > +        qemu_iovec_to_buf(req->read_qiov, 0, req->bounce_buffer, len);
> 
> Shouldn't it be qemu_iovec_from_buf()?
> 
> Makes me wonder if qtest cases might be doable...
> 
> > +        qemu_iovec_destroy(req->read_qiov);
> > +        g_slice_free(QEMUIOVector, req->read_qiov);
> > +    }
> > +
> > +    qemu_vfree(req->bounce_buffer);
> > +
> >      qemu_iovec_from_buf(req->inhdr, 0, &hdr, sizeof(hdr));
> >      qemu_iovec_destroy(req->inhdr);
> >      g_slice_free(QEMUIOVector, req->inhdr);
> > @@ -136,6 +147,29 @@ static int do_rdwr_cmd(VirtIOBlockDataPlane *s, bool read,
> >                         QEMUIOVector *inhdr)
> >  {
> >      struct iocb *iocb;
> > +    QEMUIOVector qiov;
> > +    struct iovec bounce_iov;
> > +    void *bounce_buffer = NULL;
> > +    QEMUIOVector *read_qiov = NULL;
> > +
> > +    qemu_iovec_init_external(&qiov, iov, iov_cnt);
> > +    if (!bdrv_qiov_is_aligned(s->blk->conf.bs, &qiov)) {
> > +        /* Redirect I/O to aligned bounce buffer */
> > +        bounce_buffer = qemu_blockalign(s->blk->conf.bs, qiov.size);
> > +        bounce_iov.iov_base = bounce_buffer;
> > +        bounce_iov.iov_len = qiov.size;
> > +        iov = &bounce_iov;
> > +        iov_cnt = 1;
> > +
> > +        if (read) {
> > +            /* Need to copy back from bounce buffer on completion */
> > +            read_qiov = g_slice_new(QEMUIOVector);
> > +            qemu_iovec_init(read_qiov, iov_cnt);
> > +            qemu_iovec_concat_iov(read_qiov, iov, iov_cnt, 0, qiov.size);
> 
> This would have to be the original iov and iov_cnt, but they are already
> overwritten here.

Good point.  What's really weird is that I tested this with a Windows
guest - probably the buffer cache fooled me so I didn't notice read was
completely broken.

Stefan

  parent reply	other threads:[~2013-01-11 14:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-10 16:48 [Qemu-devel] [PATCH 0/3] dataplane: misaligned buffers support for Windows guests Stefan Hajnoczi
2013-01-10 16:48 ` [Qemu-devel] [PATCH 1/3] block: make qiov_is_aligned() public Stefan Hajnoczi
2013-01-10 16:48 ` [Qemu-devel] [PATCH 2/3] dataplane: extract virtio-blk read/write processing into do_rdwr_cmd() Stefan Hajnoczi
2013-01-10 16:48 ` [Qemu-devel] [PATCH 3/3] dataplane: handle misaligned virtio-blk requests Stefan Hajnoczi
2013-01-11 12:39   ` Kevin Wolf
2013-01-11 13:27     ` Paolo Bonzini
2013-01-11 15:44       ` [Qemu-devel] libqos - was: " Andreas Färber
2013-01-11 16:25         ` Paolo Bonzini
2013-01-11 14:38     ` Stefan Hajnoczi [this message]
2013-01-11 12:43 ` [Qemu-devel] [PATCH 0/3] dataplane: misaligned buffers support for Windows guests Kevin Wolf

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=20130111143807.GA2310@stefanha-thinkpad.muc.redhat.com \
    --to=stefanha@redhat.com \
    --cc=kwolf@redhat.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).