random: unify batched entropy implementations
authorJason A. Donenfeld <Jason@zx2c4.com>
Sat, 14 May 2022 22:22:05 +0000 (00:22 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Thu, 19 May 2022 14:54:15 +0000 (16:54 +0200)
commit3092adcef3ffd2ef59634998297ca8358461ebce
tree85622e184a0d9c523368ed4c1ab3f08ddcfbf29e
parent5ad7dd882e45d7fe432c32e896e2aaa0b21746ea
random: unify batched entropy implementations

There are currently two separate batched entropy implementations, for
u32 and u64, with nearly identical code, with the goal of avoiding
unaligned memory accesses and letting the buffers be used more
efficiently. Having to maintain these two functions independently is a
bit of a hassle though, considering that they always need to be kept in
sync.

This commit factors them out into a type-generic macro, so that the
expansion produces the same code as before, such that diffing the
assembly shows no differences. This will also make it easier in the
future to add u16 and u8 batches.

This was initially tested using an always_inline function and letting
gcc constant fold the type size in, but the code gen was less efficient,
and in general it was more verbose and harder to follow. So this patch
goes with the boring macro solution, similar to what's already done for
the _wait functions in random.h.

Cc: Dominik Brodowski <linux@dominikbrodowski.net>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
drivers/char/random.c