From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: linux-kernel@vger.kernel.org, linux@dominikbrodowski.net
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>, Theodore Ts'o <tytso@mit.edu>
Subject: [PATCH 3/3] random: use trylock in irq handler rather than spinning
Date: Sun, 13 Feb 2022 00:10:22 +0100 [thread overview]
Message-ID: <20220212231022.679926-4-Jason@zx2c4.com> (raw)
In-Reply-To: <20220212231022.679926-1-Jason@zx2c4.com>
crng_pre_init_inject() (and prior crng_fast_load()) uses a trylock when
in fast mode, so that it never contends. We should be doing the same
when grabbing a spinlock for mixing into the entropy pool. So switch to
doing that before calling the underscored _mix_pool_bytes().
Cc: Dominik Brodowski <linux@dominikbrodowski.net>
Cc: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
drivers/char/random.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 9a8e1bb9845d..ca224c3f2561 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1286,13 +1286,10 @@ void add_interrupt_randomness(int irq)
atomic_set(&fast_pool->count, 0);
fast_pool->last = now;
- /*
- * Technically this call means that we're using a spinlock_t
- * in the IRQ handler, which isn't terrific for PREEMPT_RT.
- * However, this only happens during boot, and then never
- * again, so we live with it.
- */
- mix_pool_bytes(&fast_pool->pool, sizeof(fast_pool->pool));
+ if (spin_trylock(&input_pool.lock)) {
+ _mix_pool_bytes(&fast_pool->pool, sizeof(fast_pool->pool));
+ spin_unlock(&input_pool.lock);
+ }
}
return;
}
--
2.35.0
next prev parent reply other threads:[~2022-02-12 23:10 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-12 23:10 [PATCH 0/3] cleanup init-time fast/slow key loading Jason A. Donenfeld
2022-02-12 23:10 ` [PATCH 1/3] random: unify early init crng load accounting Jason A. Donenfeld
2022-02-13 6:55 ` Dominik Brodowski
2022-02-13 10:56 ` Jason A. Donenfeld
2022-02-21 5:50 ` Eric Biggers
2022-02-21 15:22 ` Jason A. Donenfeld
2022-02-12 23:10 ` [PATCH 2/3] random: check for crng_init == 0, not crng_ready() in add_device_randomness() Jason A. Donenfeld
2022-02-13 6:55 ` Dominik Brodowski
2022-02-21 5:38 ` Eric Biggers
2022-02-12 23:10 ` Jason A. Donenfeld [this message]
2022-02-13 6:55 ` [PATCH 3/3] random: use trylock in irq handler rather than spinning Dominik Brodowski
2022-02-13 10:51 ` Jason A. Donenfeld
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220212231022.679926-4-Jason@zx2c4.com \
--to=jason@zx2c4.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@dominikbrodowski.net \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox