Skip to content

Commit e976568

Browse files
committed
Merge tag 'efi-next' of git://git.kernel.org/pub/scm/linux/kernel/git/efi/efi into efi/core
Pull EFI updates for v5.7 from Ard Biesheuvel: This time, the set of changes for the EFI subsystem is much larger than usual. The main reasons are: - Get things cleaned up before EFI support for RISC-V arrives, which will increase the size of the validation matrix, and therefore the threshold to making drastic changes, - After years of defunct maintainership, the GRUB project has finally started to consider changes from the distros regarding UEFI boot, some of which are highly specific to the way x86 does UEFI secure boot and measured boot, based on knowledge of both shim internals and the layout of bootparams and the x86 setup header. Having this maintenance burden on other architectures (which don't need shim in the first place) is hard to justify, so instead, we are introducing a generic Linux/UEFI boot protocol. Summary of changes: - Boot time GDT handling changes (Arvind) - Simplify handling of EFI properties table on arm64 - Generic EFI stub cleanups, to improve command line handling, file I/O, memory allocation, etc. - Introduce a generic initrd loading method based on calling back into the firmware, instead of relying on the x86 EFI handover protocol or device tree. - Introduce a mixed mode boot method that does not rely on the x86 EFI handover protocol either, and could potentially be adopted by other architectures (if another one ever surfaces where one execution mode is a superset of another) - Clean up the contents of struct efi, and move out everything that doesn't need to be stored there. - Incorporate support for UEFI spec v2.8A changes that permit firmware implementations to return EFI_UNSUPPORTED from UEFI runtime services at OS runtime, and expose a mask of which ones are supported or unsupported via a configuration table. - Various documentation updates and minor code cleanups (Heinrich) - Partial fix for the lack of by-VA cache maintenance in the decompressor on 32-bit ARM. Note that these patches were deliberately put at the beginning so they can be used as a stable branch that will be shared with a PR containing the complete fix, which I will send to the ARM tree. Signed-off-by: Ingo Molnar <mingo@kernel.org>
2 parents c5f8689 + dc235d6 commit e976568

66 files changed

Lines changed: 2718 additions & 2638 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Documentation/x86/boot.rst‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -490,15 +490,11 @@ Protocol: 2.00+
490490
kernel) to not write early messages that require
491491
accessing the display hardware directly.
492492

493-
Bit 6 (write): KEEP_SEGMENTS
493+
Bit 6 (obsolete): KEEP_SEGMENTS
494494

495495
Protocol: 2.07+
496496

497-
- If 0, reload the segment registers in the 32bit entry point.
498-
- If 1, do not reload the segment registers in the 32bit entry point.
499-
500-
Assume that %cs %ds %ss %es are all set to flat segments with
501-
a base of 0 (or the equivalent for their environment).
497+
- This flag is obsolete.
502498

503499
Bit 7 (write): CAN_USE_HEAP
504500

‎arch/arm/boot/compressed/efi-header.S‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ optional_header:
6060
.long __pecoff_code_size @ SizeOfCode
6161
.long __pecoff_data_size @ SizeOfInitializedData
6262
.long 0 @ SizeOfUninitializedData
63-
.long efi_stub_entry - start @ AddressOfEntryPoint
63+
.long efi_entry - start @ AddressOfEntryPoint
6464
.long start_offset @ BaseOfCode
6565
.long __pecoff_data_start - start @ BaseOfData
6666

@@ -70,8 +70,8 @@ extra_header_fields:
7070
.long SZ_512 @ FileAlignment
7171
.short 0 @ MajorOsVersion
7272
.short 0 @ MinorOsVersion
73-
.short 0 @ MajorImageVersion
74-
.short 0 @ MinorImageVersion
73+
.short LINUX_EFISTUB_MAJOR_VERSION @ MajorImageVersion
74+
.short LINUX_EFISTUB_MINOR_VERSION @ MinorImageVersion
7575
.short 0 @ MajorSubsystemVersion
7676
.short 0 @ MinorSubsystemVersion
7777
.long 0 @ Win32VersionValue

‎arch/arm/boot/compressed/head.S‎

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,30 +1437,28 @@ __enter_kernel:
14371437
reloc_code_end:
14381438

14391439
#ifdef CONFIG_EFI_STUB
1440-
.align 2
1441-
_start: .long start - .
1442-
1443-
ENTRY(efi_stub_entry)
1444-
@ allocate space on stack for passing current zImage address
1445-
@ and for the EFI stub to return of new entry point of
1446-
@ zImage, as EFI stub may copy the kernel. Pointer address
1447-
@ is passed in r2. r0 and r1 are passed through from the
1448-
@ EFI firmware to efi_entry
1449-
adr ip, _start
1450-
ldr r3, [ip]
1451-
add r3, r3, ip
1452-
stmfd sp!, {r3, lr}
1453-
mov r2, sp @ pass zImage address in r2
1454-
bl efi_entry
1455-
1456-
@ Check for error return from EFI stub. r0 has FDT address
1457-
@ or error code.
1458-
cmn r0, #1
1459-
beq efi_load_fail
1460-
1461-
@ Preserve return value of efi_entry() in r4
1462-
mov r4, r0
1440+
ENTRY(efi_enter_kernel)
1441+
mov r7, r0 @ preserve image base
1442+
mov r4, r1 @ preserve DT pointer
1443+
1444+
mov r0, r4 @ DT start
1445+
add r1, r4, r2 @ DT end
1446+
bl cache_clean_flush
1447+
1448+
mov r0, r7 @ relocated zImage
1449+
ldr r1, =_edata @ size of zImage
1450+
add r1, r1, r0 @ end of zImage
14631451
bl cache_clean_flush
1452+
1453+
@ The PE/COFF loader might not have cleaned the code we are
1454+
@ running beyond the PoU, and so calling cache_off below from
1455+
@ inside the PE/COFF loader allocated region is unsafe. Let's
1456+
@ assume our own zImage relocation code did a better job, and
1457+
@ jump into its version of this routine before proceeding.
1458+
ldr r1, .Ljmp
1459+
sub r1, r7, r1
1460+
mov pc, r1 @ no mode switch
1461+
0:
14641462
bl cache_off
14651463

14661464
@ Set parameters for booting zImage according to boot protocol
@@ -1469,18 +1467,10 @@ ENTRY(efi_stub_entry)
14691467
mov r0, #0
14701468
mov r1, #0xFFFFFFFF
14711469
mov r2, r4
1472-
1473-
@ Branch to (possibly) relocated zImage that is in [sp]
1474-
ldr lr, [sp]
1475-
ldr ip, =start_offset
1476-
add lr, lr, ip
1477-
mov pc, lr @ no mode switch
1478-
1479-
efi_load_fail:
1480-
@ Return EFI_LOAD_ERROR to EFI firmware on error.
1481-
ldr r0, =0x80000001
1482-
ldmfd sp!, {ip, pc}
1483-
ENDPROC(efi_stub_entry)
1470+
b __efi_start
1471+
ENDPROC(efi_enter_kernel)
1472+
.align 2
1473+
.Ljmp: .long start - 0b
14841474
#endif
14851475

14861476
.align

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,6 @@ efi_status_t __efi_rt_asm_wrapper(void *, const char *, ...);
5757

5858
/* arch specific definitions used by the stub code */
5959

60-
/*
61-
* AArch64 requires the DTB to be 8-byte aligned in the first 512MiB from
62-
* start of kernel and may not cross a 2MiB boundary. We set alignment to
63-
* 2MiB so we know it won't cross a 2MiB boundary.
64-
*/
65-
#define EFI_FDT_ALIGN SZ_2M /* used by allocate_new_fdt_and_exit_boot() */
66-
6760
/*
6861
* In some configurations (e.g. VMAP_STACK && 64K pages), stacks built into the
6962
* kernel need greater alignment than we require the segments to be padded to.
@@ -107,9 +100,6 @@ static inline void free_screen_info(struct screen_info *si)
107100
{
108101
}
109102

110-
/* redeclare as 'hidden' so the compiler will generate relative references */
111-
extern struct screen_info screen_info __attribute__((__visibility__("hidden")));
112-
113103
static inline void efifb_setup_from_dmi(struct screen_info *si, const char *opt)
114104
{
115105
}

‎arch/arm64/kernel/efi-entry.S‎

Lines changed: 17 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -10,81 +10,35 @@
1010

1111
#include <asm/assembler.h>
1212

13-
#define EFI_LOAD_ERROR 0x8000000000000001
14-
1513
__INIT
1614

