On Wed, Oct 15, 2025 at 11:00:28AM +0800, Gary Lin via Grub-devel wrote: > When both "dest" and "src" are aligned, copying the data in chunks > (grub_addr_t) is more efficient than a byte-by-byte copy. > > Also tweak '__aeabi_memcpy()', '__aeabi_memcpy4()', and > '__aeabi_memcpy8()', since 'grub_memcpy()' is not inline anymore. > > Optimization for unaligned buffers was omitted to maintain code > simplicity and readability. The current chunk-copy optimization > for aligned buffers already provides a noticeable performance > improvement(*) for Argon2 keyslot decryption. > > (*) On my system, for a LUKS2 keyslot configured with a 1 GB Argon2 > memory requirement, this patch reduces the decryption time from 22 > seconds to 12 seconds. > > Signed-off-by: Gary Lin <[email protected]>
Reviewed-by: Daniel Kiper <[email protected]> But a nit below... > --- > grub-core/kern/compiler-rt.c | 8 ++++---- > grub-core/kern/misc.c | 31 +++++++++++++++++++++++++++++++ > include/grub/misc.h | 8 +------- > 3 files changed, 36 insertions(+), 11 deletions(-) > > diff --git a/grub-core/kern/compiler-rt.c b/grub-core/kern/compiler-rt.c > index eda689a0c..8f3865e95 100644 > --- a/grub-core/kern/compiler-rt.c > +++ b/grub-core/kern/compiler-rt.c > @@ -24,7 +24,7 @@ > void * GRUB_BUILTIN_ATTR > memcpy (void *dest, const void *src, grub_size_t n) > { > - return grub_memmove (dest, src, n); > + return grub_memcpy (dest, src, n); > } > void * GRUB_BUILTIN_ATTR > memmove (void *dest, const void *src, grub_size_t n) > @@ -372,11 +372,11 @@ grub_int32_t > __aeabi_idiv (grub_int32_t a, grub_int32_t b) > __attribute__ ((alias ("__divsi3"))); > void *__aeabi_memcpy (void *dest, const void *src, grub_size_t n) > - __attribute__ ((alias ("grub_memcpy"))); > + __attribute__ ((alias ("memcpy"))); > void *__aeabi_memcpy4 (void *dest, const void *src, grub_size_t n) > - __attribute__ ((alias ("grub_memcpy"))); > + __attribute__ ((alias ("memcpy"))); > void *__aeabi_memcpy8 (void *dest, const void *src, grub_size_t n) > - __attribute__ ((alias ("grub_memcpy"))); > + __attribute__ ((alias ("memcpy"))); > void *__aeabi_memset (void *s, int c, grub_size_t n) > __attribute__ ((alias ("memset"))); > > diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c > index b9ac86c18..db9623224 100644 > --- a/grub-core/kern/misc.c > +++ b/grub-core/kern/misc.c > @@ -99,6 +99,37 @@ grub_memmove (void *dest, const void *src, grub_size_t n) > return dest; > } > > +static void * > +__memcpy_aligned (void *dest, const void *src, grub_size_t n) > +{ > + grub_addr_t *dw = (grub_addr_t *) dest; > + const grub_addr_t *sw = (const grub_addr_t *) src; > + grub_uint8_t *d; > + const grub_uint8_t *s; > + > + for (; n >= sizeof (grub_addr_t); n -= sizeof (grub_addr_t)) > + *dw++ = *sw++; > + > + d = (grub_uint8_t *) dw; > + s = (const grub_uint8_t *) sw; > + for (; n > 0; n--) > + *d++ = *s++; > + > + return dest; > +} > + > +void * > +grub_memcpy (void *dest, const void *src, grub_size_t n) > +{ > + /* Check if 'dest' and 'src' are aligned */ ... and n >= sizeof (grub_addr_t). I will fix it for you... > + if (((grub_addr_t) dest & (sizeof (grub_addr_t) - 1)) == 0 && > + ((grub_addr_t) src & (sizeof (grub_addr_t) - 1)) == 0 && > + n >= sizeof (grub_addr_t)) > + return __memcpy_aligned (dest, src, n); > + > + return grub_memmove (dest, src, n); > +} Daniel _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
