All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/2] virtio-rng: fix old guest kernel hang
@ 2018-06-27  8:22 Pankaj Gupta
  2018-06-27  8:22 ` [Qemu-devel] [PATCH 1/2] virtio-rng: process pending requests when driver is ready Pankaj Gupta
  2018-06-27  8:22 ` [Qemu-devel] [PATCH 2/2] virtio: Set status early in VirtIODevice parent object Pankaj Gupta
  0 siblings, 2 replies; 5+ messages in thread
From: Pankaj Gupta @ 2018-06-27  8:22 UTC (permalink / raw)
  To: mst, amit, qemu-devel; +Cc: stefanha, slopezpa

 virtio-rng device causing old guest kernels(2.6.32) to hang on latest qemu.
 The driver attempts to read from the virtio-rng device too early in it's
 initialization. Qemu detects guest is not ready and returns, resulting in
 hang. Below patches fix this.


Stefan Hajnoczi(1):
  virtio-rng: process pending requests when driver is ready

Pankaj Gupta(1):
  virtio: Set status early in VirtIODevice parent object

 virtio-rng.c |   13 +++++++++++++
 virtio.c     |    3 ++-
 2 files changed, 15 insertions(+), 1 deletion(-)

-- 
2.14.3

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

* [Qemu-devel] [PATCH 1/2] virtio-rng: process pending requests when driver is ready
  2018-06-27  8:22 [Qemu-devel] [PATCH 0/2] virtio-rng: fix old guest kernel hang Pankaj Gupta
@ 2018-06-27  8:22 ` Pankaj Gupta
  2018-06-27  8:22 ` [Qemu-devel] [PATCH 2/2] virtio: Set status early in VirtIODevice parent object Pankaj Gupta
  1 sibling, 0 replies; 5+ messages in thread
From: Pankaj Gupta @ 2018-06-27  8:22 UTC (permalink / raw)
  To: mst, amit, qemu-devel; +Cc: stefanha, slopezpa

 virtio-rng device causing old guest kernels(2.6.32) to hang on latest qemu.
 The driver attempts to read from the virtio-rng device too early in it's
 initialization. Qemu detects guest is not ready and returns, resulting in
 hang.

 Fix is to handle pending request when guest is running and driver status is 
 set to 'VIRTIO_CONFIG_S_DRIVER_OK'.

Reported-by: Sergio lopez <slopezpa@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 hw/virtio/virtio-rng.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/hw/virtio/virtio-rng.c b/hw/virtio/virtio-rng.c
index 289bbcac03..49e2d0c10a 100644
--- a/hw/virtio/virtio-rng.c
+++ b/hw/virtio/virtio-rng.c
@@ -156,6 +156,18 @@ static void check_rate_limit(void *opaque)
     vrng->activate_timer = true;
 }
 
+static void virtio_rng_set_status(VirtIODevice *vdev, uint8_t status)
+{
+    VirtIORNG *vrng = VIRTIO_RNG(vdev);
+
+    if (!vdev->vm_running) {
+        return;
+    }
+
+    /* Something changed, try to process buffers */
+    virtio_rng_process(vrng);
+}
+
 static void virtio_rng_device_realize(DeviceState *dev, Error **errp)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
@@ -261,6 +273,7 @@ static void virtio_rng_class_init(ObjectClass *klass, void *data)
     vdc->realize = virtio_rng_device_realize;
     vdc->unrealize = virtio_rng_device_unrealize;
     vdc->get_features = get_features;
