From 5885e48e4412e75be5495fe889cec6762b165197 Mon Sep 17 00:00:00 2001 From: Fabian Frederick Date: Sun, 27 Jul 2014 07:30:01 +0930 Subject: virtio: console: remove unnecessary null test before debugfs_remove_recursive Fix checkpatch warning: WARNING: debugfs_remove_recursive(NULL) is safe this check is probably not required Cc: Arnd Bergmann Cc: virtualization@lists.linux-foundation.org Reviewed-by: Amit Shah Signed-off-by: Fabian Frederick Signed-off-by: Rusty Russell --- drivers/char/virtio_console.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c index 60aafb8a1f2e..b585b4789822 100644 --- a/drivers/char/virtio_console.c +++ b/drivers/char/virtio_console.c @@ -2262,8 +2262,7 @@ static int __init init(void) unregister: unregister_virtio_driver(&virtio_console); free: - if (pdrvdata.debugfs_dir) - debugfs_remove_recursive(pdrvdata.debugfs_dir); + debugfs_remove_recursive(pdrvdata.debugfs_dir); class_destroy(pdrvdata.class); return err; } @@ -2276,8 +2275,7 @@ static void __exit fini(void) unregister_virtio_driver(&virtio_rproc_serial); class_destroy(pdrvdata.class); - if (pdrvdata.debugfs_dir) - debugfs_remove_recursive(pdrvdata.debugfs_dir); + debugfs_remove_recursive(pdrvdata.debugfs_dir); } module_init(init); module_exit(fini); -- cgit v1.2.3 From cef340e6aa2ac16651f6a49d93551b27a9ee24bb Mon Sep 17 00:00:00 2001 From: Benoit Taine Date: Sun, 27 Jul 2014 07:31:01 +0930 Subject: virtio: Replace DEFINE_PCI_DEVICE_TABLE macro use We should prefer `struct pci_device_id` over `DEFINE_PCI_DEVICE_TABLE` to meet kernel coding style guidelines. This issue was reported by checkpatch. Signed-off-by: Benoit Taine Signed-off-by: Rusty Russell --- drivers/virtio/virtio_pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/virtio/virtio_pci.c b/drivers/virtio/virtio_pci.c index 101db3faf5d4..3d1463c6b120 100644 --- a/drivers/virtio/virtio_pci.c +++ b/drivers/virtio/virtio_pci.c @@ -91,7 +91,7 @@ struct virtio_pci_vq_info }; /* Qumranet donated their vendor ID for devices 0x1000 thru 0x10FF. */ -static DEFINE_PCI_DEVICE_TABLE(virtio_pci_id_table) = { +static const struct pci_device_id virtio_pci_id_table[] = { { PCI_DEVICE(0x1af4, PCI_ANY_ID) }, { 0 } }; -- cgit v1.2.3 From 373445d02befffe2efe31ebf1ab7e566d877e3ee Mon Sep 17 00:00:00 2001 From: Amit Shah Date: Sun, 27 Jul 2014 07:32:01 +0930 Subject: virtio: rng: remove unused struct element vdev is unused in struct virtrng_info, remove it. CC: Amos Kong Signed-off-by: Amit Shah Signed-off-by: Rusty Russell --- drivers/char/hw_random/virtio-rng.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c index e9b15bc18b4d..d8ffebdc2014 100644 --- a/drivers/char/hw_random/virtio-rng.c +++ b/drivers/char/hw_random/virtio-rng.c @@ -28,7 +28,6 @@ static DEFINE_IDA(rng_index_ida); struct virtrng_info { - struct virtio_device *vdev; struct hwrng hwrng; struct virtqueue *vq; unsigned int data_avail; -- cgit v1.2.3 From 6062829fcdcae4518436f51336c0e05bd1f04806 Mon Sep 17 00:00:00 2001 From: Amit Shah Date: Sun, 27 Jul 2014 07:33:01 +0930 Subject: virtio: rng: re-arrange struct elements for better packing Re-arrange the elements of the virtrng_info struct to pack it better. Signed-off-by: Amit Shah Signed-off-by: Rusty Russell --- drivers/char/hw_random/virtio-rng.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c index d8ffebdc2014..a1562841f539 100644 --- a/drivers/char/hw_random/virtio-rng.c +++ b/drivers/char/hw_random/virtio-rng.c @@ -30,11 +30,11 @@ static DEFINE_IDA(rng_index_ida); struct virtrng_info { struct hwrng hwrng; struct virtqueue *vq; - unsigned int data_avail; struct completion have_data; - bool busy; char name[25]; + unsigned int data_avail; int index; + bool busy; }; static bool probe_done; -- cgit v1.2.3 From 5c06273401f2eb7b290cadbae18ee00f8f65e893 Mon Sep 17 00:00:00 2001 From: Amit Shah Date: Sun, 27 Jul 2014 07:34:01 +0930 Subject: virtio: rng: delay hwrng_register() till driver is ready Instead of calling hwrng_register() in the probe routing, call it in the scan routine. This ensures that when hwrng_register() is successful, and it requests a few random bytes to seed the kernel's pool at init, we're ready to service that request. This will also enable us to remove the workaround added previously to check whether probe was completed, and only then ask for data from the host. The revert follows in the next commit. There's a slight behaviour change here on unsuccessful hwrng_register(). Previously, when hwrng_register() failed, the probe() routine would fail, and the vqs would be torn down, and driver would be marked not initialized. Now, the vqs will remain initialized, driver would be marked initialized as well, but won't be available in the list of RNGs available to hwrng core. To fix the failures, the procedure remains the same, i.e. unload and re-load the module, and hope things succeed the next time around. Signed-off-by: Amit Shah Signed-off-by: Rusty Russell --- drivers/char/hw_random/virtio-rng.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c index a1562841f539..d9927eb4fa98 100644 --- a/drivers/char/hw_random/virtio-rng.c +++ b/drivers/char/hw_random/virtio-rng.c @@ -35,6 +35,7 @@ struct virtrng_info { unsigned int data_avail; int index; bool busy; + bool hwrng_register_done; }; static bool probe_done; @@ -136,15 +137,6 @@ static int probe_common(struct virtio_device *vdev) return err; } - err = hwrng_register(&vi->hwrng); - if (err) { - vdev->config->del_vqs(vdev); - vi->vq = NULL; - kfree(vi); - ida_simple_remove(&rng_index_ida, index); - return err; - } - probe_done = true; return 0; } @@ -152,9 +144,11 @@ static int probe_common(struct virtio_device *vdev) static void remove_common(struct virtio_device *vdev) { struct virtrng_info *vi = vdev->priv; + vdev->config->reset(vdev); vi->busy = false; - hwrng_unregister(&vi->hwrng); + if (vi->hwrng_register_done) + hwrng_unregister(&vi->hwrng); vdev->config->del_vqs(vdev); ida_simple_remove(&rng_index_ida, vi->index); kfree(vi); @@ -170,6 +164,16 @@ static void virtrng_remove(struct virtio_device *vdev) remove_common(vdev); } +static void virtrng_scan(struct virtio_device *vdev) +{ + struct virtrng_info *vi = vdev->priv; + int err; + + err = hwrng_register(&vi->hwrng); + if (!err) + vi->hwrng_register_done = true; +} + #ifdef CONFIG_PM_SLEEP static int virtrng_freeze(struct virtio_device *vdev) { @@ -194,6 +198,7 @@ static struct virtio_driver virtio_rng_driver = { .id_table = id_table, .probe = virtrng_probe, .remove = virtrng_remove, + .scan = virtrng_scan, #ifdef CONFIG_PM_SLEEP .freeze = virtrng_freeze, .restore = virtrng_restore, -- cgit v1.2.3 From eeec626366ffe558fc3d5685bd2b49a962acf57d Mon Sep 17 00:00:00 2001 From: Amit Shah Date: Sun, 27 Jul 2014 07:35:01 +0930 Subject: Revert "hwrng: virtio - ensure reads happen after successful probe" This reverts commit e052dbf554610e2104c5a7518c4d8374bed701bb. Now that we use the virtio ->scan() function to register with the hwrng core, we will not get read requests till probe is successfully finished. So revert the workaround we had in place to refuse read requests while we were not yet setup completely. Signed-off-by: Amit Shah Signed-off-by: Rusty Russell --- drivers/char/hw_random/core.c | 6 ------ drivers/char/hw_random/virtio-rng.c | 9 --------- 2 files changed, 15 deletions(-) diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c index c4419ea1ab07..2a451b14b3cc 100644 --- a/drivers/char/hw_random/core.c +++ b/drivers/char/hw_random/core.c @@ -68,12 +68,6 @@ static void add_early_randomness(struct hwrng *rng) unsigned char bytes[16]; int bytes_read; - /* - * Currently only virtio-rng cannot return data during device - * probe, and that's handled in virtio-rng.c itself. If there - * are more such devices, this call to rng_get_data can be - * made conditional here instead of doing it per-device. - */ bytes_read = rng_get_data(rng, bytes, sizeof(bytes), 1); if (bytes_read > 0) add_device_randomness(bytes, bytes_read); diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c index d9927eb4fa98..0027137daa56 100644 --- a/drivers/char/hw_random/virtio-rng.c +++ b/drivers/char/hw_random/virtio-rng.c @@ -38,7 +38,6 @@ struct virtrng_info { bool hwrng_register_done; }; -static bool probe_done; static void random_recv_done(struct virtqueue *vq) { @@ -69,13 +68,6 @@ 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; - /* - * Don't ask host for data till we're setup. This call can - * happen during hwrng_register(), after commit d9e7972619. - */ - if (unlikely(!probe_done)) - return 0; - if (!vi->busy) { vi->busy = true; init_completion(&vi->have_data); @@ -137,7 +129,6 @@ static int probe_common(struct virtio_device *vdev) return err; } - probe_done = true; return 0; } -- cgit v1.2.3