From patchwork Fri Sep 15 09:37:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 140455 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp1083272vqi; Fri, 15 Sep 2023 07:21:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH2DQ09byFzm4LwEV9lpvB9uJhdawJHMI/Wiyf0vvTlod+qdAdgkynLEFp1NwuYlyTi4zTb X-Received: by 2002:a05:6a00:995:b0:68f:c081:3d5c with SMTP id u21-20020a056a00099500b0068fc0813d5cmr2087672pfg.8.1694787671357; Fri, 15 Sep 2023 07:21:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694787671; cv=none; d=google.com; s=arc-20160816; b=a1EcFiUpmqnd5kZSkhzfinchFLrozms9YbfNZxarW15jEksSMVTEsGDLXQdqJRu+Bw 79I/umGuX3YX+1lMRwL4iX3llOO6dv9mhVT4GKaHBFEmjL8Tj+NZifDkifDDb337L+Y6 DgqCYKvJH1C+XbP6t5yrUuxFsCtidWDxP6wsq1Fbkc/LIGBJcIIi21os6/3RRdHtwqrc scT0wT5RBZ//XlvSM3qaOfbrz1YD8ZH4QSlEoAlo8T2+CGHvBQdiVkvoHl+MY9g8QZST eqG80rcQpEGpTlsi0KjPvBD6YlgXvUpXMw+ipGH9x300a3lajOpozxTHstyJazDoHIb0 Y5Dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=02CNNYdQjVfmj16GKHZtFnohxkv6LTnS13rVtwj3by8=; fh=mh/EFXDyWz6SYA4qEbcbMgOZ07AT4DlRJonTEXgTb50=; b=Igndtf3gsnGBRMgJcVgVRPnA7/vVuMcXHnrnuBELylG7EBayL+J39zHKJlpeJmlzz4 bSoCcvSHbruhWnDxIkSnhLSCj2i8qr+I5rghOSZr4udMCEIAWL3kcGl7A7tDGpJkKRjm Kg65665WX4vi901f1Kl8YK9qilG6UEapm4CPmkmoUFlHtahPGclCVrTFT1Js7XknvNfO kw/3qV35oE4XoVxoaOwJ66ntAGqO0Im13E7HP11c1l6r+TlzwGmv69M838xhpHtned0i KrDg5Agu0UhsjbItA78c9C315oPvCoXTmYa8TosvLhRmHkP/586GqWbhCHTy2UpwoJBC 7Xxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Xbqfen0L; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id q7-20020a056a00150700b00656f1d69ec6si3511387pfu.292.2023.09.15.07.21.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 07:21:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Xbqfen0L; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 456E883B362C; Fri, 15 Sep 2023 02:38:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233828AbjIOJiV (ORCPT + 32 others); Fri, 15 Sep 2023 05:38:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233779AbjIOJiQ (ORCPT ); Fri, 15 Sep 2023 05:38:16 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D58772121; Fri, 15 Sep 2023 02:37:49 -0700 (PDT) Date: Fri, 15 Sep 2023 09:37:47 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694770668; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=02CNNYdQjVfmj16GKHZtFnohxkv6LTnS13rVtwj3by8=; b=Xbqfen0LUvyCYp0eYT79H7LUhDwbh0ZlGygp6KogUPTQSfwx1hR1KTghu9OoJo+uDXUPPJ qE23DCX99XyyV8VxbLtAWcS3k6t42lvB/vN7IuCHY5NbRDyQSVH1NXgp/sgPWZQgWGCoum DmwKQd5kqs9hUl8mOVzGi43MRlYh/+r1rWBUWYYk+Q5ALtv7rXen/T5WevFl2kuBGZL7vL Q5HVVYJmAerpUMiyq5JJLH6YxwLPwuy5yrJBwGt/UT7m/a2njXiCYyVDoicQ/8AczVWncY cTvIDgGehPFTfO/cP0l2Q5kHE8mPLhw67ounbLHFVO5f4bCJgTRLEwHcTFbwxQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694770668; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=02CNNYdQjVfmj16GKHZtFnohxkv6LTnS13rVtwj3by8=; b=wD8FyGhcPZ3ohclfdo6szcTy4S825eWyf1Ou8uUO+GXp9Eoqj5uXnzN5Q4Hvdjir55wv3w jVKtdnk6xxnpbKDQ== From: "tip-bot2 for Ard Biesheuvel" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/boot] x86/boot: Omit compression buffer from PE/COFF image memory footprint Cc: Ard Biesheuvel , Ingo Molnar , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230912090051.4014114-22-ardb@google.com> References: <20230912090051.4014114-22-ardb@google.com> MIME-Version: 1.0 Message-ID: <169477066777.27769.18147290809049651725.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Fri, 15 Sep 2023 02:38:28 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776884675540465048 X-GMAIL-MSGID: 1777113677278420271 The following commit has been merged into the x86/boot branch of tip: Commit-ID: 8eace5b3555606e684739bef5bcdfcfe68235257 Gitweb: https://git.kernel.org/tip/8eace5b3555606e684739bef5bcdfcfe68235257 Author: Ard Biesheuvel AuthorDate: Tue, 12 Sep 2023 09:00:56 Committer: Ingo Molnar CommitterDate: Fri, 15 Sep 2023 11:18:41 +02:00 x86/boot: Omit compression buffer from PE/COFF image memory footprint Now that the EFI stub decompresses the kernel and hands over to the decompressed image directly, there is no longer a need to provide a decompression buffer as part of the .BSS allocation of the PE/COFF image. It also means the PE/COFF image can be loaded anywhere in memory, and setting the preferred image base is unnecessary. So drop the handling of this from the header and from the build tool. Signed-off-by: Ard Biesheuvel Signed-off-by: Ingo Molnar Link: https://lore.kernel.org/r/20230912090051.4014114-22-ardb@google.com --- arch/x86/boot/header.S | 6 +--- arch/x86/boot/tools/build.c | 50 ++++-------------------------------- 2 files changed, 8 insertions(+), 48 deletions(-) diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S index b24fa50..a87d913 100644 --- a/arch/x86/boot/header.S +++ b/arch/x86/boot/header.S @@ -90,12 +90,10 @@ optional_header: #endif extra_header_fields: - # PE specification requires ImageBase to be 64k aligned - .set image_base, (LOAD_PHYSICAL_ADDR + 0xffff) & ~0xffff #ifdef CONFIG_X86_32 - .long image_base # ImageBase + .long 0 # ImageBase #else - .quad image_base # ImageBase + .quad 0 # ImageBase #endif .long 0x20 # SectionAlignment .long 0x20 # FileAlignment diff --git a/arch/x86/boot/tools/build.c b/arch/x86/boot/tools/build.c index bd24769..0354c22 100644 --- a/arch/x86/boot/tools/build.c +++ b/arch/x86/boot/tools/build.c @@ -65,7 +65,6 @@ static unsigned long efi_pe_entry; static unsigned long efi32_pe_entry; static unsigned long kernel_info; static unsigned long startup_64; -static unsigned long _ehead; static unsigned long _end; /*----------------------------------------------------------------------*/ @@ -229,35 +228,22 @@ static void update_pecoff_setup_and_reloc(unsigned int size) #endif } -static void update_pecoff_text(unsigned int text_start, unsigned int file_sz, - unsigned int init_sz) +static void update_pecoff_text(unsigned int text_start, unsigned int file_sz) { unsigned int pe_header; unsigned int text_sz = file_sz - text_start; - unsigned int bss_sz = init_sz - file_sz; + unsigned int bss_sz = _end - text_sz; pe_header = get_unaligned_le32(&buf[0x3c]); /* - * The PE/COFF loader may load the image at an address which is - * misaligned with respect to the kernel_alignment field in the setup - * header. - * - * In order to avoid relocating the kernel to correct the misalignment, - * add slack to allow the buffer to be aligned within the declared size - * of the image. - */ - bss_sz += CONFIG_PHYSICAL_ALIGN; - init_sz += CONFIG_PHYSICAL_ALIGN; - - /* * Size of code: Subtract the size of the first sector (512 bytes) * which includes the header. */ put_unaligned_le32(file_sz - 512 + bss_sz, &buf[pe_header + 0x1c]); /* Size of image */ - put_unaligned_le32(init_sz, &buf[pe_header + 0x50]); + put_unaligned_le32(file_sz + bss_sz, &buf[pe_header + 0x50]); /* * Address of entry point for PE/COFF executable @@ -308,8 +294,7 @@ static void efi_stub_entry_update(void) static inline void update_pecoff_setup_and_reloc(unsigned int size) {} static inline void update_pecoff_text(unsigned int text_start, - unsigned int file_sz, - unsigned int init_sz) {} + unsigned int file_sz) {} static inline void efi_stub_defaults(void) {} static inline void efi_stub_entry_update(void) {} @@ -360,7 +345,6 @@ static void parse_zoffset(char *fname) PARSE_ZOFS(p, efi32_pe_entry); PARSE_ZOFS(p, kernel_info); PARSE_ZOFS(p, startup_64); - PARSE_ZOFS(p, _ehead); PARSE_ZOFS(p, _end); p = strchr(p, '\n'); @@ -371,7 +355,7 @@ static void parse_zoffset(char *fname) int main(int argc, char ** argv) { - unsigned int i, sz, setup_sectors, init_sz; + unsigned int i, sz, setup_sectors; int c; u32 sys_size; struct stat sb; @@ -442,31 +426,9 @@ int main(int argc, char ** argv) buf[0x1f1] = setup_sectors-1; put_unaligned_le32(sys_size, &buf[0x1f4]); - init_sz = get_unaligned_le32(&buf[0x260]); -#ifdef CONFIG_EFI_STUB - /* - * The decompression buffer will start at ImageBase. When relocating - * the compressed kernel to its end, we must ensure that the head - * section does not get overwritten. The head section occupies - * [i, i + _ehead), and the destination is [init_sz - _end, init_sz). - * - * At present these should never overlap, because 'i' is at most 32k - * because of SETUP_SECT_MAX, '_ehead' is less than 1k, and the - * calculation of INIT_SIZE in boot/header.S ensures that - * 'init_sz - _end' is at least 64k. - * - * For future-proofing, increase init_sz if necessary. - */ - - if (init_sz - _end < i + _ehead) { - init_sz = (i + _ehead + _end + 4095) & ~4095; - put_unaligned_le32(init_sz, &buf[0x260]); - } -#endif - update_pecoff_text(setup_sectors * 512, i + (sys_size * 16), init_sz); + update_pecoff_text(setup_sectors * 512, i + (sys_size * 16)); efi_stub_entry_update(); - /* Update kernel_info offset. */ put_unaligned_le32(kernel_info, &buf[0x268]);