Hi Rusty, These are a few fixes for the virtio-rng driver. These were tested using the not-yet-upstream virtio-rng device patch to qemu: http://thread.gmane.org/gmane.comp.emulators.qemu/152668 Please apply. Amit Shah (5): virtio ids: fix comment for virtio-rng virtio: rng: allow tasks to be killed that are waiting for rng input virtio: rng: don't wait on host when module is going away virtio: rng: split out common code in probe / remove for s3/s4 ops virtio: rng: s3/s4 support drivers/char/hw_random/virtio-rng.c | 37 ++++++++++++++++++++++++++++++++-- include/linux/virtio_ids.h | 2 +- 2 files changed, 35 insertions(+), 4 deletions(-) -- 1.7.7.6
It's virtio-rng, not virtio-ring. Signed-off-by: Amit Shah <amit.shah at redhat.com> --- include/linux/virtio_ids.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/include/linux/virtio_ids.h b/include/linux/virtio_ids.h index 7529b85..270fb22 100644 --- a/include/linux/virtio_ids.h +++ b/include/linux/virtio_ids.h @@ -32,7 +32,7 @@ #define VIRTIO_ID_NET 1 /* virtio net */ #define VIRTIO_ID_BLOCK 2 /* virtio block */ #define VIRTIO_ID_CONSOLE 3 /* virtio console */ -#define VIRTIO_ID_RNG 4 /* virtio ring */ +#define VIRTIO_ID_RNG 4 /* virtio rng */ #define VIRTIO_ID_BALLOON 5 /* virtio balloon */ #define VIRTIO_ID_RPMSG 7 /* virtio remote processor messaging */ #define VIRTIO_ID_SCSI 8 /* virtio scsi */ -- 1.7.7.6
Amit Shah
2012-May-28 06:48 UTC
[PATCH 2/5] virtio: rng: allow tasks to be killed that are waiting for rng input
Use wait_for_completion_killable() instead of wait_for_completion() when waiting for the host to send us entropy. Without this, # cat /dev/hwrng ^C just hangs. Signed-off-by: Amit Shah <amit.shah at redhat.com> --- drivers/char/hw_random/virtio-rng.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c index 723725b..c8a9350 100644 --- a/drivers/char/hw_random/virtio-rng.c +++ b/drivers/char/hw_random/virtio-rng.c @@ -55,6 +55,7 @@ static void register_buffer(u8 *buf, size_t size) static int virtio_read(struct hwrng *rng, void *buf, size_t size, bool wait) { + int ret; if (!busy) { busy = true; @@ -65,7 +66,9 @@ static int virtio_read(struct hwrng *rng, void *buf, size_t size, bool wait) if (!wait) return 0; - wait_for_completion(&have_data); + ret = wait_for_completion_killable(&have_data); + if (ret < 0) + return ret; busy = false; -- 1.7.7.6
Amit Shah
2012-May-28 06:48 UTC
[PATCH 3/5] virtio: rng: don't wait on host when module is going away
No use waiting for input from host when the module is being removed. We're going to remove the vq in the next step anyway, so just perform any other steps for cleanup (currently none). Signed-off-by: Amit Shah <amit.shah at redhat.com> --- drivers/char/hw_random/virtio-rng.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c index c8a9350..2dc9ce1 100644 --- a/drivers/char/hw_random/virtio-rng.c +++ b/drivers/char/hw_random/virtio-rng.c @@ -109,6 +109,7 @@ static int virtrng_probe(struct virtio_device *vdev) static void __devexit virtrng_remove(struct virtio_device *vdev) { vdev->config->reset(vdev); + busy = false; hwrng_unregister(&virtio_hwrng); vdev->config->del_vqs(vdev); } -- 1.7.7.6
Amit Shah
2012-May-28 06:48 UTC
[PATCH 4/5] virtio: rng: split out common code in probe / remove for s3/s4 ops
The freeze/restore s3/s4 operations will use code that's common to the probe and remove routines. Put the common code in separate funcitons. Signed-off-by: Amit Shah <amit.shah at redhat.com> --- drivers/char/hw_random/virtio-rng.c | 14 ++++++++++++-- 1 files changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c index 2dc9ce1..a9673a7 100644 --- a/drivers/char/hw_random/virtio-rng.c +++ b/drivers/char/hw_random/virtio-rng.c @@ -88,7 +88,7 @@ static struct hwrng virtio_hwrng = { .read = virtio_read, }; -static int virtrng_probe(struct virtio_device *vdev) +static int probe_common(struct virtio_device *vdev) { int err; @@ -106,7 +106,7 @@ static int virtrng_probe(struct virtio_device *vdev) return 0; } -static void __devexit virtrng_remove(struct virtio_device *vdev) +static void remove_common(struct virtio_device *vdev) { vdev->config->reset(vdev); busy = false; @@ -114,6 +114,16 @@ static void __devexit virtrng_remove(struct virtio_device *vdev) vdev->config->del_vqs(vdev); } +static int virtrng_probe(struct virtio_device *vdev) +{ + return probe_common(vdev); +} + +static void __devexit virtrng_remove(struct virtio_device *vdev) +{ + remove_common(vdev); +} + static struct virtio_device_id id_table[] = { { VIRTIO_ID_RNG, VIRTIO_DEV_ANY_ID }, { 0 }, -- 1.7.7.6
Unregister from the hwrng interface and remove the vq before entering the S3 or S4 states. Add the vq and re-register with hwrng on restore. Signed-off-by: Amit Shah <amit.shah at redhat.com> --- drivers/char/hw_random/virtio-rng.c | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 deletions(-) diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c index a9673a7..5708299 100644 --- a/drivers/char/hw_random/virtio-rng.c +++ b/drivers/char/hw_random/virtio-rng.c @@ -124,6 +124,19 @@ static void __devexit virtrng_remove(struct virtio_device *vdev) remove_common(vdev); } +#ifdef CONFIG_PM +static int virtrng_freeze(struct virtio_device *vdev) +{ + remove_common(vdev); + return 0; +} + +static int virtrng_restore(struct virtio_device *vdev) +{ + return probe_common(vdev); +} +#endif + static struct virtio_device_id id_table[] = { { VIRTIO_ID_RNG, VIRTIO_DEV_ANY_ID }, { 0 }, @@ -135,6 +148,10 @@ static struct virtio_driver virtio_rng_driver = { .id_table = id_table, .probe = virtrng_probe, .remove = __devexit_p(virtrng_remove), +#ifdef CONFIG_PM + .freeze = virtrng_freeze, + .restore = virtrng_restore, +#endif }; static int __init init(void) -- 1.7.7.6
On Mon, 28 May 2012 12:18:38 +0530, Amit Shah <amit.shah at redhat.com> wrote:> Hi Rusty, > > These are a few fixes for the virtio-rng driver. These were tested > using the not-yet-upstream virtio-rng device patch to qemu: > > http://thread.gmane.org/gmane.comp.emulators.qemu/152668 > > Please apply.Thanks, applied. Cheers, Rusty.
Reasonably Related Threads
- [PATCH 0/5] virtio: rng: fixes
- [PATCH v2 0/4] virtio-rng: contribute to early randomness requests
- [PATCH v2 0/4] virtio-rng: contribute to early randomness requests
- [3.16 stable PATCH v2 1/2] virtio: rng: delay hwrng_register() till driver is ready
- [3.16 stable PATCH v2 1/2] virtio: rng: delay hwrng_register() till driver is ready