Subject: Re: [PATCH v3] random: handle archrandom with multiple longs

From: Catalin Marinas <[email-masked]>
Date: Tue, 19 Jul 2022 14:48:42 +0100

On Tue, Jul 19, 2022 at 03:02:07PM +0200, Jason A. Donenfeld wrote:
> The archrandom interface was originally designed for x86, which supplies
> RDRAND/RDSEED for receiving random words into registers, resulting in
> one function to generate an int and another to generate a long. However,
> other architectures don't follow this.
> 
> On arm64, the SMCCC TRNG interface can return between 1 and 3 longs. On
> s390, the CPACF TRNG interface can return arbitrary amounts, with 32
> longs having the same cost as one. On UML, the os_getrandom() interface
> can return arbitrary amounts.
> 
> So change the api signature to take a "max_longs" parameter designating
> the maximum number of longs requested, and then return the number of
> longs generated.
> 
> Since callers need to check this return value and loop anyway, each arch
> implementation does not bother implementing its own loop to try again to
> fill the maximum number of longs. Additionally, all existing callers
> pass in a constant max_longs parameter. Taken together, these two things
> mean that the codegen doesn't really change much for one-word-at-a-time
> platforms, while performance is greatly improved on platforms such as
> s390.
> 
> Cc: Will Deacon <[email-masked]>
> Cc: Alexander Gordeev <[email-masked]>
> Cc: Thomas Gleixner <[email-masked]>
> Cc: H. Peter Anvin <[email-masked]>
> Cc: Catalin Marinas <[email-masked]>
> Cc: Borislav Petkov <[email-masked]>
> Cc: Heiko Carstens <[email-masked]>
> Cc: Johannes Berg <[email-masked]>
> Cc: Mark Rutland <[email-masked]>
> Cc: Harald Freudenberger <[email-masked]>
> Acked-by: Michael Ellerman <[email-masked]>
> Signed-off-by: Jason A. Donenfeld <[email-masked]>

For arm64:

Acked-by: Catalin Marinas <[email-masked]>