Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1582701ybh; Thu, 23 Jul 2020 12:32:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygnoXCTf3MehAYNc7/YHiDiF1Bp5/YqSi9+U4m3T4IfWczP5eudt0aaISFT3QkpIJEPWVL X-Received: by 2002:a17:906:1250:: with SMTP id u16mr5494807eja.299.1595532746439; Thu, 23 Jul 2020 12:32:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595532746; cv=none; d=google.com; s=arc-20160816; b=FxzTex4RzrJQbKsox0gv58HXA6myxfEHT2BNWBB44Rm3GC3d1CUhpmhPAOFI8x1j4H bWKrRHkOcT03pJjdexlz17XC/1Jgx5BHifuQJy4wUzC7hgSF27UjHDIUk7HOGdlszwpT l8q8oAHCOVZfyxW3VacmFZ9UyV2soYRsJczVTpmShmWWsL2+Zv6B5sA1n+4FPDsSvwSu LwTnba0P3mr9KMWchdWZNAYrwgB8SQpw9ghij8wn+hHf9IW+6RFta5rRxmbWm1izhyGh UqLBR3arZkP7f7JEWBRzwQlLSM+SCxvuUPTfuXGjWvYeK8RbBEbbtxm6oijhqlMb16/Y uTVg== 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=fmIcvsol2hVEYD4hslBcgfIPlSJK4NAnFqyLqCM1gdk=; b=TXWa9ii11FNSqlq15yOVpwyt8Wjg96rET5BwlZKikm+1gS6TX2tKijIV7GG+vUHaYE kFLSaEu0tgqv4AJmDnrsnRd0GkcHVGWMaJBclMhAksGvAkZAqtiMU037ipEn8LLr92WK 7PyHa9UJtR2e06qSs/gxDjySiYnHH7BKRX99+FnngaJ9er+Blqkt2B60SLLbojKeomDl bBHiYR415TWGl4qKoULz1yI1febAdKmTZLRDoedwe0oON9mXd8tlRQ1nH1W52q8K2kFE pj1x0ff8juGsU5+QCEytTMAaPmokZWZc5LnHdjxU188XriTx9QUjrn2gPlsQXUyOU58r BCmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=if0tqqlT; 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 j18si2717816eja.217.2020.07.23.12.32.02; Thu, 23 Jul 2020 12:32:26 -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=if0tqqlT; 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 S1726686AbgGWTan (ORCPT + 99 others); Thu, 23 Jul 2020 15:30:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725894AbgGWTam (ORCPT ); Thu, 23 Jul 2020 15:30:42 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6A4BC0619E2; Thu, 23 Jul 2020 12:30:42 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id k1so3667751pjt.5; Thu, 23 Jul 2020 12:30:42 -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=fmIcvsol2hVEYD4hslBcgfIPlSJK4NAnFqyLqCM1gdk=; b=if0tqqlT1PKw4Xb47pom4OOkDXy+0T4tdEWtgS3Ih1Ig6xIL7ov/Jq0JscLE5vZDTx Yq2UvbDv72LkIoBetdhbFLenWST4WfBepw0f2QWBt+ZISpRzsmSNteQvfZOAPzHAMtd8 yYQ90PN3OJH7/S8H7h2gJvZ7kO31VUVXqFWVa6COWh3VifhzQlwrUN+hkaqjlKj/wZju V94aGPZPkZycFnopZiEppnBpHGuiRt6DIsiS5s6B/dMhxuhjwhAUj6VuFtdGX8JRFtDQ G+kzkIYZwyh8epLh/OQnKWECtorTjU0sbyxX9vnWmeByT/3Whhn0EGYjgBJFsib+4VZJ GkWA== 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=fmIcvsol2hVEYD4hslBcgfIPlSJK4NAnFqyLqCM1gdk=; b=anqfcLJdHcx9+3S+QP8630u7PeF3YyNntEYK/Gedn59DW6t/ezmW4lTkye9TH3UH5K 2x4hbL7ojLebe7KwhQDxHeQBIgMYE+6s7S8SXaL+2LAWX/UoeMniy1bHbiyqQ/vIYxfM dhKTLJC9pYWrSwNPdoH8TcxvmjFmJ11/u/N4HFcGZf6GNplsHRLnmJNzyFslIXk7wMYC RfcYE0F15PVNtSmL3wguVegTgNDXldY1DG5LpC9v2vwEnFKN+v1i9riWjf19E/oqVdLW LKcGd65mqekgvoqiWDLms2ZmxWRm0aStyhF2mufonnSDK1h/IsgxO/VGSujZTRAjcarG Zc2g== X-Gm-Message-State: AOAM5314yvZH6Gn4jDODMIaO3SDKAkMe9gaRuUNpngDNsl8ZYZLVO9Gs H9wf/mtLsWudpRergw6c77Q= X-Received: by 2002:a17:90a:1f81:: with SMTP id x1mr1645438pja.115.1595532642072; Thu, 23 Jul 2020 12:30:42 -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.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jul 2020 12:30:41 -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 4/7] usr: add support for zstd compressed initramfs Date: Thu, 23 Jul 2020 12:27:58 -0700 Message-Id: <20200723192801.351114-5-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 * Add support for a zstd compressed initramfs. * Add compression for compressing built-in initramfs with zstd. I have tested this patch by boot testing with buildroot and QEMU. Specifically, I booted the kernel with both a zstd and gzip compressed initramfs, both built into the kernel and separate. I ensured that the correct compression algorithm was used. I tested on arm, aarch64, i386, and x86_64. This patch has been tested in production on aarch64 and x86_64 devices. Additionally, I have performance measurements from internal use in production. On an aarch64 device we saw 19 second boot time improvement from switching from lzma to zstd (27 seconds to 8 seconds). On an x86_64 device we saw a 9 second boot time reduction from switching from xz to zstd. Reviewed-by: Kees Cook Tested-by: Sedat Dilek Signed-off-by: Nick Terrell --- usr/Kconfig | 20 ++++++++++++++++++++ usr/Makefile | 1 + 2 files changed, 21 insertions(+) diff --git a/usr/Kconfig b/usr/Kconfig index 96afb03b65f9..2599bc21c1b2 100644 --- a/usr/Kconfig +++ b/usr/Kconfig @@ -100,6 +100,15 @@ config RD_LZ4 Support loading of a LZ4 encoded initial ramdisk or cpio buffer If unsure, say N. +config RD_ZSTD + bool "Support initial ramdisk/ramfs compressed using ZSTD" + default y + depends on BLK_DEV_INITRD + select DECOMPRESS_ZSTD + help + Support loading of a ZSTD encoded initial ramdisk or cpio buffer. + If unsure, say N. + choice prompt "Built-in initramfs compression mode" depends on INITRAMFS_SOURCE != "" @@ -196,6 +205,17 @@ config INITRAMFS_COMPRESSION_LZ4 If you choose this, keep in mind that most distros don't provide lz4 by default which could cause a build failure. +config INITRAMFS_COMPRESSION_ZSTD + bool "ZSTD" + depends on RD_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. + + If you choose this, keep in mind that you may need to install the zstd + tool to be able to compress the initram. + config INITRAMFS_COMPRESSION_NONE bool "None" help diff --git a/usr/Makefile b/usr/Makefile index c12e6b15ce72..b1a81a40eab1 100644 --- a/usr/Makefile +++ b/usr/Makefile @@ -15,6 +15,7 @@ compress-$(CONFIG_INITRAMFS_COMPRESSION_LZMA) := lzma compress-$(CONFIG_INITRAMFS_COMPRESSION_XZ) := xzmisc compress-$(CONFIG_INITRAMFS_COMPRESSION_LZO) := lzo compress-$(CONFIG_INITRAMFS_COMPRESSION_LZ4) := lz4 +compress-$(CONFIG_INITRAMFS_COMPRESSION_ZSTD) := zstd obj-$(CONFIG_BLK_DEV_INITRD) := initramfs_data.o -- 2.27.0