Skip to content

Commit 32e2d7c

Browse files
committed
Merge branch 'efi-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull EFI updates from Ingo Molnar: "The main changes in this cycle were: - Changes to the EFI init code to establish whether secure boot authentication was performed at boot time. (Josh Boyer, David Howells) - Wire up the UEFI memory attributes table for x86. This eliminates any runtime memory regions that are both writable and executable, on recent firmware versions. (Sai Praneeth) - Move the BGRT init code to an earlier stage so that we can still use efi_mem_reserve(). (Dave Young) - Preserve debug symbols in the ARM/arm64 UEFI stub (Ard Biesheuvel) - Code deduplication work and various other cleanups (Lukas Wunner) - ... plus various other fixes and cleanups" * 'efi-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: efi/libstub: Make file I/O chunking x86-specific efi: Print the secure boot status in x86 setup_arch() efi: Disable secure boot if shim is in insecure mode efi: Get and store the secure boot status efi: Add SHIM and image security database GUID definitions arm/efi: Allow invocation of arbitrary runtime services x86/efi: Allow invocation of arbitrary runtime services efi/libstub: Preserve .debug sections after absolute relocation check efi/x86: Add debug code to print cooked memmap efi/x86: Move the EFI BGRT init code to early init code efi: Use typed function pointers for the runtime services table efi/esrt: Fix typo in pr_err() message x86/efi: Add support for EFI_MEMORY_ATTRIBUTES_TABLE efi: Introduce the EFI_MEM_ATTR bit and set it from the memory attributes table efi: Make EFI_MEMORY_ATTRIBUTES_TABLE initialization common across all architectures x86/efi: Deduplicate efi_char16_printk() efi: Deduplicate efi_file_size() / _read() / _close()
2 parents f7458a5 + b3879a4 commit 32e2d7c

27 files changed

Lines changed: 383 additions & 413 deletions

File tree

‎Documentation/x86/zero-page.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Offset Proto Name Meaning
3131
1E9/001 ALL eddbuf_entries Number of entries in eddbuf (below)
3232
1EA/001 ALL edd_mbr_sig_buf_entries Number of entries in edd_mbr_sig_buffer
3333
(below)
34+
1EB/001 ALL kbd_status Numlock is enabled
35+
1EC/001 ALL secure_boot Secure boot is enabled in the firmware
3436
1EF/001 ALL sentinel Used to detect broken bootloaders
3537
290/040 ALL edd_mbr_sig_buffer EDD MBR signatures
3638
2D0/A00 ALL e820_map E820 memory map table

‎arch/arm/include/asm/efi.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ void efi_virtmap_unload(void);
5555

5656
#define efi_call_early(f, ...) sys_table_arg->boottime->f(__VA_ARGS__)
5757
#define __efi_call_early(f, ...) f(__VA_ARGS__)
58+
#define efi_call_runtime(f, ...) sys_table_arg->runtime->f(__VA_ARGS__)
5859
#define efi_is_64bit() (false)
5960

6061
#define efi_call_proto(protocol, f, instance, ...) \

‎arch/arm64/include/asm/efi.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ int efi_set_mapping_permissions(struct mm_struct *mm, efi_memory_desc_t *md);
5050

5151
#define efi_call_early(f, ...) sys_table_arg->boottime->f(__VA_ARGS__)
5252
#define __efi_call_early(f, ...) f(__VA_ARGS__)
53+
#define efi_call_runtime(f, ...) sys_table_arg->runtime->f(__VA_ARGS__)
5354
#define efi_is_64bit() (true)
5455

5556
#define efi_call_proto(protocol, f, instance, ...) \

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

Lines changed: 10 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -32,160 +32,13 @@ static void setup_boot_services##bits(struct efi_config *c) \
3232
\
3333
table = (typeof(table))sys_table; \
3434
\
35+
c->runtime_services = table->runtime; \
3536
c->boot_services = table->boottime; \
3637
c->text_output = table->con_out; \
3738
}
3839
BOOT_SERVICES(32);
3940
BOOT_SERVICES(64);
4041

