]> git.baikalelectronics.ru Git - kernel.git/commitdiff
random: avoid reading two cache lines on irq randomness
authorJason A. Donenfeld <Jason@zx2c4.com>
Thu, 22 Sep 2022 16:46:04 +0000 (18:46 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 15 Oct 2022 05:54:40 +0000 (07:54 +0200)
commit 6ec29fe083cb65fa8ac4aa360f19d841be5483ca upstream.

In order to avoid reading and dirtying two cache lines on every IRQ,
move the work_struct to the bottom of the fast_pool struct. add_
interrupt_randomness() always touches .pool and .count, which are
currently split, because .mix pushes everything down. Instead, move .mix
to the bottom, so that .pool and .count are always in the first cache
line, since .mix is only accessed when the pool is full.

Fixes: b4d32c9bcc75 ("random: defer fast pool mixing to worker")
Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/char/random.c

index cdfd97f000b2b5b25ca1b774f0638639fac23cc3..5fad80149c1ad2a2fed20fcbfb7b80e0c10e84dd 100644 (file)
@@ -890,10 +890,10 @@ void __init add_bootloader_randomness(const void *buf, size_t len)
 }
 
 struct fast_pool {
-       struct work_struct mix;
        unsigned long pool[4];
        unsigned long last;
        unsigned int count;
+       struct work_struct mix;
 };
 
 static DEFINE_PER_CPU(struct fast_pool, irq_randomness) = {