Messages in this thread Patch in this message | | | From | Sebastian Andrzej Siewior <> | Subject | [PATCH 4/5] random: Move the fast_pool reset into the caller. | Date | Tue, 7 Dec 2021 13:17:36 +0100 |
| |
The state of the fast_pool (number of added entropy, timestamp of last addition) is reset after entropy has been consumed.
Move the reset of the fast_pool into the caller. This is a preparations step to ease PREEMPT_RT support.
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> --- drivers/char/random.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)
diff --git a/drivers/char/random.c b/drivers/char/random.c index dfc38d87125f5..4bcaa7886201d 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -1242,37 +1242,35 @@ static __u32 get_reg(struct fast_pool *f, struct pt_regs *regs) return *ptr; } -static void process_interrupt_randomness_pool(struct fast_pool *fast_pool) +static bool process_interrupt_randomness_pool(struct fast_pool *fast_pool) { struct entropy_store *r; - unsigned long now = jiffies; if (unlikely(crng_init == 0)) { + bool pool_reset = false; + if ((fast_pool->count >= 64) && crng_fast_load((char *) fast_pool->pool, - sizeof(fast_pool->pool))) { - fast_pool->count = 0; - fast_pool->last = now; - } - return; + sizeof(fast_pool->pool))) + pool_reset = true; + + return pool_reset; } if ((fast_pool->count < 64) && - !time_after(now, fast_pool->last + HZ)) - return; + !time_after(jiffies, fast_pool->last + HZ)) + return false; r = &input_pool; if (!spin_trylock(&r->lock)) - return; + return false; - fast_pool->last = now; __mix_pool_bytes(r, &fast_pool->pool, sizeof(fast_pool->pool)); spin_unlock(&r->lock); - fast_pool->count = 0; - /* award one bit for the contents of the fast pool */ credit_entropy_bits(r, 1); + return true; } void add_interrupt_randomness(int irq) @@ -1298,7 +1296,10 @@ void add_interrupt_randomness(int irq) fast_mix(fast_pool); add_interrupt_bench(cycles); - process_interrupt_randomness_pool(fast_pool); + if (process_interrupt_randomness_pool(fast_pool)) { + fast_pool->last = now; + fast_pool->count = 0; + } } EXPORT_SYMBOL_GPL(add_interrupt_randomness); -- 2.34.1
| |