virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Amos Kong <akong@redhat.com>
To: virtualization@lists.linux-foundation.org
Cc: amit.shah@redhat.com, stable@vger.kernel.org, kvm@vger.kernel.org
Subject: [PATCH v2] virtio-rng: fix stuck of hot-unplugging busy device
Date: Tue,  9 Sep 2014 19:14:02 +0800	[thread overview]
Message-ID: <1410261242-16328-1-git-send-email-akong@redhat.com> (raw)

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

             reply	other threads:[~2014-09-09 11:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-09 11:14 Amos Kong [this message]
2014-09-10  5:34 ` [PATCH v2] virtio-rng: fix stuck of hot-unplugging busy device Amit Shah
2014-09-10  6:12   ` Amos Kong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1410261242-16328-1-git-send-email-akong@redhat.com \
    --to=akong@redhat.com \
    --cc=amit.shah@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=virtualization@lists.linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).