linux-sg2042/drivers/char/hw_random
David Tolnay aef027db48 hwrng: virtio - Avoid repeated init of completion
The virtio-rng driver uses a completion called have_data to wait for a
virtio read to be fulfilled by the hypervisor. The completion is reset
before placing a buffer on the virtio queue and completed by the virtio
callback once data has been written into the buffer.

Prior to this commit, the driver called init_completion on this
completion both during probe as well as when registering virtio buffers
as part of a hwrng read operation. The second of these init_completion
calls should instead be reinit_completion because the have_data
completion has already been inited by probe. As described in
Documentation/scheduler/completion.txt, "Calling init_completion() twice
on the same completion object is most likely a bug".

This bug was present in the initial implementation of virtio-rng in
f7f510ec19 ("virtio: An entropy device, as suggested by hpa"). Back
then the have_data completion was a single static completion rather than
a member of one of potentially multiple virtrng_info structs as
implemented later by 08e53fbdb8 ("virtio-rng: support multiple
virtio-rng devices"). The original driver incorrectly used
init_completion rather than INIT_COMPLETION to reset have_data during
read.

Tested by running `head -c48 /dev/random | hexdump` within crosvm, the
Chrome OS virtual machine monitor, and confirming that the virtio-rng
driver successfully produces random bytes from the host.

Signed-off-by: David Tolnay <dtolnay@gmail.com>
Tested-by: David Tolnay <dtolnay@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2019-01-25 18:41:52 +08:00
..
Kconfig hwrng: msm - remove msm hw_random driver 2018-07-27 19:04:30 +08:00
Makefile hwrng: msm - remove msm hw_random driver 2018-07-27 19:04:30 +08:00
amd-rng.c hwrng: amd - Revert managed API changes 2017-03-16 17:43:10 +08:00
atmel-rng.c headers: separate linux/mod_devicetable.h from linux/platform_device.h 2018-07-07 17:52:26 +02:00
bcm2835-rng.c hwrng: bcm2835 - Switch to SPDX identifier 2018-11-16 14:11:04 +08:00
cavium-rng-vf.c hwrng: cavium - make two functions static 2018-03-09 22:45:34 +08:00
cavium-rng.c hwrng: cavium - make two functions static 2018-03-09 22:45:34 +08:00
core.c hwrng: core - document the quality field 2018-10-05 10:16:56 +08:00
exynos-trng.c headers: separate linux/mod_devicetable.h from linux/platform_device.h 2018-07-07 17:52:26 +02:00
geode-rng.c hwrng: geode - Revert managed API changes 2017-03-16 17:43:11 +08:00
hisi-rng.c hwrng: hisi - Add support for Hisilicon SoC RNG 2016-04-15 22:36:36 +08:00
imx-rngc.c headers: separate linux/mod_devicetable.h from linux/platform_device.h 2018-07-07 17:52:26 +02:00
intel-rng.c hwrng: printk replacement 2014-10-02 14:35:00 +08:00
iproc-rng200.c hwrng: iproc-rng200 - Add support for BCM7278 2017-11-10 19:20:12 +08:00
ixp4xx-rng.c IXP4xx: HW pseudo-random generator is available on IXP45x/46x only. 2012-11-22 03:35:39 +00:00
ks-sa-rng.c hwrng: ks-sa - add hw_random driver 2018-03-23 23:40:08 +08:00
meson-rng.c hwrng: meson - add clock handling to driver 2017-03-16 17:58:49 +08:00
mtk-rng.c hwrng: mediatek - Setup default RNG quality 2018-01-18 22:52:25 +11:00
mxc-rnga.c hwrng: mxc-rnga - add driver support on boards with device tree 2018-03-16 23:35:44 +08:00
n2-asm.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
n2-drv.c hwrng: n2 - fix spelling mistake: "restesting" -> "retesting" 2018-05-19 00:13:53 +08:00
n2rng.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
nomadik-rng.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6 2014-04-03 09:28:16 -07:00
octeon-rng.c hwrng: octeon - Use devm_hwrng_register 2015-09-21 22:00:38 +08:00
omap-rng.c hwrng: omap - Fix clock resource by adding a register clock 2018-03-09 22:45:45 +08:00
omap3-rom-rng.c hwrng: omap3-rom - Handle return value of clk_prepare_enable 2017-05-23 12:52:03 +08:00
pasemi-rng.c hwrng: pasemi - Use linux/io.h instead of asm/io.h 2016-09-13 20:27:21 +08:00
pic32-rng.c hwrng: Make explicit that max >= 32 always 2016-11-21 22:50:45 +08:00
powernv-rng.c headers: separate linux/mod_devicetable.h from linux/platform_device.h 2018-07-07 17:52:26 +02:00
pseries-rng.c hwrng: pseries - constify vio_device_id 2017-09-22 17:43:05 +08:00
s390-trng.c s390/trng: Introduce s390 TRNG device driver. 2017-04-26 13:41:36 +02:00
st-rng.c hwrng: st - Fix missing clk_disable_unprepare() on error in st_rng_probe() 2016-09-13 20:27:24 +08:00
stm32-rng.c hwrng: stm32 - fix pm_suspend issue 2018-05-05 14:52:49 +08:00
timeriomem-rng.c hwrng: timeriomem - Remove 'max < 4' condition check 2017-09-22 17:43:14 +08:00
tx4939-rng.c hwrng: tx4939 - Use devm_hwrng_register instead of hwrng_register 2016-08-31 23:00:49 +08:00
via-rng.c hwrng: via - support new Centaur CPU 2018-04-21 00:59:03 +08:00
virtio-rng.c hwrng: virtio - Avoid repeated init of completion 2019-01-25 18:41:52 +08:00
xgene-rng.c hwrng: xgene - Convert timers to use timer_setup() 2017-11-03 22:11:16 +08:00