From patchwork Sun Sep 17 18:12:51 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: 141177 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2256139vqi; Sun, 17 Sep 2023 11:41:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGwfrn//Hbr3Kvac/y6beyGS+RNYhAXky8pgai8Yz8ROsmB+OUf3AVHdjW5rb+aCjZmNLGj X-Received: by 2002:a05:6358:3193:b0:135:7c30:523 with SMTP id q19-20020a056358319300b001357c300523mr9167278rwd.16.1694976098627; Sun, 17 Sep 2023 11:41:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694976098; cv=none; d=google.com; s=arc-20160816; b=RYPSDQTapREM+4QuuMT+zecyxdAsjlrIF57ZuNYLtwebG6tARoi4hgh9kke3XxFC7i 3X6VoBn9s6B4tXKkwM4MXiIiMAbaaTB4Oa6BYtOctasjnbKShrNg901rTxvwsA2SgkXA qPl/JQvn675dgMkQ8/uq3NwpC66EbK/jY+YEPTTh1gQuFf6S/vT8skfSTvITml7EZ5Br HoseXS/oaewFcX4gtXe7TlZAtA0oOtLd2VJkKWCclpun8y8wT0eeFjQrlhPdo9lCdXRr KEt9s2ei6BBEaGn2vNXJ3GqBD6PIvq0XzHLK6EX+GXwfxohXB8zq5ajt98S50eyuXsM4 z5Fg== 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=kmbTHz0oxyRq0ilV2+qpm/m2KASgVKj0aN/6CNBu2n0=; fh=mh/EFXDyWz6SYA4qEbcbMgOZ07AT4DlRJonTEXgTb50=; b=z0Hnn5IPQdACJmTfKHBMTb0ReiQdBwl7IZljTeiQ5DFdq0GTc+vmQT6VHqpu1ct47d tHtCCQTyTQ9NYKrd/0F6uN1VClWdXiJplNhwOXPnAbV5u0Aw38xWIEKEytBw89aqNq3H 77HuvWoKp20Lh691iTayr5a8pewzP2eriVkZdbZcdYbXInLc9/llCQ9I3zemgd7aZa+L r98ol0ka3ARavBA7z5b0NkaFn2VX9x/2sY5SYY1tGfaBNW5VvWH44bdpndlC7nij2/Yk wXp0dJh9uVKebunRqfbtLVtRGgA3Ple9/vgoQr8ysf3zLMCds43pWq2p4H4LCnfU1HdT eSfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=EGp9U5jK; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id o3-20020a056a001bc300b006826c8d5a31si6783825pfw.21.2023.09.17.11.41.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Sep 2023 11:41:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=EGp9U5jK; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 002E181F356C; Sun, 17 Sep 2023 11:16:43 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238654AbjIQSNR (ORCPT + 28 others); Sun, 17 Sep 2023 14:13:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238333AbjIQSNC (ORCPT ); Sun, 17 Sep 2023 14:13:02 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85B3B135; Sun, 17 Sep 2023 11:12:55 -0700 (PDT) Date: Sun, 17 Sep 2023 18:12:51 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694974372; 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=kmbTHz0oxyRq0ilV2+qpm/m2KASgVKj0aN/6CNBu2n0=; b=EGp9U5jKCdAnqeqoXL9HlPux59j3cMJpx4by/43tl/Jwa2jMUGzGB3SGFT3ZHhx6JU2MPl 8fqNtyWTvDp6UQK8ksaQKH1jyafi+HqmSKn9fC2icIJ0om341TJRUCVx9zMrM3eUqKS3g4 rwZ0WgoLHmRyUkWQU4Ycw6b0GcPrq3Y5wa7hFFPd9ocHX5UGnx8iTrab2dIGoKljd3UKfG b0zinTB4RV9eE0GjOKo/FbFweAjObjQbuP+bS1K2LadLzPIVBUo8Y6mIf2fOb6uVH8VOSp gaAT0ft0/pzC5X1QCfPQ2H1SmeBLBPCwjFgILLfjeU4iETKPOsGllbC54F2mMw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694974372; 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=kmbTHz0oxyRq0ilV2+qpm/m2KASgVKj0aN/6CNBu2n0=; b=Wy/mhCPoblq8Xhev5zkKx3LCwm5bfQ2slL5LHd//eG655iov3qoXRcclv80MbyEg3BJZtM SPvVF3qdXV40PqDQ== 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: Define setup size in linker script Cc: Ard Biesheuvel , Ingo Molnar , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230915171623.655440-13-ardb@google.com> References: <20230915171623.655440-13-ardb@google.com> MIME-Version: 1.0 Message-ID: <169497437144.27769.10481980684639575351.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Sun, 17 Sep 2023 11:16:44 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777141012692594456 X-GMAIL-MSGID: 1777311257759655116 The following commit has been merged into the x86/boot branch of tip: Commit-ID: 093ab258e3fb1d1d3afdfd4a69403d44ce90e360 Gitweb: https://git.kernel.org/tip/093ab258e3fb1d1d3afdfd4a69403d44ce90e360 Author: Ard Biesheuvel AuthorDate: Fri, 15 Sep 2023 17:16:27 Committer: Ingo Molnar CommitterDate: Sun, 17 Sep 2023 19:48:42 +02:00 x86/boot: Define setup size in linker script The setup block contains the real mode startup code that is used when booting from a legacy BIOS, along with the boot_params/setup_data that is used by legacy x86 bootloaders to pass the command line and initial ramdisk parameters, among other things. The setup block also contains the PE/COFF header of the entire combined image, which includes the compressed kernel image, the decompressor and the EFI stub. This PE header describes the layout of the executable image in memory, and currently, the fact that the setup block precedes it makes it rather fiddly to get the right values into the right place in the final image. Let's make things a bit easier by defining the setup_size in the linker script so it can be referenced from the asm code directly, rather than having to rely on the build tool to calculate it. For the time being, add 64 bytes of fixed padding for the .reloc and .compat sections - this will be removed in a subsequent patch after the PE/COFF header has been reorganized. This change has no impact on the resulting bzImage binary when configured with CONFIG_EFI_MIXED=y. Signed-off-by: Ard Biesheuvel Signed-off-by: Ingo Molnar Link: https://lore.kernel.org/r/20230915171623.655440-13-ardb@google.com --- arch/x86/boot/header.S | 2 +- arch/x86/boot/setup.ld | 4 ++++ arch/x86/boot/tools/build.c | 6 ------ 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S index 72744ba..06bd72a 100644 --- a/arch/x86/boot/header.S +++ b/arch/x86/boot/header.S @@ -231,7 +231,7 @@ sentinel: .byte 0xff, 0xff /* Used to detect broken loaders */ .globl hdr hdr: -setup_sects: .byte 0 /* Filled in by build.c */ + .byte setup_sects - 1 root_flags: .word ROOT_RDONLY syssize: .long 0 /* Filled in by build.c */ ram_size: .word 0 /* Obsolete */ diff --git a/arch/x86/boot/setup.ld b/arch/x86/boot/setup.ld index b11c45b..9bd5c1a 100644 --- a/arch/x86/boot/setup.ld +++ b/arch/x86/boot/setup.ld @@ -39,6 +39,10 @@ SECTIONS .signature : { setup_sig = .; LONG(0x5a5aaa55) + + /* Reserve some extra space for the reloc and compat sections */ + setup_size = ALIGN(ABSOLUTE(.) + 64, 512); + setup_sects = ABSOLUTE(setup_size / 512); } diff --git a/arch/x86/boot/tools/build.c b/arch/x86/boot/tools/build.c index 0694975..745d64b 100644 --- a/arch/x86/boot/tools/build.c +++ b/arch/x86/boot/tools/build.c @@ -48,12 +48,7 @@ typedef unsigned int u32; u8 buf[SETUP_SECT_MAX*512]; #define PECOFF_RELOC_RESERVE 0x20 - -#ifdef CONFIG_EFI_MIXED #define PECOFF_COMPAT_RESERVE 0x20 -#else -#define PECOFF_COMPAT_RESERVE 0x0 -#endif static unsigned long efi_pe_entry; static unsigned long efi32_pe_entry; @@ -388,7 +383,6 @@ int main(int argc, char ** argv) #endif /* Patch the setup code with the appropriate size parameters */ - buf[0x1f1] = setup_sectors-1; put_unaligned_le32(sys_size, &buf[0x1f4]); update_pecoff_text(setup_sectors * 512, i + (sys_size * 16));