Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Etienne Cordonnier <ecordonnier@snap.com>
Cc: Jason@zx2c4.com, ardb@kernel.org, linux-crypto@vger.kernel.org
Subject: Re: [PATCH v2] lib/crypto: mpi: use a 128-bit multiply for umul_ppmm() when available
Date: Sat, 5 Dec 2026 18:10:20 -0800	[thread overview]
Message-ID: <20261206021020.GB362402@quark> (raw)
In-Reply-To: <20261127221711.3585352-1-ecordonnier@snap.com>

On Fri, Nov 27, 2026 at 11:17:11PM +0100, Etienne Cordonnier wrote:
> longlong.h only has architecture-specific umul_ppmm() implementations
> for a handful of CPUs. On every other 64-bit architecture, including
> arm64 and x86_64, umul_ppmm() falls back to generic C that builds each
> 64x64->128 product out of four 32x32 multiplications plus carry
> handling. umul_ppmm() is in the inner loops of mpihelp_mul_1(),
> mpihelp_addmul_1(), mpihelp_submul_1() and the division code, so this
> slows down every mpi_powm(), e.g. each RSA signature verification
> (module signatures, X.509).
> 
> Add a variant of umul_ppmm() based on a u128 multiplication, for 64-bit
> architectures that select CONFIG_ARCH_SUPPORTS_INT128. It sits just
> before the generic fallback, so architectures that provide their own
> umul_ppmm() are unaffected. The compiler turns it into a widening
> multiply: mul + umulh on arm64, mul on x86_64.
> 
> On an arm64 Cortex-A55 at 1.5 GHz, the time spent in mpi_powm() per
> RSA-4096 module signature verification (measured with kprobes on a 6.1
> kernel with the arm64 version of this change backported) goes from
> 1286 us to 1201 us (-6.6%). A userspace build of the same code shows
> the same direction at other modulus sizes (2048/3072/4096 bits:
> 0.42/0.85/1.44 ms before, 0.35/0.70/1.19 ms after). Other
> architectures were not benchmarked.
> 
> The new macro gives the same results as the generic C one on 200 million
> random and edge-case inputs. It builds without warnings on arm64 and
> x86_64. On arm64 (QEMU virt, cortex-a57), rsa-generic passes the
> self-tests with CONFIG_CRYPTO_SELFTESTS_FULL. It was not run on x86_64 or
> other architectures.
> 
> AI assistance: this patch and its changelog were written by Claude
> Sonnet 5.5 (Anthropic), used through Claude Code, and reviewed by the
> submitter.
> 
> Signed-off-by: Etienne Cordonnier <ecordonnier@snap.com>
> ---
> Changes in v2 (suggested by Eric Biggers):
>  - Drop the __aarch64__ condition and put the u128 variant right before
>    the generic fallback, so it applies to every 64-bit architecture that
>    selects CONFIG_ARCH_SUPPORTS_INT128 and has no umul_ppmm() of its own.
>  - Retitle and reword the changelog accordingly.
>  - v1 was arm64-only.

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

- Eric

      reply	other threads:[~2026-12-06  2:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 22:17 [PATCH v2] lib/crypto: mpi: use a 128-bit multiply for umul_ppmm() when available Etienne Cordonnier
2026-12-06  2:10 ` 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=20261206021020.GB362402@quark \
    --to=ebiggers@kernel.org \
    --cc=Jason@zx2c4.com \
    --cc=ardb@kernel.org \
    --cc=ecordonnier@snap.com \
    --cc=linux-crypto@vger.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