All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] virtio-balloon: stats vq migration spec compliance
@ 2016-08-15 21:32 Michael S. Tsirkin
  2016-08-16  7:31 ` Ladi Prosek
  2016-08-16 10:30 ` Stefan Hajnoczi
  0 siblings, 2 replies; 4+ messages in thread
From: Michael S. Tsirkin @ 2016-08-15 21:32 UTC (permalink / raw)
  To: qemu-devel; +Cc: Ladi Prosek

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 <lprosek@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 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);
-- 
MST

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] virtio-balloon: stats vq migration spec compliance
  2016-08-15 21:32 [Qemu-devel] [PATCH] virtio-balloon: stats vq migration spec compliance Michael S. Tsirkin
@ 2016-08-16  7:31 ` Ladi Prosek
  2016-08-16 10:30 ` Stefan Hajnoczi
  1 sibling, 0 replies; 4+ messages in thread
From: Ladi Prosek @ 2016-08-16  7:31 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: qemu-devel

On Mon, Aug 15, 2016 at 11:32 PM, Michael S. Tsirkin <mst@redhat.com> 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 <lprosek@redhat.com>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

Looks good! Do you want me to add this to the patch that introduces
virtio_balloon_vmstate_cb or will you apply it on top of it?

Thanks,
Ladi

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] virtio-balloon: stats vq migration spec compliance
  2016-08-15 21:32 [Qemu-devel] [PATCH] virtio-balloon: stats vq migration spec compliance Michael S. Tsirkin
  2016-08-16  7:31 ` Ladi Prosek
@ 2016-08-16 10:30 ` Stefan Hajnoczi
  2016-08-23 19:12   ` Michael S. Tsirkin
  1 sibling, 1 reply; 4+ messages in thread
From: Stefan Hajnoczi @ 2016-08-16 10:30 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: qemu-devel, Ladi Prosek

[-- Attachment #1: Type: text/plain, Size: 1854 bytes --]

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 <lprosek@redhat.com>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>  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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] virtio-balloon: stats vq migration spec compliance
  2016-08-16 10:30 ` Stefan Hajnoczi
@ 2016-08-23 19:12   ` Michael S. Tsirkin
  0 siblings, 0 replies; 4+ messages in thread
From: Michael S. Tsirkin @ 2016-08-23 19:12 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: qemu-devel, 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 <lprosek@redhat.com>
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> >  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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-08-23 19:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-15 21:32 [Qemu-devel] [PATCH] virtio-balloon: stats vq migration spec compliance Michael S. Tsirkin
2016-08-16  7:31 ` Ladi Prosek
2016-08-16 10:30 ` Stefan Hajnoczi
2016-08-23 19:12   ` Michael S. Tsirkin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.