Amos Kong
2014-Aug-05 17:35 UTC
[PATCH] virtio-rng: complete have_data completion in removing device
When we try to hot-remove a busy virtio-rng device from QEMU monitor, the device can't be hot-removed. Because virtio-rng driver hangs at wait_for_completion_killable(). This patch fixed the hang by completing have_data completion before unregistering a virtio-rng device. Signed-off-by: Amos Kong <akong at redhat.com> Cc: stable at vger.kernel.org --- drivers/char/hw_random/virtio-rng.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c index 0027137..416b15c 100644 --- a/drivers/char/hw_random/virtio-rng.c +++ b/drivers/char/hw_random/virtio-rng.c @@ -137,6 +137,7 @@ static void remove_common(struct virtio_device *vdev) struct virtrng_info *vi = vdev->priv; vdev->config->reset(vdev); + complete(&vi->have_data); vi->busy = false; if (vi->hwrng_register_done) hwrng_unregister(&vi->hwrng); -- 1.9.3
Amos Kong
2014-Aug-06 08:05 UTC
[PATCH] virtio-rng: complete have_data completion in removing device
On Wed, Aug 06, 2014 at 01:35:15AM +0800, Amos Kong wrote:> When we try to hot-remove a busy virtio-rng device from QEMU monitor, > the device can't be hot-removed. Because virtio-rng driver hangs at > wait_for_completion_killable(). > > This patch fixed the hang by completing have_data completion before > unregistering a virtio-rng device.Hi Amit, Before applying this patch, it's blocking insider wait_for_completion_killable() Applied this patch, wait_for_completion_killable() returns 0, and vi->data_avail becomes 0, then rng_get_date() will return 0. Is it expected result?> Signed-off-by: Amos Kong <akong at redhat.com> > Cc: stable at vger.kernel.org > --- > drivers/char/hw_random/virtio-rng.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c > index 0027137..416b15c 100644 > --- a/drivers/char/hw_random/virtio-rng.c > +++ b/drivers/char/hw_random/virtio-rng.c > @@ -137,6 +137,7 @@ static void remove_common(struct virtio_device *vdev) > struct virtrng_info *vi = vdev->priv; > > vdev->config->reset(vdev); > + complete(&vi->have_data); > vi->busy = false; > if (vi->hwrng_register_done) > hwrng_unregister(&vi->hwrng); > -- > 1.9.3 > > _______________________________________________ > Virtualization mailing list > Virtualization at lists.linux-foundation.org > https://lists.linuxfoundation.org/mailman/listinfo/virtualization-- Amos.
Amit Shah
2014-Aug-06 08:25 UTC
[PATCH] virtio-rng: complete have_data completion in removing device
On (Wed) 06 Aug 2014 [16:05:41], Amos Kong wrote:> On Wed, Aug 06, 2014 at 01:35:15AM +0800, Amos Kong wrote: > > When we try to hot-remove a busy virtio-rng device from QEMU monitor, > > the device can't be hot-removed. Because virtio-rng driver hangs at > > wait_for_completion_killable(). > > > > This patch fixed the hang by completing have_data completion before > > unregistering a virtio-rng device. > > Hi Amit, > > Before applying this patch, it's blocking insider wait_for_completion_killable() > Applied this patch, wait_for_completion_killable() returns 0, > and vi->data_avail becomes 0, then rng_get_date() will return 0.Thanks for checking this.> Is it expected result?I think what will happen is vi->data_avail will be set to whatever it was set last. In case of a previous successful read request, the data_avail will be set to whatever number of bytes the host gave. On doing a hot-unplug on the succeeding wait, the value in data_avail will be re-used, and the hwrng core will wrongly take some bytes in the buffer as input from the host. So, I think we need to set vi->data_avail = 0; before calling wait_event_completion_killable(). Amit
Apparently Analagous Threads
- [PATCH] virtio-rng: complete have_data completion in removing device
- [PATCH] virtio-rng: complete have_data completion in removing device
- [PATCH] virtio-rng: complete have_data completion in removing device
- [PATCH v3 0/2] virtio-rng: fix hotunplug
- [PATCH v3 0/2] virtio-rng: fix hotunplug