Skip to content

Enable Hardware Acceleration for SHA2 Family

Gary Lin via Grub-devel grub-devel 3 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest10 patches 0 repliesNew
  2. v210 patches 1 replySuperseded
  3. v110 patches 4 repliesSuperseded

Changes in v3 from the cover letter

- Dropping 'inline' from the functions in grub-core/lib/x86_64/efi/hwfeatures-gcry.c

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/10Tweak autoconf/automake files to detect x86_64 featuresconf/Makefile.common configure.ac+235 -00 replies
2/10lib/hwfeatures-gcry: Introduce functions to manage hardware featuresMakefile.util.def grub-core/Makefile.core.def grub-core/lib/hwfeatures-gcry.c +1 more+71 -00 replies
3/10lib/hwfeatures-gcry: Enable SSE and AVX for x86_64 EFIgrub-core/Makefile.core.def grub-core/lib/hwfeatures-gcry.c grub-core/lib/x86_64/efi/hwfeatures-gcry.c +2 more+282 -00 replies
4/10libgcrypt: Copy sha256 x86_64 assembly filesautogen.sh+7 -00 replies
5/10libgcrypt: Copy sha512 x86_64 assembly filesautogen.sh+1 -10 replies
6/10libgcrypt: Implement _gcry_get_hw_features()autogen.sh conf/Makefile.extra-dist grub-core/lib/libgcrypt-patches/13_add_hwfeatures.patch +1 more+97 -20 replies
7/10libgcrypt: Declare the sha256 shaext functionconf/Makefile.extra-dist grub-core/lib/libgcrypt-patches/14_fix_build_shaext.patch+36 -00 replies
8/10libgcrypt: Add hardware acceleration for gcry_sha256conf/Makefile.extra-dist grub-core/lib/libgcrypt-patches/15_build_sha256_x86_64_efi_opt_code.patch+44 -00 replies
9/10libgcrypt: Add hardware acceleration for gcry_sha512conf/Makefile.extra-dist grub-core/lib/libgcrypt-patches/16_build_sha512_x86_64_efi_opt_code.patch+36 -00 replies
10/10disk/cryptodisk: Add '--hw-accel' to enable hardware accelerationdocs/grub.texi grub-core/disk/cryptodisk.c grub-core/normal/main.c+28 -60 replies

Reviews trailers per patch

All 10 patches have a Reviewed-by or Acked-by.

PatchDaniel Kiper
1/10R-b
2/10R-b
3/10R-b
4/10R-b
5/10R-b
6/10R-b
7/10R-b
8/10R-b
9/10R-b
10/10R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH v3 00/10] Enable Hardware Acceleration for SHA2 Family

This patch series speeds up LUKS PBKDF2 unlocking by using assembly files from libgcrypt 1.11.0 to enable hardware-accelerated SHA-256 and SHA-512.

As an initial step, the scope is limited to x86_64 EFI targets.

Patch 1 modifies autoconf/automake files to check the availablity of special CPU instructions.
Patch 2 and 3 introduce the functions to enable/disable the hardware features.
Patch 4 and 5 copy the selected assembly files.
Patch 6 implements _gcry_get_hw_features() to control the hardware features detection in libgcrypt.
Patch 7 fixes a potential build error when compiling the Intel SHA extention function for the gcry_sha256 module.
Patch 8 and 9 build the gcry_sha256 and gcry_sha512 modules with the assembly files.
Patch 10 adds a new option to cryptomount to enable hardware acceleration.

NOTE: The libgcrypt patch numbering begins at 13 to follow the Argon2 patch set(*).

(*) https://lists.gnu.org/archive/html/grub-devel/2025-10/msg00235.html

v3:
- Dropping 'inline' from the functions in grub-core/lib/x86_64/efi/hwfeatures-gcry.c
v2:
- Fixing the coding style issues in patch 3
- Removing 'inline' from get_cpuid_ecx() and get_cpuid_ecx()
- Rebasing to the latest git master

