@@ -260,25 +260,23 @@ static void crng_fast_key_erasure(u8 key[CHACHA_KEY_SIZE],
260260}
261261
262262/*
263- * Return whether the crng seed is considered to be sufficiently old
264- * that a reseeding is needed. This happens if the last reseeding
265- * was CRNG_RESEED_INTERVAL ago, or during early boot, at an interval
263+ * Return the interval until the next reseeding, which is normally
264+ * CRNG_RESEED_INTERVAL, but during early boot, it is at an interval
266265 * proportional to the uptime.
267266 */
268- static bool crng_has_old_seed (void )
267+ static unsigned int crng_reseed_interval (void )
269268{
270269 static bool early_boot = true;
271- unsigned long interval = CRNG_RESEED_INTERVAL ;
272270
273271 if (unlikely (READ_ONCE (early_boot ))) {
274272 time64_t uptime = ktime_get_seconds ();
275273 if (uptime >= CRNG_RESEED_INTERVAL / HZ * 2 )
276274 WRITE_ONCE (early_boot , false);
277275 else
278- interval = max_t (unsigned int , CRNG_RESEED_START_INTERVAL ,
279- (unsigned int )uptime / 2 * HZ );
276+ return max_t (unsigned int , CRNG_RESEED_START_INTERVAL ,
277+ (unsigned int )uptime / 2 * HZ );
280278 }
281- return time_is_before_jiffies ( READ_ONCE ( base_crng . birth ) + interval ) ;
279+ return CRNG_RESEED_INTERVAL ;
282280}
283281
284282/*
@@ -320,7 +318,7 @@ static void crng_make_state(u32 chacha_state[CHACHA_STATE_WORDS],
320318 * If the base_crng is old enough, we reseed, which in turn bumps the
321319 * generation counter that we check below.
322320 */
323- if (unlikely (crng_has_old_seed ( )))
321+ if (unlikely (time_is_before_jiffies ( READ_ONCE ( base_crng . birth ) + crng_reseed_interval () )))
324322 crng_reseed ();
325323
326324 local_lock_irqsave (& crngs .lock , flags );
@@ -866,11 +864,11 @@ void add_hwgenerator_randomness(const void *buf, size_t len, size_t entropy)
866864 credit_init_bits (entropy );
867865
868866 /*
869- * Throttle writing to once every CRNG_RESEED_INTERVAL , unless
870- * we're not yet initialized.
867+ * Throttle writing to once every reseed interval , unless we're not yet
868+ * initialized.
871869 */
872870 if (!kthread_should_stop () && crng_ready ())
873- schedule_timeout_interruptible (CRNG_RESEED_INTERVAL );
871+ schedule_timeout_interruptible (crng_reseed_interval () );
874872}
875873EXPORT_SYMBOL_GPL (add_hwgenerator_randomness );
876874
0 commit comments