Skip to content

Commit b7d5c92

Browse files
committed
Merge branch 'x86-boot-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 boot updates from Thomas Gleixner: "Assorted updates to kexec/kdump: - Proper kexec support for 4/5-level paging and jumping from a 5-level to a 4-level paging kernel. - Make the EFI support for kexec/kdump more robust - Enforce that the GDT is properly aligned instead of getting the alignment by chance" * 'x86-boot-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/kdump/64: Restrict kdump kernel reservation to <64TB x86/kexec/64: Prevent kexec from 5-level paging to a 4-level only kernel x86/boot: Add xloadflags bits to check for 5-level paging support x86/boot: Make the GDT 8-byte aligned x86/kexec: Add the ACPI NVS region to the ident map x86/boot: Call get_rsdp_addr() after console_init() Revert "x86/boot: Disable RSDP parsing temporarily" x86/boot: Use efi_setup_data for searching RSDP on kexec-ed kernels x86/kexec: Add the EFI system tables and ACPI tables to the ident map
2 parents 608745f + 8ff80fb commit b7d5c92

9 files changed

Lines changed: 234 additions & 43 deletions

File tree

‎arch/x86/boot/compressed/acpi.c‎

Lines changed: 107 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,109 @@ static acpi_physical_address get_acpi_rsdp(void)
4444
return addr;
4545
}
4646

47-
/* Search EFI system tables for RSDP. */
48-
static acpi_physical_address efi_get_rsdp_addr(void)
47+
/*
48+
* Search EFI system tables for RSDP. If both ACPI_20_TABLE_GUID and
49+
* ACPI_TABLE_GUID are found, take the former, which has more features.
50+
*/
51+
static acpi_physical_address
52+
__efi_get_rsdp_addr(unsigned long config_tables, unsigned int nr_tables,
53+
bool efi_64)
4954
{
5055
acpi_physical_address rsdp_addr = 0;
5156

5257
#ifdef CONFIG_EFI
53-
unsigned long systab, systab_tables, config_tables;
58+
int i;
59+
60+
/* Get EFI tables from systab. */
61+
for (i = 0; i < nr_tables; i++) {
62+
acpi_physical_address table;
63+
efi_guid_t guid;
64+
65+
if (efi_64) {
66+
efi_config_table_64_t *tbl = (efi_config_table_64_t *)config_tables + i;
67+
68+
guid = tbl->guid;
69+
table = tbl->table;
70+
71+
if (!IS_ENABLED(CONFIG_X86_64) && table >> 32) {
72+
debug_putstr("Error getting RSDP address: EFI config table located above 4GB.\n");
73+
return 0;
74+
}
75+
} else {
76+
efi_config_table_32_t *tbl = (efi_config_table_32_t *)config_tables + i;
77+
78+
guid = tbl->guid;
79+
table = tbl->table;
80+
}
81+
82+
if (!(efi_guidcmp(guid, ACPI_TABLE_GUID)))
83+
rsdp_addr = table;
84+
else if (!(efi_guidcmp(guid, ACPI_20_TABLE_GUID)))
85+
return table;
86+
}
87+
#endif
88+
return rsdp_addr;
89+
}
90+
91+
/* EFI/kexec support is 64-bit only. */
92+
#ifdef CONFIG_X86_64
93+
static struct efi_setup_data *get_kexec_setup_data_addr(void)
94+
{
95+
struct setup_data *data;
96+
u64 pa_data;
97+
98+
pa_data = boot_params->hdr.setup_data;
99+
while (pa_data) {
100+
data = (struct setup_data *)pa_data;
101+
if (data->type == SETUP_EFI)
102+
return (struct efi_setup_data *)(pa_data + sizeof(struct setup_data));
103+
104+
pa_data = data->next;
105+
}
106+
return NULL;
107+
}
108+
109+
static acpi_physical_address kexec_get_rsdp_addr(void)
110+
{
111+
efi_system_table_64_t *systab;
112+
struct efi_setup_data *esd;
113+
struct efi_info *ei;
114+
char *sig;
115+
116+
esd = (struct efi_setup_data *)get_kexec_setup_data_addr();
117+
if (!esd)
118+
return 0;
119+
120+
if (!esd->tables) {
121+
debug_putstr("Wrong kexec SETUP_EFI data.\n");
122+
return 0;
123+
}
124+
125+
ei = &boot_params->efi_info;
126+
sig = (char *)&ei->efi_loader_signature;
127+
if (strncmp(sig, EFI64_LOADER_SIGNATURE, 4)) {
128+
debug_putstr("Wrong kexec EFI loader signature.\n");
129+
return 0;
130+
}
131+
132+
/* Get systab from boot params. */
133+
systab = (efi_system_table_64_t *) (ei->efi_systab | ((__u64)ei->efi_systab_hi << 32));
134+
if (!systab)
135+
error("EFI system table not found in kexec boot_params.");
136+
137+
return __efi_get_rsdp_addr((unsigned long)esd->tables, systab->nr_tables, true);
138+
}
139+
#else
140+
static acpi_physical_address kexec_get_rsdp_addr(void) { return 0; }
141+
#endif /* CONFIG_X86_64 */
142+
143+
static acpi_physical_address efi_get_rsdp_addr(void)
144+
{
145+
#ifdef CONFIG_EFI
146+
unsigned long systab, config_tables;
54147
unsigned int nr_tables;
55148
struct efi_info *ei;
56149
bool efi_64;
57-
int size, i;
58150
char *sig;
59151

60152
ei = &boot_params->efi_info;
@@ -88,49 +180,20 @@ static acpi_physical_address efi_get_rsdp_addr(void)
88180

89181
config_tables = stbl->tables;
90182
nr_tables = stbl->nr_tables;
91-
size = sizeof(efi_config_table_64_t);
92183
} else {
93184
efi_system_table_32_t *stbl = (efi_system_table_32_t *)systab;
94185

95186
config_tables = stbl->tables;
96187
nr_tables = stbl->nr_tables;
97-
size = sizeof(efi_config_table_32_t);
98188
}
99189

