Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp798549ybt; Wed, 8 Jul 2020 11:58:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbxx6zUQuniqtEIlujFSDelRzF/80LCoSWPvhxaNdBzhP7Hdq+8puwUzvdICTQxJHcK9E9 X-Received: by 2002:a17:906:5f98:: with SMTP id a24mr51453870eju.241.1594234731329; Wed, 08 Jul 2020 11:58:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594234731; cv=none; d=google.com; s=arc-20160816; b=tGc9G9cRjR7cWJMi683/qCUQ5MRVpWQgEj+IHgTrYbGIfUPCo786SIDUel3BDgt2Ik bJibFZnnGzjSVjHaNgjsEytSC/KdGoSS0dUrwvkZqJ/zLbra6svd5CUnS2WJtXo7CLLm QDBW7KPFYon1s0lu2ZORMExzOwfkiC4uCgNU8hidiZRKq6cOk5/2v8utdur3oCpnEIrP g1A66OsYY5STFjcRuxIYhqSA9DzXJ77PqECU7y0o1Qw6eOLJCvlaxgZZRoUvw35V+5YL zmrjE5uiLat6Mm5LKHiNSgG5iwYgemVP1QIBvfTe3OKJSG1VXX+voN6W2jklzOSLqGLn BxRQ== 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=MUWrYtVIM9tfCaLF1z9FO1yR7VJ62EYaOv1KIBaD3eo=; b=FC2jM1SYWIxYc5S3aTaa5rxoHzM0lYDLk/Daq+nkOvFIXVEnCrl2SQb58x+wQD+G3g fJyaZ7S3D0OCAfE8EEsbz6EszXkcfskrCFet95joiUw8uzvr6syO2wzRzvc9+j9HONjf NNjL9GOfoxBMj3kBz89roj36lC6Ebbx4VSrFo4DyiKEQ8H/6Q9QwGMUnFPMsXaEPXzRh oJTspGYcIAhYy+ZHtUF5rL5aSbMB0R5NcvaJNV6NNeB4Nuh8VMvF0oyqB+4Ng/zWr1AT +fZOExsSI00MLEX7Qgf1hS5J8Ku4vRGPFLsyfhS9l+M4BLXx/IHk3MBEvgWgFVSDatNr hleA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fGLNg4vi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id i6si415724ejj.508.2020.07.08.11.58.28; Wed, 08 Jul 2020 11:58:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fGLNg4vi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1727003AbgGHSz3 (ORCPT + 99 others); Wed, 8 Jul 2020 14:55:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726941AbgGHSz1 (ORCPT ); Wed, 8 Jul 2020 14:55:27 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8219CC061A0B; Wed, 8 Jul 2020 11:55:27 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id j19so15233502pgm.11; Wed, 08 Jul 2020 11:55:27 -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=MUWrYtVIM9tfCaLF1z9FO1yR7VJ62EYaOv1KIBaD3eo=; b=fGLNg4viVLiVDgAorBTr4rh3YasKLOQda/JkCNBUGvl7ZFZEfO5XZegq8PbH8JFtx1 N/KyDYFJ51C+9yq7aCufep9n9lqgom7pvUbjK7XT77XeIA84oTxmVoTe8QzsxDX7Caok C5OokRQgmfOQyBcT+7X9bR2XxHPzuvSd2yEEFptpQ+5OVf67CBGG/WFVcFISqZM/AaOF xTSpbKYoM1G/qb+MO8vdWuy1lINiSamPlLBk3I0raVyCTmwM/AnFEZ6fbzcythBm9Tsb ZfgW20op0vf9Jh3oFW5BvmK6IUkPD1NK9AjuxHHVJMYktQfmfqM3b+QIjpwcJfwLd2Q6 QZxA== 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=MUWrYtVIM9tfCaLF1z9FO1yR7VJ62EYaOv1KIBaD3eo=; b=A6jSoTSkfhSviQARCzDPZWhHQn3KNEZBYsGwa+tNayJTZ1/VnhMIf2XSkNuhdbUSI8 r0WTPJFCdz2EJOXe4MX4Hr/gy5lPzuekzJSUrEnHhIe65+lmfb0zA5n40oQ4DIaB8EtX joD2aCTX0RTY74e0OYO8km1lrnbHj6nG6ZiwsQUW5+HZrKP8mU1MGLJo3ijA+b7anyko V2aeQbLYz0X9WIXx2yBHpc5CK19vCKwMrXOlv3Ekae6YsweT+7+7vGqSPmDgVyaCXfzK aes+nUIYVSr8imskSofrKfNj5G8bKWALoMIhyOULrxQWLclR6VAMLEpqAdwtptws3GnZ +xJA== X-Gm-Message-State: AOAM532LVMplLiInnQ6Ir8xz9puO7hTWXkPiqaN+ee49K2DYFT46MxR0 Br6kegR4aliIADqJ+Uhvxqw= X-Received: by 2002:aa7:938c:: with SMTP id t12mr53679634pfe.37.1594234526963; Wed, 08 Jul 2020 11:55:26 -0700 (PDT) Received: from nickserv.localdomain (c-98-33-101-203.hsd1.ca.comcast.net. [98.33.101.203]) by smtp.gmail.com with ESMTPSA id c132sm485606pfb.112.2020.07.08.11.55.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2020 11:55:26 -0700 (PDT) From: Nick Terrell To: Borislav Petkov , Thomas Gleixner 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 , Norbert Lange , Andrew Morton , Alex Xu , Nick Terrell Subject: [PATCH v7 6/7] x86: Add support for ZSTD compressed kernel Date: Wed, 8 Jul 2020 11:50:23 -0700 Message-Id: <20200708185024.2767937-7-nickrterrell@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200708185024.2767937-1-nickrterrell@gmail.com> References: <20200708185024.2767937-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 5325c71ca877..7fafc7ac00d7 100644 --- a/Documentation/x86/boot.rst +++ b/Documentation/x86/boot.rst @@ -782,9 +782,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 883da0abf779..4a64395bc35d 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -188,6 +188,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 7619742f91c9..3498cd990869 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -26,7 +26,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,zstd22) 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.27.0