Skip to content

Commit 2b95bb0

Browse files
committed
Merge tag 'x86-boot-2023-10-28' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 boot updates from Ingo Molnar: - Rework PE header generation, primarily to generate a modern, 4k aligned kernel image view with narrower W^X permissions. - Further refine init-lifetime annotations - Misc cleanups & fixes * tag 'x86-boot-2023-10-28' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (23 commits) x86/boot: efistub: Assign global boot_params variable x86/boot: Rename conflicting 'boot_params' pointer to 'boot_params_ptr' x86/head/64: Move the __head definition to <asm/init.h> x86/head/64: Add missing __head annotation to startup_64_load_idt() x86/head/64: Mark 'startup_gdt[]' and 'startup_gdt_descr' as __initdata x86/boot: Harmonize the style of array-type parameter for fixup_pointer() calls x86/boot: Fix incorrect startup_gdt_descr.size x86/boot: Compile boot code with -std=gnu11 too x86/boot: Increase section and file alignment to 4k/512 x86/boot: Split off PE/COFF .data section x86/boot: Drop PE/COFF .reloc section x86/boot: Construct PE/COFF .text section from assembler x86/boot: Derive file size from _edata symbol x86/boot: Define setup size in linker script x86/boot: Set EFI handover offset directly in header asm x86/boot: Grab kernel_info offset from zoffset header directly x86/boot: Drop references to startup_64 x86/boot: Drop redundant code setting the root device x86/boot: Omit compression buffer from PE/COFF image memory footprint x86/boot: Remove the 'bugger off' message ...
2 parents 3b8b4b4 + 50dcc2e commit 2b95bb0

File tree

21 files changed

+174
-507
lines changed

21 files changed

+174
-507
lines changed

arch/x86/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ endif
4343

4444
# How to compile the 16-bit code. Note we always compile for -march=i386;
4545
# that way we can complain to the user if the CPU is insufficient.
46-
REALMODE_CFLAGS := -m16 -g -Os -DDISABLE_BRANCH_PROFILING -D__DISABLE_EXPORTS \
46+
REALMODE_CFLAGS := -std=gnu11 -m16 -g -Os -DDISABLE_BRANCH_PROFILING -D__DISABLE_EXPORTS \
4747
-Wall -Wstrict-prototypes -march=i386 -mregparm=3 \
4848
-fno-strict-aliasing -fomit-frame-pointer -fno-pic \
4949
-mno-mmx -mno-sse $(call cc-option,-fcf-protection=none)

arch/x86/boot/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ $(obj)/vmlinux.bin: $(obj)/compressed/vmlinux FORCE
8989

9090
SETUP_OBJS = $(addprefix $(obj)/,$(setup-y))
9191

92-
sed-zoffset := -e 's/^\([0-9a-fA-F]*\) [a-zA-Z] \(startup_32\|startup_64\|efi32_stub_entry\|efi64_stub_entry\|efi_pe_entry\|efi32_pe_entry\|input_data\|kernel_info\|_end\|_ehead\|_text\|z_.*\)$$/\#define ZO_\2 0x\1/p'
92+
sed-zoffset := -e 's/^\([0-9a-fA-F]*\) [a-zA-Z] \(startup_32\|efi.._stub_entry\|efi\(32\)\?_pe_entry\|input_data\|kernel_info\|_end\|_ehead\|_text\|_e\?data\|z_.*\)$$/\#define ZO_\2 0x\1/p'
9393

9494
quiet_cmd_zoffset = ZOFFSET $@
9595
cmd_zoffset = $(NM) $< | sed -n $(sed-zoffset) > $@

