Amos Kong
2014-Sep-09 11:14 UTC
[PATCH v2] virtio-rng: fix stuck of hot-unplugging busy 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 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 at redhat.com> Cc: stable at 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
Amit Shah
2014-Sep-10 05:34 UTC
[PATCH v2] virtio-rng: fix stuck of hot-unplugging busy device
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 at redhat.com> > Cc: stable at vger.kernel.org > --- > V2: reset data_avail (Amit) > adjust unregister orderThanks, this looks good. Can you please split into two parts, the complete() in one, and the hwrng_register_done stuff into another? Thanks, Amit
Amos Kong
2014-Sep-10 06:12 UTC
[PATCH v2] virtio-rng: fix stuck of hot-unplugging busy device
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 at redhat.com> > > Cc: stable at 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.
Reasonably Related Threads
- [PATCH v2] virtio-rng: fix stuck of hot-unplugging busy device
- [PATCH v2] virtio-rng: fix stuck of hot-unplugging busy device
- [PATCH v3 1/2] virtio-rng: fix stuck of hot-unplugging busy device
- [PATCH v3 1/2] virtio-rng: fix stuck of hot-unplugging busy device
- [PATCH v3 1/2] virtio-rng: fix stuck of hot-unplugging busy device