Enable Hardware Acceleration for SHA2 Family
cover 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-09/msg00020.html
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 | 244 ++++++++++++++++++ grub-core/normal/main.c | 2 +- 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, 833 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
Signature · 7 lines
2.51.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 1/10 Tweak autoconf/automake files to detect x86_64 features
To enable hardware acceleration, this commit ports the feature detection logic from libgcrypt. This allows us to check if the compiler supports specific assembly instructions, including SSSE3, Intel SHA extensions, SSE4.1, AVX, AVX2, AVX512, and BMI2.
To simplify the initial implementation, support for x86_64 feature detection is currently limited to the x86_64 EFI target.
--- conf/Makefile.common | 2 + configure.ac | 233 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 235 insertions(+)
conf/Makefile.common +2 -0
@@ -24,6 +24,8 @@ if COND_HAVE_PCI CFLAGS_PLATFORM += -DGRUB_HAS_PCI endif +CPPFLAGS_GCRY_ASM = @CPPFLAGS_GCRY_ASM@ + # Other options CPPFLAGS_DEFAULT = -DGRUB_FILE=\"$(subst $(srcdir)/,,$<)\"
configure.ac +233 -0
239 lines not on this page · raw message
Signature · 7 lines
2.51.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 2/10 lib/hwfeatures-gcry: Introduce functions to manage hardware features
In reply to Gary Lin via Grub-develThis commit introduces the generic functions to manage the hardware features in libgcrypt. These functions are stubs for future platform-specific implementations.
* grub_gcry_hwf_enabled() returns '__gcry_use_hwf' which indicates if the hardware features are enabled specifically by grub_enable_gcry_hwf().
* grub_enable_gcry_hwf() invokes the architecture specific enablement functions and sets '__gcry_use_hwf' to 'true'.
* grub_reset_gcry_hwf() invokes the architecture specific reset functions and sets '__gcry_use_hwf' to 'false'.
--- Makefile.util.def | 1 + grub-core/Makefile.core.def | 1 + grub-core/lib/hwfeatures-gcry.c | 43 +++++++++++++++++++++++++++++++++ include/grub/hwfeatures-gcry.h | 26 ++++++++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 grub-core/lib/hwfeatures-gcry.c create mode 100644 include/grub/hwfeatures-gcry.h
Makefile.util.def +1 -0
@@ -36,6 +36,7 @@ library = { common = grub-core/kern/misc.c; common = grub-core/kern/partition.c; common = grub-core/lib/crypto.c; + common = grub-core/lib/hwfeatures-gcry.c; common = grub-core/lib/json/json.c; common = grub-core/disk/luks.c; common = grub-core/disk/luks2.c;
grub-core/Makefile.core.def +1 -0
@@ -1685,6 +1685,7 @@ module = { module = { name = crypto; common = lib/crypto.c; + common = lib/hwfeatures-gcry.c; extra_dist = lib/libgcrypt-grub/cipher/crypto.lst; };
grub-core/lib/hwfeatures-gcry.c new file +43 -0
43 lines not on this page · raw message
include/grub/hwfeatures-gcry.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2025 Free Software Foundation, Inc. +* +* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HWF_GCRY_HEADER +#define HWF_GCRY_HEADER 1 + +extern bool grub_gcry_hwf_enabled (void ); +extern void grub_enable_gcry_hwf (void ); +extern void grub_reset_gcry_hwf (void ); + +#endif /* HWF_GCRY_HEADER */
Signature · 7 lines
2.51.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 3/10 lib/hwfeatures-gcry: Enable SSE and AVX for x86_64 EFI
In reply to Gary Lin via Grub-develImplement the necessary functions to dynamically enable SSE and AVX on x86_64 EFI systems when the hardware is capable.
--- grub-core/Makefile.core.def | 1 + grub-core/lib/hwfeatures-gcry.c | 9 + grub-core/lib/x86_64/efi/hwfeatures-gcry.c | 244 +++++++++++++++++++++ include/grub/x86_64/cpuid.h | 1 + include/grub/x86_64/efi/hwfeatures-gcry.h | 25 +++ 5 files changed, 280 insertions(+) create mode 100644 grub-core/lib/x86_64/efi/hwfeatures-gcry.c create mode 100644 include/grub/x86_64/cpuid.h create mode 100644 include/grub/x86_64/efi/hwfeatures-gcry.h
grub-core/Makefile.core.def +1 -0
@@ -1686,6 +1686,7 @@ module = { name = crypto; common = lib/crypto.c; common = lib/hwfeatures-gcry.c; + x86_64_efi = lib/x86_64/efi/hwfeatures-gcry.c; extra_dist = lib/libgcrypt-grub/cipher/crypto.lst; };
grub-core/lib/hwfeatures-gcry.c +9 -0
@@ -19,6 +19,9 @@#include <grub/dl.h> #include <grub/hwfeatures-gcry.h> +#if defined (__x86_64__) && defined (GRUB_MACHINE_EFI ) +#include <grub/x86_64/efi/hwfeatures-gcry.h> +#endif GRUB_MOD_LICENSE ("GPLv3+" );
@@ -33,11 +36,17 @@ grub_gcry_hwf_enabled (void)void grub_enable_gcry_hwf (void ) { +#if defined (__x86_64__) && defined (GRUB_MACHINE_EFI ) +grub_enable_gcry_hwf_x86_64_efi (); +#endif __gcry_use_hwf = true; }void grub_reset_gcry_hwf (void ) { +#if defined (__x86_64__) && defined (GRUB_MACHINE_EFI ) +grub_reset_gcry_hwf_x86_64_efi (); +#endif __gcry_use_hwf = false; }
grub-core/lib/x86_64/efi/hwfeatures-gcry.c new file +244 -0
244 lines not on this page · raw message
include/grub/x86_64/cpuid.h new file +1 -0
@@ -0,0 +1 @@ +#include <grub/i386/cpuid.h>
include/grub/x86_64/efi/hwfeatures-gcry.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2025 Free Software Foundation, Inc. +* +* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HWF_GCRY_X86_64_EFI_HEADER +#define HWF_GCRY_X86_64_EFI_HEADER 1 + +extern void grub_enable_gcry_hwf_x86_64_efi (void ); +extern void grub_reset_gcry_hwf_x86_64_efi (void ); + +#endif /* HWF_GCRY_X86_64_EFI_HEADER */
Signature · 7 lines
2.51.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 03/10] lib/hwfeatures-gcry: Enable SSE and AVX for x86_64 EFI
Quoted 86 lines · Gary Lin via Grub-devel
Implement the necessary functions to dynamically enable SSE and AVX on
x86_64EFI systems when the hardware is capable.Signed-off-by Gary Lin <[email protected]>--- grub-core/Makefile.core.def | 1 + grub-core/lib/hwfeatures-gcry.c | 9 + grub-core/lib/x86_64/efi/hwfeatures-gcry.c | 244 +++++++++++++++++++++ include/grub/x86_64/cpuid.h | 1 + include/grub/x86_64/efi/hwfeatures-gcry.h | 25 +++ 5 files changed, 280 insertions(+) create mode 100644 grub-core/lib/x86_64/efi/hwfeatures-gcry.c create mode 100644 include/grub/x86_64/cpuid.h create mode 100644 include/grub/x86_64/efi/hwfeatures-gcry.hgrub-core/Makefile.core.def +1
-0@@ -1686,6 +1686,7 @@ module = { name = crypto; common = lib/crypto.c; common = lib/hwfeatures-gcry.c; + x86_64_efi = lib/x86_64/efi/hwfeatures-gcry.c; extra_dist = lib/libgcrypt-grub/cipher/crypto.lst; };grub-core/lib/hwfeatures-gcry.c +9
-0@@ -19,6 +19,9 @@#include <grub/dl.h> #include <grub/hwfeatures-gcry.h> +#if defined (__x86_64__) && defined (GRUB_MACHINE_EFI ) +#include <grub/x86_64/efi/hwfeatures-gcry.h> +#endif GRUB_MOD_LICENSE ("GPLv3+" );@@ -33,11 +36,17 @@ grub_gcry_hwf_enabled (void)void grub_enable_gcry_hwf (void ) { +#if defined (__x86_64__) && defined (GRUB_MACHINE_EFI ) +grub_enable_gcry_hwf_x86_64_efi (); +#endif __gcry_use_hwf = true; }void grub_reset_gcry_hwf (void ) { +#if defined (__x86_64__) && defined (GRUB_MACHINE_EFI ) +grub_reset_gcry_hwf_x86_64_efi (); +#endif __gcry_use_hwf = false; }grub-core/lib/x86_64/efi/hwfeatures-gcry.c new file +21
-0@@ -0,0 +1,244 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2025 Free Software Foundation, Inc. +* +* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/types.h> +#include <grub/x86_64/efi/hwfeatures-gcry.h> +#include <grub/x86_64/cpuid.h>
grub-core/lib/x86_64/efi/hwfeatures-gcry.c line 31
Quoted 10 lines
grub-core/lib/x86_64/efi/hwfeatures-gcry.c new file +10
-0+#include <grub/misc.h> + +/* +* Older versions of GCC may reorder the inline asm, which can lead to +* unexpected behavior when reading the Control Registers. The __FORCE_ORDER +* macro is used to prevent this. +* +* Ref: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=aa5cacdc29d76a005cbbee018a47faa6e724dd2d +*/ +#define __FORCE_ORDER "m"(*(unsigned int *)0x1000UL)
Missing space before 0x1000UL...
grub-core/lib/x86_64/efi/hwfeatures-gcry.c line 39
Quoted 7 lines
grub-core/lib/x86_64/efi/hwfeatures-gcry.c new file +7
-0+#define HW_FEATURE_X86_64_SSE (1 << 0) +#define HW_FEATURE_X86_64_AVX (1 << 1) + +static grub_uint32_t hw_features =0 ; +static grub_uint64_t old_cr0, old_cr4, old_xcr0; + +static inline grub_uint64_t
I am not entirely sure why you force inlining here and there. I think mostly it is not needed and compiler should be free to do (almost) any optimization which is needed...
grub-core/lib/x86_64/efi/hwfeatures-gcry.c line 42
Quoted 3 lines
grub-core/lib/x86_64/efi/hwfeatures-gcry.c new file +3
-0+read_cr0 (void) +{ +grub_uint64_t val;
Missing empty line here...
grub-core/lib/x86_64/efi/hwfeatures-gcry.c line 50
Quoted 8 lines
grub-core/lib/x86_64/efi/hwfeatures-gcry.c new file +8
-0+ asm volatile ("mov %%cr0, %0" : "=r" (val) : __FORCE_ORDER); +return val; +} + +static inline grub_uint64_t +read_cr4 (void ) +{ +grub_uint64_t val;
Ditto...
grub-core/lib/x86_64/efi/hwfeatures-gcry.c line 53
Quoted 3 lines
grub-core/lib/x86_64/efi/hwfeatures-gcry.c new file +3
-0+ asm volatile ("mov %%cr4,%0" : "=r" (val) : __FORCE_ORDER); +return val; +}
Anyway, in general I am OK with the patch set except these minor issues mentioned above. If you fix them you can add my RB to all patches.
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 03/10] lib/hwfeatures-gcry: Enable SSE and AVX for x86_64 EFI
Quoted 91 lines · Daniel Kiper
Quoted 90 lines · Gary Lin via Grub-devel
Implement the necessary functions to dynamically enable SSE and AVX on
x86_64EFI systems when the hardware is capable.Signed-off-by Gary Lin <[email protected]>--- grub-core/Makefile.core.def | 1 + grub-core/lib/hwfeatures-gcry.c | 9 + grub-core/lib/x86_64/efi/hwfeatures-gcry.c | 244 +++++++++++++++++++++ include/grub/x86_64/cpuid.h | 1 + include/grub/x86_64/efi/hwfeatures-gcry.h | 25 +++ 5 files changed, 280 insertions(+) create mode 100644 grub-core/lib/x86_64/efi/hwfeatures-gcry.c create mode 100644 include/grub/x86_64/cpuid.h create mode 100644 include/grub/x86_64/efi/hwfeatures-gcry.hgrub-core/Makefile.core.def +1
-0@@ -1686,6 +1686,7 @@ module = { name = crypto; common = lib/crypto.c; common = lib/hwfeatures-gcry.c; + x86_64_efi = lib/x86_64/efi/hwfeatures-gcry.c; extra_dist = lib/libgcrypt-grub/cipher/crypto.lst; };grub-core/lib/hwfeatures-gcry.c +9
-0@@ -19,6 +19,9 @@#include <grub/dl.h> #include <grub/hwfeatures-gcry.h> +#if defined (__x86_64__) && defined (GRUB_MACHINE_EFI ) +#include <grub/x86_64/efi/hwfeatures-gcry.h> +#endif GRUB_MOD_LICENSE ("GPLv3+" );@@ -33,11 +36,17 @@ grub_gcry_hwf_enabled (void)void grub_enable_gcry_hwf (void ) { +#if defined (__x86_64__) && defined (GRUB_MACHINE_EFI ) +grub_enable_gcry_hwf_x86_64_efi (); +#endif __gcry_use_hwf = true; }void grub_reset_gcry_hwf (void ) { +#if defined (__x86_64__) && defined (GRUB_MACHINE_EFI ) +grub_reset_gcry_hwf_x86_64_efi (); +#endif __gcry_use_hwf = false; }grub-core/lib/x86_64/efi/hwfeatures-gcry.c new file +25
-0@@ -0,0 +1,244 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2025 Free Software Foundation, Inc. +* +* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/types.h> +#include <grub/x86_64/efi/hwfeatures-gcry.h> +#include <grub/x86_64/cpuid.h> +#include <grub/misc.h> + +/* +* Older versions of GCC may reorder the inline asm, which can lead to
Quoted 9 lines
grub-core/lib/x86_64/efi/hwfeatures-gcry.c line 31
Quoted 6 lines
grub-core/lib/x86_64/efi/hwfeatures-gcry.c new file +6
-0+* unexpected behavior when reading the Control Registers. The __FORCE_ORDER +* macro is used to prevent this. +* +* Ref: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=aa5cacdc29d76a005cbbee018a47faa6e724dd2d +*/ +#define __FORCE_ORDER "m"(*(unsigned int *)0x1000UL)Missing space before
0x1000UL...
Will fix it in v2.
Quoted 12 lines
grub-core/lib/x86_64/efi/hwfeatures-gcry.c line 39
Quoted 7 lines
grub-core/lib/x86_64/efi/hwfeatures-gcry.c new file +7
-0+#define HW_FEATURE_X86_64_SSE (1 << 0) +#define HW_FEATURE_X86_64_AVX (1 << 1) + +static grub_uint32_t hw_features =0 ; +static grub_uint64_t old_cr0, old_cr4, old_xcr0; + +static inline grub_uint64_tI am not entirely sure why you force inlining here and there. I think mostly it is not needed and compiler should be free to do (almost) any optimization which is needed...
Setting the control registers wrongly may cause CPU execption and crash the system immediately. For saftey, I followed Linux kernel to use inline and memory barrier to ensure the order of the asm insn.
On the other hand, it looks okay to remove inline from get_cpuid_*(). I'll update get_cpuid_*() in v2.
Quoted 6 lines
grub-core/lib/x86_64/efi/hwfeatures-gcry.c line 42
Quoted 3 lines
grub-core/lib/x86_64/efi/hwfeatures-gcry.c new file +3
-0+read_cr0 (void) +{ +grub_uint64_t val;Missing empty line here...
Will fix all the missing empty lines in v2.
Quoted 11 lines
grub-core/lib/x86_64/efi/hwfeatures-gcry.c line 50
Quoted 8 lines
grub-core/lib/x86_64/efi/hwfeatures-gcry.c new file +8
-0+ asm volatile ("mov %%cr0, %0" : "=r" (val) : __FORCE_ORDER); +return val; +} + +static inline grub_uint64_t +read_cr4 (void ) +{ +grub_uint64_t val;Ditto...
Quoted 7 lines
grub-core/lib/x86_64/efi/hwfeatures-gcry.c line 53
Quoted 3 lines
grub-core/lib/x86_64/efi/hwfeatures-gcry.c new file +3
-0+ asm volatile ("mov %%cr4,%0" : "=r" (val) : __FORCE_ORDER); +return val; +}Anyway, in general I am OK with the patch set except these minor issues mentioned above. If you fix them you can add my RB to all patches.
Thanks!
BTW, is there any chance to get my PBKDF2 patches reviewed?
https://lore.kernel.org/grub-devel/[email protected]/
It's a small patch set and reduces the decryption time hugely.
Combining all optimization patches (PBKDF2, HW accel, and the memcpy() patch in the Argon2 patch set), the decryption time of my testing PBKDF2 key slot reduces from 15 second to 1 second. It will be a huge performance gain for 2.14.
Gary Lin
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 03/10] lib/hwfeatures-gcry: Enable SSE and AVX for x86_64 EFI
Quoted 115 lines · Gary Lin
Quoted 91 lines · Daniel Kiper
Quoted 90 lines · Gary Lin via Grub-devel
Implement the necessary functions to dynamically enable SSE and AVX on
x86_64EFI systems when the hardware is capable.Signed-off-by Gary Lin <[email protected]>--- grub-core/Makefile.core.def | 1 + grub-core/lib/hwfeatures-gcry.c | 9 + grub-core/lib/x86_64/efi/hwfeatures-gcry.c | 244 +++++++++++++++++++++ include/grub/x86_64/cpuid.h | 1 + include/grub/x86_64/efi/hwfeatures-gcry.h | 25 +++ 5 files changed, 280 insertions(+) create mode 100644 grub-core/lib/x86_64/efi/hwfeatures-gcry.c create mode 100644 include/grub/x86_64/cpuid.h create mode 100644 include/grub/x86_64/efi/hwfeatures-gcry.hgrub-core/Makefile.core.def +1
-0@@ -1686,6 +1686,7 @@ module = { name = crypto; common = lib/crypto.c; common = lib/hwfeatures-gcry.c; + x86_64_efi = lib/x86_64/efi/hwfeatures-gcry.c; extra_dist = lib/libgcrypt-grub/cipher/crypto.lst; };grub-core/lib/hwfeatures-gcry.c +9
-0@@ -19,6 +19,9 @@#include <grub/dl.h> #include <grub/hwfeatures-gcry.h> +#if defined (__x86_64__) && defined (GRUB_MACHINE_EFI ) +#include <grub/x86_64/efi/hwfeatures-gcry.h> +#endif GRUB_MOD_LICENSE ("GPLv3+" );@@ -33,11 +36,17 @@ grub_gcry_hwf_enabled (void)void grub_enable_gcry_hwf (void ) { +#if defined (__x86_64__) && defined (GRUB_MACHINE_EFI ) +grub_enable_gcry_hwf_x86_64_efi (); +#endif __gcry_use_hwf = true; }void grub_reset_gcry_hwf (void ) { +#if defined (__x86_64__) && defined (GRUB_MACHINE_EFI ) +grub_reset_gcry_hwf_x86_64_efi (); +#endif __gcry_use_hwf = false; }grub-core/lib/x86_64/efi/hwfeatures-gcry.c new file +25
-0@@ -0,0 +1,244 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2025 Free Software Foundation, Inc. +* +* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/types.h> +#include <grub/x86_64/efi/hwfeatures-gcry.h> +#include <grub/x86_64/cpuid.h> +#include <grub/misc.h> + +/* +* Older versions of GCC may reorder the inline asm, which can lead to Quoted 9 lines
grub-core/lib/x86_64/efi/hwfeatures-gcry.c line 31
Quoted 6 lines
grub-core/lib/x86_64/efi/hwfeatures-gcry.c new file +6
-0+* unexpected behavior when reading the Control Registers. The __FORCE_ORDER +* macro is used to prevent this. +* +* Ref: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=aa5cacdc29d76a005cbbee018a47faa6e724dd2d +*/ +#define __FORCE_ORDER "m"(*(unsigned int *)0x1000UL)Missing space before
0x1000UL...Will fix it in v2.
Quoted 12 lines
grub-core/lib/x86_64/efi/hwfeatures-gcry.c line 39
Quoted 7 lines
grub-core/lib/x86_64/efi/hwfeatures-gcry.c new file +7
-0+#define HW_FEATURE_X86_64_SSE (1 << 0) +#define HW_FEATURE_X86_64_AVX (1 << 1) + +static grub_uint32_t hw_features =0 ; +static grub_uint64_t old_cr0, old_cr4, old_xcr0; + +static inline grub_uint64_tI am not entirely sure why you force inlining here and there. I think mostly it is not needed and compiler should be free to do (almost) any optimization which is needed...
Quoted 3 lines
Setting the control registers wrongly may cause CPU execption and crash the system immediately. For saftey, I followed Linux kernel to use inline and memory barrier to ensure the order of the asm insn.
These functions are inlined because they are in a header file in the Linux kernel. And it looks reading/writing cr0 and cr4 does not require inlining contrary to, e.g., cr2 which are tagged with __always_inline. So, I would drop "inline" from all these functions.
[...]
Quoted 9 lines
BTW, is there any chance to get my PBKDF2 patches reviewed?
https://lore.kernel.org/grub-devel/[email protected]/It's a small patch set and reduces the decryption time hugely.
Combining all optimization patches (PBKDF2, HW accel, and the
memcpy()patch in the Argon2 patch set), the decryption time of my testing PBKDF2 key slot reduces from 15 second to 1 second. It will be a huge performance gain for 2.14.
I will take a look...
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 03/10] lib/hwfeatures-gcry: Enable SSE and AVX for x86_64 EFI
Quoted 116 lines · Daniel Kiper
Quoted 115 lines · Gary Lin
Quoted 91 lines · Daniel Kiper
Quoted 90 lines · Gary Lin via Grub-devel
Implement the necessary functions to dynamically enable SSE and AVX on
x86_64EFI systems when the hardware is capable.Signed-off-by Gary Lin <[email protected]>--- grub-core/Makefile.core.def | 1 + grub-core/lib/hwfeatures-gcry.c | 9 + grub-core/lib/x86_64/efi/hwfeatures-gcry.c | 244 +++++++++++++++++++++ include/grub/x86_64/cpuid.h | 1 + include/grub/x86_64/efi/hwfeatures-gcry.h | 25 +++ 5 files changed, 280 insertions(+) create mode 100644 grub-core/lib/x86_64/efi/hwfeatures-gcry.c create mode 100644 include/grub/x86_64/cpuid.h create mode 100644 include/grub/x86_64/efi/hwfeatures-gcry.hgrub-core/Makefile.core.def +1
-0@@ -1686,6 +1686,7 @@ module = { name = crypto; common = lib/crypto.c; common = lib/hwfeatures-gcry.c; + x86_64_efi = lib/x86_64/efi/hwfeatures-gcry.c; extra_dist = lib/libgcrypt-grub/cipher/crypto.lst; };grub-core/lib/hwfeatures-gcry.c +9
-0@@ -19,6 +19,9 @@#include <grub/dl.h> #include <grub/hwfeatures-gcry.h> +#if defined (__x86_64__) && defined (GRUB_MACHINE_EFI ) +#include <grub/x86_64/efi/hwfeatures-gcry.h> +#endif GRUB_MOD_LICENSE ("GPLv3+" );@@ -33,11 +36,17 @@ grub_gcry_hwf_enabled (void)void grub_enable_gcry_hwf (void ) { +#if defined (__x86_64__) && defined (GRUB_MACHINE_EFI ) +grub_enable_gcry_hwf_x86_64_efi (); +#endif __gcry_use_hwf = true; }void grub_reset_gcry_hwf (void ) { +#if defined (__x86_64__) && defined (GRUB_MACHINE_EFI ) +grub_reset_gcry_hwf_x86_64_efi (); +#endif __gcry_use_hwf = false; }grub-core/lib/x86_64/efi/hwfeatures-gcry.c new file +25
-0@@ -0,0 +1,244 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2025 Free Software Foundation, Inc. +* +* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/types.h> +#include <grub/x86_64/efi/hwfeatures-gcry.h> +#include <grub/x86_64/cpuid.h> +#include <grub/misc.h> + +/* +* Older versions of GCC may reorder the inline asm, which can lead to Quoted 9 lines
grub-core/lib/x86_64/efi/hwfeatures-gcry.c line 31
Quoted 6 lines
grub-core/lib/x86_64/efi/hwfeatures-gcry.c new file +6
-0+* unexpected behavior when reading the Control Registers. The __FORCE_ORDER +* macro is used to prevent this. +* +* Ref: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=aa5cacdc29d76a005cbbee018a47faa6e724dd2d +*/ +#define __FORCE_ORDER "m"(*(unsigned int *)0x1000UL)Missing space before
0x1000UL...Will fix it in v2.
Quoted 12 lines
grub-core/lib/x86_64/efi/hwfeatures-gcry.c line 39
Quoted 7 lines
grub-core/lib/x86_64/efi/hwfeatures-gcry.c new file +7
-0+#define HW_FEATURE_X86_64_SSE (1 << 0) +#define HW_FEATURE_X86_64_AVX (1 << 1) + +static grub_uint32_t hw_features =0 ; +static grub_uint64_t old_cr0, old_cr4, old_xcr0; + +static inline grub_uint64_tI am not entirely sure why you force inlining here and there. I think mostly it is not needed and compiler should be free to do (almost) any optimization which is needed...
Quoted 9 lines
Quoted 3 lines
Setting the control registers wrongly may cause CPU execption and crash the system immediately. For saftey, I followed Linux kernel to use inline and memory barrier to ensure the order of the asm insn.
These functions are inlined because they are in a header file in the Linux kernel. And it looks reading/writing cr0 and cr4 does not require inlining contrary to, e.g., cr2 which are tagged with
__always_inline. So, I would drop "inline" from all these functions.
I see. Then I'm fine to drop all 'inline' from those functions.
Quoted 5 lines
[...]
Quoted 3 lines
BTW, is there any chance to get my PBKDF2 patches reviewed?
https://lore.kernel.org/grub-devel/[email protected]/
Quoted 9 lines
Quoted 6 lines
It's a small patch set and reduces the decryption time hugely.
Combining all optimization patches (PBKDF2, HW accel, and the
memcpy()patch in the Argon2 patch set), the decryption time of my testing PBKDF2 key slot reduces from 15 second to 1 second. It will be a huge performance gain for 2.14.I will take a look...
Thanks!
Gary Lin
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 4/10 libgcrypt: Copy sha256 x86_64 assembly files
In reply to Gary Lin via Grub-develCopy the selected x86_64 assembly files to support hardware acceleration for sha256.
--- autogen.sh | 7 +++++++ 1 file changed, 7 insertions(+)
autogen.sh +7 -0
@@ -52,6 +52,13 @@ for x in mpi-asm-defs.h mpih-add1.c mpih-sub1.c mpih-mul1.c mpih-mul2.c mpih-mul cp grub-core/lib/libgcrypt-grub/mpi/generic/"$x" grub-core/lib/libgcrypt-grub/mpi/"$x" done +for x in sha256-ssse3-amd64.S sha256-avx-amd64.S sha256-avx2-bmi2-amd64.S sha256-intel-shaext.c; do + if [ -h grub-core/lib/libgcrypt-grub/cipher/"$x" ] || [ -f grub-core/lib/libgcrypt-grub/cipher/"$x" ]; then + rm grub-core/lib/libgcrypt-grub/cipher/"$x" + fi + cp grub-core/lib/libgcrypt/cipher/"$x" grub-core/lib/libgcrypt-grub/cipher/"$x" +done + for x in grub-core/lib/libgcrypt-patches/*.patch; do patch -i $x -p1 done
Signature · 7 lines
2.51.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 5/10 libgcrypt: Copy sha512 x86_64 assembly files
In reply to Gary Lin via Grub-develCopy the selected x86_64 assembly files to support hardware acceleration for sha512.
--- autogen.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
autogen.sh +1 -1
@@ -52,7 +52,7 @@ for x in mpi-asm-defs.h mpih-add1.c mpih-sub1.c mpih-mul1.c mpih-mul2.c mpih-mul cp grub-core/lib/libgcrypt-grub/mpi/generic/"$x" grub-core/lib/libgcrypt-grub/mpi/"$x" done -for x in sha256-ssse3-amd64.S sha256-avx-amd64.S sha256-avx2-bmi2-amd64.S sha256-intel-shaext.c; do +for x in sha256-ssse3-amd64.S sha256-avx-amd64.S sha256-avx2-bmi2-amd64.S sha256-intel-shaext.c sha512-ssse3-amd64.S sha512-avx-amd64.S sha512-avx2-bmi2-amd64.S sha512-avx512-amd64.S; do if [ -h grub-core/lib/libgcrypt-grub/cipher/"$x" ] || [ -f grub-core/lib/libgcrypt-grub/cipher/"$x" ]; then rm grub-core/lib/libgcrypt-grub/cipher/"$x" fi
Signature · 7 lines
2.51.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 6/10 libgcrypt: Implement _gcry_get_hw_features()
In reply to Gary Lin via Grub-develImplement _gcry_get_hw_features() and enable hardware feature detection for x86_64.
--- autogen.sh | 4 + conf/Makefile.extra-dist | 1 + .../libgcrypt-patches/13_add_hwfeatures.patch | 87 +++++++++++++++++++ include/grub/crypto.h | 7 +- 4 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 grub-core/lib/libgcrypt-patches/13_add_hwfeatures.patch
autogen.sh +4 -0
@@ -59,6 +59,10 @@ for x in sha256-ssse3-amd64.S sha256-avx-amd64.S sha256-avx2-bmi2-amd64.S sha256 cp grub-core/lib/libgcrypt/cipher/"$x" grub-core/lib/libgcrypt-grub/cipher/"$x" done +if [ -f grub-core/lib/libgcrypt-grub/src/hwfeatures.c ]; then + rm grub-core/lib/libgcrypt-grub/src/hwfeatures.c +fi + for x in grub-core/lib/libgcrypt-patches/*.patch; do patch -i $x -p1 done
conf/Makefile.extra-dist +1 -0
@@ -47,6 +47,7 @@ EXTRA_DIST += grub-core/lib/libgcrypt-patches/09-blake2b-hash-buffers.patch EXTRA_DIST += grub-core/lib/libgcrypt-patches/10-kdf-use-GPG-errs.patch EXTRA_DIST += grub-core/lib/libgcrypt-patches/11-kdf-remove-unsupported-kdfs.patch EXTRA_DIST += grub-core/lib/libgcrypt-patches/12-kdf-use-grub_divmod64.patch +EXTRA_DIST += grub-core/lib/libgcrypt-patches/13_add_hwfeatures.patch EXTRA_DIST += grub-core/lib/libtasn1-patches/0001-libtasn1-disable-code-not-needed-in-grub.patch EXTRA_DIST += grub-core/lib/libtasn1-patches/0002-libtasn1-replace-strcat-with-strcpy-in-_asn1_str_cat.patch
grub-core/lib/libgcrypt-patches/13_add_hwfeatures.patch new file +87 -0
87 lines not on this page · raw message
include/grub/crypto.h +5 -2
@@ -611,11 +611,14 @@ _gcry_ct_memequal (const void *b1, const void *b2, grub_size_t len);unsigned int _gcry_ct_not_memequal (const void *b1,const void *b2,grub_size_t len); - -static inline unsigned int _gcry_get_hw_features (void ) +#if defined (GRUB_UTIL ) +static inline unsigned int _gcry_get_hw_features (void ) {return 0 ; } +#else +extern unsigned int _gcry_get_hw_features (void ); +#endif void *_gcry_malloc (grub_size_t n);void *_gcry_malloc_secure (grub_size_t n);
Signature · 7 lines
2.51.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 7/10 libgcrypt: Declare the sha256 shaext function
In reply to Gary Lin via Grub-develThere is no prototype of _gcry_sha256_transform_intel_shaext() defined in the header or libgcrypt-grub/cipher/sha256.c, and gcc may complain the missing-prototypes error when compiling sha256-intel-shaext.c.
Declare the prototype in sha256-intel-shaext.c to avoid the error.
--- conf/Makefile.extra-dist | 1 + .../14_fix_build_shaext.patch | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 grub-core/lib/libgcrypt-patches/14_fix_build_shaext.patch
conf/Makefile.extra-dist +1 -0
@@ -48,6 +48,7 @@ EXTRA_DIST += grub-core/lib/libgcrypt-patches/10-kdf-use-GPG-errs.patch EXTRA_DIST += grub-core/lib/libgcrypt-patches/11-kdf-remove-unsupported-kdfs.patch EXTRA_DIST += grub-core/lib/libgcrypt-patches/12-kdf-use-grub_divmod64.patch EXTRA_DIST += grub-core/lib/libgcrypt-patches/13_add_hwfeatures.patch +EXTRA_DIST += grub-core/lib/libgcrypt-patches/14_fix_build_shaext.patch EXTRA_DIST += grub-core/lib/libtasn1-patches/0001-libtasn1-disable-code-not-needed-in-grub.patch EXTRA_DIST += grub-core/lib/libtasn1-patches/0002-libtasn1-replace-strcat-with-strcpy-in-_asn1_str_cat.patch
grub-core/lib/libgcrypt-patches/14_fix_build_shaext.patch new file +35 -0
@@ -0,0 +1,35 @@ +From 5698f7c5055ea481d0040ea4495829e5d02781cc Mon Sep 17 00:00:00 2001 +From: Gary Lin <[email protected]> +Date: Fri, 18 Jul 2025 15:34:21 +0800 +Subject: [PATCH 2/4] libgcrypt: Declare the sha256 shaext function + +There is no prototype of _gcry_sha256_transform_intel_shaext() defined +in the header or libgcrypt-grub/cipher/sha256.c, and gcc may complain +the missing-prototypes error when compiling sha256-intel-shaext.c. + +Declare the prototype in sha256-intel-shaext.c to avoid the error. + +Signed-off-by: Gary Lin <[email protected]> +--- + grub-core/lib/libgcrypt-grub/cipher/sha256-intel-shaext.c | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/grub-core/lib/libgcrypt-grub/cipher/sha256-intel-shaext.c b/grub-core/lib/libgcrypt-grub/cipher/sha256-intel-shaext.c +index 48c09eefe..7ec49f05e 100644 +--- a/grub-core/lib/libgcrypt-grub/cipher/sha256-intel-shaext.c ++++ b/grub-core/lib/libgcrypt-grub/cipher/sha256-intel-shaext.c +@@ -95,6 +95,11 @@ typedef struct u128_s + u32 a, b, c, d; + } u128_t; + ++ ++unsigned int ASM_FUNC_ATTR ++_gcry_sha256_transform_intel_shaext(u32 state[8], const unsigned char *data, ++ size_t nblks); ++ + /* + * Transform nblks*64 bytes (nblks*16 32-bit words) at DATA. + */ +-- +2.51.0 +
Signature · 7 lines
2.51.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 8/10 libgcrypt: Add hardware acceleration for gcry_sha256
In reply to Gary Lin via Grub-develEnable hardware acceleration for the gcry_sha256 module when building for the x86_64 EFI target.
--- conf/Makefile.extra-dist | 1 + .../15_build_sha256_x86_64_efi_opt_code.patch | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 grub-core/lib/libgcrypt-patches/15_build_sha256_x86_64_efi_opt_code.patch
conf/Makefile.extra-dist +1 -0
@@ -49,6 +49,7 @@ EXTRA_DIST += grub-core/lib/libgcrypt-patches/11-kdf-remove-unsupported-kdfs.pat EXTRA_DIST += grub-core/lib/libgcrypt-patches/12-kdf-use-grub_divmod64.patch EXTRA_DIST += grub-core/lib/libgcrypt-patches/13_add_hwfeatures.patch EXTRA_DIST += grub-core/lib/libgcrypt-patches/14_fix_build_shaext.patch +EXTRA_DIST += grub-core/lib/libgcrypt-patches/15_build_sha256_x86_64_efi_opt_code.patch EXTRA_DIST += grub-core/lib/libtasn1-patches/0001-libtasn1-disable-code-not-needed-in-grub.patch EXTRA_DIST += grub-core/lib/libtasn1-patches/0002-libtasn1-replace-strcat-with-strcpy-in-_asn1_str_cat.patch
grub-core/lib/libgcrypt-patches/15_build_sha256_x86_64_efi_opt_code.patch new file +43 -0
43 lines not on this page · raw message
Signature · 7 lines
2.51.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 9/10 libgcrypt: Add hardware acceleration for gcry_sha512
In reply to Gary Lin via Grub-develEnable hardware acceleration for the gcry_sha512 module when building for the x86_64 EFI target.
--- conf/Makefile.extra-dist | 1 + .../16_build_sha512_x86_64_efi_opt_code.patch | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 grub-core/lib/libgcrypt-patches/16_build_sha512_x86_64_efi_opt_code.patch
conf/Makefile.extra-dist +1 -0
@@ -50,6 +50,7 @@ EXTRA_DIST += grub-core/lib/libgcrypt-patches/12-kdf-use-grub_divmod64.patch EXTRA_DIST += grub-core/lib/libgcrypt-patches/13_add_hwfeatures.patch EXTRA_DIST += grub-core/lib/libgcrypt-patches/14_fix_build_shaext.patch EXTRA_DIST += grub-core/lib/libgcrypt-patches/15_build_sha256_x86_64_efi_opt_code.patch +EXTRA_DIST += grub-core/lib/libgcrypt-patches/16_build_sha512_x86_64_efi_opt_code.patch EXTRA_DIST += grub-core/lib/libtasn1-patches/0001-libtasn1-disable-code-not-needed-in-grub.patch EXTRA_DIST += grub-core/lib/libtasn1-patches/0002-libtasn1-replace-strcat-with-strcpy-in-_asn1_str_cat.patch
grub-core/lib/libgcrypt-patches/16_build_sha512_x86_64_efi_opt_code.patch new file +35 -0
@@ -0,0 +1,35 @@ +From f62c2c7565237bbf059220e90d3f1f8c8d6eebd5 Mon Sep 17 00:00:00 2001 +From: Gary Lin <[email protected]> +Date: Wed, 3 Sep 2025 16:26:55 +0800 +Subject: [PATCH 4/4] libgcrypt: Add hardware acceleration for gcry_sha512 + +Enable hardware acceleration for the gcry_sha512 module when building +for the x86_64 EFI target. + +Signed-off-by: Gary Lin <[email protected]> +--- + grub-core/Makefile.gcry.def | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +diff --git a/grub-core/Makefile.gcry.def b/grub-core/Makefile.gcry.def +index ac1d9a088..64ea5ee24 100644 +--- a/grub-core/Makefile.gcry.def ++++ b/grub-core/Makefile.gcry.def +@@ -186,8 +186,13 @@ module = { + name = gcry_sha512; + common = lib/libgcrypt-grub/cipher/sha512.c; + common = lib/libgcrypt-grub/cipher/hash-common.c; ++ x86_64_efi = lib/libgcrypt-grub/cipher/sha512-ssse3-amd64.S; ++ x86_64_efi = lib/libgcrypt-grub/cipher/sha512-avx-amd64.S; ++ x86_64_efi = lib/libgcrypt-grub/cipher/sha512-avx2-bmi2-amd64.S; ++ x86_64_efi = lib/libgcrypt-grub/cipher/sha512-avx512-amd64.S; ++ + cflags = '$(CFLAGS_GCRY) -Wno-cast-align'; +- cppflags = '$(CPPFLAGS_GCRY)'; ++ cppflags = '$(CPPFLAGS_GCRY) -DUSE_SHA512 $(CPPFLAGS_GCRY_ASM)'; + }; + + module = { +-- +2.51.0 +
Signature · 7 lines
2.51.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 10/10 disk/cryptodisk: Add '--hw-accel' to enable hardware acceleration
In reply to Gary Lin via Grub-develThe '--hw-accel' option has been added to cryptomount to speed up decryption by temporarily enabling hardware-specific instruction sets (e.g., AVX, SSE) in libgcrypt.
A new feature, "feature_gcry_hw_accel", is also introduced to mark the availability of the new option.
--- docs/grub.texi | 5 +++-- grub-core/disk/cryptodisk.c | 26 +++++++++++++++++++++++--- grub-core/normal/main.c | 2 +- 3 files changed, 27 insertions(+), 6 deletions(-)
docs/grub.texi +3 -2
@@ -6767,7 +6767,7 @@ The option @option{--quiet} can be given to suppress the output. @node cryptomount @subsection cryptomount -@deffn Command cryptomount [ [@option{-p} password] | [@option{-k} keyfile [@option{-O} keyoffset] [@option{-S} keysize] ] | [@option{-P} protector] ] [@option{-H} file] device|@option{-u} uuid|@option{-a}|@option{-b} +@deffn Command cryptomount [ [@option{-p} password] | [@option{-k} keyfile [@option{-O} keyoffset] [@option{-S} keysize] ] | [@option{-P} protector] | [@option{-A}] ] [@option{-H} file] device|@option{-u} uuid|@option{-a}|@option{-b} Setup access to encrypted device. A passphrase will be requested interactively, if neither the @option{-p} nor @option{-k} options are given. The option @option{-p} can be used to supply a passphrase (useful for scripts).
@@ -6775,7 +6775,8 @@ Alternatively the @option{-k} option can be used to supply a keyfile with options @option{-O} and @option{-S} optionally supplying the offset and size, respectively, of the key data in the given key file. Besides the keyfile, the key can be stored in a key protector, and option @option{-P} configures -specific key protector, e.g. tpm2, to retrieve the key from. +specific key protector, e.g. tpm2, to retrieve the key from. The option @option{-A} +enables hardware acceleration in libgcrypt to speed up decryption. The @option{-H} options can be used to supply cryptomount backends with an alternative header file (aka detached header). Not all backends have headers nor support alternative header files (currently only LUKS1 and LUKS2 support them).
grub-core/disk/cryptodisk.c +23 -3
@@ -29,6 +29,7 @@#include <grub/partition.h> #include <grub/key_protector.h> #include <grub/safemath.h> +#include <grub/hwfeatures-gcry.h> #ifdef GRUB_UTIL #include <grub/emu/hostdisk.h>
@@ -48,7 +49,8 @@ enumOPTION_KEYFILE_OFFSET ,OPTION_KEYFILE_SIZE ,OPTION_HEADER , -OPTION_PROTECTOR +OPTION_PROTECTOR , +OPTION_HWACCEL }; static const struct grub_arg_option options[] =
@@ -64,6 +66,7 @@ static const struct grub_arg_option options[] = {"header", 'H', 0, N_("Read header from file"), 0, ARG_TYPE_STRING}, {"protector", 'P', GRUB_ARG_OPTION_REPEATABLE, N_("Unlock volume(s) using key protector(s)."), 0, ARG_TYPE_STRING}, + {"hw-accel", 'A', 0, N_("Enable hardware acceleration."), 0, 0}, {0, 0, 0, 0, 0, 0} };
@@ -1420,7 +1423,7 @@ grub_cryptodisk_clear_key_cache (struct grub_cryptomount_args *cargs) }static grub_err_t -grub_cmd_cryptomount (grub_extcmd_context_t ctxt,int argc,char **args) +__grub_cmd_cryptomount (grub_extcmd_context_t ctxt,int argc,char **args) {struct grub_arg_list *state = ctxt->state;struct grub_cryptomount_args cargs = {0 };
@@ -1629,6 +1632,23 @@ grub_cmd_cryptomount (grub_extcmd_context_t ctxt, int argc, char **args) } } +static grub_err_t +grub_cmd_cryptomount (grub_extcmd_context_t ctxt,int argc,char **args) +{ +struct grub_arg_list *state = ctxt->state; +grub_err_t err; + +if (state[OPTION_HWACCEL ].set) +grub_enable_gcry_hwf (); + + err =__grub_cmd_cryptomount (ctxt, argc, args); + +if (state[OPTION_HWACCEL ].set) +grub_reset_gcry_hwf (); + +return err; +} +static struct grub_disk_dev grub_cryptodisk_dev = { .name ="cryptodisk" , .id =GRUB_DISK_DEVICE_CRYPTODISK_ID ,
@@ -1898,7 +1918,7 @@ GRUB_MOD_INIT (cryptodisk) cmd =grub_register_extcmd ("cryptomount" , grub_cmd_cryptomount,0 ,N_ ("[ [-p password] | [-k keyfile" " [-O keyoffset] [-S keysize] ] ] [-H file]" -" [-P protector [-P protector ...]]" +" [-P protector [-P protector ...]] | [-A]" " <SOURCE|-u UUID|-a|-b>" ),N_ ("Mount a crypto device." ), options);grub_procfs_register ("luks_script" , &luks_script);
grub-core/normal/main.c +1 -1
@@ -512,7 +512,7 @@ static const char *features[] = {"feature_default_font_path" ,"feature_all_video_module" ,"feature_menuentry_id" ,"feature_menuentry_options" ,"feature_200_final" ,"feature_nativedisk_cmd" ,"feature_timeout_style" , - "feature_search_cryptodisk_only" +"feature_search_cryptodisk_only" ,"feature_gcry_hw_accel" };GRUB_MOD_INIT (normal)
Signature · 7 lines
2.51.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel