From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33536) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcH7e-0002Ls-9J for qemu-devel@nongnu.org; Tue, 23 Aug 2016 15:12:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bcH7a-0005o5-0y for qemu-devel@nongnu.org; Tue, 23 Aug 2016 15:12:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39496) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcH7Z-0005nu-Rb for qemu-devel@nongnu.org; Tue, 23 Aug 2016 15:12:25 -0400 Date: Tue, 23 Aug 2016 22:12:23 +0300 From: "Michael S. Tsirkin" Message-ID: <20160823221159-mutt-send-email-mst@kernel.org> References: <1471296770-7984-1-git-send-email-mst@redhat.com> <20160816103016.GB8157@stefanha-x1.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160816103016.GB8157@stefanha-x1.localdomain> Subject: Re: [Qemu-devel] [PATCH] virtio-balloon: stats vq migration spec compliance List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: qemu-devel@nongnu.org, Ladi Prosek On Tue, Aug 16, 2016 at 11:30:16AM +0100, Stefan Hajnoczi wrote: > On Tue, Aug 16, 2016 at 12:32:55AM +0300, Michael S. Tsirkin wrote: > > virtio spec says that devices must not touch VQs > > before DRIVER_OK is set. > > > > Additionally, balloon must not touch stats VQ > > unless the stats feature bit has been negotiated. > > > > Cc: Ladi Prosek > > Signed-off-by: Michael S. Tsirkin > > --- > > hw/virtio/virtio-balloon.c | 4 +++- > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c > > index 65457e9..7189260 100644 > > --- a/hw/virtio/virtio-balloon.c > > +++ b/hw/virtio/virtio-balloon.c > > @@ -427,6 +427,7 @@ static void virtio_balloon_vmstate_cb(void *opaque, int running, > > RunState state) > > { > > VirtIOBalloon *s = opaque; > > + VirtIODevice *vdev = VIRTIO_DEVICE(s); > > > > if (!running) { > > /* put the stats element back if the VM is not running */ > > @@ -436,7 +437,8 @@ static void virtio_balloon_vmstate_cb(void *opaque, int running, > > s->stats_vq_elem = NULL; > > } > > > > - } else { > > + } else if (balloon_stats_supported(s) && > > + (vdev->status & VIRTIO_CONFIG_S_DRIVER_OK)) { > > /* poll stats queue for the element we may have discarded > > * when the VM was stopped */ > > virtio_balloon_receive_stats(VIRTIO_DEVICE(s), s->svq); > > Another suspect case is when the feature bit was negotiated, > VIRTIO_CONFIG_S_DRIVER_OK is set, but the virtqueue PFN wasn't set up. > > In that case virtqueue_pop() will access junk values. > > I'm not sure if anything terrible can happen but a check that > vq->vring.desc != 0 would be nice - just like we do in > virtio_queue_notify_vq(). > > Can you add a virtio_queue_get_addr() call to see if the PFN has been > set? > > Stefan DRIVER_OK is set after VQs are initialized so I think that's enough.