Skip to content

Commit 394b19d

Browse files
nivedita76torvalds
authored andcommitted
x86/boot/compressed: Use builtin mem functions for decompressor
Since commits c041b5a ("x86, boot: Create a separate string.h file to provide standard string functions") fb4cac5 ("x86, boot: Move memcmp() into string.h and string.c") the decompressor stub has been using the compiler's builtin memcpy, memset and memcmp functions, _except_ where it would likely have the largest impact, in the decompression code itself. Remove the #undef's of memcpy and memset in misc.c so that the decompressor code also uses the compiler builtins. The rationale given in the comment doesn't really apply: just because some functions use the out-of-line version is no reason to not use the builtin version in the rest. Replace the comment with an explanation of why memzero and memmove are being #define'd. Drop the suggestion to #undef in boot/string.h as well: the out-of-line versions are not really optimized versions, they're generic code that's good enough for the preboot environment. The compiler will likely generate better code for constant-size memcpy/memset/memcmp if it is allowed to. Most decompressors' performance is unchanged, with the exception of LZ4 and 64-bit ZSTD. Before After ARCH LZ4 73ms 10ms 32 LZ4 120ms 10ms 64 ZSTD 90ms 74ms 64 Measurements on QEMU on 2.2GHz Broadwell Xeon, using defconfig kernels. Decompressor code size has small differences, with the largest being that 64-bit ZSTD decreases just over 2k. The largest code size increase was on 64-bit XZ, of about 400 bytes. Signed-off-by: Arvind Sankar <[email protected]> Suggested-by: Nick Terrell <[email protected]> Tested-by: Nick Terrell <[email protected]> Acked-by: Kees Cook <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 18445bf commit 394b19d

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

arch/x86/boot/compressed/misc.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,9 @@
3030
#define STATIC static
3131

3232
/*
33-
* Use normal definitions of mem*() from string.c. There are already
34-
* included header files which expect a definition of memset() and by
35-
* the time we define memset macro, it is too late.
33+
* Provide definitions of memzero and memmove as some of the decompressors will
34+
* try to define their own functions if these are not defined as macros.
3635
*/
37-
#undef memcpy
38-
#undef memset
3936
#define memzero(s, n) memset((s), 0, (n))
4037
#define memmove memmove
4138

arch/x86/boot/string.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ void *memcpy(void *dst, const void *src, size_t len);
1111
void *memset(void *dst, int c, size_t len);
1212
int memcmp(const void *s1, const void *s2, size_t len);
1313

14-
/*
15-
* Access builtin version by default. If one needs to use optimized version,
16-
* do "undef memcpy" in .c file and link against right string.c
17-
*/
14+
/* Access builtin version by default. */
1815
#define memcpy(d,s,l) __builtin_memcpy(d,s,l)
1916
#define memset(d,c,l) __builtin_memset(d,c,l)
2017
#define memcmp __builtin_memcmp

0 commit comments

Comments
 (0)