From: Theodore Ts'o Date: Sun, 12 Jun 2016 22:11:51 +0000 (-0400) Subject: random: initialize the non-blocking pool via add_hwgenerator_randomness() X-Git-Tag: firefly_0821_release~176^2~4^2~31^2~390 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=f41fc0bfede5bbeca4f09d75c76c4db5d6c0d2ee;p=firefly-linux-kernel-4.4.55.git 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 Signed-off-by: Greg Kroah-Hartman --- 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); }