Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: linux-crypto@vger.kernel.org
Cc: Ard Biesheuvel <ardb@kernel.org>,
	"Jason A . Donenfeld" <Jason@zx2c4.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	x86@kernel.org
Subject: Re: [PATCH 2/3] lib/crypto: x86: Opt out of initializing MXCSR and 387 state
Date: Sat, 7 Nov 2026 13:56:02 -0800	[thread overview]
Message-ID: <20261107215602.GJ137269@quark> (raw)
In-Reply-To: <20261105005523.84925-3-ebiggers@kernel.org>

On Wed, Nov 04, 2026 at 04:55:22PM -0800, Eric Biggers wrote:
> The crypto code using "kernel-mode FPU" is integer code that does not
> use any MMX or x87 instructions.  To the extent that float-domain
> instructions are used at all, they are only moves and shuffles, neither
> of which raises SIMD floating-point exceptions or depends on MXCSR.
> 
> Therefore, there's no need to initialize MXCSR or the 387 FPU state.
> 
> Opt out of this initialization by using kernel_fpu_begin_mask(0) instead
> of kernel_fpu_begin().  This eliminates an 'ldmxcsr' instruction in
> every kernel-mode FPU section, reducing overhead, which matters most for
> short input lengths.  On 32-bit kernels it also eliminates 'fninit'.
> 
> A precedent for this optimization can be found in
> commit a58db7ad80e8 ("netfilter: nft_set_pipapo_avx2: Skip LDMXCSR, we
> don't need a valid MXCSR state").
> 
> Signed-off-by: Eric Biggers <ebiggers@kernel.org>
> ---
>  lib/crypto/x86/aes.h       | 24 ++++++++++++------------
>  lib/crypto/x86/blake2s.h   |  2 +-
>  lib/crypto/x86/chacha.h    |  4 ++--
>  lib/crypto/x86/gf128hash.h |  8 ++++----
>  lib/crypto/x86/nh.h        |  2 +-
>  lib/crypto/x86/poly1305.h  |  2 +-
>  lib/crypto/x86/sha1.h      |  4 ++--
>  lib/crypto/x86/sha256.h    |  4 ++--
>  lib/crypto/x86/sha512.h    |  2 +-
>  lib/crypto/x86/sm3.h       |  2 +-
>  10 files changed, 27 insertions(+), 27 deletions(-)

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git/log/?h=libcrypto-next

Reviews and acks appreciated!

- Eric

  reply	other threads:[~2026-11-07 21:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-05  0:55 [PATCH 0/3] crc, crypto: Opt out of initializing MXCSR and 387 state Eric Biggers
2026-11-05  0:55 ` [PATCH 1/3] lib/crc: x86: " Eric Biggers
2026-11-07 21:34   ` Eric Biggers
2026-11-05  0:55 ` [PATCH 2/3] lib/crypto: " Eric Biggers
2026-11-07 21:56   ` Eric Biggers [this message]
2026-11-05  0:55 ` [PATCH 3/3] crypto: x86 - " Eric Biggers
2026-11-07 21:57   ` Eric Biggers

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=20261107215602.GJ137269@quark \
    --to=ebiggers@kernel.org \
    --cc=Jason@zx2c4.com \
    --cc=ardb@kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=x86@kernel.org \
    /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