Skip to content

Commit 28bb223

Browse files
yhluIngo Molnar
authored andcommitted
x86: move reserve_setup_data to setup.c
Ying Huang would like setup_data to be reserved, but not included in the no save range. Here we try to modify the e820 table to reserve that range early. also add that in early_res in case bootloader messes up with the ramdisk. other solution would be 1. add early_res_to_highmem... 2. early_res_to_e820... but they could reserve another type memory wrongly, if early_res has some resource reserved early, and not needed later, but it is not removed from early_res in time. Like the RAMDISK (already handled). Signed-off-by: Yinghai Lu <yhlu.kernel@gmail.com> Cc: andi@firstfloor.org Tested-by: Huang, Ying <ying.huang@intel.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent 102d0a4 commit 28bb223

File tree

6 files changed

+34
-28
lines changed

6 files changed

+34
-28
lines changed

arch/x86/kernel/e820.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ void __init e820_print_map(char *who)
120120
(e820.map[i].addr + e820.map[i].size));
121121
switch (e820.map[i].type) {
122122
case E820_RAM:
123+
case E820_RESERVED_KERN:
123124
printk(KERN_CONT "(usable)\n");
124125
break;
125126
case E820_RESERVED:
@@ -611,7 +612,7 @@ void __init e820_mark_nosave_regions(unsigned long limit_pfn)
611612
register_nosave_region(pfn, PFN_UP(ei->addr));
612613

613614
pfn = PFN_DOWN(ei->addr + ei->size);
614-
if (ei->type != E820_RAM)
615+
if (ei->type != E820_RAM && ei->type != E820_RESERVED_KERN)
615616
register_nosave_region(PFN_UP(ei->addr), pfn);
616617

617618
if (pfn >= limit_pfn)
@@ -1207,6 +1208,7 @@ void __init e820_reserve_resources(void)
12071208
res = alloc_bootmem_low(sizeof(struct resource) * e820.nr_map);
12081209
for (i = 0; i < e820.nr_map; i++) {
12091210
switch (e820.map[i].type) {
1211+
case E820_RESERVED_KERN:
12101212
case E820_RAM: res->name = "System RAM"; break;
12111213
case E820_ACPI: res->name = "ACPI Tables"; break;
12121214
case E820_NVS: res->name = "ACPI Non-volatile Storage"; break;

arch/x86/kernel/head.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,3 @@ void __init reserve_ebda_region(void)
5353
/* reserve all memory between lowmem and the 1MB mark */
5454
reserve_early_overlap_ok(lowmem, 0x100000, "BIOS reserved");
5555
}
56-
57-
void __init reserve_setup_data(void)
58-
{
59-
struct setup_data *data;
60-
u64 pa_data;
61-
char buf[32];
62-
63-
if (boot_params.hdr.version < 0x0209)
64-
return;
65-
pa_data = boot_params.hdr.setup_data;
66-
while (pa_data) {
67-
data = early_ioremap(pa_data, sizeof(*data));
68-
sprintf(buf, "setup data %x", data->type);
69-
reserve_early(pa_data, pa_data+sizeof(*data)+data->len, buf);
70-
pa_data = data->next;
71-
early_iounmap(data, sizeof(*data));
72-
}
73-
}

arch/x86/kernel/head64.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ void __init x86_64_start_reservations(char *real_mode_data)
128128
#endif
129129

130130
reserve_ebda_region();
131-
reserve_setup_data();
132131

133132
/*
134133
* At this point everything still needed from the boot loader

arch/x86/kernel/setup.c

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -389,14 +389,34 @@ static void __init parse_setup_data(void)
389389
default:
390390
break;
391391
}
392-
#ifndef CONFIG_DEBUG_BOOT_PARAMS
393-
free_early(pa_data, pa_data+sizeof(*data)+data->len);
394-
#endif
395392
pa_data = data->next;
396393
early_iounmap(data, PAGE_SIZE);
397394
}
398395
}
399396

397+
static void __init reserve_setup_data(void)
398+
{
399+
struct setup_data *data;
400+
u64 pa_data;
401+
char buf[32];
402+
403+
if (boot_params.hdr.version < 0x0209)
404+
return;
405+
pa_data = boot_params.hdr.setup_data;
406+
while (pa_data) {
407+
data = early_ioremap(pa_data, sizeof(*data));
408+
sprintf(buf, "setup data %x", data->type);
409+
reserve_early(pa_data, pa_data+sizeof(*data)+data->len, buf);
410+
e820_update_range(pa_data, sizeof(*data)+data->len,
411+
E820_RAM, E820_RESERVED_KERN);
412+
pa_data = data->next;
413+
early_iounmap(data, sizeof(*data));
414+
}
415+
sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
416+
printk(KERN_INFO "extended physical RAM map:\n");
417+
e820_print_map("reserve setup_data");
418+
}
419+
400420
/*
401421
* --------- Crashkernel reservation ------------------------------
402422
*/
@@ -523,7 +543,6 @@ void __init setup_arch(char **cmdline_p)
523543
memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data));
524544
pre_setup_arch_hook();
525545
early_cpu_init();
526-
reserve_setup_data();
527546
#else
528547
printk(KERN_INFO "Command line: %s\n", boot_command_line);
529548
#endif
@@ -567,6 +586,8 @@ void __init setup_arch(char **cmdline_p)
567586
ARCH_SETUP
568587

569588
setup_memory_map();
589+
parse_setup_data();
590+
570591
copy_edd();
571592

572593
if (!boot_params.hdr.root_flags)
@@ -593,10 +614,11 @@ void __init setup_arch(char **cmdline_p)
593614
strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
594615
*cmdline_p = command_line;
595616

596-
parse_setup_data();
597-
598617
parse_early_param();
599618

619+
/* after early param, so could get panic from serial */
620+
reserve_setup_data();
621+
600622
if (acpi_mps_check()) {
601623
#ifdef CONFIG_X86_LOCAL_APIC
602624
disable_apic = 1;

include/asm-x86/bootparam.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,4 @@ struct boot_params {
108108
__u8 _pad9[276]; /* 0xeec */
109109
} __attribute__((packed));
110110

111-
void reserve_setup_data(void);
112-
113111
#endif /* _ASM_BOOTPARAM_H */

include/asm-x86/e820.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
#define E820_ACPI 3
4545
#define E820_NVS 4
4646

47+
/* reserved RAM used by kernel itself */
48+
#define E820_RESERVED_KERN 128
49+
4750
#ifndef __ASSEMBLY__
4851
struct e820entry {
4952
__u64 addr; /* start of memory segment */

0 commit comments

Comments
 (0)