* [PATCH v2] virtio-rng: fix stuck of hot-unplugging busy device
@ 2014-09-09 11:14 Amos Kong
2014-09-10 5:34 ` Amit Shah
0 siblings, 1 reply; 3+ messages in thread
From: Amos Kong @ 2014-09-09 11:14 UTC (permalink / raw)
To: virtualization; +Cc: amit.shah, stable, kvm
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 exits the waiting by completing have_data completion before
unregistering, resets data_avail to avoid the hwrng core use wrong
buffer bytes. Before real unregistering we should return -ENODEV for
reading.
When we hot-unplug the device, dd process in guest will exit.
$ dd if=/dev/hwrng of=/dev/null
dd: error reading ‘/dev/hwrng’: No such device
Signed-off-by: Amos Kong <akong@redhat.com>
Cc: stable@vger.kernel.org
---
V2: reset data_avail (Amit)
adjust unregister order
---
drivers/char/hw_random/virtio-rng.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c
index 2e3139e..e76433b 100644
--- a/drivers/char/hw_random/virtio-rng.c
+++ b/drivers/char/hw_random/virtio-rng.c
@@ -68,6 +68,10 @@ static int virtio_read(struct hwrng *rng, void *buf, size_t size, bool wait)
int ret;
struct virtrng_info *vi = (struct virtrng_info *)rng->priv;
+ if (!vi->hwrng_register_done) {
+ return -ENODEV;
+ }
+
if (!vi->busy) {
vi->busy = true;
init_completion(&vi->have_data);
@@ -137,10 +141,14 @@ static void remove_common(struct virtio_device *vdev)
{
struct virtrng_info *vi = vdev->priv;
+ vi->data_avail = 0;
+ complete(&vi->have_data);
vdev->config->reset(vdev);
vi->busy = false;
- if (vi->hwrng_register_done)
+ if (vi->hwrng_register_done) {
+ vi->hwrng_register_done = false;
hwrng_unregister(&vi->hwrng);
+ }
vdev->config->del_vqs(vdev);
ida_simple_remove(&rng_index_ida, vi->index);
kfree(vi);
--
1.9.3
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] virtio-rng: fix stuck of hot-unplugging busy device
2014-09-09 11:14 [PATCH v2] virtio-rng: fix stuck of hot-unplugging busy device Amos Kong
@ 2014-09-10 5:34 ` Amit Shah
2014-09-10 6:12 ` Amos Kong
0 siblings, 1 reply; 3+ messages in thread
From: Amit Shah @ 2014-09-10 5:34 UTC (permalink / raw)
To: Amos Kong; +Cc: stable, kvm, virtualization
Hi Amos,
On (Tue) 09 Sep 2014 [19:14:02], 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 exits the waiting by completing have_data completion before
> unregistering, resets data_avail to avoid the hwrng core use wrong
> buffer bytes. Before real unregistering we should return -ENODEV for
> reading.
>
> When we hot-unplug the device, dd process in guest will exit.
> $ dd if=/dev/hwrng of=/dev/null
> dd: error reading ‘/dev/hwrng’: No such device
>
> Signed-off-by: Amos Kong <akong@redhat.com>
> Cc: stable@vger.kernel.org
> ---
> V2: reset data_avail (Amit)
> adjust unregister order
Thanks, this looks good.
Can you please split into two parts, the complete() in one, and the
hwrng_register_done stuff into another?
Thanks,
Amit
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] virtio-rng: fix stuck of hot-unplugging busy device
2014-09-10 5:34 ` Amit Shah
@ 2014-09-10 6:12 ` Amos Kong
0 siblings, 0 replies; 3+ messages in thread
From: Amos Kong @ 2014-09-10 6:12 UTC (permalink / raw)
To: Amit Shah; +Cc: stable, kvm, virtualization
On Wed, Sep 10, 2014 at 11:04:54AM +0530, Amit Shah wrote:
> Hi Amos,
>
> On (Tue) 09 Sep 2014 [19:14:02], 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 exits the waiting by completing have_data completion before
> > unregistering, resets data_avail to avoid the hwrng core use wrong
> > buffer bytes. Before real unregistering we should return -ENODEV for
> > reading.
> >
> > When we hot-unplug the device, dd process in guest will exit.
> > $ dd if=/dev/hwrng of=/dev/null
> > dd: error reading ‘/dev/hwrng’: No such device
> >
> > Signed-off-by: Amos Kong <akong@redhat.com>
> > Cc: stable@vger.kernel.org
> > ---
> > V2: reset data_avail (Amit)
> > adjust unregister order
>
> Thanks, this looks good.
>
> Can you please split into two parts, the complete() in one, and the
> hwrng_register_done stuff into another?
I just posted the V3, split to two patches, and updated the commitlog
to describe why we need to return ENODEV for reading.
> Thanks,
>
> Amit
--
Amos.
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-09-10 6:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-09 11:14 [PATCH v2] virtio-rng: fix stuck of hot-unplugging busy device Amos Kong
2014-09-10 5:34 ` Amit Shah
2014-09-10 6:12 ` Amos Kong
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).