Skip to content

Commit b967696

Browse files
ardbiesheuvelIngo Molnar
authored andcommitted
efi/arm64: Clean EFI stub exit code from cache instead of avoiding it
Commit 9f92237 ("efi/libstub/arm: Make efi_entry() an ordinary PE/COFF entrypoint") modified the handover code written in assembler, and for maintainability, aligned the logic with the logic used in the 32-bit ARM version, which is to avoid cache maintenance on the remaining instructions in the subroutine that will be executed with the MMU and caches off, and instead, branch into the relocated copy of the kernel image. However, this assumes that this copy is executable, and this means we expect EFI_LOADER_DATA regions to be executable as well, which is not a reasonable assumption to make, even if this is true for most UEFI implementations today. So change this back, and add a __clean_dcache_area_poc() call to cover the remaining code in the subroutine. While at it, switch the other call site over to __clean_dcache_area_poc() as well, and clean up the terminology in comments to avoid using 'flush' in the context of cache maintenance. Also, let's switch to the new style asm annotations. Signed-off-by: Ard Biesheuvel <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Cc: [email protected] Cc: Ingo Molnar <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Heinrich Schuchardt <[email protected]> Cc: Tom Lendacky <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 0698fac commit b967696

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

arch/arm64/kernel/efi-entry.S

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,32 @@
1212

1313
__INIT
1414

15-
ENTRY(efi_enter_kernel)
15+
SYM_CODE_START(efi_enter_kernel)
1616
/*
1717
* efi_entry() will have copied the kernel image if necessary and we
1818
* end up here with device tree address in x1 and the kernel entry
1919
* point stored in x0. Save those values in registers which are
2020
* callee preserved.
2121
*/
22-
mov x19, x0 // relocated Image address
22+
ldr w2, =stext_offset
23+
add x19, x0, x2 // relocated Image entrypoint
2324
mov x20, x1 // DTB address
2425

2526
/*
26-
* Flush the copied Image to the PoC, and ensure it is not shadowed by
27+
* Clean the copied Image to the PoC, and ensure it is not shadowed by
2728
* stale icache entries from before relocation.
2829
*/
2930
ldr w1, =kernel_size
30-
bl __flush_dcache_area
31+
bl __clean_dcache_area_poc
3132
ic ialluis
32-
dsb sy
3333

3434
/*
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.
35+
* Clean the remainder of this routine to the PoC
36+
* so that we can safely disable the MMU and caches.
3737
*/
38-
ldr w0, .Ljmp
39-
sub x0, x19, w0, sxtw
40-
br x0
38+
adr x0, 0f
39+
ldr w1, 3f
40+
bl __clean_dcache_area_poc
4141
0:
4242
/* Turn off Dcache and MMU */
4343
mrs x0, CurrentEL
@@ -63,6 +63,6 @@ ENTRY(efi_enter_kernel)
6363
mov x1, xzr
6464
mov x2, xzr
6565
mov x3, xzr
66-
b stext
67-
ENDPROC(efi_enter_kernel)
68-
.Ljmp: .long _text - 0b
66+
br x19
67+
SYM_CODE_END(efi_enter_kernel)
68+
3: .long . - 0b

arch/arm64/kernel/image-vars.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifdef CONFIG_EFI
1414

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

1718

1819
/*
@@ -34,7 +35,7 @@ __efistub_strnlen = __pi_strnlen;
3435
__efistub_strcmp = __pi_strcmp;
3536
__efistub_strncmp = __pi_strncmp;
3637
__efistub_strrchr = __pi_strrchr;
37-
__efistub___flush_dcache_area = __pi___flush_dcache_area;
38+
__efistub___clean_dcache_area_poc = __pi___clean_dcache_area_poc;
3839

3940
#ifdef CONFIG_KASAN
4041
__efistub___memcpy = __pi_memcpy;
@@ -43,7 +44,6 @@ __efistub___memset = __pi_memset;
4344
#endif
4445

4546
__efistub__text = _text;
46-
__efistub_stext = stext;
4747
__efistub__end = _end;
4848
__efistub__edata = _edata;
4949
__efistub_screen_info = screen_info;

0 commit comments

Comments
 (0)