aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/random.c
diff options
context:
space:
mode:
authorStephen Boyd <swboyd@chromium.org>2019-08-19 11:02:45 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2019-08-22 00:39:36 -0400
commitff296293b3538d19278a7f7cd1f3aa600ad9164c (patch)
treee4de7392c51fd80f41d7c0316efc13da08ac3325 /drivers/char/random.c
parent198429631a85622da1d08d360ef02cfb84c95919 (diff)
random: Support freezable kthreads in add_hwgenerator_randomness()
The kthread calling this function is freezable after commit 03a3bb7ae631 ("hwrng: core - Freeze khwrng thread during suspend") is applied. Unfortunately, this function uses wait_event_interruptible() but doesn't check for the kthread being woken up by the fake freezer signal. When a user suspends the system, this kthread will wake up and if it fails the entropy size check it will immediately go back to sleep and not go into the freezer. Eventually, suspend will fail because the task never froze and a warning message like this may appear: PM: suspend entry (deep) Filesystems sync: 0.000 seconds Freezing user space processes ... (elapsed 0.001 seconds) done. OOM killer disabled. Freezing remaining freezable tasks ... Freezing of tasks failed after 20.003 seconds (1 tasks refusing to freeze, wq_busy=0): hwrng R running task 0 289 2 0x00000020 [<c08c64c4>] (__schedule) from [<c08c6a10>] (schedule+0x3c/0xc0) [<c08c6a10>] (schedule) from [<c05dbd8c>] (add_hwgenerator_randomness+0xb0/0x100) [<c05dbd8c>] (add_hwgenerator_randomness) from [<bf1803c8>] (hwrng_fillfn+0xc0/0x14c [rng_core]) [<bf1803c8>] (hwrng_fillfn [rng_core]) from [<c015abec>] (kthread+0x134/0x148) [<c015abec>] (kthread) from [<c01010e8>] (ret_from_fork+0x14/0x2c) Check for a freezer signal here and skip adding any randomness if the task wakes up because it was frozen. This should make the kthread freeze properly and suspend work again. Fixes: 03a3bb7ae631 ("hwrng: core - Freeze khwrng thread during suspend") Reported-by: Keerthy <j-keerthy@ti.com> Tested-by: Keerthy <j-keerthy@ti.com> Signed-off-by: Stephen Boyd <swboyd@chromium.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/char/random.c')
-rw-r--r--drivers/char/random.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 5d5ea4ce1442..e2e85ca16410 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -2429,6 +2429,7 @@ void add_hwgenerator_randomness(const char *buffer, size_t count,
2429 size_t entropy) 2429 size_t entropy)
2430{ 2430{
2431 struct entropy_store *poolp = &input_pool; 2431 struct entropy_store *poolp = &input_pool;
2432 bool frozen = false;
2432 2433
2433 if (unlikely(crng_init == 0)) { 2434 if (unlikely(crng_init == 0)) {
2434 crng_fast_load(buffer, count); 2435 crng_fast_load(buffer, count);
@@ -2439,9 +2440,12 @@ void add_hwgenerator_randomness(const char *buffer, size_t count,
2439 * We'll be woken up again once below random_write_wakeup_thresh, 2440 * We'll be woken up again once below random_write_wakeup_thresh,
2440 * or when the calling thread is about to terminate. 2441 * or when the calling thread is about to terminate.
2441 */ 2442 */
2442 wait_event_interruptible(random_write_wait, kthread_should_stop() || 2443 wait_event_interruptible(random_write_wait,
2444 kthread_freezable_should_stop(&frozen) ||
2443 ENTROPY_BITS(&input_pool) <= random_write_wakeup_bits); 2445 ENTROPY_BITS(&input_pool) <= random_write_wakeup_bits);
2444 mix_pool_bytes(poolp, buffer, count); 2446 if (!frozen) {
2445 credit_entropy_bits(poolp, entropy); 2447 mix_pool_bytes(poolp, buffer, count);
2448 credit_entropy_bits(poolp, entropy);
2449 }
2446} 2450}
2447EXPORT_SYMBOL_GPL(add_hwgenerator_randomness); 2451EXPORT_SYMBOL_GPL(add_hwgenerator_randomness);