From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: vladimir.murzin@arm.com, linux-kernel@vger.kernel.org
Cc: linux-crypto@vger.kernel.org, ebiggers@google.com, tytso@mit.edu,
torvalds@linux-foundation.org,
"Jason A. Donenfeld" <Jason@zx2c4.com>
Subject: [PATCH] random: cap jitter samples per bit to factor of HZ
Date: Wed, 13 Jul 2022 17:11:15 +0200 [thread overview]
Message-ID: <20220713151115.1014188-1-Jason@zx2c4.com> (raw)
In-Reply-To: <CAHmME9rrQVm72P6cLL4dUnSw+9nnXszDbQXRd3epRaQgKTy8BQ@mail.gmail.com>
Currently the jitter mechanism will require two timer ticks per
iteration, and it requires N iterations per bit. This N is determined
with a small measurement, and if it's too big, it won't waste time with
jitter entropy because it'd take too long or not have sufficient entropy
anyway.
With the current max N of 32, there are large timeouts on systems with a
small CONFIG_HZ. Rather than set that maximum to 32, instead choose a
factor of CONFIG_HZ. In this case, 1/30 seems to yield sane values for
different configurations of CONFIG_HZ.
Reported-by: Vladimir Murzin <vladimir.murzin@arm.com>
Fixes: 78c768e619fb ("random: vary jitter iterations based on cycle counter speed")
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
Vladimir - Can you let me know if this appears to fix the issue you're
seeing? -Jason
drivers/char/random.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/char/random.c b/drivers/char/random.c
index e3dd1dd3dd22..a1af90bacc9f 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1174,7 +1174,7 @@ static void __cold entropy_timer(struct timer_list *timer)
*/
static void __cold try_to_generate_entropy(void)
{
- enum { NUM_TRIAL_SAMPLES = 8192, MAX_SAMPLES_PER_BIT = 32 };
+ enum { NUM_TRIAL_SAMPLES = 8192, MAX_SAMPLES_PER_BIT = HZ / 30 };
struct entropy_timer_state stack;
unsigned int i, num_different = 0;
unsigned long last = random_get_entropy();
--
2.35.1
next prev parent reply other threads:[~2022-07-13 15:11 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-22 13:20 [PATCH] random: vary jitter iterations based on cycle counter speed Jason A. Donenfeld
2022-07-13 14:31 ` Vladimir Murzin
2022-07-13 14:40 ` Jason A. Donenfeld
2022-07-13 14:52 ` Vladimir Murzin
2022-07-13 14:53 ` Jason A. Donenfeld
2022-07-13 15:11 ` Jason A. Donenfeld [this message]
2022-07-13 15:52 ` [PATCH] random: cap jitter samples per bit to factor of HZ Vladimir Murzin
2022-07-13 16:21 ` Jason A. Donenfeld
2022-07-16 17:45 ` Linus Torvalds
2022-07-16 18:09 ` 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=20220713151115.1014188-1-Jason@zx2c4.com \
--to=jason@zx2c4.com \
--cc=ebiggers@google.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=tytso@mit.edu \
--cc=vladimir.murzin@arm.com \
/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