forked from luck/tmp_suning_uos_patched
394b19d6cb
Since commitsc041b5ad86
("x86, boot: Create a separate string.h file to provide standard string functions")fb4cac573e
("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 <nivedita@alum.mit.edu> Suggested-by: Nick Terrell <nickrterrell@gmail.com> Tested-by: Nick Terrell <nickrterrell@gmail.com> Acked-by: Kees Cook <keescook@chromium.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
32 lines
1.1 KiB
C
32 lines
1.1 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef BOOT_STRING_H
|
|
#define BOOT_STRING_H
|
|
|
|
/* Undef any of these macros coming from string_32.h. */
|
|
#undef memcpy
|
|
#undef memset
|
|
#undef memcmp
|
|
|
|
void *memcpy(void *dst, const void *src, size_t len);
|
|
void *memset(void *dst, int c, size_t len);
|
|
int memcmp(const void *s1, const void *s2, size_t len);
|
|
|
|
/* Access builtin version by default. */
|
|
#define memcpy(d,s,l) __builtin_memcpy(d,s,l)
|
|
#define memset(d,c,l) __builtin_memset(d,c,l)
|
|
#define memcmp __builtin_memcmp
|
|
|
|
extern int strcmp(const char *str1, const char *str2);
|
|
extern int strncmp(const char *cs, const char *ct, size_t count);
|
|
extern size_t strlen(const char *s);
|
|
extern char *strstr(const char *s1, const char *s2);
|
|
extern char *strchr(const char *s, int c);
|
|
extern size_t strnlen(const char *s, size_t maxlen);
|
|
extern unsigned int atou(const char *s);
|
|
extern unsigned long long simple_strtoull(const char *cp, char **endp,
|
|
unsigned int base);
|
|
|
|
int kstrtoull(const char *s, unsigned int base, unsigned long long *res);
|
|
int boot_kstrtoul(const char *s, unsigned int base, unsigned long *res);
|
|
#endif /* BOOT_STRING_H */
|