100190
if (!config_tables)
101191
error("EFI config tables not found.");
102192

103-
/* Get EFI tables from systab. */
104-
for (i = 0; i < nr_tables; i++) {
105-
acpi_physical_address table;
106-
efi_guid_t guid;
107-
108-
config_tables += size;
109-
110-
if (efi_64) {
111-
efi_config_table_64_t *tbl = (efi_config_table_64_t *)config_tables;
112-
113-
guid = tbl->guid;
114-
table = tbl->table;
115-
116-
if (!IS_ENABLED(CONFIG_X86_64) && table >> 32) {
117-
debug_putstr("Error getting RSDP address: EFI config table located above 4GB.\n");
118-
return 0;
119-
}
120-
} else {
121-
efi_config_table_32_t *tbl = (efi_config_table_32_t *)config_tables;
122-
123-
guid = tbl->guid;
124-
table = tbl->table;
125-
}
126-
127-
if (!(efi_guidcmp(guid, ACPI_TABLE_GUID)))
128-
rsdp_addr = table;
129-
else if (!(efi_guidcmp(guid, ACPI_20_TABLE_GUID)))
130-
return table;
131-
}
193+
return __efi_get_rsdp_addr(config_tables, nr_tables, efi_64);
194+
#else
195+
return 0;
132196
#endif
133-
return rsdp_addr;
134197
}
135198

136199
static u8 compute_checksum(u8 *buffer, u32 length)
@@ -220,6 +283,14 @@ acpi_physical_address get_rsdp_addr(void)
220283
if (!pa)
221284
pa = boot_params->acpi_rsdp_addr;
222285

286+
/*
287+
* Try to get EFI data from setup_data. This can happen when we're a
288+
* kexec'ed kernel and kexec(1) has passed all the required EFI info to
289+
* us.
290+
*/
291+
if (!pa)
292+
pa = kexec_get_rsdp_addr();
293+
223294
if (!pa)
224295
pa = efi_get_rsdp_addr();
225296

‎arch/x86/boot/compressed/head_64.S‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,7 @@ no_longmode:
659659
gdt64:
660660
.word gdt_end - gdt
661661
.quad 0
662+
.balign 8
662663
gdt:
663664
.word gdt_end - gdt
664665
.long gdt