41-
void efi_char16_printk(efi_system_table_t *, efi_char16_t *);
42-
43-
static efi_status_t
44-
__file_size32(void *__fh, efi_char16_t *filename_16,
45-
void **handle, u64 *file_sz)
46-
{
47-
efi_file_handle_32_t *h, *fh = __fh;
48-
efi_file_info_t *info;
49-
efi_status_t status;
50-
efi_guid_t info_guid = EFI_FILE_INFO_ID;
51-
u32 info_sz;
52-
53-
status = efi_early->call((unsigned long)fh->open, fh, &h, filename_16,
54-
EFI_FILE_MODE_READ, (u64)0);
55-
if (status != EFI_SUCCESS) {
56-
efi_printk(sys_table, "Failed to open file: ");
57-
efi_char16_printk(sys_table, filename_16);
58-
efi_printk(sys_table, "\n");
59-
return status;
60-
}
61-
62-
*handle = h;
63-
64-
info_sz = 0;
65-
status = efi_early->call((unsigned long)h->get_info, h, &info_guid,
66-
&info_sz, NULL);
67-
if (status != EFI_BUFFER_TOO_SMALL) {
68-
efi_printk(sys_table, "Failed to get file info size\n");
69-
return status;
70-
}
71-
72-
grow:
73-
status = efi_call_early(allocate_pool, EFI_LOADER_DATA,
74-
info_sz, (void **)&info);
75-
if (status != EFI_SUCCESS) {
76-
efi_printk(sys_table, "Failed to alloc mem for file info\n");
77-
return status;
78-
}
79-
80-
status = efi_early->call((unsigned long)h->get_info, h, &info_guid,
81-
&info_sz, info);
82-
if (status == EFI_BUFFER_TOO_SMALL) {
83-
efi_call_early(free_pool, info);
84-
goto grow;
85-
}
86-
87-
*file_sz = info->file_size;
88-
efi_call_early(free_pool, info);
89-
90-
if (status != EFI_SUCCESS)
91-
efi_printk(sys_table, "Failed to get initrd info\n");
92-
93-
return status;
94-
}
95-
96-
static efi_status_t
97-
__file_size64(void *__fh, efi_char16_t *filename_16,
98-
void **handle, u64 *file_sz)
99-
{
100-
efi_file_handle_64_t *h, *fh = __fh;
101-
efi_file_info_t *info;
102-
efi_status_t status;
103-
efi_guid_t info_guid = EFI_FILE_INFO_ID;
104-
u64 info_sz;
105-
106-
status = efi_early->call((unsigned long)fh->open, fh, &h, filename_16,
107-
EFI_FILE_MODE_READ, (u64)0);
108-
if (status != EFI_SUCCESS) {
109-
efi_printk(sys_table, "Failed to open file: ");
110-
efi_char16_printk(sys_table, filename_16);
111-
efi_printk(sys_table, "\n");
112-
return status;
113-
}
114-
115-
*handle = h;
116-
117-
info_sz = 0;
118-
status = efi_early->call((unsigned long)h->get_info, h, &info_guid,
119-
&info_sz, NULL);
120-
if (status != EFI_BUFFER_TOO_SMALL) {
121-
efi_printk(sys_table, "Failed to get file info size\n");
122-
return status;
123-
}
124-
125-
grow:
126-
status = efi_call_early(allocate_pool, EFI_LOADER_DATA,
127-
info_sz, (void **)&info);
128-
if (status != EFI_SUCCESS) {
129-
efi_printk(sys_table, "Failed to alloc mem for file info\n");
130-
return status;
131-
}
132-
133-
status = efi_early->call((unsigned long)h->get_info, h, &info_guid,
134-
&info_sz, info);
135-
if (status == EFI_BUFFER_TOO_SMALL) {
136-
efi_call_early(free_pool, info);
137-
goto grow;
138-
}
139-
140-
*file_sz = info->file_size;
141-
efi_call_early(free_pool, info);
142-
143-
if (status != EFI_SUCCESS)
144-
efi_printk(sys_table, "Failed to get initrd info\n");
145-
146-
return status;
147-
}
148-
efi_status_t
149-
efi_file_size(efi_system_table_t *sys_table, void *__fh,
150-
efi_char16_t *filename_16, void **handle, u64 *file_sz)
151-
{
152-
if (efi_early->is64)
153-
return __file_size64(__fh, filename_16, handle, file_sz);
154-
155-
return __file_size32(__fh, filename_16, handle, file_sz);
156-
}
157-
158-
efi_status_t
159-
efi_file_read(void *handle, unsigned long *size, void *addr)
160-
{
161-
unsigned long func;
162-
163-
if (efi_early->is64) {
164-
efi_file_handle_64_t *fh = handle;
165-
166-
func = (unsigned long)fh->read;
167-
return efi_early->call(func, handle, size, addr);
168-
} else {
169-
efi_file_handle_32_t *fh = handle;
170-
171-
func = (unsigned long)fh->read;
172-
return efi_early->call(func, handle, size, addr);
173-
}
174-
}
175-
176-
efi_status_t efi_file_close(void *handle)
177-
{
178-
if (efi_early->is64) {
179-
efi_file_handle_64_t *fh = handle;
180-
181-
return efi_early->call((unsigned long)fh->close, handle);
182-
} else {
183-
efi_file_handle_32_t *fh = handle;
184-
185-
return efi_early->call((unsigned long)fh->close, handle);
186-
}
187-
}
188-
18942
static inline efi_status_t __open_volume32(void *__image, void **__fh)
19043
{
19144
efi_file_io_interface_t *io;
@@ -249,30 +102,8 @@ efi_open_volume(efi_system_table_t *sys_table, void *__image, void **__fh)
249102

250103
void efi_char16_printk(efi_system_table_t *table, efi_char16_t *str)
251104
{
252-
unsigned long output_string;
253-
size_t offset;
254-
255-
if (efi_early->is64) {
256-
struct efi_simple_text_output_protocol_64 *out;
257-
u64 *func;
258-
259-
offset = offsetof(typeof(*out), output_string);
260-
output_string = efi_early->text_output + offset;
261-
out = (typeof(out))(unsigned long)efi_early->text_output;
262-
func = (u64 *)output_string;
263-
264-
efi_early->call(*func, out, str);
265-
} else {
266-
struct efi_simple_text_output_protocol_32 *out;
267-
u32 *func;
268-
269-
offset = offsetof(typeof(*out), output_string);
270-
output_string = efi_early->text_output + offset;
271-
out = (typeof(out))(unsigned long)efi_early->text_output;
272-
func = (u32 *)output_string;
273-
274-
efi_early->call(*func, out, str);
275-
}
105+
efi_call_proto(efi_simple_text_output_protocol, output_string,
106+
efi_early->text_output, str);
276107
}
277108

278109
static efi_status_t
@@ -1157,6 +988,13 @@ struct boot_params *efi_main(struct efi_config *c,
1157988
else
1158989
setup_boot_services32(efi_early);
1159990

991+
/*
992+
* If the boot loader gave us a value for secure_boot then we use that,
993+
* otherwise we ask the BIOS.
994+
*/
995+
if (boot_params->secure_boot == efi_secureboot_mode_unset)
996+
boot_params->secure_boot = efi_get_secureboot(sys_table);
997+
1160998
setup_graphics(boot_params);
1161999

11621000
setup_efi_pci(boot_params);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ ENTRY(efi_pe_entry)
8282

8383
/* Relocate efi_config->call() */
8484
leal efi32_config(%esi), %eax
85-
add %esi, 32(%eax)
85+
add %esi, 40(%eax)
8686
pushl %eax
8787

8888
call make_boot_params
@@ -108,7 +108,7 @@ ENTRY(efi32_stub_entry)
108108

109109
/* Relocate efi_config->call() */
110110
leal efi32_config(%esi), %eax
111-
add %esi, 32(%eax)
111+
add %esi, 40(%eax)
112112
pushl %eax
113113
2:
114114
call efi_main
@@ -264,7 +264,7 @@ relocated:
264264
#ifdef CONFIG_EFI_STUB
265265
.data
266266
efi32_config:
267-
.fill 4,8,0
267+
.fill 5,8,0
268268
.long efi_call_phys
269269
.long 0
270270
.byte 0

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ ENTRY(efi_pe_entry)
264264
/*
265265
* Relocate efi_config->call().
266266
*/
267-
addq %rbp, efi64_config+32(%rip)
267+
addq %rbp, efi64_config+40(%rip)
268268

269269
movq %rax, %rdi
270270
call make_boot_params
@@ -284,7 +284,7 @@ handover_entry:
284284
* Relocate efi_config->call().
285285
*/
286286
movq efi_config(%rip), %rax
287-
addq %rbp, 32(%rax)
287+
addq %rbp, 40(%rax)
288288
2:
289289
movq efi_config(%rip), %rdi
290290
call efi_main
@@ -456,14 +456,14 @@ efi_config:
456456
#ifdef CONFIG_EFI_MIXED
457457
.global efi32_config
458458
efi32_config:
459-
.fill 4,8,0
459+
.fill 5,8,0
460460
.quad efi64_thunk
461461
.byte 0
462462
#endif
463463

464464
.global efi64_config
465465
efi64_config:
466-
.fill 4,8,0
466+
.fill 5,8,0
467467
.quad efi_call
468468
.byte 1
469469
#endif /* CONFIG_EFI_STUB */

‎arch/x86/include/asm/efi.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ static inline efi_status_t efi_thunk_set_virtual_address_map(
191191
struct efi_config {
192192
u64 image_handle;
193193
u64 table;
194+
u64 runtime_services;
194195
u64 boot_services;
195196
u64 text_output;
196197
efi_status_t (*call)(unsigned long, ...);
@@ -226,6 +227,10 @@ static inline bool efi_is_64bit(void)
226227
#define __efi_call_early(f, ...) \
227228
__efi_early()->call((unsigned long)f, __VA_ARGS__);
228229

230+
#define efi_call_runtime(f, ...) \
231+
__efi_early()->call(efi_table_attr(efi_runtime_services, f, \
232+
__efi_early()->runtime_services), __VA_ARGS__)
233+
229234
extern bool efi_reboot_required(void);
230235

231236
#else

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ struct boot_params {
135135
__u8 eddbuf_entries; /* 0x1e9 */
136136
__u8 edd_mbr_sig_buf_entries; /* 0x1ea */
137137
__u8 kbd_status; /* 0x1eb */
138-
__u8 _pad5[3]; /* 0x1ec */
138+
__u8 secure_boot; /* 0x1ec */
139+
__u8 _pad5[2]; /* 0x1ed */
139140
/*
140141
* The sentinel is set to a nonzero value (0xff) in header.S.
141142
*

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <linux/bootmem.h>
3636
#include <linux/ioport.h>
3737
#include <linux/pci.h>
38+
#include <linux/efi-bgrt.h>
3839

3940
#include <asm/irqdomain.h>
4041
#include <asm/pci_x86.h>
@@ -1557,6 +1558,12 @@ int __init early_acpi_boot_init(void)
15571558
return 0;
15581559
}
15591560

1561+
static int __init acpi_parse_bgrt(struct acpi_table_header *table)
1562+
{
1563+
efi_bgrt_init(table);
1564+
return 0;
1565+
}
1566+
15601567
int __init acpi_boot_init(void)
15611568
{
15621569
/* those are executed after early-quirks are executed */
@@ -1581,6 +1588,8 @@ int __init acpi_boot_init(void)
15811588
acpi_process_madt();
15821589

15831590
acpi_table_parse(ACPI_SIG_HPET, acpi_parse_hpet);
1591+
if (IS_ENABLED(CONFIG_ACPI_BGRT))
1592+
acpi_table_parse(ACPI_SIG_BGRT, acpi_parse_bgrt);
15841593

15851594
if (!acpi_noirq)
15861595
x86_init.pci.init = pci_acpi_init;

‎arch/x86/kernel/asm-offsets.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ void common(void) {
8181

8282
BLANK();
8383
OFFSET(BP_scratch, boot_params, scratch);
84+
OFFSET(BP_secure_boot, boot_params, secure_boot);
8485
OFFSET(BP_loadflags, boot_params, hdr.loadflags);
8586
OFFSET(BP_hardware_subarch, boot_params, hdr.hardware_subarch);
8687
OFFSET(BP_version, boot_params, hdr.version);

0 commit comments

Comments
 (0)