From: Eric Biggers <ebiggers@kernel.org>
To: "Becker, Hanno" <beckphan@amazon.co.uk>
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>,
"linux-crypto@vger.kernel.org" <linux-crypto@vger.kernel.org>,
David Howells <dhowells@redhat.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
Luis Chamberlain <mcgrof@kernel.org>,
Petr Pavlu <petr.pavlu@suse.com>,
Daniel Gomez <da.gomez@kernel.org>,
Sami Tolvanen <samitolvanen@google.com>,
Ard Biesheuvel <ardb@kernel.org>,
Stephan Mueller <smueller@chronox.de>,
Lukas Wunner <lukas@wunner.de>,
Ignat Korchagin <ignat@cloudflare.com>,
"keyrings@vger.kernel.org" <keyrings@vger.kernel.org>,
"linux-modules@vger.kernel.org" <linux-modules@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"matthias@kannwischer.eu" <matthias@kannwischer.eu>
Subject: Re: [PATCH 1/4] lib/crypto: Add ML-DSA verification support
Date: Sun, 30 Nov 2025 11:06:01 -0800 [thread overview]
Message-ID: <20251130190601.GC1395@sol> (raw)
In-Reply-To: <1CB2640E-B918-4C90-933D-61D5B1954E6C@amazon.co.uk>
On Sun, Nov 30, 2025 at 07:15:22AM +0000, Becker, Hanno wrote:
> > - Vector registers (e.g. AVX) can be used in the kernel only in some
> > contexts, and only when they are explicitly saved and restored. So
> > we have to do our own integration of any code that uses them anyway.
> > There is also more overhead to each vector-optimized function than
> > there is in userspace, so very fine-grained optimization (e.g. as is
> > used in the Dilithium reference code) doesn't work too well.
>
> That's very useful, can you say more? Would one want some sort of
> configurable preamble/postamble in the top-level API which takes care of
> the necessary save/restore logic?
>
> What is the per-function overhead?
It varies by architecture, but usually it looks something like:
if (irq_fpu_usable()) {
kernel_fpu_begin();
avx_function();
kernel_fpu_end();
} else {
generic_function();
}
The overhead varies significantly by CPU, kernel config options, and
whether it's the first use since the current task last entered the
kernel. But it can be up to a few hundred cycles.
> > Note that the kernel already has optimized Keccak code. That already
> > covers the most performance-critical part of ML-DSA.
>
> No, this would need _batched_ Keccak. An ML-DSA implementation using
> only 1x-Keccak will never have competitive performance. See
> https://github.com/pq-code-package/mldsa-native/pull/754 for the
> performance loss from using unbatched Keccak only, on a variety of
> platforms; it's >2x for some.
>
> In turn, if you want to integrate batched Keccak -- but perhaps only on
> some platforms? -- you need to rewrite your entire code to make use of
> it. That's not a simple change, and part of what I mean when I say that
> the challenges are just deferred. Note that the official reference and
> AVX2 implementations duck this problem by duplicating the code and
> adjusting it, rather than looking for a common structure that could host
> both 'plain' and batched Keccak. I assume the amount of code duplication
> this brings would be unacceptable.
At least in my code, only the matrix expansion code would need to change
to take advantage of interleaved Keccak. The fact that other
implementations apparently are having trouble with this actually
suggests to me that perhaps they're not good implementations to use.
Anyway, no one has said they want this particular optimization in the
kernel anyway. And hopefully the future is native Keccak support
anyway; s390 already has it, and (at least) RISC-V is working on it.
- Eric
next prev parent reply other threads:[~2025-11-30 19:07 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-20 0:36 [PATCH 0/4] lib/crypto: ML-DSA verification support Eric Biggers
2025-11-20 0:36 ` [PATCH 1/4] lib/crypto: Add " Eric Biggers
2025-11-29 20:00 ` Becker, Hanno
2025-11-30 0:19 ` Eric Biggers
2025-11-30 1:05 ` Jason A. Donenfeld
2025-11-30 7:15 ` Becker, Hanno
2025-11-30 19:06 ` Eric Biggers [this message]
2025-11-20 0:36 ` [PATCH 2/4] lib/crypto: tests: Add KUnit tests for ML-DSA Eric Biggers
2025-11-20 2:29 ` Elliott, Robert (Servers)
2025-11-20 0:36 ` [PATCH 3/4] lib/crypto: tests: Add ML-DSA-65 test cases Eric Biggers
2025-11-20 0:36 ` [PATCH 4/4] lib/crypto: tests: Add ML-DSA-87 " Eric Biggers
2025-11-20 8:11 ` [PATCH 0/4] lib/crypto: ML-DSA verification support David Howells
2025-11-21 6:16 ` Eric Biggers
2025-11-20 8:14 ` [PATCH 1/4] lib/crypto: Add " David Howells
2025-11-21 2:15 ` Eric Biggers
2025-11-20 9:10 ` David Howells
2025-11-21 0:09 ` Eric Biggers
2025-11-20 13:55 ` David Howells
2025-11-21 0:50 ` Eric Biggers
2025-11-21 12:41 ` David Howells
2025-11-21 17:14 ` Eric Biggers
2025-11-25 4:29 ` Eric Biggers
2025-11-21 17:41 ` David Howells
2025-11-21 21:39 ` David Howells
2025-11-21 22:23 ` Eric Biggers
2025-11-21 22:29 ` Lukas Wunner
2025-11-21 22:48 ` 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=20251130190601.GC1395@sol \
--to=ebiggers@kernel.org \
--cc=Jason@zx2c4.com \
--cc=ardb@kernel.org \
--cc=beckphan@amazon.co.uk \
--cc=da.gomez@kernel.org \
--cc=dhowells@redhat.com \
--cc=herbert@gondor.apana.org.au \
--cc=ignat@cloudflare.com \
--cc=keyrings@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=matthias@kannwischer.eu \
--cc=mcgrof@kernel.org \
--cc=petr.pavlu@suse.com \
--cc=samitolvanen@google.com \
--cc=smueller@chronox.de \
/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).