From patchwork Fri Sep 15 09:37:46 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: 140311 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp919585vqi; Fri, 15 Sep 2023 02:38:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH3ZbyKRRj7JnO0WiFFJQA3FEazhHErruRe+7C1cB40uTrWly/yYOUi7v229ePiR3w5pWfX X-Received: by 2002:a05:6a00:b87:b0:68a:3b25:50cc with SMTP id g7-20020a056a000b8700b0068a3b2550ccmr1310494pfj.30.1694770733444; Fri, 15 Sep 2023 02:38:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694770733; cv=none; d=google.com; s=arc-20160816; b=ldY3Q1jU4lC/zXRmZj2wV9KlsCd0/fVS36UiQShU+CzQkbP+2DMwFccsDx1D0XAppz rh13Pp88+1k0TUnHoboc/iRGwCC15RzU23W80vSLM36vlAcJsy1Ymf7yIIsohenI6fxZ Sct7THdzm26chNAZJ0KHBLnY8xWWNCrLltfEcZ0aLATuTJ/kCTj9wqPI8zQqZmbi9jol KHd8wLHcpZNV5M+lqHYypANpZj3NUocTC3RGTUZB6L3bnPxoRQ5XzZ8SQh/ZeZC2/bmd CVYaapKGWGLdXq6jPTcjMoiybQQujYy8aathb5KaBEdsa8VvT9B4khTiK+0NCSadXB63 vg/w== 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=SOPVTewIEsdJFEdGxeIXrxTA0ujLRVLPJN1kHfZ4fqc=; fh=mh/EFXDyWz6SYA4qEbcbMgOZ07AT4DlRJonTEXgTb50=; b=CfP5OGSLa9B3+a5SydecCJFlCpfRgPu9jEPtX89+1KHTcOUoIl45hj0f8LPHWKtQCN B5b12oFfax5x6wetUPdCeMy6LLBET2nKBGTlJpmnTr9N7eU6HAxWdvfhu9EwqyYV+Yk2 we+lcRgtMRcuKVVT7slpkNlk4MZyXmYf5vuOs1WcVlem6wrqScJLfuTwEm+BKOEDlX8W GTplHRVClfRkGNdwJqjXw7R1UjyrHL6WWwxn0sZS12tX+yjuM8h1oR8SHFFQ+fwGbKrC t112VFWZuK42U8wSVaQ/M1q/rkwqhKAyBz5nN8Ma7DKDDcoiELOH8ojj+Zoj/WGTuN4K 405w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=C07p3FS6; 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.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id b10-20020a6567ca000000b005775e17f560si2993873pgs.82.2023.09.15.02.38.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 02:38:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=C07p3FS6; 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.32 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 agentk.vger.email (Postfix) with ESMTP id 3DDC182CFF2E; Fri, 15 Sep 2023 02:38:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233740AbjIOJiN (ORCPT + 32 others); Fri, 15 Sep 2023 05:38:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233471AbjIOJiM (ORCPT ); Fri, 15 Sep 2023 05:38:12 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0693D210A; Fri, 15 Sep 2023 02:37:48 -0700 (PDT) Date: Fri, 15 Sep 2023 09:37:46 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694770666; 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=SOPVTewIEsdJFEdGxeIXrxTA0ujLRVLPJN1kHfZ4fqc=; b=C07p3FS6Q6cg7DFbkQCpwtH4JoozO7AQvOmfWYBFu6zbh/VOR0/EjuFBEJpJnITomY22pS yPS8GSpCVWkD2XEebFo24hY63r2GFYMZQ5QJ4GspsxAzFbw523DSz0gHm6Nt6i/S6SAPWn xlKnS+2sqszz3pN59+n3YWDZc+pewqdogN9gnitc0wSACCfs1o0X9RyBh4aJ2krubEOOkk z2AZB5RS/3MIj+uNSroqGjAN/+3iKvwe79tbruc6gMtZ8bGZcl5Wlrejfjwd4mBJVyjynP WSzewe6qzPtKfWfyihpMlyW2rtmZtl5pSNQJ16sWXrWVNW+HAynQ2v95XhjaKw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694770666; 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=SOPVTewIEsdJFEdGxeIXrxTA0ujLRVLPJN1kHfZ4fqc=; b=DQEgUkr7/pZLTpcEvXF5vBx0qHZmTGPh49AkU/8RInL/+NNSoh0+JusRvTFY7Rv6Lbn7rc vdpMRu3qlQdk1uDA== 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: <20230912090051.4014114-27-ardb@google.com> References: <20230912090051.4014114-27-ardb@google.com> MIME-Version: 1.0 Message-ID: <169477066609.27769.6739184359715822628.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 agentk.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 (agentk.vger.email [0.0.0.0]); Fri, 15 Sep 2023 02:38:18 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776889338581511554 X-GMAIL-MSGID: 1777095916244144817 The following commit has been merged into the x86/boot branch of tip: Commit-ID: 988b52b207a9fe74c3699bda8c2256714926b94b Gitweb: https://git.kernel.org/tip/988b52b207a9fe74c3699bda8c2256714926b94b Author: Ard Biesheuvel AuthorDate: Tue, 12 Sep 2023 09:01:01 Committer: Ingo Molnar CommitterDate: Fri, 15 Sep 2023 11:18: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/20230912090051.4014114-27-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 6059f87..36011b2 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..f125f17 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 = ABSOLUTE(ALIGN(. + 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 10b0207..bcbae88 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 efi32_stub_entry; static unsigned long efi64_stub_entry; @@ -413,7 +408,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));