From: "H. Peter Anvin" <hpa@zytor.com>
To: Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
Uros Bizjak <ubizjak@gmail.com>, Petr Mladek <pmladek@suse.com>,
Andrew Morton <akpm@linux-foundation.org>,
Kees Cook <kees@kernel.org>,
"Peter Zijlstra (Intel)" <peterz@infradead.org>,
Nathan Chancellor <nathan@kernel.org>,
Kiryl Shutsemau <kas@kernel.org>,
Rick Edgecombe <rick.p.edgecombe@intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>,
linux-kernel@vger.kernel.org, linux-coco@lists.linux.dev,
x86@kernel.org
Subject: [PATCH v1 04/14] x86/boot: modernize the segment structure for the header and setup
Date: Tue, 20 Jan 2026 11:53:56 -0800 [thread overview]
Message-ID: <20260120195407.1163051-5-hpa@zytor.com> (raw)
In-Reply-To: <20260120195407.1163051-1-hpa@zytor.com>
Modernize the segment structure for the EFI and bzImage headers and
the 16-bit setup.
1. The ".bstext" section (EFI header) has not had code in it for a
while now. Merge it into the .header section.
2. Move the contents of the .signature section to assembly rather than
the linker script. As a side benefit, the magic number is now
private to header.S.
3. Add additional asserts to the linker script.
4. Fill gaps in code sections with int3 instead of nop.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
---
| 27 +++++++++++++++++++--------
arch/x86/boot/setup.ld | 26 ++++++++++++--------------
2 files changed, 31 insertions(+), 22 deletions(-)
--git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
index bda20395658f..85a21d576f5b 100644
--- a/arch/x86/boot/header.S
+++ b/arch/x86/boot/header.S
@@ -40,7 +40,7 @@ SYSSEG = 0x1000 /* historical load address >> 4 */
.set falign, 0x200
.code16
- .section ".bstext", "ax"
+ .section ".header", "a"
#ifdef CONFIG_EFI_STUB
# "MZ", MS-DOS header
.word IMAGE_DOS_SIGNATURE
@@ -221,15 +221,16 @@ pecompat_fstart:
IMAGE_SCN_MEM_WRITE # Characteristics
.set section_count, (. - section_table) / 40
+
#endif /* CONFIG_EFI_STUB */
- # Kernel attributes; used by setup. This is part 1 of the
- # header, from the old boot sector.
+ # hdr should be at address 0x1f1; -2 for the sentinel
+ .org 0x1f1-2, 0xff # Fill with 0xff
- .section ".header", "a"
.globl sentinel
sentinel: .byte 0xff, 0xff /* Used to detect broken loaders */
+ # The bzImage struct setup_header
.globl hdr
hdr:
.byte setup_sects - 1
@@ -240,15 +241,15 @@ vid_mode: .word SVGA_MODE
root_dev: .word 0 /* Default to major/minor 0/0 */
boot_flag: .word 0xAA55
- # offset 512, entry point
+ # offset 512, entry point AND struct setup_header length marker
.globl _start
_start:
# Explicitly enter this as bytes, or the assembler
- # tries to generate a 3-byte jump here, which causes
+ # might try to generate a 3-byte jump here, which causes
# everything else to push off to the wrong offset.
.byte 0xeb # short (2-byte) jump
- .byte start_of_setup-1f
+ .byte end_of_bzheader-1f
1:
# Part 2 of the header, from the old setup.S
@@ -541,9 +542,13 @@ init_size: .long INIT_SIZE # kernel initialization size
handover_offset: __handover_offset
kernel_info_offset: .long ZO_kernel_info
+ .globl end_of_bzheader
+end_of_bzheader:
+
# End of setup header #####################################################
.section ".entrytext", "ax"
+ .globl start_of_setup
start_of_setup:
# Force %es = %ds
movw %ds, %ax
@@ -585,7 +590,8 @@ start_of_setup:
6:
# Check signature at end of setup
- cmpl $0x5a5aaa55, setup_sig
+SETUP_SIGNATURE = 0x5a5aaa55
+ cmpl $SETUP_SIGNATURE, setup_sig
jne setup_bad
# Zero the bss
@@ -620,3 +626,8 @@ die:
setup_corrupt:
.byte 7
.string "No setup signature found...\n"
+
+ .section ".signature", "a"
+ .balign 4
+setup_sig:
+ .long SETUP_SIGNATURE
diff --git a/arch/x86/boot/setup.ld b/arch/x86/boot/setup.ld
index e1d594a60204..7515ab011783 100644
--- a/arch/x86/boot/setup.ld
+++ b/arch/x86/boot/setup.ld
@@ -10,19 +10,14 @@ ENTRY(_start)
SECTIONS
{
. = 0;
- .bstext : {
- *(.bstext)
- . = 495;
- } =0xffffffff
-
.header : { *(.header) }
- .entrytext : { *(.entrytext) }
- .inittext : { *(.inittext) }
+ .entrytext : { *(.entrytext) } = 0xcccccccc
+ .inittext : { *(.inittext) } = 0xcccccccc
.initdata : { *(.initdata) }
__end_init = .;
- .text : { *(.text .text.*) }
- .text32 : { *(.text32) }
+ .text : { *(.text .text.*) } = 0xcccccccc
+ .text32 : { *(.text32) } = 0xcccccccc
.pecompat : { *(.pecompat) }
PROVIDE(pecompat_fsize = setup_size - pecompat_fstart);
@@ -40,9 +35,7 @@ SECTIONS
.data : { *(.data*) }
.signature : {
- setup_sig = .;
- LONG(0x5a5aaa55)
-
+ *(.signature)
setup_size = ALIGN(ABSOLUTE(.), 4096);
setup_sects = ABSOLUTE(setup_size / 512);
ASSERT(setup_sects >= 5, "The setup must be at least 5 sectors in size");
@@ -64,11 +57,16 @@ SECTIONS
}
/*
- * The ASSERT() sink to . is intentional, for binutils 2.14 compatibility:
+ * The ASSERT() sink to . is intentional. A bare ASSERT()
+ * outside of an output section is believed to have been broken
+ * in some binutils versions, although it is supposed to have
+ * been supported since binutils 2.15. Either way, it doesn't hurt,
+ * so there is no reason to drop it.
*/
. = ASSERT(_end <= 0x8000, "Setup too big!");
. = ASSERT(hdr == 0x1f1, "The setup header has the wrong offset!");
+ . = ASSERT(end_of_bzheader <= 512+2+127, "bzImage header overflow!");
+ . = ASSERT(end_of_bzheader == start_of_setup, "padding bytes between .bzheader and .entrytext!");
/* Necessary for the very-old-loader check to work... */
. = ASSERT(__end_init <= 5*512, "init sections too big!");
-
}
--
2.52.0
next prev parent reply other threads:[~2026-01-20 19:55 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260119192923.651588-1-hpa@zytor.com>
2026-01-20 19:53 ` [PATCH v1 00/14] x86 boot code cleanups, batch 1 H. Peter Anvin
2026-01-20 19:53 ` [PATCH v1 01/14] x86/realmode: remove I/O port paravirtualization H. Peter Anvin
2026-01-20 21:47 ` David Laight
2026-01-21 12:27 ` Kiryl Shutsemau
2026-01-28 17:01 ` Borislav Petkov
2026-01-20 19:53 ` [PATCH v1 02/14] x86/realmode: make %gs == 0 an invariant H. Peter Anvin
2026-01-20 22:40 ` David Laight
2026-01-20 22:51 ` H. Peter Anvin
2026-01-21 0:47 ` H. Peter Anvin
2026-01-21 10:03 ` Uros Bizjak
2026-01-20 19:53 ` [PATCH v1 03/14] x86/boot: use <linux/compiler.h> H. Peter Anvin
2026-01-21 10:04 ` Uros Bizjak
2026-01-20 19:53 ` H. Peter Anvin [this message]
2026-01-20 19:53 ` [PATCH v1 05/14] x86/boot: call puts() from within die() H. Peter Anvin
2026-01-21 10:07 ` Uros Bizjak
2026-01-20 19:53 ` [PATCH v1 06/14] x86/boot: add comment barriers for the different headers H. Peter Anvin
2026-01-20 19:53 ` [PATCH v1 07/14] x86/boot: factor out the 16-bit startup code from header.S H. Peter Anvin
2026-01-21 10:08 ` Uros Bizjak
2026-01-20 19:54 ` [PATCH v1 08/14] x86: make CONFIG_EFI_STUB unconditional H. Peter Anvin
2026-01-20 19:54 ` [PATCH v1 09/14] x86/boot: make the relocatable kernel unconditional H. Peter Anvin
2026-01-20 19:54 ` [PATCH v1 10/14] x86/boot: explicitly put the old command line pointer in header.S H. Peter Anvin
2026-01-20 19:54 ` [PATCH v1 11/14] x86/boot: use __seg_fs and __seg_gs in the real-mode boot code H. Peter Anvin
2026-01-21 8:56 ` Uros Bizjak
2026-01-21 9:40 ` Uros Bizjak
2026-01-21 15:13 ` H. Peter Anvin
2026-01-21 16:03 ` Uros Bizjak
2026-01-22 18:57 ` [PATCH v1 08/14] x86: make CONFIG_EFI_STUB unconditional Simon Glass
2026-01-23 0:11 ` H. Peter Anvin
2026-01-26 21:19 ` Simon Glass
2026-01-26 22:20 ` H. Peter Anvin
2026-01-27 1:44 ` Simon Glass
2026-01-27 2:39 ` H. Peter Anvin
2026-01-27 2:54 ` H. Peter Anvin
2026-01-27 3:14 ` Simon Glass
2026-01-27 3:21 ` H. Peter Anvin
2026-01-29 22:13 ` Simon Glass
2026-01-29 22:22 ` H. Peter Anvin
2026-01-21 16:07 ` [PATCH v1 11/14] x86/boot: use __seg_fs and __seg_gs in the real-mode boot code Uros Bizjak
2026-01-20 19:54 ` [PATCH v1 12/14] x86/boot: tweak a20.c for better code generation H. Peter Anvin
2026-01-21 10:10 ` Uros Bizjak
2026-01-21 11:49 ` David Laight
2026-01-24 3:00 ` Maciej W. Rozycki
2026-01-24 4:24 ` H. Peter Anvin
2026-01-24 23:07 ` David Laight
2026-01-24 23:16 ` H. Peter Anvin
2026-01-24 23:40 ` H. Peter Anvin
2026-01-20 19:54 ` [PATCH v1 13/14] x86/boot: simplify x86/boot/cmdline.c by using __seg_fs H. Peter Anvin
2026-01-21 10:11 ` Uros Bizjak
2026-01-20 19:54 ` [PATCH v1 14/14] compiler-gcc: Remove obsolete RELOC_HIDE() macro H. Peter Anvin
2026-01-21 10:18 ` [PATCH v1 00/14] x86 boot code cleanups, batch 1 Uros Bizjak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260120195407.1163051-5-hpa@zytor.com \
--to=hpa@zytor.com \
--cc=akpm@linux-foundation.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=kas@kernel.org \
--cc=kees@kernel.org \
--cc=linux-coco@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=nathan@kernel.org \
--cc=peterz@infradead.org \
--cc=pmladek@suse.com \
--cc=rick.p.edgecombe@intel.com \
--cc=tglx@kernel.org \
--cc=ubizjak@gmail.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®