From: Eric Biggers <ebiggers@kernel.org>
To: linux-crypto@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel <ardb@kernel.org>,
"Jason A . Donenfeld" <Jason@zx2c4.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
Thorsten Blum <thorsten.blum@linux.dev>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <nick.desaulniers+lkml@gmail.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>,
David Laight <david.laight@runbox.com>,
David Sterba <dsterba@suse.com>,
llvm@lists.linux.dev, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v2] lib/crypto: blake2b: Roll up BLAKE2b round loop on 32-bit
Date: Mon, 8 Dec 2025 15:09:41 -0800 [thread overview]
Message-ID: <20251208230941.GB1853@quark> (raw)
In-Reply-To: <20251205050330.89704-1-ebiggers@kernel.org>
On Thu, Dec 04, 2025 at 09:03:30PM -0800, Eric Biggers 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.
>
> To avoid having to duplicate the code, just write code once using a
> loop, and conditionally use 'unrolled_full' from <linux/unroll.h>.
>
> Then, fold the now-unneeded ROUND() macro into the loop. Finally, also
> remove the now-unneeded 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")
> Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
> Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git/log/?h=libcrypto-fixes
- Eric
prev parent reply other threads:[~2025-12-08 23:09 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-05 5:03 [PATCH v2] lib/crypto: blake2b: Roll up BLAKE2b round loop on 32-bit Eric Biggers
2025-12-08 23:09 ` Eric Biggers [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251208230941.GB1853@quark \
--to=ebiggers@kernel.org \
--cc=Jason@zx2c4.com \
--cc=ardb@kernel.org \
--cc=david.laight@runbox.com \
--cc=dsterba@suse.com \
--cc=herbert@gondor.apana.org.au \
--cc=justinstitt@google.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=nick.desaulniers+lkml@gmail.com \
--cc=thorsten.blum@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).