virtio: rng: fixes
cover virtio: rng: fixes
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(-)
Signature · 1 line
1.7.7.6
PATCH 1/5 virtio ids: fix comment for virtio-rng
It's virtio-rng, not virtio-ring.
--- include/linux/virtio_ids.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
include/linux/virtio_ids.h +1 -1
@@ -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 */
Signature · 1 line
1.7.7.6
PATCH 2/5 virtio: rng: allow tasks to be killed that are waiting for rng input
In reply to Amit ShahUse 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.
--- drivers/char/hw_random/virtio-rng.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
drivers/char/hw_random/virtio-rng.c +4 -1
@@ -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;
Signature · 1 line
1.7.7.6
PATCH 3/5 virtio: rng: don't wait on host when module is going away
In reply to Amit ShahNo 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).
--- drivers/char/hw_random/virtio-rng.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/char/hw_random/virtio-rng.c +1 -0
@@ -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); }
Signature · 1 line
1.7.7.6
PATCH 4/5 virtio: rng: split out common code in probe / remove for s3/s4 ops
In reply to Amit ShahThe freeze/restore s3/s4 operations will use code that's common to the probe and remove routines. Put the common code in separate funcitons.
--- drivers/char/hw_random/virtio-rng.c | 14 ++++++++++++-- 1 files changed, 12 insertions(+), 2 deletions(-)
drivers/char/hw_random/virtio-rng.c +12 -2
@@ -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 },
Signature · 1 line
1.7.7.6
PATCH 5/5 virtio: rng: s3/s4 support
In reply to Amit ShahUnregister 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.
--- drivers/char/hw_random/virtio-rng.c | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 deletions(-)
drivers/char/hw_random/virtio-rng.c +17 -0
@@ -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 )
Signature · 1 line
1.7.7.6
Rusty Russell
AppliedQuoted 8 lines · Amit Shah
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.