Gary Lin (10):
Tweak autoconf/automake files to detect x86_64 features lib/hwfeatures-gcry: Introduce functions to manage hardware features lib/hwfeatures-gcry: Enable SSE and AVX for x86_64 EFI
libgcrypt: Copy sha256 x86_64 assembly files
libgcrypt: Copy sha512 x86_64 assembly files
libgcrypt: Implement _gcry_get_hw_features()
libgcrypt: Declare the sha256 shaext function
libgcrypt: Add hardware acceleration for gcry_sha256
libgcrypt: Add hardware acceleration for gcry_sha512 disk/cryptodisk: Add '--hw-accel' to enable hardware acceleration

 Makefile.util.def                             |   1 +
 autogen.sh                                    |  11 +
 conf/Makefile.common                          |   2 +
 conf/Makefile.extra-dist                      |   4 +
 configure.ac                                  | 233 +++++++++++++++++
 docs/grub.texi                                |   5 +-
 grub-core/Makefile.core.def                   |   2 +
 grub-core/disk/cryptodisk.c                   |  26 +-
 grub-core/lib/hwfeatures-gcry.c               |  52 ++++
 .../libgcrypt-patches/13_add_hwfeatures.patch |  87 +++++++
 .../14_fix_build_shaext.patch                 |  35 +++
 .../15_build_sha256_x86_64_efi_opt_code.patch |  43 +++
 .../16_build_sha512_x86_64_efi_opt_code.patch |  35 +++
 grub-core/lib/x86_64/efi/hwfeatures-gcry.c    | 246 ++++++++++++++++++
 grub-core/normal/main.c                       |   3 +-
 include/grub/crypto.h                         |   7 +-
 include/grub/hwfeatures-gcry.h                |  26 ++
 include/grub/x86_64/cpuid.h                   |   1 +
 include/grub/x86_64/efi/hwfeatures-gcry.h     |  25 ++
 19 files changed, 836 insertions(+), 8 deletions(-)
 create mode 100644 grub-core/lib/hwfeatures-gcry.c
 create mode 100644 grub-core/lib/libgcrypt-patches/13_add_hwfeatures.patch
 create mode 100644 grub-core/lib/libgcrypt-patches/14_fix_build_shaext.patch
 create mode 100644 grub-core/lib/libgcrypt-patches/15_build_sha256_x86_64_efi_opt_code.patch
 create mode 100644 grub-core/lib/libgcrypt-patches/16_build_sha512_x86_64_efi_opt_code.patch
 create mode 100644 grub-core/lib/x86_64/efi/hwfeatures-gcry.c
 create mode 100644 include/grub/hwfeatures-gcry.h
 create mode 100644 include/grub/x86_64/cpuid.h
 create mode 100644 include/grub/x86_64/efi/hwfeatures-gcry.h

Range-diff against v2:

 -:  --------- >  1:  1890cf937 Tweak autoconf/automake files to detect x86_64 features
 -:  --------- >  2:  0992871e9 lib/hwfeatures-gcry: Introduce functions to manage hardware features
 1:  baf25b5ad !  3:  325befd0f lib/hwfeatures-gcry: Enable SSE and AVX for x86_64 EFI
    @@ grub-core/lib/x86_64/efi/hwfeatures-gcry.c (new)
     +static grub_uint32_t hw_features = 0;
     +static grub_uint64_t old_cr0, old_cr4, old_xcr0;
     +
    -+static inline grub_uint64_t
    ++static grub_uint64_t
     +read_cr0 (void)
     +{
     +  grub_uint64_t val;
    @@ grub-core/lib/x86_64/efi/hwfeatures-gcry.c (new)
     +  return val;
     +}
     +
    -+static inline grub_uint64_t
    ++static grub_uint64_t
     +read_cr4 (void)
     +{
     +  grub_uint64_t val;
    @@ grub-core/lib/x86_64/efi/hwfeatures-gcry.c (new)
     +  return val;
     +}
     +
    -+static inline void
    ++static void
     +write_cr0 (grub_uint64_t val)
     +{
     +  asm volatile ("mov %0,%%cr4": "+r" (val) : : "memory");
     +}
     +
    -+static inline void
    ++static void
     +write_cr4 (grub_uint64_t val)
     +{
     +  asm volatile ("mov %0,%%cr4": "+r" (val) : : "memory");
    @@ grub-core/lib/x86_64/efi/hwfeatures-gcry.c (new)
     +  return true;
     +}
     +
    -+static inline grub_uint64_t
    ++static grub_uint64_t
     +xgetbv (grub_uint32_t index)
     +{
     +  grub_uint32_t eax, edx;
    @@ grub-core/lib/x86_64/efi/hwfeatures-gcry.c (new)
     +  return eax + ((grub_uint64_t)edx << 32);
     +}
     +
    -+static inline void
    ++static void
     +xsetbv (grub_uint32_t index, grub_uint64_t value)
     +{
     +  grub_uint32_t eax = (grub_uint32_t)value;
 2:  5195b898a =  4:  46facef36 libgcrypt: Copy sha256 x86_64 assembly files
 3:  77d309e18 =  5:  ab67070fc libgcrypt: Copy sha512 x86_64 assembly files
 4:  61042e067 =  6:  4666f89c8 libgcrypt: Implement _gcry_get_hw_features()
 5:  9a5776f31 =  7:  36054eef5 libgcrypt: Declare the sha256 shaext function
 6:  2df17f531 =  8:  a38b914a0 libgcrypt: Add hardware acceleration for gcry_sha256
 7:  ba3a8ac3a =  9:  b5f6b6473 libgcrypt: Add hardware acceleration for gcry_sha512
 8:  9798849dd = 10:  ddd674688 disk/cryptodisk: Add '--hw-accel' to enable hardware acceleration
Signature · 7 lines
2.51.0


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel