From nobody Wed Jan 22 10:00:38 2025 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE6E818AE2 for ; Tue, 21 Jan 2025 22:16:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737497781; cv=none; b=jUNwPQcXpkoaFNEPb9Wly3iRgahbaRm4HU6OOwO80QMX8j/B9HyOo1fzaogbXelJdjXv3dQhOCqoIaOm9DmjxyK27ncU3FDxUDT8sClWU8Esd1eOR7Ia8OSv6+S9mRBLe5vGvq67JRPH/Kt9hLoOeFKgb4rsawIJCTu8qa6JUt4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737497781; c=relaxed/simple; bh=kuS9+usQUnoAJ7h3I+IY6V/rxzIi2s09XeV3LdJfMj4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=NCoQb7x2APqZtEfrgenbzbRm+XNmdXOFQcLVnd/0HwgWTiDEqBgJVtGruNJg6QtT94khVxAkaRqpYI0ueDROpjfJ/VXXtL+F3j79UEy5QQNfqvG2gaZ3bpOU04zMV7lXelYaM9T3Lk8WMqS3XUodNwMqB0kVEZLwxH6LZqGarsY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=tarpvpuv; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="tarpvpuv" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4361d5730caso6235e9.1 for ; Tue, 21 Jan 2025 14:16:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1737497778; x=1738102578; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=mzmBoQbCE7e2VTnHw9DXW5AVmYWzyx5m18uEgeNFLzY=; b=tarpvpuv4xiueR/p14iFdvyCevj49Rp8T0tQQfGoeZkDzqCEyza1FVCdTBTx5PBgeA 7l2xqUS0ip+1maRwuXsaesTmiMrQDFaLkLHh1ZKemY9usfk34BqMXhR4spAXBNcXcVwZ 5ya+5j5QdhECcdeBmGDqx+m63KRgKJkBzyrM7xRgpSCq8ppsQzd01da1gSNQTrMIpMAl VnMOUtpcqfnmm8RKOJ4womfftEzGZERRNIJWvqzLfSkiLuNZs32rug1eA82oNXGjSqLC EN6bSk/40/e1MRfZcNzQ7S/RPRHjKa1ICSBLovLGsXg6TAS+/wNeJbGJpRwRqPYBHlBb iczg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737497778; x=1738102578; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=mzmBoQbCE7e2VTnHw9DXW5AVmYWzyx5m18uEgeNFLzY=; b=Ss3RKRFgvNLAN+/oeFHpLPzrCc5jCfXSnKq67G2ty+u55uQo7Lb6MtMYVd0chWc0kS 4TLq0gW0OLyNpfGPLuSyjh/RBwSJYCdku4x20pRuKgH0V0t9HLWvjhBS4dt6+3O+HVvq B2cNi3xWOcwD5RsLHbM8BrqQ9Vg03RAYtc/PQeqJSOGCgVLVt3bBaR3Woqx3U7unQWlm GiZsfl70vZ9NznidE0ypgQxz4lCgwvYKoZ8/08UJ4ctJxwaKR3QOM13A7whaPoPmQB3U csE0POUFqBhQkjlulRbLxXfsSRUtyQlW4eoTEzRYjW50o7l2IbbageSsQl5eAcoqjMWv GELw== X-Forwarded-Encrypted: i=1; AJvYcCWJqwiKnDyjmaQRsIE6tUEv8kbXrUStofxSFCSGmeRGVoNK2AQ3nUAv+WOnSDAx1iYLxyCH1AQ/zGn23ns=@vger.kernel.org X-Gm-Message-State: AOJu0YxWbO0XMWlY6pZQi6Qia4F8zMKYXzxO2yydA1E8Ga7P/dCoJ6RB ATSln3v4SFaJ0oxyaqzOcBhwlwwRmBmB7hgXBL/xXrkyUGV0KQwwxcMerRjwgg== X-Gm-Gg: ASbGnctVbqTySr8gMYtR/Y4FfUBiTUocrxgYOcRf9/4e70SDECCeiHJzsIyu6q/0UYf 84e3kv9qS9PoUwq9Fur3/zf8jXIjuFMKhMUiXxmgjDOEZErXVtkpBX0+3p8rUrJ1MjOjjnBPOHG eJFbxqRE5Rq2AfH+A/efUZ3H2xmmMD6z/3sy/TA/wzYRM7pYkisM9xx5yqqm5STnt510pQN6O6Q i/OgbFhD/S23g4EjV96iU/Ut9YcHGj/2iWlU/mJxrN00VCcMAjhx9VES3I= X-Google-Smtp-Source: AGHT+IEqPNSzuNcGCyt683L4AIyW1+5qRuiQlVD9dVHlSQohAlvQuzg66TxKiMMiLwQ9SGS4xTcpSQ== X-Received: by 2002:a05:600c:4f0d:b0:435:921b:3535 with SMTP id 5b1f17b1804b1-438b2da754fmr74955e9.3.1737497777602; Tue, 21 Jan 2025 14:16:17 -0800 (PST) Received: from localhost ([2a00:79e0:9d:4:93eb:28f6:6b52:a48e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438b318aae1sm274245e9.1.2025.01.21.14.16.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jan 2025 14:16:17 -0800 (PST) From: Jann Horn Date: Tue, 21 Jan 2025 23:16:09 +0100 Subject: [PATCH RFC] x86: Add CONFIG_KERNEL_UNCOMPRESSED support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250121-kernel-compress-fast-v1-1-fa693b6167d4@google.com> X-B4-Tracking: v=1; b=H4sIAKgckGcC/x2MMQqAMAwAvyKZDbSVgrgKPsBVHKRGDWqVRkSQ/ t3ieBx3LwgFJoEqeyHQzcKHT6DzDNwy+JmQx8RglLFKG40rBU8bumM/A4ngNMiFhVWObKm0MyW kNKmJn3/bQdvU0Mf4AVU57VBrAAAA X-Change-ID: 20250121-kernel-compress-fast-350ce5801c28 To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Masahiro Yamada , Nathan Chancellor , Nicolas Schier Cc: Ard Biesheuvel , linux-efi@vger.kernel.org, Andrew Morton , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Jann Horn X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1737497773; l=5794; i=jannh@google.com; s=20240730; h=from:subject:message-id; bh=kuS9+usQUnoAJ7h3I+IY6V/rxzIi2s09XeV3LdJfMj4=; b=vFk+qsZp8iDibxHFL/PkhT2fOb37LGRH19Iyz9tA2NghkFd8EcF3616hnZCM3I52KXUPZrI3s Jo5gw+7fi1PBsepq8YqzxMUxrU4ZYo7v/qp55xb5Z4kegUMb2Sy/6uF X-Developer-Key: i=jannh@google.com; a=ed25519; pk=AljNtGOzXeF6khBXDJVVvwSEkVDGnnZZYqfWhP1V+C8= Support storing the kernel uncompressed for developers who want to quickly iterate with one-off kernel builds. Store it in the usual format with a 4-byte length suffix and keep this new codepath as close as possible to the normal path where decompression happens. The other compression methods offered by the kernel take some time; even LZ4 (which the kernel uses at compression level 9) takes ~2.8 seconds to compress a 110M large vmlinux.bin on my machine. An alternate approach to this would be to offer customization of the LZ4 compression level through a kconfig variable; and yet another approach would be to abuse the existing gzip decompression logic by storing the kernel as "non-compressed" DEFLATE blocks, so that the decompression code will essentially end up just doing a bunch of memcpy() calls. Signed-off-by: Jann Horn --- arch/x86/Kconfig | 1 + arch/x86/boot/compressed/Makefile | 3 +++ arch/x86/boot/compressed/misc.c | 4 ++++ arch/x86/boot/header.S | 2 ++ drivers/firmware/efi/libstub/zboot.c | 2 ++ lib/decompress_dummy.c | 15 +++++++++++++++ scripts/Makefile.lib | 3 +++ 7 files changed, 30 insertions(+) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index ef6cfea9df7333c52e331f487a0b29f037a6bf14..6d468d47861ae0b6ec6b7649af6= ab4dd123eb5c8 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -250,6 +250,7 @@ config X86 select HAVE_KERNEL_LZO select HAVE_KERNEL_XZ select HAVE_KERNEL_ZSTD + select HAVE_KERNEL_UNCOMPRESSED 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/M= akefile index f2051644de9432e3466ac0ef1c4d3abc378e37d3..06079e02d9e01704cc0da06c119= 5854c8d0602ac 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -137,6 +137,8 @@ $(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE $(call if_changed,lz4_with_size) $(obj)/vmlinux.bin.zst: $(vmlinux.bin.all-y) FORCE $(call if_changed,zstd22_with_size) +$(obj)/vmlinux.bin.store: $(vmlinux.bin.all-y) FORCE + $(call if_changed,store_with_size) =20 suffix-$(CONFIG_KERNEL_GZIP) :=3D gz suffix-$(CONFIG_KERNEL_BZIP2) :=3D bz2 @@ -145,6 +147,7 @@ suffix-$(CONFIG_KERNEL_XZ) :=3D xz suffix-$(CONFIG_KERNEL_LZO) :=3D lzo suffix-$(CONFIG_KERNEL_LZ4) :=3D lz4 suffix-$(CONFIG_KERNEL_ZSTD) :=3D zst +suffix-$(CONFIG_KERNEL_UNCOMPRESSED) :=3D store =20 quiet_cmd_mkpiggy =3D MKPIGGY $@ cmd_mkpiggy =3D $(obj)/mkpiggy $< > $@ diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/mis= c.c index 0d37420cad0259554f8160dea0c502cb7e2fc6cd..5d514a147d5d1ae252419e4c7cd= c09e9c29f110f 100644 --- a/arch/x86/boot/compressed/misc.c +++ b/arch/x86/boot/compressed/misc.c @@ -88,6 +88,10 @@ static int cols __section(".data"); #ifdef CONFIG_KERNEL_ZSTD #include "../../../../lib/decompress_unzstd.c" #endif + +#ifdef CONFIG_KERNEL_UNCOMPRESSED +#include "../../../../lib/decompress_dummy.c" +#endif /* * NOTE: When adding a new decompressor, please update the analysis in * ../header.S. diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S index b5c79f43359bcde2c4c3c5ed796e8780f7979774..8397470231cf571a33ac75f7ca7= 020608e170eef 100644 --- a/arch/x86/boot/header.S +++ b/arch/x86/boot/header.S @@ -483,6 +483,8 @@ pref_address: .quad LOAD_PHYSICAL_ADDR # preferred loa= d addr # larger margin. # # extra_bytes =3D (uncompressed_size >> 8) + 131072 +# +# Uncompressed data does not grow. =20 #define ZO_z_extra_bytes ((ZO_z_output_len >> 8) + 131072) #if ZO_z_output_len > ZO_z_input_len diff --git a/drivers/firmware/efi/libstub/zboot.c b/drivers/firmware/efi/li= bstub/zboot.c index af23b3c502282f9bd644c38af445875c225cdf42..1c43a6ae5e665aa3bff3bd467c8= a2f5525b1a6e9 100644 --- a/drivers/firmware/efi/libstub/zboot.c +++ b/drivers/firmware/efi/libstub/zboot.c @@ -27,6 +27,8 @@ static unsigned long free_mem_ptr, free_mem_end_ptr; #include "../../../../lib/decompress_unxz.c" #elif defined(CONFIG_KERNEL_ZSTD) #include "../../../../lib/decompress_unzstd.c" +#elif defined(CONFIG_KERNEL_UNCOMPRESSED) +#include "../../../../lib/decompress_dummy.c" #endif =20 extern char efi_zboot_header[]; diff --git a/lib/decompress_dummy.c b/lib/decompress_dummy.c new file mode 100644 index 0000000000000000000000000000000000000000..49435e199a07f6ed376ff93adea= e8ee08a9dd3d7 --- /dev/null +++ b/lib/decompress_dummy.c @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 +STATIC int INIT __decompress(unsigned char *buf, long len, + long (*fill)(void*, unsigned long), + long (*flush)(void*, unsigned long), + unsigned char *out_buf, long out_len, + long *pos, + void (*error)(char *x)) +{ + if (out_len < len-4) { + error("output buffer too small"); + return -1; + } + memcpy(out_buf, buf, len-4); + return 0; +} diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 7395200538da89a2f6e6d21f8959f3f60d291d79..bb8116ba8ba189d5246fcb0e71c= 7be6e05ce5148 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -525,6 +525,9 @@ quiet_cmd_zstd22 =3D ZSTD22 $@ quiet_cmd_zstd22_with_size =3D ZSTD22 $@ cmd_zstd22_with_size =3D { cat $(real-prereqs) | $(ZSTD) -22 --ultra= ; $(size_append); } > $@ =20 +quiet_cmd_store_with_size =3D STORE $@ + cmd_store_with_size =3D { cat $(real-prereqs); $(size_append); } > $@ + # ASM offsets # ------------------------------------------------------------------------= --- =20 --- base-commit: 95ec54a420b8f445e04a7ca0ea8deb72c51fe1d3 change-id: 20250121-kernel-compress-fast-350ce5801c28 --=20 Jann Horn