From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795982661; b=r/3R6i4lE1zm5iXsNPTcTf8y4GORSgyqFlxSvlOzIMMYDVftqbZYsTgT3PISSpUwOVfK GLvgFCymOgt+DcoxNrZOnvRwY7Ep56lCmH0Vn+V7EM1faYdaMlJ5EGMa4ViQ28LZ6giwP kyL0Din9BxDcgAn/LUo0E85TRQnA6lwpDrYLZygjxE43RNISqpyLcf/F5Tb+lZVQLC1OX v9xSkoA5IQrMn+OTg37WeJuil64fU7H+nfdqRkcy8BX+t4JkgoWGPi3WJ737e4EkPKPow HfyZhEBpylWck9vbHU8X0tDbqugZm+oxB3Oz9lzXmnTanhsDo8hFv/VVbKyt+7YHW1g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795982661; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: MIME-Version:Content-Transfer-Encoding; bh=5cpU3PhkA3PRIFRcZK30e30avfquqbKi9TdeA1p8pQc=; b=HpSQEvCqGEWG7AXpL94i5Y4p3/eRqAJT35z7ciCmQLnnH3U4AOFAo+bqf6ke2ZN22fA7 kBCwDSlK8CwZ5JTc44QGYcokjTVJt9WR1dE/uT8FZDFOgue9orFfFxNkWSOlu3sv2b325 0WGq4k090JFSAZpxisEszM0tg0EHd5RkG2zE5sqOYUZrxo4G87bHG2/KU8CgB9GsmLzmg bLjk7Y1gieurJkc6vnlR+T6dywT57DLObUhov0scVwdu1Q413yL0x0c/yySNQqYSfPUcJ I7YMOqtpRUu4VqJOM/fgPCVR5UZfQ4kUKH4LKYwCf2TBftnGorOgg2MszRolQ1nK/kQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="oaMS/+GJ"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5B25606A31C for ; Sun, 29 Nov 2026 20:04:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=oaMS/+GJ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A6BB1F00896; Sun, 29 Nov 2026 20:04:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795982661; bh=5cpU3PhkA3PRIFRcZK30e30avfquqbKi9TdeA1p8pQc=; h=From:To:Cc:Subject:Date; b=oaMS/+GJJ/qFjRUR3qkEfIrXLxL96wn8e7IddEzaFY0DW6IOFqUu1glHKm0FltAeG 3oYtBbvwaV817ZCL9K299qMj/qF05/dCe0lQWXOfGhjFWTBz6By8l4KOLA+yd4J939 IoQ2r7BvSQfF2HhcfM/OrnMNsh0iXOk4nsbr8f9Qim+k/7e1PRAD9KpEWJmC7z6D2r Pu+VmWjFFz3iPyPgK2BkCWG6kUXtMP/8vTl1Sg/9eXh7NQFhTWocW9SAsAvNu7r+2m iWcegdab7FOF970aLPV0+kH9XgZsAaGVOtgQovj+jLb4TibT7IcjCsSHaA35fKGkpn 2GAeoQIeEDSxw== From: Eric Biggers To: linux-crypto@vger.kernel.org Cc: Ard Biesheuvel , "Jason A . Donenfeld" , Herbert Xu , x86@kernel.org, Antonio Quartulli , Eric Biggers Subject: [PATCH 00/11] Migrate x86_64 AES-GCM code into library Date: Sun, 29 Nov 2026 12:02:34 -0800 Message-ID: <20261129200245.146503-1-ebiggers@kernel.org> X-Mailer: git-send-email 2.56.1 X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This series is targeting libcrypto-next. It can also be retrieved from: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git aes-gcm-x86-v1 This series migrates the x86_64 optimized AES-GCM code into lib/crypto/, fully optimizing the AES-GCM library functions on x86_64. (As usual, it also fixes the longstanding issue where the architecture-optimized code was disabled by default. The library always enables optimizations, as long as the algorithm is enabled at all.) It's divided into several parts: - Patches 1-2 fix a couple existing bugs. - Patches 3-4 add architecture hooks for one-shot AES-GCM and add a linear fast path to AES-GCM. These are needed for parity with the existing short message optimizations used in aesni-intel_glue.c. - Patches 5-7 replace the existing, not very well optimized GHASH and POLYVAL library code with new highly optimized code. It's roughly based on the GHASH code in the three AES-GCM assembly files, and like the AES-GCM code there are three versions for different CPU feature sets: pclmul, vpclmul+avx2, and vpclmul+avx512. This was a prerequisite for migrating the AES-GCM code (since the AES-GCM library uses the GHASH library, including its key format). But I've gone a bit further and unified the GHASH and POLYVAL code as well, with the same assembly macros generating support for both. GHASH and POLYVAL are nearly identical, so this makes a lot of sense. - Patches 8-10 migrate the x86_64 optimized AES-GCM code into the library, one patch per assembly file. - Patch 11 deletes the aesni-intel module (which no longer has any functionality left in it) and keeps CRYPTO_AES_NI_INTEL only as a transitional symbol that causes AES-XTS support to be selected. On long lengths, the KUnit benchmarks of the crypto library code on AMD Ryzen 9 9950X (Zen 5) show the following performance improvements: GHASH: 1928 MB/s => 39348 MB/s POLYVAL: 10689 MB/s => 39020 MB/s AES-GCM: 1747 MB/s => 26937 MB/s Patches 5-10 contain more library benchmark results. AES-GCM crypto_aead performance did not significantly change (except for very long associated data lengths without VAES, which got much faster). HCTR2 crypto_skcipher performance got faster due to the POLYVAL speedup. AI disclosure: AI coding tools were used to help write, revise, and review this patchset. But as usual it went through a lot of iterations, with extensive manual review and editing (and prompting) to get things the way I wanted. Eric Biggers (11): crypto: aes - Flush dcache in CBC-CTS and XTS linear fast paths lib/crypto: gf128hash: Link libgf128hash before libaes lib/crypto: aes-gcm: Add one-shot AES-GCM arch hooks crypto: aes - Add linear fast path for AES-GCM lib/crypto: x86/gf128hash: Optimize GHASH and POLYVAL with PCLMULQDQ and AVX lib/crypto: x86/gf128hash: Optimize GHASH and POLYVAL with VPCLMULQDQ and AVX2 lib/crypto: x86/gf128hash: Optimize GHASH and POLYVAL with VPCLMULQDQ and AVX512 lib/crypto: x86/aes-gcm: Migrate AES-NI optimized code into library lib/crypto: x86/aes-gcm: Migrate VAES+AVX2 optimized code into library lib/crypto: x86/aes-gcm: Migrate VAES+AVX512 optimized code into library crypto: x86/aesni-intel - Remove empty module Documentation/filesystems/fscrypt.rst | 2 - arch/x86/crypto/Kconfig | 25 - arch/x86/crypto/Makefile | 6 - arch/x86/crypto/aesni-intel_glue.c | 888 ------------------ crypto/Kconfig | 9 + crypto/aes.c | 213 ++++- include/crypto/gf128hash.h | 48 +- lib/crypto/Kconfig | 2 +- lib/crypto/Makefile | 64 +- lib/crypto/aes.c | 97 +- .../crypto/x86}/aes-gcm-aesni-x86_64.S | 414 +++----- .../crypto/x86}/aes-gcm-vaes-avx2.S | 419 ++------- .../crypto/x86}/aes-gcm-vaes-avx512.S | 374 ++------ lib/crypto/x86/aes.h | 352 ++++++- lib/crypto/x86/gf128hash-cpu.h | 54 ++ lib/crypto/x86/gf128hash-pclmul.S | 559 +++++++++++ lib/crypto/x86/gf128hash-vpclmul-avx2.S | 537 +++++++++++ lib/crypto/x86/gf128hash-vpclmul-avx512.S | 516 ++++++++++ lib/crypto/x86/gf128hash.h | 322 +++++-- lib/crypto/x86/ghash-pclmul.S | 127 --- lib/crypto/x86/polyval-pclmul-avx.S | 319 ------- 21 files changed, 2933 insertions(+), 2414 deletions(-) delete mode 100644 arch/x86/crypto/aesni-intel_glue.c rename {arch/x86/crypto => lib/crypto/x86}/aes-gcm-aesni-x86_64.S (75%) rename {arch/x86/crypto => lib/crypto/x86}/aes-gcm-vaes-avx2.S (69%) rename {arch/x86/crypto => lib/crypto/x86}/aes-gcm-vaes-avx512.S (74%) create mode 100644 lib/crypto/x86/gf128hash-cpu.h create mode 100644 lib/crypto/x86/gf128hash-pclmul.S create mode 100644 lib/crypto/x86/gf128hash-vpclmul-avx2.S create mode 100644 lib/crypto/x86/gf128hash-vpclmul-avx512.S delete mode 100644 lib/crypto/x86/ghash-pclmul.S delete mode 100644 lib/crypto/x86/polyval-pclmul-avx.S base-commit: 7845a3cc6e006f849ff882737afbd46584168eac -- 2.56.1