Skip to content

Commit 1227334

Browse files
committed
random: schedule jitter credit for next jiffy, not in two jiffies
Counterintuitively, mod_timer(..., jiffies + 1) will cause the timer to fire not in the next jiffy, but in two jiffies. The way to cause the timer to fire in the next jiffy is with mod_timer(..., jiffies). Doing so then lets us bump the upper bound back up again. Fixes: 50ee752 ("random: try to actively add entropy rather than passively wait for it") Fixes: 829d680 ("random: cap jitter samples per bit to factor of HZ") Cc: Dominik Brodowski <[email protected]> Cc: Sebastian Andrzej Siewior <[email protected]> Cc: Sultan Alsawaf <[email protected]> Signed-off-by: Jason A. Donenfeld <[email protected]>
1 parent 4c95236 commit 1227334

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/char/random.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,7 @@ static void __cold entropy_timer(struct timer_list *timer)
12051205
*/
12061206
static void __cold try_to_generate_entropy(void)
12071207
{
1208-
enum { NUM_TRIAL_SAMPLES = 8192, MAX_SAMPLES_PER_BIT = HZ / 30 };
1208+
enum { NUM_TRIAL_SAMPLES = 8192, MAX_SAMPLES_PER_BIT = HZ / 15 };
12091209
struct entropy_timer_state stack;
12101210
unsigned int i, num_different = 0;
12111211
unsigned long last = random_get_entropy();
@@ -1224,7 +1224,7 @@ static void __cold try_to_generate_entropy(void)
12241224
timer_setup_on_stack(&stack.timer, entropy_timer, 0);
12251225
while (!crng_ready() && !signal_pending(current)) {
12261226
if (!timer_pending(&stack.timer))
1227-
mod_timer(&stack.timer, jiffies + 1);
1227+
mod_timer(&stack.timer, jiffies);
12281228
mix_pool_bytes(&stack.entropy, sizeof(stack.entropy));
12291229
schedule();
12301230
stack.entropy = random_get_entropy();

0 commit comments

Comments
 (0)