summaryrefslogtreecommitdiff
path: root/drivers/char
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2016-06-12 18:11:51 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2016-08-20 18:09:20 +0200
commitf41fc0bfede5bbeca4f09d75c76c4db5d6c0d2ee (patch)
tree989c683e91c7282f439370ba6b6fc45c908a547a /drivers/char
parentadc58bfd4d75183a65f806b1b5354d1b65f832c6 (diff)
random: initialize the non-blocking pool via add_hwgenerator_randomness()
commit 3371f3da08cff4b75c1f2dce742d460539d6566d upstream. If we have a hardware RNG and are using the in-kernel rngd, we should use this to initialize the non-blocking pool so that getrandom(2) doesn't block unnecessarily. Signed-off-by: Theodore Ts'o <tytso@mit.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/char')
-rw-r--r--drivers/char/random.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 0227b0465b40..802d0c840865 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1847,12 +1847,18 @@ void add_hwgenerator_randomness(const char *buffer, size_t count,
{
struct entropy_store *poolp = &input_pool;
- /* Suspend writing if we're above the trickle threshold.
- * We'll be woken up again once below random_write_wakeup_thresh,
- * or when the calling thread is about to terminate.
- */
- wait_event_interruptible(random_write_wait, kthread_should_stop() ||
+ if (unlikely(nonblocking_pool.initialized == 0))
+ poolp = &nonblocking_pool;
+ else {
+ /* Suspend writing if we're above the trickle
+ * threshold. We'll be woken up again once below
+ * random_write_wakeup_thresh, or when the calling
+ * thread is about to terminate.
+ */
+ wait_event_interruptible(random_write_wait,
+ kthread_should_stop() ||
ENTROPY_BITS(&input_pool) <= random_write_wakeup_bits);
+ }
mix_pool_bytes(poolp, buffer, count);
credit_entropy_bits(poolp, entropy);
}