linux/drivers/char/hw_random
Jiri Slaby 1ab87298cb hwrng: core - sleep interruptible in read
hwrng kthread can be waiting via hwrng_fillfn for some data from a rng
like virtio-rng:
hwrng           D ffff880093e17798     0   382      2 0x00000000
...
Call Trace:
 [<ffffffff817339c6>] wait_for_completion_killable+0x96/0x210
 [<ffffffffa00aa1b7>] virtio_read+0x57/0xf0 [virtio_rng]
 [<ffffffff814f4a35>] hwrng_fillfn+0x75/0x130
 [<ffffffff810aa243>] kthread+0xf3/0x110

And when some user program tries to read the /dev node in this state,
we get:
rngd            D ffff880093e17798     0   762      1 0x00000004
...
Call Trace:
 [<ffffffff817351ac>] mutex_lock_nested+0x15c/0x3e0
 [<ffffffff814f478e>] rng_dev_read+0x6e/0x240
 [<ffffffff81231958>] __vfs_read+0x28/0xe0
 [<ffffffff81232393>] vfs_read+0x83/0x130

And this is indeed unkillable. So use mutex_lock_interruptible
instead of mutex_lock in rng_dev_read and exit immediatelly when
interrupted. And possibly return already read data, if any (as POSIX
allows).

v2: use ERESTARTSYS instead of EINTR

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Matt Mackall <mpm@selenic.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: <linux-crypto@vger.kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2015-12-04 22:21:45 +08:00
..
amd-rng.c hwrng: printk replacement 2014-10-02 14:35:00 +08:00
atmel-rng.c Driver core patches for 3.19-rc1 2014-12-14 16:10:09 -08:00
bcm63xx-rng.c hwrng: bcm63xx - Fix driver compilation 2015-05-04 17:49:52 +08:00
bcm2835-rng.c char: hw_random: drop owner assignment from platform_drivers 2014-10-20 16:20:20 +02:00
core.c hwrng: core - sleep interruptible in read 2015-12-04 22:21:45 +08:00
exynos-rng.c hwrng: exynos - Add Device Tree support 2015-10-20 22:13:59 +08:00
geode-rng.c hwrng: printk replacement 2014-10-02 14:35:00 +08:00
intel-rng.c hwrng: printk replacement 2014-10-02 14:35:00 +08:00
iproc-rng200.c hwrng: iproc-rng200 - make use of devm_hwrng_register 2015-03-16 21:45:56 +11:00
ixp4xx-rng.c IXP4xx: HW pseudo-random generator is available on IXP45x/46x only. 2012-11-22 03:35:39 +00:00
Kconfig hwrng: stm32 - add support for STM32 HW RNG 2015-10-14 22:23:36 +08:00
Makefile hwrng: stm32 - add support for STM32 HW RNG 2015-10-14 22:23:36 +08:00
msm-rng.c hwrng: msm - make use of devm_hwrng_register 2015-03-16 21:45:55 +11:00
mxc-rnga.c hwrng: mxc-rnga - Use the preferred format for kzalloc 2015-09-21 22:00:39 +08:00
n2-asm.S
n2-drv.c char: hw_random: drop owner assignment from platform_drivers 2014-10-20 16:20:20 +02:00
n2rng.h
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
omap3-rom-rng.c hwrng: omap3-rom - convert timer to delayed work 2015-11-23 20:55:54 +08:00
omap-rng.c hwrng: omap - Change RNG_CONFIG_REG to RNG_CONTROL_REG in init 2015-03-17 22:32:05 +11:00
pasemi-rng.c hwrng: Fix module autoload for OF platform drivers 2015-09-21 22:00:39 +08:00
powernv-rng.c char: constify of_device_id array 2015-03-16 21:10:28 +01:00
ppc4xx-rng.c hwrng: Fix module autoload for OF platform drivers 2015-09-21 22:00:39 +08:00
pseries-rng.c hwrng: pseries - remove incorrect __init/__exit markups 2015-03-12 01:11:06 +11:00
st-rng.c hwrng: st - Improve FIFO size/depth description 2015-10-08 21:42:25 +08:00
stm32-rng.c hwrng: stm32 - Fix build with CONFIG_PM 2015-10-15 09:50:39 +08:00
timeriomem-rng.c char: hw_random: drop owner assignment from platform_drivers 2014-10-20 16:20:20 +02:00
tpm-rng.c hw_random: add support for the TPM chip as a hardware RNG source 2012-08-22 11:11:41 -05:00
tx4939-rng.c char: hw_random: drop owner assignment from platform_drivers 2014-10-20 16:20:20 +02:00
via-rng.c x86/fpu: Rename i387.h to fpu/api.h 2015-05-19 15:47:30 +02:00
virtio-rng.c hwrng: virtio - drop extra empty line 2015-01-26 11:34:23 +11:00
xgene-rng.c hwrng: xgene - fix handling platform_get_irq 2015-09-21 22:57:37 +08:00