+    vdc->set_status = virtio_rng_set_status;
 }
 
 static const TypeInfo virtio_rng_info = {
-- 
2.14.3

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

* [Qemu-devel] [PATCH 2/2] virtio: Set status early in VirtIODevice parent object
  2018-06-27  8:22 [Qemu-devel] [PATCH 0/2] virtio-rng: fix old guest kernel hang Pankaj Gupta
  2018-06-27  8:22 ` [Qemu-devel] [PATCH 1/2] virtio-rng: process pending requests when driver is ready Pankaj Gupta
@ 2018-06-27  8:22 ` Pankaj Gupta
  2018-06-27 10:21   ` Stefan Hajnoczi
  1 sibling, 1 reply; 5+ messages in thread
From: Pankaj Gupta @ 2018-06-27  8:22 UTC (permalink / raw)
  To: mst, amit, qemu-devel; +Cc: stefanha, slopezpa

 To process pending requests for driver status 'VIRTIO_CONFIG_S_DRIVER_OK',
 virtio-rng 'set_status' calls 'is_guest_ready' function. This checks if 
 virtqueue is ready and status is set to 'VIRTIO_CONFIG_S_DRIVER_OK'. 

 This call is made before new status is updated in VirtIODevice parent object 
 and calling function uses old status value.

Signed-off-by: Pankaj Gupta <pagupta@redhat.com>
---
 hw/virtio/virtio.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index d4e4d98b59..37dc59a686 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -1154,10 +1154,11 @@ int virtio_set_status(VirtIODevice *vdev, uint8_t val)
             }
         }
     }
+    vdev->status = val;
+
     if (k->set_status) {
         k->set_status(vdev, val);
     }
-    vdev->status = val;
     return 0;
 }
 
-- 
2.14.3

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

* Re: [Qemu-devel] [PATCH 2/2] virtio: Set status early in VirtIODevice parent object
  2018-06-27  8:22 ` [Qemu-devel] [PATCH 2/2] virtio: Set status early in VirtIODevice parent object Pankaj Gupta
@ 2018-06-27 10:21   ` Stefan Hajnoczi
  2018-06-27 11:06     ` Pankaj Gupta
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Hajnoczi @ 2018-06-27 10:21 UTC (permalink / raw)
  To: Pankaj Gupta; +Cc: mst, amit, qemu-devel, slopezpa

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

On Wed, Jun 27, 2018 at 01:52:48PM +0530, Pankaj Gupta wrote:
>  To process pending requests for driver status 'VIRTIO_CONFIG_S_DRIVER_OK',
>  virtio-rng 'set_status' calls 'is_guest_ready' function. This checks if 
>  virtqueue is ready and status is set to 'VIRTIO_CONFIG_S_DRIVER_OK'. 
> 
>  This call is made before new status is updated in VirtIODevice parent object 
>  and calling function uses old status value.
> 
> Signed-off-by: Pankaj Gupta <pagupta@redhat.com>
> ---
>  hw/virtio/virtio.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index d4e4d98b59..37dc59a686 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -1154,10 +1154,11 @@ int virtio_set_status(VirtIODevice *vdev, uint8_t val)
>              }
>          }
>      }
> +    vdev->status = val;
> +
>      if (k->set_status) {
>          k->set_status(vdev, val);
>      }
> -    vdev->status = val;

This breaks existing ->set_status() callbacks that rely on vdev->status
containing the old value.  Have you audited them?

For example, virtio_net_set_status -> virtio_net_vnet_endian_status uses
vdev->status!

It may be easier to modify virtio-rng.c so that the old status value
isn't used.

Stefan

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

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

* Re: [Qemu-devel] [PATCH 2/2] virtio: Set status early in VirtIODevice parent object
  2018-06-27 10:21   ` Stefan Hajnoczi
@ 2018-06-27 11:06     ` Pankaj Gupta
  0 siblings, 0 replies; 5+ messages in thread
From: Pankaj Gupta @ 2018-06-27 11:06 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: mst, amit, qemu-devel, slopezpa


> 
> On Wed, Jun 27, 2018 at 01:52:48PM +0530, Pankaj Gupta wrote:
> >  To process pending requests for driver status 'VIRTIO_CONFIG_S_DRIVER_OK',
> >  virtio-rng 'set_status' calls 'is_guest_ready' function. This checks if
> >  virtqueue is ready and status is set to 'VIRTIO_CONFIG_S_DRIVER_OK'.
> > 
> >  This call is made before new status is updated in VirtIODevice parent
> >  object
> >  and calling function uses old status value.
> > 
> > Signed-off-by: Pankaj Gupta <pagupta@redhat.com>
> > ---
> >  hw/virtio/virtio.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> > index d4e4d98b59..37dc59a686 100644
> > --- a/hw/virtio/virtio.c
> > +++ b/hw/virtio/virtio.c
> > @@ -1154,10 +1154,11 @@ int virtio_set_status(VirtIODevice *vdev, uint8_t
> > val)
> >              }
> >          }
> >      }
> > +    vdev->status = val;
> > +
> >      if (k->set_status) {
> >          k->set_status(vdev, val);
> >      }
> > -    vdev->status = val;
> 
> This breaks existing ->set_status() callbacks that rely on vdev->status
> containing the old value.  Have you audited them?

I did not audit them all. I thought that's the way it should be base object
first get updated. But you are right, it can break things where old status is used.

> 
> For example, virtio_net_set_status -> virtio_net_vnet_endian_status uses
> vdev->status!
> 
> It may be easier to modify virtio-rng.c so that the old status value
> isn't used.

Just updating status only for virtio_rng_set_status looks okay? This will avoid
multiple copies of status as different functions are using it.

I will send a V2.

+static void virtio_rng_set_status(VirtIODevice *vdev, uint8_t status)
+{
+    VirtIORNG *vrng = VIRTIO_RNG(vdev);
+
+    if (!vdev->vm_running) {
+        return;
+    }
+    vdev->status = status;
+
+    /* Something changed, try to process buffers */
+    virtio_rng_process(vrng);
+}
+


Thanks,
Pankaj

> 
> Stefan
> 

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

end of thread, other threads:[~2018-06-27 11:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-27  8:22 [Qemu-devel] [PATCH 0/2] virtio-rng: fix old guest kernel hang Pankaj Gupta
2018-06-27  8:22 ` [Qemu-devel] [PATCH 1/2] virtio-rng: process pending requests when driver is ready Pankaj Gupta
2018-06-27  8:22 ` [Qemu-devel] [PATCH 2/2] virtio: Set status early in VirtIODevice parent object Pankaj Gupta
2018-06-27 10:21   ` Stefan Hajnoczi
2018-06-27 11:06     ` Pankaj Gupta

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.