Skip to content

Commit c0dfadf

Browse files
committed
Merge tag 'x86-boot-2020-08-03' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 boot updates from Ingo Molnar: "The main change in this cycle was to add support for ZSTD-compressed kernel and initrd images. ZSTD has a very fast decompressor, yet it compresses better than gzip" * tag 'x86-boot-2020-08-03' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: Documentation: dontdiff: Add zstd compressed files .gitignore: Add ZSTD-compressed files x86: Add support for ZSTD compressed kernel x86: Bump ZO_z_extra_bytes margin for zstd usr: Add support for zstd compressed initramfs init: Add support for zstd compressed kernel lib: Add zstd support to decompress lib: Prepare zstd for preboot environment, improve performance
2 parents ba77c56 + 1ac1efa commit c0dfadf

File tree

21 files changed

+469
-26
lines changed

21 files changed

+469
-26
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
*.tab.[ch]
4545
*.tar
4646
*.xz
47+
*.zst
4748
Module.symvers
4849
modules.builtin
4950
modules.order

Documentation/dontdiff

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
*.ver
5656
*.xml
5757
*.xz
58+
*.zst
5859
*_MODULES
5960
*_vga16.c
6061
*~

Documentation/x86/boot.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -782,9 +782,9 @@ Protocol: 2.08+
782782
uncompressed data should be determined using the standard magic
783783
numbers. The currently supported compression formats are gzip
784784
(magic numbers 1F 8B or 1F 9E), bzip2 (magic number 42 5A), LZMA
785-
(magic number 5D 00), XZ (magic number FD 37), and LZ4 (magic number
786-
02 21). The uncompressed payload is currently always ELF (magic
787-
number 7F 45 4C 46).
785+
(magic number 5D 00), XZ (magic number FD 37), LZ4 (magic number
786+
02 21) and ZSTD (magic number 28 B5). The uncompressed payload is
787+
currently always ELF (magic number 7F 45 4C 46).
788788

789789
============ ==============
790790
Field name: payload_length

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ KLZOP = lzop
464464
LZMA = lzma
465465
LZ4 = lz4c
466466
XZ = xz
467+
ZSTD = zstd
467468

468469
CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
469470
-Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF)
@@ -512,7 +513,7 @@ CLANG_FLAGS :=
512513
export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC
513514
export CPP AR NM STRIP OBJCOPY OBJDUMP OBJSIZE READELF PAHOLE LEX YACC AWK INSTALLKERNEL
514515
export PERL PYTHON PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX
515-
export KGZIP KBZIP2 KLZOP LZMA LZ4 XZ
516+
export KGZIP KBZIP2 KLZOP LZMA LZ4 XZ ZSTD
516517
export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE
517518

518519
export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS

arch/x86/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ config X86
188188
select HAVE_KERNEL_LZMA
189189
select HAVE_KERNEL_LZO
190190
select HAVE_KERNEL_XZ
191+
select HAVE_KERNEL_ZSTD
191192
select HAVE_KPROBES
192193
select HAVE_KPROBES_ON_FTRACE
193194
select HAVE_FUNCTION_ERROR_INJECTION

arch/x86/boot/compressed/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ OBJECT_FILES_NON_STANDARD := y
2626
KCOV_INSTRUMENT := n
2727

2828
targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma \
29-
vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4
29+
vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4 vmlinux.bin.zst
3030

3131
KBUILD_CFLAGS := -m$(BITS) -O2
3232
KBUILD_CFLAGS += -fno-strict-aliasing $(call cc-option, -fPIE, -fPIC)
@@ -42,6 +42,7 @@ KBUILD_CFLAGS += $(call cc-disable-warning, gnu)
4242
KBUILD_CFLAGS += -Wno-pointer-sign
4343
KBUILD_CFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
4444
KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
45+
KBUILD_CFLAGS += -D__DISABLE_EXPORTS
4546