17-
/*
18-
* We arrive here from the EFI boot manager with:
19-
*
20-
* * CPU in little-endian mode
21-
* * MMU on with identity-mapped RAM
22-
* * Icache and Dcache on
23-
*
24-
* We will most likely be running from some place other than where
25-
* we want to be. The kernel image wants to be placed at TEXT_OFFSET
26-
* from start of RAM.
27-
*/
28-
ENTRY(entry)
29-
/*
30-
* Create a stack frame to save FP/LR with extra space
31-
* for image_addr variable passed to efi_entry().
32-
*/
33-
stp x29, x30, [sp, #-32]!
34-
mov x29, sp
35-
36-
/*
37-
* Call efi_entry to do the real work.
38-
* x0 and x1 are already set up by firmware. Current runtime
39-
* address of image is calculated and passed via *image_addr.
40-
*
41-
* unsigned long efi_entry(void *handle,
42-
* efi_system_table_t *sys_table,
43-
* unsigned long *image_addr) ;
44-
*/
45-
adr_l x8, _text
46-
add x2, sp, 16
47-
str x8, [x2]
48-
bl efi_entry
49-
cmn x0, #1
50-
b.eq efi_load_fail
51-
15+
ENTRY(efi_enter_kernel)
5216
/*
5317
* efi_entry() will have copied the kernel image if necessary and we
54-
* return here with device tree address in x0 and the kernel entry
55-
* point stored at *image_addr. Save those values in registers which
56-
* are callee preserved.
57-
*/
58-
mov x20, x0 // DTB address
59-
ldr x0, [sp, #16] // relocated _text address
60-
ldr w21, =stext_offset
61-
add x21, x0, x21
62-
63-
/*
64-
* Calculate size of the kernel Image (same for original and copy).
18+
* end up here with device tree address in x1 and the kernel entry
19+
* point stored in x0. Save those values in registers which are
20+
* callee preserved.
6521
*/
66-
adr_l x1, _text
67-
adr_l x2, _edata
68-
sub x1, x2, x1
22+
mov x19, x0 // relocated Image address
23+
mov x20, x1 // DTB address
6924

7025
/*
7126
* Flush the copied Image to the PoC, and ensure it is not shadowed by
7227
* stale icache entries from before relocation.
7328
*/
29+
ldr w1, =kernel_size
7430
bl __flush_dcache_area
7531
ic ialluis
32+
dsb sy
7633

7734
/*
78-
* Ensure that the rest of this function (in the original Image) is
79-
* visible when the caches are disabled. The I-cache can't have stale
80-
* entries for the VA range of the current image, so no maintenance is
81-
* necessary.
35+
* Jump across, into the copy of the image that we just cleaned
36+
* to the PoC, so that we can safely disable the MMU and caches.
8237
*/
83-
adr x0, entry
84-
adr x1, entry_end
85-
sub x1, x1, x0
86-
bl __flush_dcache_area
87-
38+
ldr w0, .Ljmp
39+
sub x0, x19, w0, sxtw
40+
br x0
41+
0:
8842
/* Turn off Dcache and MMU */
8943
mrs x0, CurrentEL
9044
cmp x0, #CurrentEL_EL2
@@ -109,12 +63,6 @@ ENTRY(entry)
10963
mov x1, xzr
11064
mov x2, xzr
11165
mov x3, xzr
112-
br x21
113-
114-
efi_load_fail:
115-
mov x0, #EFI_LOAD_ERROR
116-
ldp x29, x30, [sp], #32
117-
ret
118-
119-
entry_end:
120-
ENDPROC(entry)
66+
b stext
67+
ENDPROC(efi_enter_kernel)
68+
.Ljmp: .long _text - 0b

‎arch/arm64/kernel/efi-header.S‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ optional_header:
2727
.long __initdata_begin - efi_header_end // SizeOfCode
2828
.long __pecoff_data_size // SizeOfInitializedData
2929
.long 0 // SizeOfUninitializedData
30-
.long __efistub_entry - _head // AddressOfEntryPoint
30+
.long __efistub_efi_entry - _head // AddressOfEntryPoint
3131
.long efi_header_end - _head // BaseOfCode
3232

3333
extra_header_fields:
@@ -36,8 +36,8 @@ extra_header_fields:
3636
.long PECOFF_FILE_ALIGNMENT // FileAlignment
3737
.short 0 // MajorOperatingSystemVersion
3838
.short 0 // MinorOperatingSystemVersion
39-
.short 0 // MajorImageVersion
40-
.short 0 // MinorImageVersion
39+
.short LINUX_EFISTUB_MAJOR_VERSION // MajorImageVersion
40+
.short LINUX_EFISTUB_MINOR_VERSION // MinorImageVersion
4141
.short 0 // MajorSubsystemVersion
4242
.short 0 // MinorSubsystemVersion
4343
.long 0 // Win32VersionValue

‎arch/arm64/kernel/image-vars.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
#ifdef CONFIG_EFI
1414

15-
__efistub_stext_offset = stext - _text;
15+
__efistub_kernel_size = _edata - _text;
16+
1617

1718
/*
1819
* The EFI stub has its own symbol namespace prefixed by __efistub_, to
@@ -42,9 +43,11 @@ __efistub___memset = __pi_memset;
4243
#endif
4344

4445
__efistub__text = _text;
46+
__efistub_stext = stext;
4547
__efistub__end = _end;
4648
__efistub__edata = _edata;
4749
__efistub_screen_info = screen_info;
50+
__efistub__ctype = _ctype;
4851

4952
#endif
5053

‎arch/ia64/kernel/efi.c‎

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,21 @@
4545

4646
#define EFI_DEBUG 0
4747

48+
#define ESI_TABLE_GUID \
49+
EFI_GUID(0x43EA58DC, 0xCF28, 0x4b06, 0xB3, \
50+
0x91, 0xB7, 0x50, 0x59, 0x34, 0x2B, 0xD4)
51+
52+
static unsigned long mps_phys = EFI_INVALID_TABLE_ADDR;
4853
static __initdata unsigned long palo_phys;
4954

55+
unsigned long __initdata esi_phys = EFI_INVALID_TABLE_ADDR;
56+
unsigned long hcdp_phys = EFI_INVALID_TABLE_ADDR;
5057
unsigned long sal_systab_phys = EFI_INVALID_TABLE_ADDR;
5158

52-
static __initdata efi_config_table_type_t arch_tables[] = {
59+
static const efi_config_table_type_t arch_tables[] __initconst = {
60+
{ESI_TABLE_GUID, "ESI", &esi_phys},
61+
{HCDP_TABLE_GUID, "HCDP", &hcdp_phys},
62+
{MPS_TABLE_GUID, "MPS", &mps_phys},
5363
{PROCESSOR_ABSTRACTION_LAYER_OVERWRITE_GUID, "PALO", &palo_phys},
5464
{SAL_SYSTEM_TABLE_GUID, "SALsystab", &sal_systab_phys},
5565
{NULL_GUID, NULL, 0},
@@ -474,11 +484,10 @@ efi_map_pal_code (void)
474484
void __init
475485
efi_init (void)
476486
{
487+
const efi_system_table_t *efi_systab;
477488
void *efi_map_start, *efi_map_end;
478-
efi_char16_t *c16;
479489
u64 efi_desc_size;
480-
char *cp, vendor[100] = "unknown";
481-
int i;
490+
char *cp;
482491

483492
set_bit(EFI_BOOT, &efi.flags);
484493
set_bit(EFI_64BIT, &efi.flags);
@@ -508,42 +517,29 @@ efi_init (void)
508517
printk(KERN_INFO "Ignoring memory above %lluMB\n",
509518
max_addr >> 20);
510519

511-
efi.systab = __va(ia64_boot_param->efi_systab);
520+
efi_systab = __va(ia64_boot_param->efi_systab);
512521

513522
/*
514523
* Verify the EFI Table
515524
*/
516-
if (efi.systab == NULL)
525+
if (efi_systab == NULL)
517526
panic("Whoa! Can't find EFI system table.\n");
518-
if (efi.systab->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
527+
if (efi_systab_check_header(&efi_systab->hdr, 1))
519528
panic("Whoa! EFI system table signature incorrect\n");
520-
if ((efi.systab->hdr.revision >> 16) == 0)
521-
printk(KERN_WARNING "Warning: EFI system table version "
522-
"%d.%02d, expected 1.00 or greater\n",
523-
efi.systab->hdr.revision >> 16,
524-
efi.systab->hdr.revision & 0xffff);
525-
526-
/* Show what we know for posterity */
527-
c16 = __va(efi.systab->fw_vendor);
528-
if (c16) {
529-
for (i = 0;i < (int) sizeof(vendor) - 1 && *c16; ++i)
530-
vendor[i] = *c16++;
531-
vendor[i] = '\0';
532-
}
533529

534-
printk(KERN_INFO "EFI v%u.%.02u by %s:",
535-
efi.systab->hdr.revision >> 16,
536-
efi.systab->hdr.revision & 0xffff, vendor);
530+
efi_systab_report_header(&efi_systab->hdr, efi_systab->fw_vendor);
537531

538532
palo_phys = EFI_INVALID_TABLE_ADDR;
539533

540-
if (efi_config_init(arch_tables) != 0)
534+
if (efi_config_parse_tables(__va(efi_systab->tables),
535+
efi_systab->nr_tables,
536+
arch_tables) != 0)
541537
return;
542538

543539
if (palo_phys != EFI_INVALID_TABLE_ADDR)
544540
handle_palo(palo_phys);
545541

546-
runtime = __va(efi.systab->runtime);
542+
runtime = __va(efi_systab->runtime);
547543
efi.get_time = phys_get_time;
548544
efi.set_time = phys_set_time;
549545
efi.get_wakeup_time = phys_get_wakeup_time;
@@ -1351,3 +1347,12 @@ vmcore_find_descriptor_size (unsigned long address)
13511347
return ret;
13521348
}
13531349
#endif
1350+
1351+
char *efi_systab_show_arch(char *str)
1352+
{
1353+
if (mps_phys != EFI_INVALID_TABLE_ADDR)
1354+
str += sprintf(str, "MPS=0x%lx\n", mps_phys);
1355+
if (hcdp_phys != EFI_INVALID_TABLE_ADDR)
1356+
str += sprintf(str, "HCDP=0x%lx\n", hcdp_phys);
1357+
return str;
1358+
}

0 commit comments

Comments
 (0)