[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAMj1kXHkm=vgeymc6qSGtJRfY5AjhJhYJ7+ZD0OFdLw12vFE4w@mail.gmail.com>
Date: Thu, 4 Dec 2025 10:05:45 +0100
From: Ard Biesheuvel <ardb@...nel.org>
To: Eric Biggers <ebiggers@...nel.org>
Cc: linux-crypto@...r.kernel.org, linux-kernel@...r.kernel.org,
"Jason A . Donenfeld" <Jason@...c4.com>, Herbert Xu <herbert@...dor.apana.org.au>,
Thorsten Blum <thorsten.blum@...ux.dev>, Nathan Chancellor <nathan@...nel.org>,
Nick Desaulniers <nick.desaulniers+lkml@...il.com>, Bill Wendling <morbo@...gle.com>,
Justin Stitt <justinstitt@...gle.com>, David Laight <david.laight@...box.com>,
David Sterba <dsterba@...e.com>, llvm@...ts.linux.dev, linux-btrfs@...r.kernel.org
Subject: Re: [PATCH] lib/crypto: blake2b: Roll up BLAKE2b round loop on 32-bit
On Wed, 3 Dec 2025 at 20:09, Eric Biggers <ebiggers@...nel.org> wrote:
>
> BLAKE2b has a state of 16 64-bit words. Add the message data in and
> there are 32 64-bit words. With the current code where all the rounds
> are unrolled to enable constant-folding of the blake2b_sigma values,
> this results in a very large code size on 32-bit kernels, including a
> recurring issue where gcc uses a large amount of stack.
>
> There's just not much benefit to this unrolling when the code is already
> so large. Let's roll up the rounds when !CONFIG_64BIT. Then, remove
> the now-unnecessary override of the stack frame size warning.
>
> Code size improvements for blake2b_compress_generic():
>
> Size before (bytes) Size after (bytes)
> ------------------- ------------------
> i386, gcc 27584 3632
> i386, clang 18208 3248
> arm32, gcc 19912 2860
> arm32, clang 21336 3344
>
> Running the BLAKE2b benchmark on a !CONFIG_64BIT kernel on an x86_64
> processor shows a 16384B throughput change of 351 => 340 MB/s (gcc) or
> 442 MB/s => 375 MB/s (clang). So clearly not much of a slowdown either.
> But also that microbenchmark also effectively disregards cache usage,
> which is important in practice and is far better in the smaller code.
>
> Note: If we rolled up the loop on x86_64 too, the change would be
> 7024 bytes => 1584 bytes and 1960 MB/s => 1396 MB/s (gcc), or
> 6848 bytes => 1696 bytes and 1920 MB/s => 1263 MB/s (clang).
> Maybe still worth it, though not quite as clearly beneficial.
>
> Fixes: 91d689337fe8 ("crypto: blake2b - add blake2b generic implementation")
> Signed-off-by: Eric Biggers <ebiggers@...nel.org>
> ---
> lib/crypto/Makefile | 1 -
> lib/crypto/blake2b.c | 25 +++++++++++++------------
> 2 files changed, 13 insertions(+), 13 deletions(-)
>
Reviewed-by: Ard Biesheuvel <ardb@...nel.org>
Powered by blists - more mailing lists