qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Cornelia Huck <cornelia.huck@de.ibm.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>,
	qemu-devel@nongnu.org, Anthony Liguori <aliguori@amazon.com>,
	virtualization@lists.linux-foundation.org
Subject: Re: [Qemu-devel] [PATCH 2/2] virtio-balloon: virtio 1 support
Date: Mon, 13 Apr 2015 13:26:31 +0200	[thread overview]
Message-ID: <20150413132110-mutt-send-email-mst@redhat.com> (raw)
In-Reply-To: <20150413100258.1f2c636f.cornelia.huck@de.ibm.com>

On Mon, Apr 13, 2015 at 10:02:58AM +0200, Cornelia Huck wrote:
> On Sun, 12 Apr 2015 17:00:48 +0200
> "Michael S. Tsirkin" <mst@redhat.com> wrote:
> 
> > Virtio 1.0 doesn't include a modern balloon device.  At some point we'll
> > likely define an incompatible interface with a different ID and
> > different semantics.  But for now, it's not a big effort to support a
> > transitional balloon device: this has the advantage of supporting
> > existing drivers, transparently, as well as transports that don't allow
> > mixing virtio 0 and virtio 1 devices. And balloon is an easy device to
> > test, so it's also useful for people to test virtio core handling of
> > transitional devices.
> > 
> > The only interface issue is with the stats buffer, which has misaligned
> > fields. We could leave it as is, but this sets a bad precedent that
> > others might copy by mistake.
> > 
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> >  hw/virtio/virtio-balloon.c | 31 +++++++++++++++++++++++--------
> >  1 file changed, 23 insertions(+), 8 deletions(-)
> > 
> > diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
> > index d2d7c3e..568a008 100644
> > --- a/hw/virtio/virtio-balloon.c
> > +++ b/hw/virtio/virtio-balloon.c
> > @@ -239,7 +239,8 @@ static void virtio_balloon_receive_stats(VirtIODevice *vdev, VirtQueue *vq)
> >  {
> >      VirtIOBalloon *s = VIRTIO_BALLOON(vdev);
> >      VirtQueueElement *elem = &s->stats_vq_elem;
> > -    VirtIOBalloonStat stat;
> > +    VirtIOBalloonStat legacy_stat;
> > +    VirtIOBalloonStatModern modern_stat;
> >      size_t offset = 0;
> >      qemu_timeval tv;
> > 
> > @@ -253,14 +254,28 @@ static void virtio_balloon_receive_stats(VirtIODevice *vdev, VirtQueue *vq)
> >       */
> >      reset_stats(s);
> > 
> > -    while (iov_to_buf(elem->out_sg, elem->out_num, offset, &stat, sizeof(stat))
> > -           == sizeof(stat)) {
> > -        uint16_t tag = virtio_tswap16(vdev, stat.tag);
> > -        uint64_t val = virtio_tswap64(vdev, stat.val);
> > +    if (virtio_has_feature(vdev, VIRTIO_F_VERSION_1)) {
> > +        while (iov_to_buf(elem->out_sg, elem->out_num, offset,
> > +                          &modern_stat, sizeof(modern_stat))
> > +               == sizeof(modern_stat)) {
> > +            uint16_t tag = le16_to_cpu(modern_stat.tag);
> > +            uint64_t val = le64_to_cpu(modern_stat.val);
> > 
> > -        offset += sizeof(stat);
> > -        if (tag < VIRTIO_BALLOON_S_NR)
> > -            s->stats[tag] = val;
> > +            offset += sizeof(modern_stat);
> > +            if (tag < VIRTIO_BALLOON_S_NR)
> > +                s->stats[tag] = val;
> > +        }
> > +    } else {
> > +        while (iov_to_buf(elem->out_sg, elem->out_num, offset,
> > +                          &legacy_stat, sizeof(legacy_stat))
> > +               == sizeof(legacy_stat)) {
> > +            uint16_t tag = virtio_tswap16(vdev, legacy_stat.tag);
> > +            uint64_t val = virtio_tswap64(vdev, legacy_stat.val);
> > +
> > +            offset += sizeof(legacy_stat);
> > +            if (tag < VIRTIO_BALLOON_S_NR)
> > +                s->stats[tag] = val;
> > +        }
> >      }
> >      s->stats_vq_offset = offset;
> > 
> 
> I'm still not really convinced that changing the stat structure is an
> improvement.

The point is to avoid setting bad precedent for virtio 1 devices.
It does have a bit of cost for transitional devices.

> Without that, you wouldn't need the above change at all,
> would you?

I think so, yes. BTW I suspect the stats code is broken for
cross-endian platforms: it should do LE unconditinally,
should it not?


> Also, doesn't get_features need to be modified as well so that
> VERSION_1 is advertised?

virtio_pci_device_plugged seems to set it ATM. I'll re-test to confirm.

-- 
MST

  reply	other threads:[~2015-04-13 11:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-12 15:00 [Qemu-devel] [PATCH 1/2] virtio_balloon: header update for virtio 1 Michael S. Tsirkin
2015-04-12 15:00 ` [Qemu-devel] [PATCH 2/2] virtio-balloon: virtio 1 support Michael S. Tsirkin
2015-04-13  8:02   ` Cornelia Huck
2015-04-13 11:26     ` Michael S. Tsirkin [this message]
2015-04-13 11:35       ` Cornelia Huck
2015-04-13 11:49         ` Michael S. Tsirkin
2015-04-13 12:15           ` Cornelia Huck
2015-04-13 14:20       ` Cornelia Huck

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=20150413132110-mutt-send-email-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=aliguori@amazon.com \
    --cc=cornelia.huck@de.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rusty@rustcorp.com.au \
    --cc=virtualization@lists.linux-foundation.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).