Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1582014ybh; Thu, 23 Jul 2020 12:31:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrMz2wbAOsqDc90XFm2++be6LCngSBQ/MKgZ2Odwzf1BDDz5NfWerYn9QPh0vzjwGuCtLx X-Received: by 2002:aa7:c909:: with SMTP id b9mr5575999edt.111.1595532681845; Thu, 23 Jul 2020 12:31:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595532681; cv=none; d=google.com; s=arc-20160816; b=I4OHluLCeqIaQGTEypCwKlLMK09MtHYIcBYj+nxOhfZaVSncDYH6b20Vs+vcAxu4mn X9q3zLT4mK0CrSzrAvcFmVHmzlFNo7PmaQcL39sM0dUM114wnuwBtvdvk+q2aQzyYnzW n2vpJ3j+OuTM3I6BKD3LT2EclV+nyPmpgkxyIvMFqSFWOFPu2q6WamlOUhFD8Ru80MrI YPcg9zFryANwpq8ceAFIjk8G2qLzTH/m4g89hqCjCFWv9aH4bqepuRvTG4ACrqMd+9+O dm8tt15dSXg0pHKTZvepTBu9NU+WCs32LI+PgGNIZnJLpzyE7age1G1R8b99tw9FKOc4 sDtg== 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=8/DI/50DEIVF9w1bgg6BLrThdU6CkFz7wJynwzPDC4k=; b=U1/1kbuCO+gimG9TwzpsOxVTT6Urq6ka02u+lYK0OPnQFgogW/i3wIveTUTLYI6dAC tr7jlrdW9hysbjLMQtXsTgta98essbaa+hQCBCwcPtUtrUc9UeLhl9nm/GI8kHxUDxu7 ENel/pcjAbGyJBjFDAzD0ytpajGzUVL5oFzKSURtqumeCp5Kn5+eQhmnOZkU/hY7cmN1 K8JuvQIv9GBgnvGad53EWUzeh7vGo78ZFkD3TQumiOlYAClRHTqLbHk1TR4GqDZloNfn QESgjORts8Qn81XPZUkJacbEegcW04yURScX83ze7IOqiHas/yFTPNknlBpEojH5qrOY xEew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="oC+2/yZf"; 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 v14si2146656edy.162.2020.07.23.12.30.59; Thu, 23 Jul 2020 12:31:21 -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="oC+2/yZf"; 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 S1726636AbgGWTah (ORCPT + 99 others); Thu, 23 Jul 2020 15:30:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725894AbgGWTah (ORCPT ); Thu, 23 Jul 2020 15:30:37 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEDF2C0619DC; Thu, 23 Jul 2020 12:30:36 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id f16so3594160pjt.0; Thu, 23 Jul 2020 12:30:36 -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=8/DI/50DEIVF9w1bgg6BLrThdU6CkFz7wJynwzPDC4k=; b=oC+2/yZf/j1Im1OASbE0CaORWZlVKpThqJMnemy5R/b1RevcAWwUJrqdCm9yEnhBA/ X0kCwGwpl+LJM3pRP4z+isXWIk1UH/Hg9kPqeVo9BJUB3Pu94nj9x7RkKXnbRSom+WvF BmiYIFN3Fb0biQEfRT9C54mOma99CxbSmRfJ19GXnWq2+d57bSYfk2l6uxFywVfPo+Jb HAzNQ9fDzzwgNenkIRaCurynQkpeZ34zkjstxaJR11hbCPNhcxkIUZkkpf7Ck1LaLXJp d2zVV5Py+W0gZTIm574Die2Jva3QTMiGKqNNTYjDu9oHNg7fUui+wf+zuk0EUiW0nInN 6U2w== 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=8/DI/50DEIVF9w1bgg6BLrThdU6CkFz7wJynwzPDC4k=; b=djXI2RLdKn1+P8jTQ4wUIO4PBW1D1s5K6WHgXyfHmbdy8CFup+lWgbh14enR09Q0wv eeA1O1LRqfcuOthjbnXI1JhOSH5tTBVhaLUw3gWwxYMngcptFmiZj+6ZuBkSopZSUVLT 7dWenI1uabhiMgx4RJVVLqe476sMQsvhBjBwCvR7rC1eIkTFyg9ihFUw73Tau77JkLi1 hVrhYdvkyrzpfYRzicrm5YaMYLGUdYYysbtH0gJQFKdzvTFJzDkvuhqHk6Rb9ZZXxTuk zZTKe6EdvnzpVFE+qfMAyzd4Nzio5saZdglcbpAuJThwoN7ftzza2oqri/PvoagcB3az 6oqg== X-Gm-Message-State: AOAM533mhVyLvq9T5MXNvt0ABgvAmsssqD8onUWewkajCAbOVpMSBs2V 0iI0SXJF62ClbM0B74vtMrE= X-Received: by 2002:a17:902:7281:: with SMTP id d1mr4869503pll.247.1595532636419; Thu, 23 Jul 2020 12:30:36 -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 y18sm3794332pff.10.2020.07.23.12.30.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jul 2020 12:30:35 -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 , Arvind Sankar , Nick Terrell Subject: [PATCH v8 3/7] init: add support for zstd compressed kernel Date: Thu, 23 Jul 2020 12:27:57 -0700 Message-Id: <20200723192801.351114-4-nickrterrell@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200723192801.351114-1-nickrterrell@gmail.com> References: <20200723192801.351114-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 * Adds the zstd and zstd22 cmds to scripts/Makefile.lib * Adds the HAVE_KERNEL_ZSTD and KERNEL_ZSTD options Architecture specific support is still needed for decompression. Reviewed-by: Kees Cook Tested-by: Sedat Dilek Signed-off-by: Nick Terrell --- Makefile | 3 ++- init/Kconfig | 15 ++++++++++++++- scripts/Makefile.lib | 22 ++++++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index fe0164a654c7..d14f9b7038ba 100644 --- a/Makefile +++ b/Makefile @@ -464,6 +464,7 @@ KLZOP = lzop LZMA = lzma LZ4 = lz4c XZ = xz +ZSTD = zstd CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \ -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF) @@ -512,7 +513,7 @@ CLANG_FLAGS := export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC export CPP AR NM STRIP OBJCOPY OBJDUMP OBJSIZE READELF PAHOLE LEX YACC AWK INSTALLKERNEL export PERL PYTHON PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX -export KGZIP KBZIP2 KLZOP LZMA LZ4 XZ +export KGZIP KBZIP2 KLZOP LZMA LZ4 XZ ZSTD export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS diff --git a/init/Kconfig b/init/Kconfig index 0498af567f70..8d99f0c5e240 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -191,13 +191,16 @@ config HAVE_KERNEL_LZO config HAVE_KERNEL_LZ4 bool +config HAVE_KERNEL_ZSTD + bool + config HAVE_KERNEL_UNCOMPRESSED bool choice prompt "Kernel compression mode" default KERNEL_GZIP - depends on HAVE_KERNEL_GZIP || HAVE_KERNEL_BZIP2 || HAVE_KERNEL_LZMA || HAVE_KERNEL_XZ || HAVE_KERNEL_LZO || HAVE_KERNEL_LZ4 || HAVE_KERNEL_UNCOMPRESSED + depends on HAVE_KERNEL_GZIP || HAVE_KERNEL_BZIP2 || HAVE_KERNEL_LZMA || HAVE_KERNEL_XZ || HAVE_KERNEL_LZO || HAVE_KERNEL_LZ4 || HAVE_KERNEL_ZSTD || HAVE_KERNEL_UNCOMPRESSED help The linux kernel is a kind of self-extracting executable. Several compression algorithms are available, which differ @@ -276,6 +279,16 @@ config KERNEL_LZ4 is about 8% bigger than LZO. But the decompression speed is faster than LZO. +config KERNEL_ZSTD + bool "ZSTD" + depends on HAVE_KERNEL_ZSTD + help + ZSTD is a compression algorithm targeting intermediate compression + with fast decompression speed. It will compress better than GZIP and + decompress around the same speed as LZO, but slower than LZ4. You + will need at least 192 KB RAM or more for booting. The zstd command + line tools is required for compression. + config KERNEL_UNCOMPRESSED bool "None" depends on HAVE_KERNEL_UNCOMPRESSED diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 916b2f7f7098..54f7b7eb580b 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -413,6 +413,28 @@ quiet_cmd_xzkern = XZKERN $@ quiet_cmd_xzmisc = XZMISC $@ cmd_xzmisc = cat $(real-prereqs) | $(XZ) --check=crc32 --lzma2=dict=1MiB > $@ +# ZSTD +# --------------------------------------------------------------------------- +# Appends the uncompressed size of the data using size_append. The .zst +# format has the size information available at the beginning of the file too, +# but it's in a more complex format and it's good to avoid changing the part +# of the boot code that reads the uncompressed size. +# +# Note that the bytes added by size_append will make the zstd tool think that +# the file is corrupt. This is expected. +# +# zstd uses a maximum window size of 8 MB. zstd22 uses a maximum window size of +# 128 MB. zstd22 is used for kernel compression because it is decompressed in a +# single pass, so zstd doesn't need to allocate a window buffer. When streaming +# decompression is used, like initramfs decompression, zstd22 should likely not +# be used because it would require zstd to allocate a 128 MB buffer. + +quiet_cmd_zstd = ZSTD $@ + cmd_zstd = { cat $(real-prereqs) | $(ZSTD) -19; $(size_append); } > $@ + +quiet_cmd_zstd22 = ZSTD22 $@ + cmd_zstd22 = { cat $(real-prereqs) | $(ZSTD) -22 --ultra; $(size_append); } > $@ + # ASM offsets # --------------------------------------------------------------------------- -- 2.27.0