‎arch/x86/boot/compressed/misc.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,6 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap,
351351
/* Clear flags intended for solely in-kernel use. */
352352
boot_params->hdr.loadflags &= ~KASLR_FLAG;
353353

354-
/* Save RSDP address for later use. */
355-
/* boot_params->acpi_rsdp_addr = get_rsdp_addr(); */
356-
357354
sanitize_boot_params(boot_params);
358355

359356
if (boot_params->screen_info.orig_video_mode == 7) {
@@ -368,6 +365,14 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap,
368365
cols = boot_params->screen_info.orig_video_cols;
369366

370367
console_init();
368+
369+
/*
370+
* Save RSDP address for later use. Have this after console_init()
371+
* so that early debugging output from the RSDP parsing code can be
372+
* collected.
373+
*/
374+
boot_params->acpi_rsdp_addr = get_rsdp_addr();
375+
371376
debug_putstr("early console in extract_kernel\n");
372377

373378
free_mem_ptr = heap; /* Heap */

‎arch/x86/boot/header.S‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,17 @@ xloadflags:
419419
# define XLF4 0
420420
#endif
421421

422-
.word XLF0 | XLF1 | XLF23 | XLF4
422+
#ifdef CONFIG_X86_64
423+
#ifdef CONFIG_X86_5LEVEL
424+
#define XLF56 (XLF_5LEVEL|XLF_5LEVEL_ENABLED)
425+
#else
426+
#define XLF56 XLF_5LEVEL
427+
#endif
428+
#else
429+
#define XLF56 0
430+
#endif
431+
432+
.word XLF0 | XLF1 | XLF23 | XLF4 | XLF56
423433

424434
cmdline_size: .long COMMAND_LINE_SIZE-1 #length of the command line,
425435
#added with boot protocol

‎arch/x86/include/uapi/asm/bootparam.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#define XLF_EFI_HANDOVER_32 (1<<2)
3030
#define XLF_EFI_HANDOVER_64 (1<<3)
3131
#define XLF_EFI_KEXEC (1<<4)
32+
#define XLF_5LEVEL (1<<5)
33+
#define XLF_5LEVEL_ENABLED (1<<6)
3234

3335
#ifndef __ASSEMBLY__
3436

‎arch/x86/kernel/kexec-bzimage64.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,11 @@ static int bzImage64_probe(const char *buf, unsigned long len)
319319
return ret;
320320
}
321321

322+
if (!(header->xloadflags & XLF_5LEVEL) && pgtable_l5_enabled()) {
323+
pr_err("bzImage cannot handle 5-level paging mode.\n");
324+
return ret;
325+
}
326+
322327
/* I've got a bzImage */
323328
pr_debug("It's a relocatable bzImage64\n");
324329
ret = 0;

‎arch/x86/kernel/machine_kexec_64.c‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/io.h>
1717
#include <linux/suspend.h>
1818
#include <linux/vmalloc.h>
19+
#include <linux/efi.h>
1920

2021
#include <asm/init.h>
2122
#include <asm/pgtable.h>
@@ -27,13 +28,87 @@
2728
#include <asm/setup.h>
2829
#include <asm/set_memory.h>
2930

