]> git.itanic.dy.fi Git - linux-stable/commit
random: align entropy_timer_state to cache line
authorJason A. Donenfeld <Jason@zx2c4.com>
Wed, 30 Nov 2022 02:02:05 +0000 (03:02 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Sun, 4 Dec 2022 13:37:08 +0000 (14:37 +0100)
commit39ec9e6b141e5a9d7274f40531888f890385a013
tree3a08982293fe2b6380b160dda771d328419478c3
parentb83e45fd065c3cfdb8cc0179bbddf296ce4d4fda
random: align entropy_timer_state to cache line

The theory behind the jitter dance is that multiple things are poking at
the same cache line. This only works, however, if what's being poked at
is actually all in the same cache line. Ensure this is the case by
aligning the struct on the stack to the cache line size.

We can't use ____cacheline_aligned on a stack variable, because gcc
assumes 16 byte alignment when only 8 byte alignment is provided by the
kernel, which means gcc could technically do something pathological
like `(rsp & ~48) - 64`. It doesn't, but rather than risk it, just do
the stack alignment manually with PTR_ALIGN and an oversized buffer.

Fixes: 50ee7529ec45 ("random: try to actively add entropy rather than passively wait for it")
Cc: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
drivers/char/random.c