arch/x86/boot/compressed/acpi.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ __efi_get_rsdp_addr(unsigned long cfg_tbl_pa, unsigned int cfg_tbl_len)
3030
* Search EFI system tables for RSDP. Preferred is ACPI_20_TABLE_GUID to
3131
* ACPI_TABLE_GUID because it has more features.
3232
*/
33-
rsdp_addr = efi_find_vendor_table(boot_params, cfg_tbl_pa, cfg_tbl_len,
33+
rsdp_addr = efi_find_vendor_table(boot_params_ptr, cfg_tbl_pa, cfg_tbl_len,
3434
ACPI_20_TABLE_GUID);
3535
if (rsdp_addr)
3636
return (acpi_physical_address)rsdp_addr;
3737

3838
/* No ACPI_20_TABLE_GUID found, fallback to ACPI_TABLE_GUID. */
39-
rsdp_addr = efi_find_vendor_table(boot_params, cfg_tbl_pa, cfg_tbl_len,
39+
rsdp_addr = efi_find_vendor_table(boot_params_ptr, cfg_tbl_pa, cfg_tbl_len,
4040
ACPI_TABLE_GUID);
4141
if (rsdp_addr)
4242
return (acpi_physical_address)rsdp_addr;
@@ -56,15 +56,15 @@ static acpi_physical_address efi_get_rsdp_addr(void)
5656
enum efi_type et;
5757
int ret;
5858

59-
et = efi_get_type(boot_params);
59+
et = efi_get_type(boot_params_ptr);
6060
if (et == EFI_TYPE_NONE)
6161
return 0;
6262

63-
systab_pa = efi_get_system_table(boot_params);
63+
systab_pa = efi_get_system_table(boot_params_ptr);
6464
if (!systab_pa)
6565
error("EFI support advertised, but unable to locate system table.");
6666

67-
ret = efi_get_conf_table(boot_params, &cfg_tbl_pa, &cfg_tbl_len);
67+
ret = efi_get_conf_table(boot_params_ptr, &cfg_tbl_pa, &cfg_tbl_len);
6868
if (ret || !cfg_tbl_pa)
6969
error("EFI config table not found.");
7070

@@ -156,7 +156,7 @@ acpi_physical_address get_rsdp_addr(void)
156156
{
157157
acpi_physical_address pa;
158158

159-
pa = boot_params->acpi_rsdp_addr;
159+
pa = boot_params_ptr->acpi_rsdp_addr;
160160

161161
if (!pa)
162162
pa = efi_get_rsdp_addr();
@@ -210,7 +210,7 @@ static unsigned long get_acpi_srat_table(void)
210210
rsdp = (struct acpi_table_rsdp *)get_cmdline_acpi_rsdp();
211211
if (!rsdp)
212212
rsdp = (struct acpi_table_rsdp *)(long)
213-
boot_params->acpi_rsdp_addr;
213+
boot_params_ptr->acpi_rsdp_addr;
214214

215215
if (!rsdp)
216216
return 0;

arch/x86/boot/compressed/cmdline.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ static inline char rdfs8(addr_t addr)
1414
#include "../cmdline.c"
1515
unsigned long get_cmd_line_ptr(void)
1616
{
17-
unsigned long cmd_line_ptr = boot_params->hdr.cmd_line_ptr;
17+
unsigned long cmd_line_ptr = boot_params_ptr->hdr.cmd_line_ptr;
1818

19-
cmd_line_ptr |= (u64)boot_params->ext_cmd_line_ptr << 32;
19+
cmd_line_ptr |= (u64)boot_params_ptr->ext_cmd_line_ptr << 32;
2020

2121
return cmd_line_ptr;
2222
}

arch/x86/boot/compressed/ident_map_64.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,17 @@ void initialize_identity_maps(void *rmode)
159159
* or does not touch all the pages covering them.
160160
*/
161161
kernel_add_identity_map((unsigned long)_head, (unsigned long)_end);
162-
boot_params = rmode;
163-
kernel_add_identity_map((unsigned long)boot_params, (unsigned long)(boot_params + 1));
162+
boot_params_ptr = rmode;
163+
kernel_add_identity_map((unsigned long)boot_params_ptr,
164+
(unsigned long)(boot_params_ptr + 1));
164165
cmdline = get_cmd_line_ptr();
165166
kernel_add_identity_map(cmdline, cmdline + COMMAND_LINE_SIZE);
166167

167168
/*
168169
* Also map the setup_data entries passed via boot_params in case they
169170
* need to be accessed by uncompressed kernel via the identity mapping.
170171
*/
171-
sd = (struct setup_data *)boot_params->hdr.setup_data;
172+
sd = (struct setup_data *)boot_params_ptr->hdr.setup_data;
172173
while (sd) {
173174
unsigned long sd_addr = (unsigned long)sd;
174175

arch/x86/boot/compressed/kaslr.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static unsigned long get_boot_seed(void)
6363
unsigned long hash = 0;
6464

6565
hash = rotate_xor(hash, build_str, sizeof(build_str));
66-
hash = rotate_xor(hash, boot_params, sizeof(*boot_params));
66+
hash = rotate_xor(hash, boot_params_ptr, sizeof(*boot_params_ptr));
6767

6868
return hash;
6969
}
@@ -383,7 +383,7 @@ static void handle_mem_options(void)
383383
static void mem_avoid_init(unsigned long input, unsigned long input_size,
384384
unsigned long output)
385385
{
386-
unsigned long init_size = boot_params->hdr.init_size;
386+
unsigned long init_size = boot_params_ptr->hdr.init_size;
387387
u64 initrd_start, initrd_size;
388388
unsigned long cmd_line, cmd_line_size;
389389

@@ -395,10 +395,10 @@ static void mem_avoid_init(unsigned long input, unsigned long input_size,
395395
mem_avoid[MEM_AVOID_ZO_RANGE].size = (output + init_size) - input;
396396

397397
/* Avoid initrd. */
398-
initrd_start = (u64)boot_params->ext_ramdisk_image << 32;
399-
initrd_start |= boot_params->hdr.ramdisk_image;
400-
initrd_size = (u64)boot_params->ext_ramdisk_size << 32;
401-
initrd_size |= boot_params->hdr.ramdisk_size;
398+
initrd_start = (u64)boot_params_ptr->ext_ramdisk_image << 32;
399+
initrd_start |= boot_params_ptr->hdr.ramdisk_image;
400+
initrd_size = (u64)boot_params_ptr->ext_ramdisk_size << 32;
401+
initrd_size |= boot_params_ptr->hdr.ramdisk_size;
402402
mem_avoid[MEM_AVOID_INITRD].start = initrd_start;
403403
mem_avoid[MEM_AVOID_INITRD].size = initrd_size;
404404
/* No need to set mapping for initrd, it will be handled in VO. */
@@ -413,8 +413,8 @@ static void mem_avoid_init(unsigned long input, unsigned long input_size,
413413
}
414414

415415
/* Avoid boot parameters. */
416-
mem_avoid[MEM_AVOID_BOOTPARAMS].start = (unsigned long)boot_params;
417-
mem_avoid[MEM_AVOID_BOOTPARAMS].size = sizeof(*boot_params);
416+
mem_avoid[MEM_AVOID_BOOTPARAMS].start = (unsigned long)boot_params_ptr;
417+
mem_avoid[MEM_AVOID_BOOTPARAMS].size = sizeof(*boot_params_ptr);
418418

419419
/* We don't need to set a mapping for setup_data. */
420420

@@ -447,7 +447,7 @@ static bool mem_avoid_overlap(struct mem_vector *img,
447447
}
448448

449449
/* Avoid all entries in the setup_data linked list. */
450-
ptr = (struct setup_data *)(unsigned long)boot_params->hdr.setup_data;
450+
ptr = (struct setup_data *)(unsigned long)boot_params_ptr->hdr.setup_data;
451451
while (ptr) {
452452
struct mem_vector avoid;
453453

@@ -706,7 +706,7 @@ static inline bool memory_type_is_free(efi_memory_desc_t *md)
706706
static bool
707707
process_efi_entries(unsigned long minimum, unsigned long image_size)
708708
{
709-
struct efi_info *e = &boot_params->efi_info;
709+
struct efi_info *e = &boot_params_ptr->efi_info;
710710
bool efi_mirror_found = false;
711711
struct mem_vector region;
712712
efi_memory_desc_t *md;
@@ -777,8 +777,8 @@ static void process_e820_entries(unsigned long minimum,
777777
struct boot_e820_entry *entry;
778778

779779
/* Verify potential e820 positions, appending to slots list. */
780-
for (i = 0; i < boot_params->e820_entries; i++) {
781-
entry = &boot_params->e820_table[i];
780+
for (i = 0; i < boot_params_ptr->e820_entries; i++) {
781+
entry = &boot_params_ptr->e820_table[i];
782782
/* Skip non-RAM entries. */
783783
if (entry->type != E820_TYPE_RAM)
784784
continue;
@@ -852,7 +852,7 @@ void choose_random_location(unsigned long input,
852852
return;
853853
}
854854

855-
boot_params->hdr.loadflags |= KASLR_FLAG;
855+
boot_params_ptr->hdr.loadflags |= KASLR_FLAG;
856856

857857
if (IS_ENABLED(CONFIG_X86_32))
858858
mem_limit = KERNEL_IMAGE_SIZE;

arch/x86/boot/compressed/mem.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,17 @@ bool init_unaccepted_memory(void)
5454
enum efi_type et;
5555
int ret;
5656

57-
et = efi_get_type(boot_params);
57+
et = efi_get_type(boot_params_ptr);
5858
if (et == EFI_TYPE_NONE)
5959
return false;
6060

61-
ret = efi_get_conf_table(boot_params, &cfg_table_pa, &cfg_table_len);
61+
ret = efi_get_conf_table(boot_params_ptr, &cfg_table_pa, &cfg_table_len);
6262
if (ret) {
6363
warn("EFI config table not found.");
6464
return false;
6565
}
6666

67-
table = (void *)efi_find_vendor_table(boot_params, cfg_table_pa,
67+
table = (void *)efi_find_vendor_table(boot_params_ptr, cfg_table_pa,
6868
cfg_table_len, guid);
6969
if (!table)
7070
return false;

arch/x86/boot/compressed/misc.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void *memmove(void *dest, const void *src, size_t n);
4646
/*
4747
* This is set up by the setup-routine at boot-time
4848
*/
49-
struct boot_params *boot_params;
49+
struct boot_params *boot_params_ptr;
5050

5151
struct port_io_ops pio_ops;
5252

@@ -132,8 +132,8 @@ void __putstr(const char *s)
132132
if (lines == 0 || cols == 0)
133133
return;
134134

135-
x = boot_params->screen_info.orig_x;
136-
y = boot_params->screen_info.orig_y;
135+
x = boot_params_ptr->screen_info.orig_x;
136+
y = boot_params_ptr->screen_info.orig_y;
137137

138138
while ((c = *s++) != '\0') {
139139
if (c == '\n') {
@@ -154,8 +154,8 @@ void __putstr(const char *s)
154154
}
155155
}
156156

157-
boot_params->screen_info.orig_x = x;
158-
boot_params->screen_info.orig_y = y;
157+
boot_params_ptr->screen_info.orig_x = x;
158+
boot_params_ptr->screen_info.orig_y = y;
159159

160160
pos = (x + cols * y) * 2; /* Update cursor position */
161161
outb(14, vidport);
@@ -382,23 +382,23 @@ asmlinkage __visible void *extract_kernel(void *rmode, unsigned char *output)
382382
size_t entry_offset;
383383

384384
/* Retain x86 boot parameters pointer passed from startup_32/64. */
385-
boot_params = rmode;
385+
boot_params_ptr = rmode;
386386

387387
/* Clear flags intended for solely in-kernel use. */
388-
boot_params->hdr.loadflags &= ~KASLR_FLAG;
388+
boot_params_ptr->hdr.loadflags &= ~KASLR_FLAG;
389389

390-
sanitize_boot_params(boot_params);
390+
sanitize_boot_params(boot_params_ptr);
391391

392-
if (boot_params->screen_info.orig_video_mode == 7) {
392+
if (boot_params_ptr->screen_info.orig_video_mode == 7) {
393393
vidmem = (char *) 0xb0000;
394394
vidport = 0x3b4;
395395
} else {
396396
vidmem = (char *) 0xb8000;
397397
vidport = 0x3d4;
398398
}
399399

400-
lines = boot_params->screen_info.orig_video_lines;
401-
cols = boot_params->screen_info.orig_video_cols;
400+
lines = boot_params_ptr->screen_info.orig_video_lines;
401+
cols = boot_params_ptr->screen_info.orig_video_cols;
402402

403403
init_default_io_ops();
404404

@@ -417,7 +417,7 @@ asmlinkage __visible void *extract_kernel(void *rmode, unsigned char *output)
417417
* so that early debugging output from the RSDP parsing code can be
418418
* collected.
419419
*/
420-
boot_params->acpi_rsdp_addr = get_rsdp_addr();
420+
boot_params_ptr->acpi_rsdp_addr = get_rsdp_addr();
421421

422422
debug_putstr("early console in extract_kernel\n");
423423

arch/x86/boot/compressed/misc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ extern memptr free_mem_ptr;
6161
extern memptr free_mem_end_ptr;
6262
void *malloc(int size);
6363
void free(void *where);
64-
extern struct boot_params *boot_params;
6564
void __putstr(const char *s);
6665
void __puthex(unsigned long value);
6766
#define error_putstr(__x) __putstr(__x)

arch/x86/boot/compressed/pgtable_64.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ static char trampoline_save[TRAMPOLINE_32BIT_SIZE];
2828
*/
2929
unsigned long *trampoline_32bit __section(".data");
3030

31-
extern struct boot_params *boot_params;
3231
int cmdline_find_option_bool(const char *option);
3332

3433
static unsigned long find_trampoline_placement(void)
@@ -49,7 +48,7 @@ static unsigned long find_trampoline_placement(void)
4948
*
5049
* Only look for values in the legacy ROM for non-EFI system.
5150
*/
52-
signature = (char *)&boot_params->efi_info.efi_loader_signature;
51+
signature = (char *)&boot_params_ptr->efi_info.efi_loader_signature;
5352
if (strncmp(signature, EFI32_LOADER_SIGNATURE, 4) &&
5453
strncmp(signature, EFI64_LOADER_SIGNATURE, 4)) {
5554
ebda_start = *(unsigned short *)0x40e << 4;
@@ -65,10 +64,10 @@ static unsigned long find_trampoline_placement(void)
6564
bios_start = round_down(bios_start, PAGE_SIZE);
6665

6766
/* Find the first usable memory region under bios_start. */
68-
for (i = boot_params->e820_entries - 1; i >= 0; i--) {
67+
for (i = boot_params_ptr->e820_entries - 1; i >= 0; i--) {
6968
unsigned long new = bios_start;
7069

71-
entry = &boot_params->e820_table[i];
70+
entry = &boot_params_ptr->e820_table[i];
7271

7372
/* Skip all entries above bios_start. */
7473
if (bios_start <= entry->addr)
@@ -107,7 +106,7 @@ asmlinkage void configure_5level_paging(struct boot_params *bp, void *pgtable)
107106
bool l5_required = false;
108107

109108
/* Initialize boot_params. Required for cmdline_find_option_bool(). */
110-
boot_params = bp;
109+
boot_params_ptr = bp;
111110

112111
/*
113112
* Check if LA57 is desired and supported.

0 commit comments

Comments
 (0)