From: Cornelia Huck <cornelia.huck@de.ibm.com>
To: Greg Kurz <gkurz@linux.vnet.ibm.com>
Cc: Pierre Morel <pmorel@linux.vnet.ibm.com>,
qemu-devel@nongnu.org, stefanha@redhat.com, mst@redhat.com
Subject: Re: [Qemu-devel] [PATCH] virtio: right size for virtio_queue_get_avail_size
Date: Thu, 3 Sep 2015 11:10:06 +0200 [thread overview]
Message-ID: <20150903111006.24257f19.cornelia.huck@de.ibm.com> (raw)
In-Reply-To: <20150903102344.3c903794@bahia.local>
On Thu, 3 Sep 2015 10:23:44 +0200
Greg Kurz <gkurz@linux.vnet.ibm.com> wrote:
> On Wed, 2 Sep 2015 19:57:25 +0200
> Greg Kurz <gkurz@linux.vnet.ibm.com> wrote:
>
> > On Wed, 2 Sep 2015 17:50:55 +0200
> > Cornelia Huck <cornelia.huck@de.ibm.com> wrote:
> >
> > > On Wed, 2 Sep 2015 17:23:49 +0200
> > > Pierre Morel <pmorel@linux.vnet.ibm.com> wrote:
> > >
> > > > Being working on dataplane I notice something strange:
> > > >
> > > > virtio_queue_get_avail_size() used a 64bit size index
> > > > for the calculation of the available ring size.
> > > >
> > > > It is quite strange but it did work with the old calculation
> > > > of the avail ring, at most with performance penalty,
> > > > and I wonder where I missed something.
> > > >
> > > > This patch let use a 16bit size as defined in virtio_ring.h
> > > >
> > > > Signed-off-by: Pierre Morel <pmorel@linux.vnet.ibm.com>
> > > > ---
> > > > hw/virtio/virtio.c | 2 +-
> > > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > > >
> > > > diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> > > > index 788b556..5c856eb 100644
> > > > --- a/hw/virtio/virtio.c
> > > > +++ b/hw/virtio/virtio.c
> > > > @@ -1460,7 +1460,7 @@ hwaddr virtio_queue_get_desc_size(VirtIODevice *vdev, int n)
> > > > hwaddr virtio_queue_get_avail_size(VirtIODevice *vdev, int n)
> > > > {
> > > > return offsetof(VRingAvail, ring) +
> > > > - sizeof(uint64_t) * vdev->vq[n].vring.num;
> > > > + sizeof(uint16_t) * vdev->vq[n].vring.num;
> > > > }
> > > >
> > > > hwaddr virtio_queue_get_used_size(VirtIODevice *vdev, int n)
> > >
> > > I'm wondering about the semantics of the _size() functions. Naively I
> > > would expect (size of buffer) * (number of buffers). I think at least
> >
> > Looking at where these functions are called, it really looks like they are
> > expected to return the size of the memory region to be mapped. Since we have:
> >
>
> Acutally no... they are also used to compute the address of used_event_idx
> and avail_event_idx.
>
> > typedef struct VRingAvail
> > {
> > uint16_t flags;
> > uint16_t idx;
> > uint16_t ring[0];
> > } VRingAvail;
> >
> > Pierre's patch looks valid. But while we're here, why not introducing
> > something like:
> >
> > #define member_size(type, member) sizeof(((type *)0)->member)
> >
> > It would consolidate the _size functions and the types they are referring to:
> >
> > - sizeof(uint64_t) * vdev->vq[n].vring.num;
> > + member_size(VRingAvail, vring[0]) * vdev->vq[n].vring.num;
> >
> > > vhost expects the {used,avail} indices in there as well? The
> > > s390-virtio code seems not to expect the indices to be contained in the
> > > size, though...
> >
> >
>
> Sorry I missed the real question... should these _size functions return
> the actual size + sizeof(uint16_t) ?
>
> Indeed, I could verify the the s390-virtio code uses the _size functions
> to compute the address of used_event_idx and avail_event_idx...
> The vhost code only uses the _size functions to map memory... and
> doesn't add sizeof(uint16_t)... which looks like a bug.
Yes, this probably worked by chance because (a) the avail size is too
big anyway and (b) the used size added the offset value... and probably
nobody cares much about s390-virtio reset, but that might explain some
headscratchers we were seeing very occasionally.
next prev parent reply other threads:[~2015-09-03 9:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-02 15:23 [Qemu-devel] [PATCH] virtio: right size for virtio_queue_get_avail_size Pierre Morel
2015-09-02 15:50 ` Cornelia Huck
2015-09-02 17:57 ` Greg Kurz
2015-09-03 8:23 ` Greg Kurz
2015-09-03 9:10 ` Cornelia Huck [this message]
-- strict thread matches above, loose matches on Subject: below --
2015-09-10 11:37 Pierre Morel
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=20150903111006.24257f19.cornelia.huck@de.ibm.com \
--to=cornelia.huck@de.ibm.com \
--cc=gkurz@linux.vnet.ibm.com \
--cc=mst@redhat.com \
--cc=pmorel@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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).