Message ID | 1410261242-16328-1-git-send-email-akong@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
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 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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
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);
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(-)