4647
KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
4748
GCOV_PROFILE := n
@@ -145,13 +146,16 @@ $(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE
145146
$(call if_changed,lzo)
146147
$(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE
147148
$(call if_changed,lz4)
149+
$(obj)/vmlinux.bin.zst: $(vmlinux.bin.all-y) FORCE
150+
$(call if_changed,zstd22)
148151

149152
suffix-$(CONFIG_KERNEL_GZIP) := gz
150153
suffix-$(CONFIG_KERNEL_BZIP2) := bz2
151154
suffix-$(CONFIG_KERNEL_LZMA) := lzma
152155
suffix-$(CONFIG_KERNEL_XZ) := xz
153156
suffix-$(CONFIG_KERNEL_LZO) := lzo
154157
suffix-$(CONFIG_KERNEL_LZ4) := lz4
158+
suffix-$(CONFIG_KERNEL_ZSTD) := zst
155159

156160
quiet_cmd_mkpiggy = MKPIGGY $@
157161
cmd_mkpiggy = $(obj)/mkpiggy $< > $@

arch/x86/boot/compressed/kaslr.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@
1919
*/
2020
#define BOOT_CTYPE_H
2121

22-
/*
23-
* _ctype[] in lib/ctype.c is needed by isspace() of linux/ctype.h.
24-
* While both lib/ctype.c and lib/cmdline.c will bring EXPORT_SYMBOL
25-
* which is meaningless and will cause compiling error in some cases.
26-
*/
27-
#define __DISABLE_EXPORTS
28-
2922
#include "misc.h"
3023
#include "error.h"
3124
#include "../string.h"

arch/x86/boot/compressed/misc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ static int lines, cols;
7777
#ifdef CONFIG_KERNEL_LZ4
7878
#include "../../../../lib/decompress_unlz4.c"
7979
#endif
80+
81+
#ifdef CONFIG_KERNEL_ZSTD
82+
#include "../../../../lib/decompress_unzstd.c"
83+
#endif
8084
/*
8185
* NOTE: When adding a new decompressor, please update the analysis in
8286
* ../header.S.

arch/x86/boot/header.S

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,14 @@ pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
539539
# the size-dependent part now grows so fast.
540540
#
541541
# extra_bytes = (uncompressed_size >> 8) + 65536
542+
#
543+
# ZSTD compressed data grows by at most 3 bytes per 128K, and only has a 22
544+
# byte fixed overhead but has a maximum block size of 128K, so it needs a
545+
# larger margin.
546+
#
547+
# extra_bytes = (uncompressed_size >> 8) + 131072
542548

543-
#define ZO_z_extra_bytes ((ZO_z_output_len >> 8) + 65536)
549+
#define ZO_z_extra_bytes ((ZO_z_output_len >> 8) + 131072)
544550
#if ZO_z_output_len > ZO_z_input_len
545551
# define ZO_z_extract_offset (ZO_z_output_len + ZO_z_extra_bytes - \
546552
ZO_z_input_len)

arch/x86/include/asm/boot.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,16 @@
2424
# error "Invalid value for CONFIG_PHYSICAL_ALIGN"
2525
#endif
2626

27-
#ifdef CONFIG_KERNEL_BZIP2
27+
#if defined(CONFIG_KERNEL_BZIP2)
2828
# define BOOT_HEAP_SIZE 0x400000
29-
#else /* !CONFIG_KERNEL_BZIP2 */
29+
#elif defined(CONFIG_KERNEL_ZSTD)
30+
/*
31+
* Zstd needs to allocate the ZSTD_DCtx in order to decompress the kernel.
32+
* The ZSTD_DCtx is ~160KB, so set the heap size to 192KB because it is a
33+
* round number and to allow some slack.
34+
*/
35+
# define BOOT_HEAP_SIZE 0x30000
36+
#else
3037
# define BOOT_HEAP_SIZE 0x10000
3138
#endif
3239

0 commit comments

Comments
 (0)