31+
#ifdef CONFIG_ACPI
32+
/*
33+
* Used while adding mapping for ACPI tables.
34+
* Can be reused when other iomem regions need be mapped
35+
*/
36+
struct init_pgtable_data {
37+
struct x86_mapping_info *info;
38+
pgd_t *level4p;
39+
};
40+
41+
static int mem_region_callback(struct resource *res, void *arg)
42+
{
43+
struct init_pgtable_data *data = arg;
44+
unsigned long mstart, mend;
45+
46+
mstart = res->start;
47+
mend = mstart + resource_size(res) - 1;
48+
49+
return kernel_ident_mapping_init(data->info, data->level4p, mstart, mend);
50+
}
51+
52+
static int
53+
map_acpi_tables(struct x86_mapping_info *info, pgd_t *level4p)
54+
{
55+
struct init_pgtable_data data;
56+
unsigned long flags;
57+
int ret;
58+
59+
data.info = info;
60+
data.level4p = level4p;
61+
flags = IORESOURCE_MEM | IORESOURCE_BUSY;
62+
63+
ret = walk_iomem_res_desc(IORES_DESC_ACPI_TABLES, flags, 0, -1,
64+
&data, mem_region_callback);
65+
if (ret && ret != -EINVAL)
66+
return ret;
67+
68+
/* ACPI tables could be located in ACPI Non-volatile Storage region */
69+
ret = walk_iomem_res_desc(IORES_DESC_ACPI_NV_STORAGE, flags, 0, -1,
70+
&data, mem_region_callback);
71+
if (ret && ret != -EINVAL)
72+
return ret;
73+
74+
return 0;
75+
}
76+
#else
77+
static int map_acpi_tables(struct x86_mapping_info *info, pgd_t *level4p) { return 0; }
78+
#endif
79+
3080
#ifdef CONFIG_KEXEC_FILE
3181
const struct kexec_file_ops * const kexec_file_loaders[] = {
3282
&kexec_bzImage64_ops,
3383
NULL
3484
};
3585
#endif
3686

87+
static int
88+
map_efi_systab(struct x86_mapping_info *info, pgd_t *level4p)
89+
{
90+
#ifdef CONFIG_EFI
91+
unsigned long mstart, mend;
92+
93+
if (!efi_enabled(EFI_BOOT))
94+
return 0;
95+
96+
mstart = (boot_params.efi_info.efi_systab |
97+
((u64)boot_params.efi_info.efi_systab_hi<<32));
98+
99+
if (efi_enabled(EFI_64BIT))
100+
mend = mstart + sizeof(efi_system_table_64_t);
101+
else
102+
mend = mstart + sizeof(efi_system_table_32_t);
103+
104+
if (!mstart)
105+
return 0;
106+
107+
return kernel_ident_mapping_init(info, level4p, mstart, mend);
108+
#endif
109+
return 0;
110+
}
111+
37112
static void free_transition_pgtable(struct kimage *image)
38113
{
39114
free_page((unsigned long)image->arch.p4d);
@@ -157,6 +232,18 @@ static int init_pgtable(struct kimage *image, unsigned long start_pgtable)
157232
return result;
158233
}
159234

235+
/*
236+
* Prepare EFI systab and ACPI tables for kexec kernel since they are
237+
* not covered by pfn_mapped.
238+
*/
239+
result = map_efi_systab(&info, level4p);
240+
if (result)
241+
return result;
242+
243+
result = map_acpi_tables(&info, level4p);
244+
if (result)
245+
return result;
246+
160247
return init_transition_pgtable(image, level4p);
161248
}
162249

‎arch/x86/kernel/setup.c‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,15 +453,24 @@ static void __init memblock_x86_reserve_range_setup_data(void)
453453
#define CRASH_ALIGN SZ_16M
454454

455455
/*
456-
* Keep the crash kernel below this limit. On 32 bits earlier kernels
457-
* would limit the kernel to the low 512 MiB due to mapping restrictions.
456+
* Keep the crash kernel below this limit.
457+
*
458+
* On 32 bits earlier kernels would limit the kernel to the low 512 MiB
459+
* due to mapping restrictions.
460+
*
461+
* On 64bit, kdump kernel need be restricted to be under 64TB, which is
462+
* the upper limit of system RAM in 4-level paing mode. Since the kdump
463+
* jumping could be from 5-level to 4-level, the jumping will fail if
464+
* kernel is put above 64TB, and there's no way to detect the paging mode
465+
* of the kernel which will be loaded for dumping during the 1st kernel
466+
* bootup.
458467
*/
459468
#ifdef CONFIG_X86_32
460469
# define CRASH_ADDR_LOW_MAX SZ_512M
461470
# define CRASH_ADDR_HIGH_MAX SZ_512M
462471
#else
463472
# define CRASH_ADDR_LOW_MAX SZ_4G
464-
# define CRASH_ADDR_HIGH_MAX MAXMEM
473+
# define CRASH_ADDR_HIGH_MAX SZ_64T
465474
#endif
466475

467476
static int __init reserve_crashkernel_low(void)

0 commit comments

Comments
 (0)