Re: [PATCH v3] random: handle archrandom with multiple longs
From: Jason A. Donenfeld
Date: Sun Jul 24 2022 - 18:48:47 EST
Hey Borislav (or other x86ers),
On Tue, Jul 19, 2022 at 3:02 PM Jason A. Donenfeld <Jason@xxxxxxxxx> 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.
This patch now has acks from Heiko, Catalin, Mark, and Michael,
covering the arm, ppc, and s390 changes. The changes to s390 and arm
were non-trivial so those acks were quite meaningful. On x86 and ppc,
the code compiles down to basically the same assembly and the change
really doesn't matter at all. Nonetheless, I thought I should give you
a final poke in case you want to ack or nack this, lest I step on the
tip.git of your shoes.
Jason