Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4801299rdb; Fri, 15 Sep 2023 12:40:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHm5bBXnD30zLuVsOiJ3LiKTHr0ysSvtsvXMEctKccpeIhUdqsbLxQp3bhb3utDzSk39a14 X-Received: by 2002:a05:6358:9143:b0:139:d24c:ed28 with SMTP id r3-20020a056358914300b00139d24ced28mr2968909rwr.12.1694806857952; Fri, 15 Sep 2023 12:40:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694806857; cv=none; d=google.com; s=arc-20160816; b=SWw5BJ097wW9UugruufPOCppk99LGgu5sonySR71ZrmZP7YjbbjmwiR/1pGMp5c/7h WpPvDknJQKZGnY+1c0iKque32urlNVq8vJTbwrBDgKSJIoyzTAeVN16Dw63X9bm1nXGK 3Y7avzIign6WVyfPBHQQPzFzJg0qxrMEUXr3ZDa/MdvmSBal+5yPOAa3rLOgvr1qaVW1 WLsfdG7yCfYxpVN2YBWMEix2JLaSWTvy4c220QY0NEjOiUdLm846yNO1oFrRfnaDihMm HCZwZRurkFdU+9aw+oU2fI/kiKXAiW5Wn0daM8kZMkOWIUsB8DL2EklVGiC3ffDbzCxT 99lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=89g8O0FeFLI+vAm3VnFZD9BW/eMlaApKHGhLfa7SlGI=; fh=WGxnbchXB1nh8WtfYTQqAYq5ggcl91wEfddYAfjE7VI=; b=eVv3UsE6vStfVxxKHpzFEo3YnR1bsZvWwlr/SG0jfJDCrND7+XoWvtWX2rPueHDNSC YDEvmQ/3a3DDK5HZUaUtNWUnI/4ALDMksEyLr6M7Gw27qPfLUt0DGkem1MMVR+Pghx1n TZ1oKpgWxWwXQH1EI4NpDSQOkgnqNwui1ctTKamtmUzkhrUQipoDv4ddHJXsbNhSnOAS e7sq1mrQlVpmuDGwrSWiFldWlpJxa5oV5Yf0ly21FF8pSVDMq0lRIyAN/yz6tjNfzH56 ialsrHDjRmfebfRGRSoWKcqeHhkAP6dAlyHsdEqCuOGgJrJKxj3q0fBsCEEqrKHlgJ3a xu3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=sqt3v+Gs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id e20-20020a656794000000b005740b4723f9si3688305pgr.811.2023.09.15.12.40.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 12:40:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=sqt3v+Gs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id DC01B80984BB; Fri, 15 Sep 2023 10:18:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235813AbjIORRb (ORCPT + 99 others); Fri, 15 Sep 2023 13:17:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235495AbjIORRL (ORCPT ); Fri, 15 Sep 2023 13:17:11 -0400 Received: from mail-wr1-x449.google.com (mail-wr1-x449.google.com [IPv6:2a00:1450:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AE3B83 for ; Fri, 15 Sep 2023 10:17:05 -0700 (PDT) Received: by mail-wr1-x449.google.com with SMTP id ffacd0b85a97d-31fb093a53aso1537096f8f.0 for ; Fri, 15 Sep 2023 10:17:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694798223; x=1695403023; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=89g8O0FeFLI+vAm3VnFZD9BW/eMlaApKHGhLfa7SlGI=; b=sqt3v+Gslbmwnsz9rQ7GnAQ5ScLQDz6UeJXuiKYq9fEQhB7XYS5CRRQhxMRiTAE4Tj URORcrpwnusJmj67M0QDuhT7T7kjKkYBKwL8+19vUV/i09vSU3oN/ER9etjRGxCPuEN/ 672CxdpiBJmfQmFYxkwFi6Txy2jYuzc8CL0AVxyJqFhAu/nrfiQo+21MrB9d8tZLY1dK yz+AHFi9j1WNeZFu7VS3nEhodnqjFNL5sMFvoX50E53Jxm7qg3BsEIET2Q6R1HA01hCm 5cECVXPtAFPEPb2ebBgVwHgCo0bxxX1FZ6LbGB19SCZ2T1JlEEdOLE9zdPXpHKcpEZeU DNIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694798223; x=1695403023; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=89g8O0FeFLI+vAm3VnFZD9BW/eMlaApKHGhLfa7SlGI=; b=liF1vg9399qJT/PC1MVSwzUbbDnrxuewNLML2h/+kU186iaezkmM27O5Guk8HXbUzm 9o5j/aglX6rSOrd5XSiRRH2bU7y37CFGiF+GHPrgIBGTyGMDZVk7Tf39JSDZL/jVVjKQ sAp7u+vIT1K5fpjFIVaqHeX89qemaTwd8cDmO+PAiVkUC25sa2BBB9slAB5uM2hPLkZM +ZXDFYbEq1Je1Nq2fdHLecgKIVHqdbYo4Zbmi4tNMMbKeEwbu5xYGi6xfIaRV+cRsW/z 45YyzAhJ3MGYsxk5RqDVbsNnoBo4R8AuHj6fDeYymNprG9zySWkqDj8uqtUc4XVZpDCA nDNw== X-Gm-Message-State: AOJu0YyQBcYO9Xaz+A/Wj3rMv/ci3IQd9wq8g/ZllCAi854n5G1xxwOW doa9qDs12PkHT8cPZnfL0tY1cnJq X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a5d:4152:0:b0:319:6fc6:151 with SMTP id c18-20020a5d4152000000b003196fc60151mr26188wrq.10.1694798223502; Fri, 15 Sep 2023 10:17:03 -0700 (PDT) Date: Fri, 15 Sep 2023 17:16:27 +0000 In-Reply-To: <20230915171623.655440-10-ardb@google.com> Mime-Version: 1.0 References: <20230915171623.655440-10-ardb@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=3059; i=ardb@kernel.org; h=from:subject; bh=be7iDzl8pMuNbGRQpSLTpnBfKOp7BhO0eZKOBUcXTVM=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIZVlYvarrBa1T7tCypYv8zz8v+iMLdPCvVM+nX3w+OanZ cFPl3uIdZSyMIhxMMiKKbIIzP77bufpiVK1zrNkYeawMoEMYeDiFICJuDxn+KdeJ977bN5qft94 28rfTS+DYouehc9+F5q8M2euULvph3mMDJPyd9+YwTAj3815m+mSQ4YOWgvWloc+1rurapWRerX Ngw0A X-Mailer: git-send-email 2.42.0.459.ge4e396fd5e-goog Message-ID: <20230915171623.655440-13-ardb@google.com> Subject: [PATCH v3 3/8] x86/boot: Define setup size in linker script From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Evgeniy Baskov , Borislav Petkov , Dave Hansen , Ingo Molnar , Thomas Gleixner , Peter Jones , Matthew Garrett , Gerd Hoffmann , Kees Cook , "H. Peter Anvin" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Fri, 15 Sep 2023 10:18:01 -0700 (PDT) From: Ard Biesheuvel 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 --- 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 72744ba440f6..06bd72a324c1 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 b11c45b9e51e..9bd5c1ada599 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 069497543164..745d64b6d930 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)); -- 2.42.0.459.ge4e396fd5e-goog