Commit e43478c1 authored by Jason A. Donenfeld's avatar Jason A. Donenfeld Committed by Jialin Zhang
Browse files

random: avoid reading two cache lines on irq randomness

stable inclusion
from stable-v5.10.148
commit c1a4423fd30f6ff4289be19786c9e76b5ac104a6
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I6D0WL

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=c1a4423fd30f6ff4289be19786c9e76b5ac104a6



--------------------------------

commit 9ee0507e 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: 58340f8e ("random: defer fast pool mixing to worker")
Reviewed-by: default avatarSebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarJialin Zhang <zhangjialin11@huawei.com>
Reviewed-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parent 0c65c874
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -895,10 +895,10 @@ void __cold add_bootloader_randomness(const void *buf, size_t len)
EXPORT_SYMBOL_GPL(add_bootloader_randomness);

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) = {