From patchwork Mon Mar 6 03:03:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 13160394 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EF462C678DB for ; Mon, 6 Mar 2023 03:05:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=WAGM0GfKByxmdEnc7kL1Hqx4tAq91UVKjkNZde3C/TY=; b=tXxDb1JpbiroDq HTGpf62ESeljobtI6x5i1KuhXUE4kmPuBLWbTjbd0ZooVA1Rwfavg2fyxVDBws6MU0QwsRLrfjHtP SrSCRPsupXHeBCEIcwmYIlmrMZIMsFiqC4TSD8yXwilnZFik0gM9nuBcwTq8yIp0hMzCsXgQ41ZUN aNwWmozh38ecd9/jplcdTWkmeRZZTwpt0w3KMo/ep3XADboCPd54GqYQuQk9vPvMxm+XyIch8gT+Y MtMHLf0GMzfewQqb7E41zGqk5AakdkCT/30lYEAQB22sEpvOLltmQSg1CqPAmxV2aBzcaxrc4vvBF bxw+ozd42ZnK7NCU7cZw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZ18g-00B2ac-2c; Mon, 06 Mar 2023 03:03:53 +0000 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZ18P-00B2Po-B7; Mon, 06 Mar 2023 03:03:35 +0000 Received: by mail-pl1-x62b.google.com with SMTP id h8so8740325plf.10; Sun, 05 Mar 2023 19:03:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678071811; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CmnZaXWwPw8Q5BGOyo7ZMPXWTzHCgCcEq5Rf19W6jjY=; b=b4ZttBFxSHV0UTeRy+Johv5uDFJa3j29vQ26lYcRbcoDE7CbND18CjCNP3MqhykBON rj2n7mnouEu7xsiSVV+YH7GdM+6a2DXFLKSILTomCAbOoX47T4VCurwDIaRolWT7uCg7 pVUyiWCz01a807z6k5LwUh2Y9dnXSZg9N797Z90QK3BfIVweyxvrubBI1ThOM5nYOf1q iK5Gs8Jnw8dNxwL/obeDe8nnQD4xnkO40Vg/gv7tLhSmjyTbXUy4yaKL+erCzyo/AXT4 owdhW/cD/0GQ8H65DF4ZuKRj07wfQNIEIndWbrL3UolVgrkyg7gEwwOO4y91pXLgnEgN J+4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678071811; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CmnZaXWwPw8Q5BGOyo7ZMPXWTzHCgCcEq5Rf19W6jjY=; b=HAgXrQEMU3T2TvEOA9DEgu+M80hyqaVipLkYze76jnOhO1AX8hwTaOqla4Y/r+Vymx b+QG8xw3FLIpW1gHaeHDLGWB7i9GoeysZb573AgK7ZwY+QVij9wdrsGmJbVaW08JjAd7 xmj3nERb9wtoYTBYlDnS+PdLB21S0/DwdYmRkgtSe1Mn2mHg9bYeSY9liwPQiqDg/EPu iMNuZza4+8TXMaFRp82UWhlnflK5ci3WBFcVcM+8kpaX1FfzRWLb7UfzpEPGYxGxklsz SilXMFQfecOfSS5+QGMcMMlQj7agcrHhkvQpgK/IpRHsdMY0bF9spF6ZgjyGcIRu/A7u Of6Q== X-Gm-Message-State: AO0yUKUVwPv2l27pcHG5All2zpKNG6sho+Vb9QOGn8f7v3OE/RSGxA51 4L0vTvPRlVVejkodnM5ES8cjumrhYw== X-Google-Smtp-Source: AK7set+bL2b6hTuCcB0SX+LFxFf2ysaT8dLQzxUAkbXYIfAN7kezIJ6869ELdfcU/Vx/Hkl1HCI8Rw== X-Received: by 2002:a17:902:c20d:b0:19e:839f:ef5a with SMTP id 13-20020a170902c20d00b0019e839fef5amr9306700pll.60.1678071811685; Sun, 05 Mar 2023 19:03:31 -0800 (PST) Received: from piliu.users.ipa.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id jy16-20020a17090342d000b0019719f752c5sm5410439plb.59.2023.03.05.19.03.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Mar 2023 19:03:31 -0800 (PST) From: Pingfan Liu To: linux-arm-kernel@lists.infradead.org Cc: Pingfan Liu , Catalin Marinas , Will Deacon , Mimi Zohar , Andrew Morton , "Naveen N. Rao" , Ard Biesheuvel , Arnd Bergmann , kexec@lists.infradead.org Subject: [PATCH 1/6] arm64: kexec: Rename kexec_image.c to kexec_raw_image.c Date: Mon, 6 Mar 2023 11:03:00 +0800 Message-Id: <20230306030305.15595-2-kernelfans@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230306030305.15595-1-kernelfans@gmail.com> References: <20230306030305.15595-1-kernelfans@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230305_190333_798281_47132CA8 X-CRM114-Status: GOOD ( 12.52 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org With the emergence of zboot image format, kexec file load needs to support multiple formats. In order to better distinguish the file's purpose, renaming kexec_image.c to kexec_raw_image.c. Signed-off-by: Pingfan Liu Cc: Catalin Marinas Cc: Will Deacon Cc: Mimi Zohar Cc: Andrew Morton Cc: "Naveen N. Rao" Cc: Ard Biesheuvel Cc: Arnd Bergmann Cc: kexec@lists.infradead.org To: linux-arm-kernel@lists.infradead.org --- arch/arm64/include/asm/kexec.h | 2 +- arch/arm64/kernel/Makefile | 2 +- arch/arm64/kernel/{kexec_image.c => kexec_raw_image.c} | 2 +- arch/arm64/kernel/machine_kexec_file.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename arch/arm64/kernel/{kexec_image.c => kexec_raw_image.c} (98%) diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 559bfae26715..3f3d5a6830b7 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -125,7 +125,7 @@ struct kimage_arch { }; #ifdef CONFIG_KEXEC_FILE -extern const struct kexec_file_ops kexec_image_ops; +extern const struct kexec_file_ops kexec_raw_ops; int arch_kimage_file_post_load_cleanup(struct kimage *image); #define arch_kimage_file_post_load_cleanup arch_kimage_file_post_load_cleanup diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index ceba6792f5b3..99b52710606a 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -63,7 +63,7 @@ obj-$(CONFIG_HIBERNATION) += hibernate.o hibernate-asm.o obj-$(CONFIG_ELF_CORE) += elfcore.o obj-$(CONFIG_KEXEC_CORE) += machine_kexec.o relocate_kernel.o \ cpu-reset.o -obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o kexec_image.o +obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o kexec_raw_image.o obj-$(CONFIG_ARM64_RELOC_TEST) += arm64-reloc-test.o arm64-reloc-test-y := reloc_test_core.o reloc_test_syms.o obj-$(CONFIG_CRASH_DUMP) += crash_dump.o diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_raw_image.c similarity index 98% rename from arch/arm64/kernel/kexec_image.c rename to arch/arm64/kernel/kexec_raw_image.c index 5ed6a585f21f..2b3412b3ad2c 100644 --- a/arch/arm64/kernel/kexec_image.c +++ b/arch/arm64/kernel/kexec_raw_image.c @@ -129,7 +129,7 @@ static void *image_load(struct kimage *image, return NULL; } -const struct kexec_file_ops kexec_image_ops = { +const struct kexec_file_ops kexec_raw_ops = { .probe = image_probe, .load = image_load, #ifdef CONFIG_KEXEC_IMAGE_VERIFY_SIG diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index a11a6e14ba89..0738020507d1 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -23,7 +23,7 @@ #include const struct kexec_file_ops * const kexec_file_loaders[] = { - &kexec_image_ops, + &kexec_raw_ops, NULL }; From patchwork Mon Mar 6 03:03:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 13160395 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 80745C678DB for ; Mon, 6 Mar 2023 03:05:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=W6huRsfNzUILe7JrIqx7o05tAmRKJCNXaSRzRAtNKYY=; b=GWXlCaalNpbN48 bE4zUMx4wDq3rtIqf2XIhSLd3Q8+6RfceOrjMch0sHXgUxq+SSv7UyjJRpr+XToJ5f/zErWuc8ReG yFsilUbA0ELzWeY50/aUEDnDY+hH7s6sBAK+UZC3m8jLAbf3lNoOjdHqf7ln1JQyc5vf8NjpyEgFF 1u1dN4693RZgSWuurNWBDz+LZhvysK/71i/mPTN1Cf1Z3+bU/nP4xHBHX9N3dCGZ1mfLhosYMDDLk Jc3f74WyULbUiZRV5Mk6kcKWwKuYoLnbCtZA35SQqLV2V2eJJaJ7/aUkOt2OZRKvhwbwggKPIbMxr 7cFjAZ2PCeI46vmw+1Lw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZ18v-00B2i7-Mt; Mon, 06 Mar 2023 03:04:05 +0000 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZ18S-00B2RF-Hc; Mon, 06 Mar 2023 03:03:37 +0000 Received: by mail-pl1-x636.google.com with SMTP id p20so8724613plw.13; Sun, 05 Mar 2023 19:03:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678071815; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Wneh97F1nMdoO/GWBYTh+FCpx49GDmImprYvE+tMGQE=; b=mvYZTLnMDzqZPw0EObR6IP1bqYOQ6tPuLXfY7xHMKAH7j8jrQKrS1JHwphC8/GTqe8 4xxtq5FjexX8PsrMWL7aNFe4yld29ji2KCki8LpGN4790OXnMpAYGVp4kBbZ8dnrGrMM 1iaerc/FEIt5qb6xFS4ynYEU4aqQLjswq24G/gyhza1Ko09zCMolEnZT0FghHnmhV3jd YNShaiXqZWYoYDQ28qel8wZxtFO2dTktPcZUK9juVERYV2Qci7OCO+tFoKztyLx2HIQI KwOSOxHWUoWK0jJtLXLy49s/JkMdmbPQXVvuPpP7ByYWalcW31aBRc7j5Erzq35nNXj2 STNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678071815; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Wneh97F1nMdoO/GWBYTh+FCpx49GDmImprYvE+tMGQE=; b=SR3vFN6xzIN190M86zrx18tj/CHbfJNT0LMHiQzSBpSMIoPA2fhkVUCTJ5wtCurBUs k9veep4Wk+dFzUhZNw6PwU2TjlrQR7R/PaR86hLjRJxtj9i2YR7XVT/Ar8mOq5nSJHD0 tkhf5mCz+ahcOMrNtnQY28978ypRbtCRMiIREaszycb0NQil7J/aSkX7Yb2M/lMcFd0W bTzSZl7pIiWAHOeZHQLvO1SQ271sW0cpVZ5FgZQf2X26RAKLSs3t13V+eQjvPHByRNXJ Jz+fx/M7ZxgMEMjSkCOMi+jmM3puwur9eGpgNhF+1CRfn+Ah72B2qH+Owxb4FtiVNGq7 pyXA== X-Gm-Message-State: AO0yUKUTTldfcsiIjcrFRFTjCYE7EORblR2sWKTacl2mc9DNgGIWSRw6 sgRaDVqYnVPDGsHHWFlrnNiyaRPDzQ== X-Google-Smtp-Source: AK7set9ZT3V2MdQmOCnCAefBY22UCEzOMyO2IU0j9xpnm0GrmRPbiXTc8e7zd/VuGWUzN5tbfyDKKg== X-Received: by 2002:a17:902:bd93:b0:19c:be03:d1a3 with SMTP id q19-20020a170902bd9300b0019cbe03d1a3mr8853729pls.40.1678071814870; Sun, 05 Mar 2023 19:03:34 -0800 (PST) Received: from piliu.users.ipa.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id jy16-20020a17090342d000b0019719f752c5sm5410439plb.59.2023.03.05.19.03.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Mar 2023 19:03:34 -0800 (PST) From: Pingfan Liu To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Pingfan Liu , Ard Biesheuvel , kexec@lists.infradead.org Subject: [PATCH 2/6] lib/decompress: Introduce decompress_method_by_name() Date: Mon, 6 Mar 2023 11:03:01 +0800 Message-Id: <20230306030305.15595-3-kernelfans@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230306030305.15595-1-kernelfans@gmail.com> References: <20230306030305.15595-1-kernelfans@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230305_190336_600064_C34AC568 X-CRM114-Status: GOOD ( 10.94 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The zboot image packs the compressed file in the data section. Instead of starting with the zip file header. It records the compressing method name 'gzip','lzma' etc in the zboot image header. Hence it is easier to decide the decompressing method by the name than by the magic number. Signed-off-by: Pingfan Liu Cc: Ard Biesheuvel Cc: kexec@lists.infradead.org To: linux-kernel@vger.kernel.org --- include/linux/decompress/generic.h | 2 ++ lib/decompress.c | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/linux/decompress/generic.h b/include/linux/decompress/generic.h index 207d80138db5..077f15ce77b9 100644 --- a/include/linux/decompress/generic.h +++ b/include/linux/decompress/generic.h @@ -37,4 +37,6 @@ typedef int (*decompress_fn) (unsigned char *inbuf, long len, decompress_fn decompress_method(const unsigned char *inbuf, long len, const char **name); +decompress_fn decompress_method_by_name(const unsigned char *name); + #endif diff --git a/lib/decompress.c b/lib/decompress.c index ab3fc90ffc64..8dd6f87e885f 100644 --- a/lib/decompress.c +++ b/lib/decompress.c @@ -2,7 +2,7 @@ /* * decompress.c * - * Detect the decompression method based on magic number + * Detect the decompression method based on magic number or name */ #include @@ -82,3 +82,15 @@ decompress_fn __init decompress_method(const unsigned char *inbuf, long len, *name = cf->name; return cf->decompressor; } + +decompress_fn __init decompress_method_by_name(const unsigned char *name) +{ + const struct compress_format *cf; + + for (cf = compressed_formats; cf->name; cf++) { + if (!strcmp(name, cf->name)) + break; + + } + return cf->decompressor; +} From patchwork Mon Mar 6 03:03:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 13160396 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 316F5C61DA4 for ; Mon, 6 Mar 2023 03:05:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=sxJu9k87e9QQM5HPZ2As31/Zvp2Knkrkbfbf1QyTlY4=; b=xc6ZQHJY8FmgMH syFVTgLts8lKGIjA+MROnsQhE6yXFolOyEr9SOZbrt/mDoyPqeBYB+tcMtQvBJpSnXO4b2xeYKIba Kn9jn9oTOsGFU9MSFh2pBknIJ0fRCtsGOMnSBYdMk7zbR4x8mSlPDSc2+Ncq3h6jS/j8CfYwux9c6 Wapie0Di2UPWEE9Qw1YYiihDcCXC+MLiIU8S2W3gTK+K7E4aMte7qFuuj6Bj4pTzA2cdHCld/L10s g/bNMmMWhpTaG1+sVKG8s96NgwYFFJhasNFcR8iPM9IRWrMLmSzBOIvNOV0ZZrmB+HKhOZq9bgo9P PfDVhkCk3V3P3FUZhm5g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZ19B-00B2z7-6v; Mon, 06 Mar 2023 03:04:21 +0000 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZ18W-00B2Sz-Ut; Mon, 06 Mar 2023 03:03:42 +0000 Received: by mail-pj1-x1031.google.com with SMTP id qa18-20020a17090b4fd200b0023750b675f5so11788140pjb.3; Sun, 05 Mar 2023 19:03:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678071819; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=B4a3X2UJpGVkEkCKZLpiC6CtZYdkpIrB0sY2y8ZRSlA=; b=OPG09K+PyjQAJLkndvQbGSHh8ZsyrlhmGiMtf07LeNaFj9x6p7KSLTNYv+9Ooqsi4h ldBdZ7+yd4X2es3XcAG9Mna/yr+K2lqcKbXIZvAK4Rnv70RoJikbkIUxeI4orZZSPw7r hmwdG5CY7Qu3xxuHsQjsWxnmeGKgwrgHCpkXVAdIF1uAG6WwS6NBHkUM7l1yOrPhHNsu YXUQ3GjmheCJ8PA+LTPOqlMjoMZ0qWht6iSLsPqKJg5JSPOZij47TfFa0TwtH9lBZhdW Ppv8m1TETpG5bvn8Mju3NX36eNpg/mE1Cull9ER3VT9630GoqoMj4Ph7CQ1/3b5vpFZl OJWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678071819; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=B4a3X2UJpGVkEkCKZLpiC6CtZYdkpIrB0sY2y8ZRSlA=; b=uOYy75O61aKcSfBg6bhQiNre8Ms4ks6aXTul4XvaC6h5+aRpWuCyMM8BaAJSG6D7PS afdZi993CqCA2sNYVcCIn0Al8SsYHJrahaiU0EFES0Fzbse6/rXcTJkpio2EnIcRq+0Z LUG2J2d5RNVHvjLeg4QnSvPxYckHUjGsH112kDpokemo0eGyIyQrcprMj0viYh6lnAjf rM2ozht1X6eKXSdyr3m1eFxMSTcbgTv4w8FcDvD9b2S9vEbSlfvO+YDFMtYN9cnZRny8 LDmMM+A8O44/qzu8NCLEIy/5HWBLzUOEWjGxS3Paw+BWANUNVGemgRWmbCfiy9K3TTpL McmA== X-Gm-Message-State: AO0yUKUYRI1WQdHSCik39dZHYEfMjV7k65ahSQ6enEPHZ1hhOTmGYPgG 04D8YH4yN6jrBrQPCpz6QjYZJChj6A== X-Google-Smtp-Source: AK7set88DNyYROwb3m9fSv9kZYyr9WinWKZoWYmcxYffbwht/af+J2U9qH/KesKw6say2sKAElKZ5w== X-Received: by 2002:a17:903:258b:b0:19a:973b:b615 with SMTP id jb11-20020a170903258b00b0019a973bb615mr8486498plb.36.1678071819212; Sun, 05 Mar 2023 19:03:39 -0800 (PST) Received: from piliu.users.ipa.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id jy16-20020a17090342d000b0019719f752c5sm5410439plb.59.2023.03.05.19.03.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Mar 2023 19:03:38 -0800 (PST) From: Pingfan Liu To: linux-arm-kernel@lists.infradead.org Cc: Pingfan Liu , Will Deacon , Nick Terrell , Herbert Xu , Eric Biggers , "Jason A. Donenfeld" , Yury Norov , Andrew Morton , Ard Biesheuvel , kexec@lists.infradead.org Subject: [PATCH 3/6] arm64: Kconfig: Pick decompressing method for kexec file load Date: Mon, 6 Mar 2023 11:03:02 +0800 Message-Id: <20230306030305.15595-4-kernelfans@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230306030305.15595-1-kernelfans@gmail.com> References: <20230306030305.15595-1-kernelfans@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230305_190341_066852_94C17287 X-CRM114-Status: GOOD ( 12.38 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org After introducing the zboot image, kexec file load should be able to decompress the Image.gz. (Do in the later patch) Unlike efi_zboot_entry() which knows the decompression method at the built time, kexec may loads compressed kernels with variant compression methods, hence it is helpful to include as many decompression method as possible. Here provide an opportunity to let users select at their will. Besides this, introduce an extra config option 'HAVE_KEXEC_DECOMPRESS' to distinguish the reference to decompression routine between kexec and boot. (used in later patch to keep the routine out of .init.text section) Signed-off-by: Pingfan Liu Cc: Will Deacon Cc: Nick Terrell Cc: Herbert Xu Cc: Eric Biggers Cc: "Jason A. Donenfeld" Cc: Yury Norov Cc: Andrew Morton Cc: Ard Biesheuvel Cc: kexec@lists.infradead.org To: linux-arm-kernel@lists.infradead.org --- arch/arm64/Kconfig | 59 ++++++++++++++++++++++++++++++++++++++++++++++ lib/Kconfig | 3 +++ 2 files changed, 62 insertions(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index c5ccca26a408..58a65bdaeffa 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -1419,6 +1419,65 @@ config KEXEC_FILE for kernel and initramfs as opposed to list of segments as accepted by previous system call. +menu "Decompress method for kexec file load" + +config KEXEC_DECOMPRESS_GZIP + bool "gzip" + depends on KEXEC_FILE + select DECOMPRESS_GZIP + select HAVE_KEXEC_DECOMPRESS + help + Enable to load the zboot image compressed by gzip + +config KEXEC_DECOMPRESS_BZIP2 + bool "bzip2" + depends on KEXEC_FILE + select DECOMPRESS_BZIP2 + select HAVE_KEXEC_DECOMPRESS + help + Enable to load the zboot image compressed by bzip2 + +config KEXEC_DECOMPRESS_LZMA + bool "lzma" + depends on KEXEC_FILE + select DECOMPRESS_LZMA + select HAVE_KEXEC_DECOMPRESS + help + Enable to load the zboot image compressed by lzma + +config KEXEC_DECOMPRESS_XZ + bool "xz" + depends on KEXEC_FILE + select DECOMPRESS_XZ + select HAVE_KEXEC_DECOMPRESS + help + Enable to load the zboot image compressed by xz + +config KEXEC_DECOMPRESS_LZO + bool "lzo" + depends on KEXEC_FILE + select DECOMPRESS_LZO + select HAVE_KEXEC_DECOMPRESS + help + Enable to load the zboot image compressed by lzo + +config KEXEC_DECOMPRESS_LZ4 + bool "lz4" + depends on KEXEC_FILE + select DECOMPRESS_LZ4 + select HAVE_KEXEC_DECOMPRESS + help + Enable to load the zboot image compressed by lz4 + +config KEXEC_DECOMPRESS_ZSTD + bool "zstd" + depends on KEXEC_FILE + select DECOMPRESS_ZSTD + select HAVE_KEXEC_DECOMPRESS + help + Enable to load the zboot image compressed by zstd +endmenu + config KEXEC_SIG bool "Verify kernel signature during kexec_file_load() syscall" depends on KEXEC_FILE diff --git a/lib/Kconfig b/lib/Kconfig index ce2abffb9ed8..18ab33511ee1 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -304,6 +304,9 @@ config RANDOM32_SELFTEST # # compression support is select'ed if needed # +config HAVE_KEXEC_DECOMPRESS + bool + config 842_COMPRESS select CRC32 tristate From patchwork Mon Mar 6 03:03:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 13160397 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 16CB6C678DB for ; Mon, 6 Mar 2023 03:06:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=NEAo9qDIz32UYStkMZYB8JZZndkzp61Su2Auw4t1mow=; b=0l64c01xeBQMQQ qap1xpZ+XQNkIJ0xZTvlLcLtGg0wAMMkAurF4sqe/HFs5HdAOFGWJQSJdg426tuaaHlu5L5wZs831 dSiyMW+bz7egPSaL8K0aE0BOuFqFRQx4koWN2JUMKKEw3KoOd2gLEiWJhlqFFHnCsJt/MorC85WXT zZiTKQL7yfeUAWoBDI7JmYsy8WbBs5MShHqYR1bh66DZhTd0P6NvPjwOyst0iWKPtNeCHcFIiaFNP wn4+cfdYIZLpuj6sjQrDOspkcq9Ci94e7qOOBJ6vG0Hj+/6M/xVs8wF89OvP6ReLukSfmBEMBOGpL dAvo2EAUwNwHtzLAcYZw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZ19Z-00B3GW-10; Mon, 06 Mar 2023 03:04:45 +0000 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZ18a-00B2VH-6C; Mon, 06 Mar 2023 03:03:46 +0000 Received: by mail-pj1-x1033.google.com with SMTP id 6-20020a17090a190600b00237c5b6ecd7so11775936pjg.4; Sun, 05 Mar 2023 19:03:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678071822; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KOC/FNu2kgiTh2xy+eQd0EULhBRFBbwS09u1PSCaics=; b=NaKYVckZLYfiEuAigzcP2ETDA+KCnwCeEG6JErjf5qgu7EvyJy413kzlsIjrrmFzwB TIMrVi28isX3LNq1vvN8kZtZv772oFypAlZ7V2rmarNnARWhk/O32RHBNeAY38G4pjLf mfogJfCiYVCDZ6szaAOYjF/PBNoCcpkYyCRiPwbqyGxeNhjak22jX5BYnpyFrg9F966K eVFGlYDCvp/OlbnBgWUGbnn9L+jhQpxcHWsL0Wew/SDtoNrqBHZMlGn906K6whpqUEGd 8annz1k4T1diofzyCnJvehBAZY1p1l+QOSiPrVJq6BtFBmT0AtmiHJR3WssGA6z4qWeZ 2hgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678071822; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KOC/FNu2kgiTh2xy+eQd0EULhBRFBbwS09u1PSCaics=; b=HugLNUc9pGDgmnfBK1lR3RS1RlJbCPdsUwbmR/SnWrDp7H5Gy8NifAvTebmTc8kWAm pTxTKDlNN6qPbfo9CFiILJghqWP8V5VN/avsDMuxS7PWu39JEqJRsxaq1+SQqUBDL3xQ M62WWQwIozmZqyiQlvNFaMqHhx/bKeBJmz0bnQAJOg60EAiqMNHMznnyv4HPOE8OcP40 7B34ndOAe0rKV2yBVdYi8ytse6YJZZR0xPuLkIiCN1ryLrT8ckPSFstLnlQq3p9Sos17 I/wU/5xPHkRoJ90fyqV+XVZN+OxMZS3UafTaru0P5Dcxk3O2YvCKkD8D584hSu2u5JlQ /HkQ== X-Gm-Message-State: AO0yUKW38mP68AVVN/KahP0mMj35vkZ7drZMu7hn9jSaWNLVJg+SCBd3 tkhSJ9hz3uYmXt/bIDQA2Z9IoEbGxQ== X-Google-Smtp-Source: AK7set9pFHfjgHVn9nJVc+fD+gdveI9XYNbDTQrxdQyJRmLKk2YuM3aJ0xZd+cpaGIwqbkF6D36UKQ== X-Received: by 2002:a17:902:c40a:b0:19a:5958:15e7 with SMTP id k10-20020a170902c40a00b0019a595815e7mr10254558plk.15.1678071822090; Sun, 05 Mar 2023 19:03:42 -0800 (PST) Received: from piliu.users.ipa.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id jy16-20020a17090342d000b0019719f752c5sm5410439plb.59.2023.03.05.19.03.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Mar 2023 19:03:41 -0800 (PST) From: Pingfan Liu To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Pingfan Liu , Ard Biesheuvel , kexec@lists.infradead.org Subject: [PATCH 4/6] lib/decompress: Keep decompress routines based on selection Date: Mon, 6 Mar 2023 11:03:03 +0800 Message-Id: <20230306030305.15595-5-kernelfans@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230306030305.15595-1-kernelfans@gmail.com> References: <20230306030305.15595-1-kernelfans@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230305_190344_250505_A7935CCC X-CRM114-Status: GOOD ( 10.54 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org At present, many decompressing routines in lib/decompress*.c are in __section(".init.text"). But they are required to decompress the kernel image when kexec file load compressed kernel. To solve this issue, define 'INIT' conditional based on the macro CONFIG_HAVE_KEXEC_DECOMPRESS. Also make lib/decompress.c adopt this way. Signed-off-by: Pingfan Liu Cc: Ard Biesheuvel Cc: kexec@lists.infradead.org To: linux-kernel@vger.kernel.org --- include/linux/decompress/mm.h | 9 ++++++++- lib/decompress.c | 5 +++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h index 9192986b1a73..33d8fd13a5c6 100644 --- a/include/linux/decompress/mm.h +++ b/include/linux/decompress/mm.h @@ -92,11 +92,18 @@ MALLOC_VISIBLE void free(void *where) #define large_malloc(a) vmalloc(a) #define large_free(a) vfree(a) -#define INIT __init #define STATIC #include +#ifndef CONFIG_HAVE_KEXEC_DECOMPRESS +#define INIT __init +#else +#define INIT +#undef __initconst +#define __initconst +#endif + #endif /* STATIC */ #endif /* DECOMPR_MM_H */ diff --git a/lib/decompress.c b/lib/decompress.c index 8dd6f87e885f..33f097fe4b51 100644 --- a/lib/decompress.c +++ b/lib/decompress.c @@ -6,6 +6,7 @@ */ #include +#include #include #include @@ -60,7 +61,7 @@ static const struct compress_format compressed_formats[] __initconst = { { {0, 0}, NULL, NULL } }; -decompress_fn __init decompress_method(const unsigned char *inbuf, long len, +decompress_fn INIT decompress_method(const unsigned char *inbuf, long len, const char **name) { const struct compress_format *cf; @@ -83,7 +84,7 @@ decompress_fn __init decompress_method(const unsigned char *inbuf, long len, return cf->decompressor; } -decompress_fn __init decompress_method_by_name(const unsigned char *name) +decompress_fn INIT decompress_method_by_name(const unsigned char *name) { const struct compress_format *cf; From patchwork Mon Mar 6 03:03:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 13160398 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6740FC678DB for ; Mon, 6 Mar 2023 03:06:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=y0wTZmRkVeYjnG2m/bhu0c7YSW4xO5k5pofAfRo2iQk=; b=kx6vIRjqCvP5uP R95kZ9nTzmMIeRIsGPCrKiUWtoeiYseESizw4X9x7GI0Mc0pM1wXV1npTYJRL6w6ud5FaLwjK7TBe QECDDM/CH6QfxkIp/8gd2YntVvUMDtETLqQn+4/IGfmadbhP3UpwKYZYjggYv/bK6AyvC6hyti+M0 CmG3KF3fhidT9uGNgIsmDRE2DBTfiVhEWFhLF0GDl9QCtlfhkqcv+tf56abQv2Vj/2U3e8vztkQ2A eFELVl5w5VE/DtidJ6e7YcAe/8zXcnBC20GQ3b9D+IL9nBYc0O6nIX7S8DYWOGWCxgBbjXR2gozIr xSADzQzT6Xbx7KdjVciA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZ1AB-00B3a2-KG; Mon, 06 Mar 2023 03:05:23 +0000 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZ18f-00B2aV-KY; Mon, 06 Mar 2023 03:03:51 +0000 Received: by mail-pj1-x1035.google.com with SMTP id m20-20020a17090ab79400b00239d8e182efso11771567pjr.5; Sun, 05 Mar 2023 19:03:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678071827; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5avoOc2LsVwG6FVeumV4bYgF8SZE6ZZN8iKqNWFSzks=; b=IxJYLpptdt+bORdBe4KXuFk2YwppFfWSKz51NfUP3p2FR5RsIbew/xtJAA+eAmorFe Zx+gik8oy6uNP5/YwV0vRdxOzwYTPUm/cEBa6yyvnt50hong8Bt7/iBtclCYGbnL6xHN 6qUVtQcPIfXhiwgYNcEDALIwayPef8vSg23mtY8Zj/sTos8++e7t2fGmRfObXplHTl9r vVAO3mpJMgSRxyBWjkR5U0HjsLaW4GTUJzV25BVBDNRjugQohiOuj5Rt8TNq8+ibc83G x+OqkF5dpKJQgV5NIqkSKkp/vXa0YSLP9u49flK7dV+ugAiKM6rC27VT3GZ1RsGRb6hf QQug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678071827; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5avoOc2LsVwG6FVeumV4bYgF8SZE6ZZN8iKqNWFSzks=; b=t89L6x24uSzW1uq6ETqpAx/Ah0RAjxFpK+v3fvkNoiYiBQmzv99vO8unEOXqNkA/gr BG97QfpJpiG8TYKv4jndJ2YL5DCwHPy3skxc52Y1JPgK6iZ5aYdY8XGWe1bzN3ZGTcT7 9uwblWCx+Qq4V3VSB/4Ncvg8EMj/yLq/dJTqGDY4tGqJQ7glGieSZoeLOzGR0WSOJAHv Zxi2awPDSdxIqoKzfoMX3/nxhHbMoryboFzblPFOUq4ztW0c5eZI6/tSHry/ho9touvI ikziKGpf11WrjXXmvxRDtErGEt7jFMZY7aXqp2xElZxzCTbGWgp43JTHgrBXaXJUARIm Iy5g== X-Gm-Message-State: AO0yUKXqFJoHfJ/24xJAL5vtaTDBGqDv9rdJGEnUkJ4FYjPDZCyT49i0 yFEN3H56tHm7uyTdHLhuV20T999u6Q== X-Google-Smtp-Source: AK7set9G19B259z8e2En7cYqTvVLBJRvkbJLo/yYJytfFSLPIUdMWYKshf31YUgtGNK582TmnZF7sg== X-Received: by 2002:a17:902:da90:b0:19a:a0d0:10f0 with SMTP id j16-20020a170902da9000b0019aa0d010f0mr11803770plx.23.1678071827511; Sun, 05 Mar 2023 19:03:47 -0800 (PST) Received: from piliu.users.ipa.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id jy16-20020a17090342d000b0019719f752c5sm5410439plb.59.2023.03.05.19.03.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Mar 2023 19:03:46 -0800 (PST) From: Pingfan Liu To: linux-arm-kernel@lists.infradead.org Cc: Pingfan Liu , Catalin Marinas , Will Deacon , Nick Terrell , Andrew Morton , Mimi Zohar , "Naveen N. Rao" , Ard Biesheuvel , Arnd Bergmann , Michal Suchanek , Baoquan He , kexec@lists.infradead.org Subject: [PATCH 5/6] arm64: kexec: Introduce zboot image loader Date: Mon, 6 Mar 2023 11:03:04 +0800 Message-Id: <20230306030305.15595-6-kernelfans@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230306030305.15595-1-kernelfans@gmail.com> References: <20230306030305.15595-1-kernelfans@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230305_190349_737751_3ED19F28 X-CRM114-Status: GOOD ( 28.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The EFI zboot kernel format can decompress and boot the vmlinux, but it relies on the EFI service, which is not available when kexec jumps to the new entry. To tackle this issue, parsing zboot image and decompressing the Image.gz part at the file loading time. But this way, in essential, the kexec boots up Image. As for decompression, it can be done either in the user space or the kernel. But due to the signature verification in kernel, it should be achieved in the kernel space. Besides this, kexec faces a situation a little different from efi_zboot_entry(), where the latter has knowledge of the system memory through EFI services, while kexec can do it through the kernel's mm. Signed-off-by: Pingfan Liu Cc: Catalin Marinas Cc: Will Deacon Cc: Nick Terrell Cc: Andrew Morton Cc: Mimi Zohar Cc: "Naveen N. Rao" Cc: Ard Biesheuvel Cc: Arnd Bergmann Cc: Michal Suchanek Cc: Baoquan He Cc: kexec@lists.infradead.org To: linux-arm-kernel@lists.infradead.org --- arch/arm64/include/asm/kexec.h | 2 + arch/arm64/kernel/Makefile | 2 +- arch/arm64/kernel/kexec_zboot_image.c | 186 +++++++++++++++++++++++++ arch/arm64/kernel/machine_kexec.c | 1 + arch/arm64/kernel/machine_kexec_file.c | 1 + include/linux/zboot.h | 26 ++++ 6 files changed, 217 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/kernel/kexec_zboot_image.c create mode 100644 include/linux/zboot.h diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 3f3d5a6830b7..8b820088323c 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -114,6 +114,7 @@ void arch_kexec_unprotect_crashkres(void); struct kimage_arch { void *dtb; + void *decompressed_kernel; phys_addr_t dtb_mem; phys_addr_t kern_reloc; phys_addr_t el2_vectors; @@ -126,6 +127,7 @@ struct kimage_arch { #ifdef CONFIG_KEXEC_FILE extern const struct kexec_file_ops kexec_raw_ops; +extern const struct kexec_file_ops kexec_zboot_ops; int arch_kimage_file_post_load_cleanup(struct kimage *image); #define arch_kimage_file_post_load_cleanup arch_kimage_file_post_load_cleanup diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 99b52710606a..ec4d3c17ef70 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -63,7 +63,7 @@ obj-$(CONFIG_HIBERNATION) += hibernate.o hibernate-asm.o obj-$(CONFIG_ELF_CORE) += elfcore.o obj-$(CONFIG_KEXEC_CORE) += machine_kexec.o relocate_kernel.o \ cpu-reset.o -obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o kexec_raw_image.o +obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o kexec_raw_image.o kexec_zboot_image.o obj-$(CONFIG_ARM64_RELOC_TEST) += arm64-reloc-test.o arm64-reloc-test-y := reloc_test_core.o reloc_test_syms.o obj-$(CONFIG_CRASH_DUMP) += crash_dump.o diff --git a/arch/arm64/kernel/kexec_zboot_image.c b/arch/arm64/kernel/kexec_zboot_image.c new file mode 100644 index 000000000000..4629091666b7 --- /dev/null +++ b/arch/arm64/kernel/kexec_zboot_image.c @@ -0,0 +1,186 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Kexec zboot image loader. + * Code is based on kexec_raw_image.c + */ + +#define pr_fmt(fmt) "kexec_file(zboot): " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int zboot_image_probe(const char *kernel_buf, unsigned long kernel_len) +{ + struct zboot_image_header *h = + (struct zboot_image_header *)(kernel_buf); + + if (!h || (kernel_len < sizeof(*h))) + return -EINVAL; + + if (memcmp(&h->magic, (char *)MZ_MAGIC, sizeof(h->magic))) + return -EINVAL; + if (strncmp(h->zimg, "zimg", 4)) + return -EINVAL; + + return 0; +} + +static void error(char *x) +{ + pr_err("%s\n", x); +} + +static void *zboot_image_load(struct kimage *image, + char *kernel, unsigned long kernel_len, + char *initrd, unsigned long initrd_len, + char *cmdline, unsigned long cmdline_len) +{ + struct zboot_image_header *zh; + struct arm64_image_header *h; + char *decompressed_buf; + u32 sz; + long out_sz; + u64 flags, value; + bool be_image, be_kernel; + struct kexec_buf kbuf; + unsigned long text_offset, kernel_segment_number; + struct kexec_segment *kernel_segment; + int ret; + decompress_fn decompressor; + + zh = (struct zboot_image_header *)kernel; + /* + * zboot has SizeOfCode, SizeOfImage, SizeOfHeaders appended at the end. And + * each occupies 4 bytes. + */ + sz = *(u32 *)(kernel + zh->gzdata_offset + zh->gzdata_size + 4); + out_sz = sz; + /* freed in machine_kexec_post_load() */ + decompressed_buf = kmalloc(sz, GFP_KERNEL); + if (!decompressed_buf) { + pr_info("Can not get enough memory to decompress the zboot image\n"); + return ERR_PTR(-ENOMEM); + } + + decompressor = decompress_method_by_name(zh->comp_type); + if (!decompressor) { + pr_info("Invalid compress-format:%s\n", zh->comp_type); + ret = -EINVAL; + goto err; + } + ret = decompressor(kernel + zh->gzdata_offset, zh->gzdata_size, NULL, NULL, + (void *)decompressed_buf, &out_sz, error); + + if (ret) { + pr_info("Fail to decompress the zboot image\n"); + ret = -EINVAL; + goto err; + } + + h = (struct arm64_image_header *)decompressed_buf; + if (!h->image_size) { + kfree(decompressed_buf); + ret = -EINVAL; + goto err; + } + + /* Check cpu features */ + flags = le64_to_cpu(h->flags); + be_image = arm64_image_flag_field(flags, ARM64_IMAGE_FLAG_BE); + be_kernel = IS_ENABLED(CONFIG_CPU_BIG_ENDIAN); + if ((be_image != be_kernel) && !system_supports_mixed_endian()) { + ret = -EINVAL; + goto err; + } + + value = arm64_image_flag_field(flags, ARM64_IMAGE_FLAG_PAGE_SIZE); + if (((value == ARM64_IMAGE_FLAG_PAGE_SIZE_4K) && + !system_supports_4kb_granule()) || + ((value == ARM64_IMAGE_FLAG_PAGE_SIZE_64K) && + !system_supports_64kb_granule()) || + ((value == ARM64_IMAGE_FLAG_PAGE_SIZE_16K) && + !system_supports_16kb_granule())) { + ret = -EINVAL; + goto err; + } + + /* Load the kernel */ + kbuf.image = image; + kbuf.buf_min = 0; + kbuf.buf_max = ULONG_MAX; + kbuf.top_down = false; + + kbuf.buffer = decompressed_buf; + kbuf.bufsz = sz; + kbuf.mem = KEXEC_BUF_MEM_UNKNOWN; + kbuf.memsz = le64_to_cpu(h->image_size); + text_offset = le64_to_cpu(h->text_offset); + kbuf.buf_align = MIN_KIMG_ALIGN; + + /* Adjust kernel segment with TEXT_OFFSET */ + kbuf.memsz += text_offset; + + kernel_segment_number = image->nr_segments; + + /* + * The location of the kernel segment may make it impossible to satisfy + * the other segment requirements, so we try repeatedly to find a + * location that will work. + */ + while ((ret = kexec_add_buffer(&kbuf)) == 0) { + /* Try to load additional data */ + kernel_segment = &image->segment[kernel_segment_number]; + ret = load_other_segments(image, kernel_segment->mem, + kernel_segment->memsz, initrd, + initrd_len, cmdline); + if (!ret) + break; + + /* + * We couldn't find space for the other segments; erase the + * kernel segment and try the next available hole. + */ + image->nr_segments -= 1; + kbuf.buf_min = kernel_segment->mem + kernel_segment->memsz; + kbuf.mem = KEXEC_BUF_MEM_UNKNOWN; + } + + if (ret) { + pr_err("Could not find any suitable kernel location!"); + goto err; + } + + kernel_segment = &image->segment[kernel_segment_number]; + kernel_segment->mem += text_offset; + kernel_segment->memsz -= text_offset; + image->start = kernel_segment->mem; + image->arch.decompressed_kernel = decompressed_buf; + + pr_debug("Loaded kernel at 0x%lx bufsz=0x%lx memsz=0x%lx\n", + kernel_segment->mem, kbuf.bufsz, + kernel_segment->memsz); + + return NULL; + +err: + kfree(decompressed_buf); + return ERR_PTR(ret); +} + +const struct kexec_file_ops kexec_zboot_ops = { + .probe = zboot_image_probe, + .load = zboot_image_load, +#ifdef CONFIG_KEXEC_IMAGE_VERIFY_SIG + .verify_sig = kexec_kernel_verify_pe_sig, +#endif +}; diff --git a/arch/arm64/kernel/machine_kexec.c b/arch/arm64/kernel/machine_kexec.c index ce3d40120f72..866c1c27a9ea 100644 --- a/arch/arm64/kernel/machine_kexec.c +++ b/arch/arm64/kernel/machine_kexec.c @@ -166,6 +166,7 @@ int machine_kexec_post_load(struct kimage *kimage) icache_inval_pou((uintptr_t)reloc_code, (uintptr_t)reloc_code + reloc_size); kexec_image_info(kimage); + kfree(kimage->arch.decompressed_kernel); return 0; } diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index 0738020507d1..02d7e4004cfb 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -24,6 +24,7 @@ const struct kexec_file_ops * const kexec_file_loaders[] = { &kexec_raw_ops, + &kexec_zboot_ops, NULL }; diff --git a/include/linux/zboot.h b/include/linux/zboot.h new file mode 100644 index 000000000000..abefcb92e1ad --- /dev/null +++ b/include/linux/zboot.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef ZBOOT_H +#define ZBOOT_H + +struct zboot_image_header { + union { + struct { + u32 magic; + /* image type, .ascii "zimg" */ + char zimg[4]; + s32 gzdata_offset; + s32 gzdata_size; + s32 reserved[2]; + /* compression type, .asciz */ + char comp_type[]; + }; + struct { + char pad[56]; + }; + }; + /* 0x818223cd */ + u32 linux_pe_magic; + s32 pe_header_offset; +} __packed; + +#endif From patchwork Mon Mar 6 03:03:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 13160399 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 69180C61DA4 for ; Mon, 6 Mar 2023 03:06:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=J/+EgqVYgeCBB1+M50APy3m07PLzXHcYWayRIjOkXUE=; b=OvdGzLNbFo+GHA uYrShvn91OTlGNrIwvQSIZxCd/wSKcyIY27+rmIcpqGF9kcqCh1QRoa7+T8tdRV5YITLzAwZBTiR8 DO1IMaTWcEkCxtLl+25FY/kVagZdnMTecQdxdpx2PiyyJZVV6ChLt69sCPRLRCLTUacr6slS93TtH 6f8rX1xKBUYvWPCI83XQ16XBZJwQtADtYO3VHt0p3kyG3ozADsiah8zd0GRCuPhzpnjVv7qHa1pkL 1my9wM97Bzm/Q/coFBmsYGylVzlN5Fi/vfZZqq3/fD+oNqILtGNMYI0NOvN8VbFjAWBIr/J/K2lgV K0xJTwiPXn7nzKJxVbDw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZ1Ab-00B3q2-GQ; Mon, 06 Mar 2023 03:05:49 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZ18j-00B2cD-TF; Mon, 06 Mar 2023 03:03:56 +0000 Received: by mail-pl1-x62a.google.com with SMTP id i5so8790483pla.2; Sun, 05 Mar 2023 19:03:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678071832; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uajbUQnIewe2JrUK08Rp36GBFla2nyzidVlnhov4v/M=; b=WZrdj+Isk4V/hOXFfckOgIgGy2pe/UdwvvkYcjTx/ES3KpvHXYilLIihzQhVPAkbWK lRifRyBwzy0RYLjGmoSGWipsoXivSfkd9bF9QBKrG78Wg/xlcl5BTzQov+qetNjMIlxZ AFTwx1JskAjmAv824RVbHx5NE8menYuABnFqROV9p/yVqcha8fdwsZjGqSQGzfHCM7kp W8kjUxAmlWqI0aQsNB7ixF0CFaB3WxCH8HAkPk7p22i0bWO9wSoXtCp7ISf1Wosqf9MS 8keWuJWbTGBuk5y9Dvf96qEB16dNVJEFH4c48AELbRLjqOBB5xM/HIMaV/BC2xwUlkaM Ur9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678071832; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uajbUQnIewe2JrUK08Rp36GBFla2nyzidVlnhov4v/M=; b=crP8+l+ryO0l2CyXoGueR0gfynWe3JV5b85dqz/6/ORCeg1S5dEYooebseiGicubbi LbpdPPkOSaULirRa3ZxogIj39eOZOUqxVPY876bzwfPBKMRtJC8BF8uHfF0rWrnp6iTz 5C0N6jJrquw7NXjwElNXcHRJLeH92WxpLRY1ncnDZaV5r3+8TcNNidwiua6aUZWw94LM e3XXXB7tbxEZ/nvm2lGiKK/vgWFxxgKFL3MR6h3D8YIxMC9G7kJOAj5Av7Q+WIAk0YKe /kMEYm4W6T/Ki+N0PhCE9kh/07Fo2B/480AANBwQkuN4zQSXrwbIBwURnWykRpnnfIDA fTMQ== X-Gm-Message-State: AO0yUKX3Br/3WNDgcoR+hh2osL3MFeAevZ89sdFs/9FrEU9DQlt43MJd d51D8XsEZbLK9lg2JtMhHHrqappXrQ== X-Google-Smtp-Source: AK7set8hmMUrNWIc99n8GyLvy/rglRTI9XgR+b/60jnclG8T/yq3ZeWruKe+7SgPeOeOv8u/sIa7qA== X-Received: by 2002:a17:903:244c:b0:19e:3b41:1828 with SMTP id l12-20020a170903244c00b0019e3b411828mr10432774pls.22.1678071832295; Sun, 05 Mar 2023 19:03:52 -0800 (PST) Received: from piliu.users.ipa.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id jy16-20020a17090342d000b0019719f752c5sm5410439plb.59.2023.03.05.19.03.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Mar 2023 19:03:51 -0800 (PST) From: Pingfan Liu To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Pingfan Liu , Andrew Morton , Nick Desaulniers , Masahiro Yamada , Johannes Weiner , Nathan Chancellor , Miguel Ojeda , Masami Hiramatsu , Ard Biesheuvel , kexec@lists.infradead.org Subject: [PATCH 6/6] init/Kconfig: Select decompressing method if compressing kernel Date: Mon, 6 Mar 2023 11:03:05 +0800 Message-Id: <20230306030305.15595-7-kernelfans@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230306030305.15595-1-kernelfans@gmail.com> References: <20230306030305.15595-1-kernelfans@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230305_190354_039571_02097A20 X-CRM114-Status: GOOD ( 10.09 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org If choosing an EFI_ZBOOT image, the corresponding decompressing method should be selected so that kexec can load that zboot image. This can be achieved when "Kernel compression mode" is determined. Signed-off-by: Pingfan Liu Cc: Andrew Morton Cc: Nick Desaulniers Cc: Masahiro Yamada Cc: Johannes Weiner Cc: Nathan Chancellor Cc: Miguel Ojeda Cc: Masami Hiramatsu Cc: Ard Biesheuvel Cc: kexec@lists.infradead.org To: linux-kernel@vger.kernel.org --- init/Kconfig | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/init/Kconfig b/init/Kconfig index 44e90b28a30f..046724208645 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -269,6 +269,7 @@ choice config KERNEL_GZIP bool "Gzip" depends on HAVE_KERNEL_GZIP + select KEXEC_DECOMPRESS_GZIP if KEXEC_FILE && EFI_ZBOOT help The old and tried gzip compression. It provides a good balance between compression ratio and decompression speed. @@ -276,6 +277,7 @@ config KERNEL_GZIP config KERNEL_BZIP2 bool "Bzip2" depends on HAVE_KERNEL_BZIP2 + select KEXEC_DECOMPRESS_BZIP2 if KEXEC_FILE && EFI_ZBOOT help Its compression ratio and speed is intermediate. Decompression speed is slowest among the choices. The kernel @@ -286,6 +288,7 @@ config KERNEL_BZIP2 config KERNEL_LZMA bool "LZMA" depends on HAVE_KERNEL_LZMA + select KEXEC_DECOMPRESS_LZMA if KEXEC_FILE && EFI_ZBOOT help This compression algorithm's ratio is best. Decompression speed is between gzip and bzip2. Compression is slowest. @@ -294,6 +297,7 @@ config KERNEL_LZMA config KERNEL_XZ bool "XZ" depends on HAVE_KERNEL_XZ + select KEXEC_DECOMPRESS_XZ if KEXEC_FILE && EFI_ZBOOT help XZ uses the LZMA2 algorithm and instruction set specific BCJ filters which can improve compression ratio of executable @@ -309,6 +313,7 @@ config KERNEL_XZ config KERNEL_LZO bool "LZO" depends on HAVE_KERNEL_LZO + select KEXEC_DECOMPRESS_LZO if KEXEC_FILE && EFI_ZBOOT help Its compression ratio is the poorest among the choices. The kernel size is about 10% bigger than gzip; however its speed @@ -317,6 +322,7 @@ config KERNEL_LZO config KERNEL_LZ4 bool "LZ4" depends on HAVE_KERNEL_LZ4 + select KEXEC_DECOMPRESS_LZ4 if KEXEC_FILE && EFI_ZBOOT help LZ4 is an LZ77-type compressor with a fixed, byte-oriented encoding. A preliminary version of LZ4 de/compression tool is available at @@ -329,6 +335,7 @@ config KERNEL_LZ4 config KERNEL_ZSTD bool "ZSTD" depends on HAVE_KERNEL_ZSTD + select KEXEC_DECOMPRESS_ZSTD if KEXEC_FILE && EFI_ZBOOT help ZSTD is a compression algorithm targeting intermediate compression with fast decompression speed. It will compress better than GZIP and