Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp255200ybb; Tue, 31 Mar 2020 22:40:11 -0700 (PDT) X-Google-Smtp-Source: APiQypIwIIm0ZaNsoiZLPllSu9+xKOlLMQPL16bxwp15snzWpmDAG5dJhri4pCA++fj/L+12pS9J X-Received: by 2002:aca:4bd3:: with SMTP id y202mr1591547oia.7.1585719611470; Tue, 31 Mar 2020 22:40:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585719611; cv=none; d=google.com; s=arc-20160816; b=n+vgmMJAHOBDBpp87wJHtcvOeJ2irhYWfXNJkCcwHtWYmtiZ7Fq4FzKi8ZqE7YOOC5 iVdT0RjvVDxAb6D9BjlPvMJQFjiGnofy9twI61qTdenGQZhhbK8TTR/Uqqs9WqCDQUo5 fWR8uv5O95iG05aBEEVK2gFuY9GXCFYzUuRGhzt+9qYWGfEy+QOOYQzBmABmgqVdEm4Q adB+jpRZ/nHDEMVWl5PrAOesaJhORCcBz9nwtlIuiGdj+OKg7XHtRSSaThmBnx7T31JS lrduFTseZsLTYhdiBiAEjheNeKtS8ev6diQDXHaK1Jo2xPDu5aysiQU5rzRNKgJVO3F0 V6Zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=L1Bh68GFLXfKwLvsPSIBdeh7yqRXFoYmwF40kxX/130=; b=J2fopdKXlF4v34+PLzj4KqCfo2Dfa+EfcwfVYlxgFfL+RBoERr8OHoW0jXZ2YhhC83 P4OXAc76XXJ0Fc6vEHCx3gkwY8bVPXc6JAW7Uonp3jjQvxHhHcVxaBaKjn72Vsaa4FYs PkQdFt+1/N5sRST8JuLkVwdtochE/6JYt6gkGFGOTeH3F738tlsOOuyYcVwKvp3c1q2D XMJstU5pr4hn+LyYf7f3QlEEj88blJnqVVJ7qsV7uWhWLKMWrZow/vwE6Dtj11EG7J8M ilAwjYRoe5QjpclMgmDmXJLbH4FjmADp1H/BESM5wNQ53GKn1Kb2tirjHAAs/QHdwXFj FUSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JsiBkHDj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n64si467231oih.256.2020.03.31.22.39.59; Tue, 31 Mar 2020 22:40:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JsiBkHDj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731872AbgDAFjG (ORCPT + 99 others); Wed, 1 Apr 2020 01:39:06 -0400 Received: from mail-pg1-f175.google.com ([209.85.215.175]:42176 "EHLO mail-pg1-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731589AbgDAFjF (ORCPT ); Wed, 1 Apr 2020 01:39:05 -0400 Received: by mail-pg1-f175.google.com with SMTP id h8so11576705pgs.9; Tue, 31 Mar 2020 22:39:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=L1Bh68GFLXfKwLvsPSIBdeh7yqRXFoYmwF40kxX/130=; b=JsiBkHDj8pt5LxpqwHgDafGuRm1tYV2oFjL+2IfbfmMo5hJojFA3G5ACwczrW9ITcB dmopszf3Ep359WU1OMTWvHNQKTRV6AWkSIy0K3NWgqwUa3AlymRvF9GXhYMxafMx2Xwz HnJH7lZqkWdlvgpRctwC/yaP2GCtHHvYGifjmlbOPPzFZnLI3Owl0WRLoy+yXIeH6Bhz HlyZ8lOcNYj5ZofNI+z2EvE6/49JvQbSh3xLjI8S2uKlGZAAvccsrBFj50ulhg0xvot8 F9bhuG/6uxiu0b8AwNI+u4qQJKwttKL+BQD5Rqbml1LdVAiMzyEfGRrbP5bXIKAVwMiN TVgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=L1Bh68GFLXfKwLvsPSIBdeh7yqRXFoYmwF40kxX/130=; b=DEIjEGSV/T460ek3LKA11O9j40PmCY+ELAoMSgqdr5lud6UydBuD2nwC9EsT5AotAB rWDOe59i7Hde56a0K3EdWKzwkJN/FFWOcY1O7oPFBvo65RndqgQ9QX7fQqsrdXyQ3oOu 8DU8iXCVKgFevA10GdaUFlM3u97RkFC2T4kWSJq3QUHGlo1QyWaeNJNSbYE5hdKbOd/3 EQTd3Ezv+6Xh/VwDcahWI265VfVO3RPrXszcP+ULMwVfYHvc/j19laygfQXf73lJZrwe HEo8QVf4xfa9GLfJ6xowcG9fWRU/DNONBN+gdTqTmrEETw/fvHizqbyyMGFzOP94r+Pp fHvQ== X-Gm-Message-State: AGi0Pua6u2lyBVKbgSNKKuTUXZ9tEpezcaPa1UfN5wG3fz/xr/r3ZwwG A0cuDXBOBWa6HnQ+3T7W4Jk= X-Received: by 2002:a63:5f10:: with SMTP id t16mr7444350pgb.20.1585719543869; Tue, 31 Mar 2020 22:39:03 -0700 (PDT) Received: from nickserv.localdomain (c-67-188-225-242.hsd1.ca.comcast.net. [67.188.225.242]) by smtp.gmail.com with ESMTPSA id w69sm683077pfc.52.2020.03.31.22.39.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Mar 2020 22:39:03 -0700 (PDT) From: Nick Terrell To: Nick Terrell Cc: linux-kernel@vger.kernel.org, Chris Mason , linux-kbuild@vger.kernel.org, x86@kernel.org, gregkh@linuxfoundation.org, Petr Malat , Kees Cook , Kernel Team , Nick Terrell , Adam Borowski , Patrick Williams , rmikey@fb.com, mingo@kernel.org, Patrick Williams , Sedat Dilek Subject: [PATCH v4 7/8] x86: Add support for ZSTD compressed kernel Date: Tue, 31 Mar 2020 22:39:12 -0700 Message-Id: <20200401053913.216783-8-nickrterrell@gmail.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200401053913.216783-1-nickrterrell@gmail.com> References: <20200401053913.216783-1-nickrterrell@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nick Terrell * Add support for zstd compressed kernel * Bump the heap size for zstd. * Update the documentation. Integrates the ZSTD decompression code to the x86 pre-boot code. Zstandard requires slightly more memory during the kernel decompression on x86 (192 KB vs 64 KB), and the memory usage is independent of the window size. This patch has been boot tested with both a zstd and gzip compressed kernel on i386 and x86_64 using buildroot and QEMU. Additionally, this has been tested in production on x86_64 devices. We saw a 2 second boot time reduction by switching kernel compression from xz to zstd. Reviewed-by: Kees Cook Tested-by: Sedat Dilek Signed-off-by: Nick Terrell --- Documentation/x86/boot.rst | 6 +++--- arch/x86/Kconfig | 1 + arch/x86/boot/compressed/Makefile | 5 ++++- arch/x86/boot/compressed/misc.c | 4 ++++ arch/x86/include/asm/boot.h | 6 ++++-- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Documentation/x86/boot.rst b/Documentation/x86/boot.rst index c9c201596c3e..cedcf4d49bf0 100644 --- a/Documentation/x86/boot.rst +++ b/Documentation/x86/boot.rst @@ -786,9 +786,9 @@ Protocol: 2.08+ uncompressed data should be determined using the standard magic numbers. The currently supported compression formats are gzip (magic numbers 1F 8B or 1F 9E), bzip2 (magic number 42 5A), LZMA - (magic number 5D 00), XZ (magic number FD 37), and LZ4 (magic number - 02 21). The uncompressed payload is currently always ELF (magic - number 7F 45 4C 46). + (magic number 5D 00), XZ (magic number FD 37), LZ4 (magic number + 02 21) and ZSTD (magic number 28 B5). The uncompressed payload is + currently always ELF (magic number 7F 45 4C 46). ============ ============== Field name: payload_length diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index beea77046f9b..12d88997a3a6 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -183,6 +183,7 @@ config X86 select HAVE_KERNEL_LZMA select HAVE_KERNEL_LZO select HAVE_KERNEL_XZ + select HAVE_KERNEL_ZSTD select HAVE_KPROBES select HAVE_KPROBES_ON_FTRACE select HAVE_FUNCTION_ERROR_INJECTION diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile index 26050ae0b27e..8233f598f15b 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -24,7 +24,7 @@ OBJECT_FILES_NON_STANDARD := y KCOV_INSTRUMENT := n targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma \ - vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4 + vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4 vmlinux.bin.zst KBUILD_CFLAGS := -m$(BITS) -O2 KBUILD_CFLAGS += -fno-strict-aliasing $(call cc-option, -fPIE, -fPIC) @@ -145,6 +145,8 @@ $(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE $(call if_changed,lzo) $(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE $(call if_changed,lz4) +$(obj)/vmlinux.bin.zst: $(vmlinux.bin.all-y) FORCE + $(call if_changed,zstd) suffix-$(CONFIG_KERNEL_GZIP) := gz suffix-$(CONFIG_KERNEL_BZIP2) := bz2 @@ -152,6 +154,7 @@ suffix-$(CONFIG_KERNEL_LZMA) := lzma suffix-$(CONFIG_KERNEL_XZ) := xz suffix-$(CONFIG_KERNEL_LZO) := lzo suffix-$(CONFIG_KERNEL_LZ4) := lz4 +suffix-$(CONFIG_KERNEL_ZSTD) := zst quiet_cmd_mkpiggy = MKPIGGY $@ cmd_mkpiggy = $(obj)/mkpiggy $< > $@ diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c index 9652d5c2afda..39e592d0e0b4 100644 --- a/arch/x86/boot/compressed/misc.c +++ b/arch/x86/boot/compressed/misc.c @@ -77,6 +77,10 @@ static int lines, cols; #ifdef CONFIG_KERNEL_LZ4 #include "../../../../lib/decompress_unlz4.c" #endif + +#ifdef CONFIG_KERNEL_ZSTD +#include "../../../../lib/decompress_unzstd.c" +#endif /* * NOTE: When adding a new decompressor, please update the analysis in * ../header.S. diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h index 680c320363db..d6dd43d25d9f 100644 --- a/arch/x86/include/asm/boot.h +++ b/arch/x86/include/asm/boot.h @@ -24,9 +24,11 @@ # error "Invalid value for CONFIG_PHYSICAL_ALIGN" #endif -#ifdef CONFIG_KERNEL_BZIP2 +#if defined(CONFIG_KERNEL_BZIP2) # define BOOT_HEAP_SIZE 0x400000 -#else /* !CONFIG_KERNEL_BZIP2 */ +#elif defined(CONFIG_KERNEL_ZSTD) +# define BOOT_HEAP_SIZE 0x30000 +#else # define BOOT_HEAP_SIZE 0x10000 #endif -- 2.26.0