Skip to content

Commit 37ba7ab

Browse files
author
H. Peter Anvin
committed
x86, boot: make kernel_alignment adjustable; new bzImage fields
Make the kernel_alignment field adjustable; this allows us to set it to a large value (intended to be 16 MB to avoid ZONE_DMA contention, memory holes and other weirdness) while a smart bootloader can still force a loading at a lesser alignment if absolutely necessary. Also export pref_address (preferred loading address, corresponding to the link-time address) and init_size, the total amount of linear memory the kernel will require during initialization. [ Impact: allows better kernel placement, gives bootloader more info ] Signed-off-by: H. Peter Anvin <[email protected]>
1 parent 99aa455 commit 37ba7ab

File tree

6 files changed

+45
-8
lines changed

6 files changed

+45
-8
lines changed

arch/x86/boot/compressed/head_32.S

+5-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,11 @@ ENTRY(startup_32)
6969

7070
#ifdef CONFIG_RELOCATABLE
7171
movl %ebp, %ebx
72-
addl $(CONFIG_PHYSICAL_ALIGN - 1), %ebx
73-
andl $(~(CONFIG_PHYSICAL_ALIGN - 1)), %ebx
72+
movl BP_kernel_alignment(%esi), %eax
73+
decl %eax
74+
addl %eax, %ebx
75+
notl %eax
76+
andl %eax, %ebx
7477
#else
7578
movl $LOAD_PHYSICAL_ADDR, %ebx
7679
#endif

arch/x86/boot/compressed/head_64.S

+10-4
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,11 @@ ENTRY(startup_32)
8484

8585
#ifdef CONFIG_RELOCATABLE
8686
movl %ebp, %ebx
87-
addl $(PMD_PAGE_SIZE -1), %ebx
88-
andl $PMD_PAGE_MASK, %ebx
87+
movl BP_kernel_alignment(%esi), %eax
88+
decl %eax
89+
addl %eax, %ebx
90+
notl %eax
91+
andl %eax, %ebx
8992
#else
9093
movl $LOAD_PHYSICAL_ADDR, %ebx
9194
#endif
@@ -224,8 +227,11 @@ ENTRY(startup_64)
224227
/* Start with the delta to where the kernel will run at. */
225228
#ifdef CONFIG_RELOCATABLE
226229
leaq startup_32(%rip) /* - $startup_32 */, %rbp
227-
addq $(PMD_PAGE_SIZE - 1), %rbp
228-
andq $PMD_PAGE_MASK, %rbp
230+
movl BP_kernel_alignment(%rsi), %eax
231+
decl %eax
232+
addq %rax, %rbp
233+
notq %rax
234+
andq %rax, %rbp
229235
#else
230236
movq $LOAD_PHYSICAL_ADDR, %rbp
231237
#endif

arch/x86/boot/header.S

+13-2
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ _start:
116116
# Part 2 of the header, from the old setup.S
117117

118118
.ascii "HdrS" # header signature
119-
.word 0x0209 # header version number (>= 0x0105)
119+
.word 0x020a # header version number (>= 0x0105)
120120
# or else old loadlin-1.5 will fail)
121121
.globl realmode_swtch
122122
realmode_swtch: .word 0, 0 # default_switch, SETUPSEG
@@ -201,7 +201,7 @@ relocatable_kernel: .byte 1
201201
#else
202202
relocatable_kernel: .byte 0
203203
#endif
204-
pad2: .byte 0
204+
min_alignment: .byte MIN_KERNEL_ALIGN_LG2 # minimum alignment
205205
pad3: .word 0
206206

207207
cmdline_size: .long COMMAND_LINE_SIZE-1 #length of the command line,
@@ -220,6 +220,17 @@ setup_data: .quad 0 # 64-bit physical pointer to
220220
# single linked list of
221221
# struct setup_data
222222

223+
pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
224+
225+
#define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_extract_offset)
226+
#define VO_INIT_SIZE (VO__end - VO__text)
227+
#if ZO_INIT_SIZE > VO_INIT_SIZE
228+
#define INIT_SIZE ZO_INIT_SIZE
229+
#else
230+
#define INIT_SIZE VO_INIT_SIZE
231+
#endif
232+
init_size: .long INIT_SIZE # kernel initialization size
233+
223234
# End of setup header #####################################################
224235

225236
.section ".inittext", "ax"

arch/x86/include/asm/boot.h

+15
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,26 @@
88

99
#ifdef __KERNEL__
1010

11+
#include <asm/page_types.h>
12+
1113
/* Physical address where kernel should be loaded. */
1214
#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
1315
+ (CONFIG_PHYSICAL_ALIGN - 1)) \
1416
& ~(CONFIG_PHYSICAL_ALIGN - 1))
1517

18+
/* Minimum kernel alignment, as a power of two */
19+
#ifdef CONFIG_x86_64
20+
#define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
21+
#else
22+
#define MIN_KERNEL_ALIGN_LG2 (PAGE_SHIFT+1)
23+
#endif
24+
#define MIN_KERNEL_ALIGN (_AC(1, UL) << MIN_KERNEL_ALIGN_LG2)
25+
26+
#if (CONFIG_PHYSICAL_ALIGN & (CONFIG_PHYSICAL_ALIGN-1)) || \
27+
(CONFIG_PHYSICAL_ALIGN < (_AC(1, UL) << MIN_KERNEL_ALIGN_LG2))
28+
#error "Invalid value for CONFIG_PHYSICAL_ALIGN"
29+
#endif
30+
1631
#ifdef CONFIG_KERNEL_BZIP2
1732
#define BOOT_HEAP_SIZE 0x400000
1833
#else /* !CONFIG_KERNEL_BZIP2 */

arch/x86/kernel/asm-offsets_32.c

+1
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,5 @@ void foo(void)
146146
OFFSET(BP_loadflags, boot_params, hdr.loadflags);
147147
OFFSET(BP_hardware_subarch, boot_params, hdr.hardware_subarch);
148148
OFFSET(BP_version, boot_params, hdr.version);
149+
OFFSET(BP_kernel_alignment, boot_params, hdr.kernel_alignment);
149150
}

arch/x86/kernel/asm-offsets_64.c

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ int main(void)
125125
OFFSET(BP_loadflags, boot_params, hdr.loadflags);
126126
OFFSET(BP_hardware_subarch, boot_params, hdr.hardware_subarch);
127127
OFFSET(BP_version, boot_params, hdr.version);
128+
OFFSET(BP_kernel_alignment, boot_params, hdr.kernel_alignment);
128129

129130
BLANK();
130131
DEFINE(PAGE_SIZE_asm, PAGE_SIZE);

0 commit comments

Comments
 (0)