EFI updates for v5.12

A few cleanups left and right, some of which were part of a initrd
 measured boot series that needs some more work, and so only the cleanup
 patches have been included for this release.
 -----BEGIN PGP SIGNATURE-----
 
 iQGzBAABCgAdFiEE+9lifEBpyUIVN1cpw08iOZLZjyQFAmAQUrwACgkQw08iOZLZ
 jySQqwv+J29DtGV3QSYBLQcgCWJLBndO8kcpz2voEhFeQRkTdg9oTRnD0OMOEOY5
 xnfr9nvsc4miskOi1I6wDT+j22MouNGxhJrI0755a+ce+/MN2JpMsgMvSzu94upp
 N5lgtSTC3F5W8uzkXZ268N3p0zepJhHYVjjpzGwhaRsaE8w51952VaocTxmL6/su
 vl797lVfVhF/gQ/HrEnN/45Ti8drTQ65hZ5Jv5RyTPpwQW0n3BV2Vhi3U6SG7zwY
 ZBtdXGNWMV1mEvYf44UoaQoSo2fwcWjpY/bcrDvUt8HVeNU6yAkuOs5Sv4gkACbG
 tC/M0SeCnSOc1CmKfUTc5o+50ROnT+CZZwwXJ1YQHfdqN4ZuLTswN5eH3PFSMBfl
 1gxK5zX/iq0ntaF/e1frSZpp+67/mSSxFLgEi3OLl5FdKZXXTjQkydXx9rifLl1B
 iUEW9DbCXoFiE0P1F8U//oPCJynw7IjG1LhueaXYmarwHIGStxkh05Es8oFlz6JZ
 EZhqiuEr
 =6iND
 -----END PGP SIGNATURE-----

Merge tag 'efi-next-for-v5.12' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull EFI updates from Ard Biesheuvel via Borislav Petkov:
 "A few cleanups left and right, some of which were part of a initrd
  measured boot series that needs some more work, and so only the
  cleanup patches have been included for this release"

* tag 'efi-next-for-v5.12' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  efi/arm64: Update debug prints to reflect other entropy sources
  efi: x86: clean up previous struct mm switching
  efi: x86: move mixed mode stack PA variable out of 'efi_scratch'
  efi/libstub: move TPM related prototypes into efistub.h
  efi/libstub: fix prototype of efi_tcg2_protocol::get_event_log()
  efi/libstub: whitespace cleanup
  efi: ia64: move IA64-only declarations to new asm/efi.h header
This commit is contained in:
Linus Torvalds 2021-02-20 19:09:26 -08:00
commit 70cd33d34c
16 changed files with 63 additions and 51 deletions

View File

@ -0,0 +1,13 @@
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _ASM_EFI_H
#define _ASM_EFI_H
typedef int (*efi_freemem_callback_t) (u64 start, u64 end, void *arg);
void *efi_get_pal_addr(void);
void efi_map_pal_code(void);
void efi_memmap_walk(efi_freemem_callback_t, void *);
void efi_memmap_walk_uc(efi_freemem_callback_t, void *);
void efi_gettimeofday(struct timespec64 *ts);
#endif

View File

@ -34,6 +34,7 @@
#include <linux/kexec.h> #include <linux/kexec.h>
#include <linux/mm.h> #include <linux/mm.h>
#include <asm/efi.h>
#include <asm/io.h> #include <asm/io.h>
#include <asm/kregs.h> #include <asm/kregs.h>
#include <asm/meminit.h> #include <asm/meminit.h>

View File

@ -16,6 +16,7 @@
#include <linux/numa.h> #include <linux/numa.h>
#include <linux/mmzone.h> #include <linux/mmzone.h>
#include <asm/efi.h>
#include <asm/numa.h> #include <asm/numa.h>
#include <asm/mmu_context.h> #include <asm/mmu_context.h>
#include <asm/setup.h> #include <asm/setup.h>

View File

@ -91,6 +91,7 @@
#include <linux/gfp.h> #include <linux/gfp.h>
#include <asm/delay.h> #include <asm/delay.h>
#include <asm/efi.h>
#include <asm/meminit.h> #include <asm/meminit.h>
#include <asm/page.h> #include <asm/page.h>
#include <asm/ptrace.h> #include <asm/ptrace.h>

View File

@ -45,6 +45,7 @@
#include <asm/cache.h> #include <asm/cache.h>
#include <asm/current.h> #include <asm/current.h>
#include <asm/delay.h> #include <asm/delay.h>
#include <asm/efi.h>
#include <asm/io.h> #include <asm/io.h>
#include <asm/irq.h> #include <asm/irq.h>
#include <asm/mca.h> #include <asm/mca.h>

View File

@ -26,6 +26,7 @@
#include <linux/sched/cputime.h> #include <linux/sched/cputime.h>
#include <asm/delay.h> #include <asm/delay.h>
#include <asm/efi.h>
#include <asm/hw_irq.h> #include <asm/hw_irq.h>
#include <asm/ptrace.h> #include <asm/ptrace.h>
#include <asm/sal.h> #include <asm/sal.h>

View File

@ -20,14 +20,12 @@
#include <linux/genalloc.h> #include <linux/genalloc.h>
#include <linux/gfp.h> #include <linux/gfp.h>
#include <linux/pgtable.h> #include <linux/pgtable.h>
#include <asm/efi.h>
#include <asm/page.h> #include <asm/page.h>
#include <asm/pal.h> #include <asm/pal.h>
#include <linux/atomic.h> #include <linux/atomic.h>
#include <asm/tlbflush.h> #include <asm/tlbflush.h>
extern void __init efi_memmap_walk_uc(efi_freemem_callback_t, void *);
struct uncached_pool { struct uncached_pool {
struct gen_pool *pool; struct gen_pool *pool;
struct mutex add_chunk_mutex; /* serialize adding a converted chunk */ struct mutex add_chunk_mutex; /* serialize adding a converted chunk */

View File

@ -21,6 +21,7 @@
#include <linux/swap.h> #include <linux/swap.h>
#include <linux/sizes.h> #include <linux/sizes.h>
#include <asm/efi.h>
#include <asm/meminit.h> #include <asm/meminit.h>
#include <asm/sections.h> #include <asm/sections.h>
#include <asm/mca.h> #include <asm/mca.h>

View File

@ -24,6 +24,7 @@
#include <linux/efi.h> #include <linux/efi.h>
#include <linux/nodemask.h> #include <linux/nodemask.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <asm/efi.h>
#include <asm/tlb.h> #include <asm/tlb.h>
#include <asm/meminit.h> #include <asm/meminit.h>
#include <asm/numa.h> #include <asm/numa.h>

View File

@ -27,6 +27,7 @@
#include <linux/swiotlb.h> #include <linux/swiotlb.h>
#include <asm/dma.h> #include <asm/dma.h>
#include <asm/efi.h>
#include <asm/io.h> #include <asm/io.h>
#include <asm/numa.h> #include <asm/numa.h>
#include <asm/patch.h> #include <asm/patch.h>

View File

@ -12,6 +12,7 @@
#include <linux/pgtable.h> #include <linux/pgtable.h>
extern unsigned long efi_fw_vendor, efi_config_table; extern unsigned long efi_fw_vendor, efi_config_table;
extern unsigned long efi_mixed_mode_stack_pa;
/* /*
* We map the EFI regions needed for runtime services non-contiguously, * We map the EFI regions needed for runtime services non-contiguously,
@ -94,22 +95,12 @@ extern asmlinkage u64 __efi_call(void *fp, ...);
__efi_call(__VA_ARGS__); \ __efi_call(__VA_ARGS__); \
}) })
/*
* struct efi_scratch - Scratch space used while switching to/from efi_mm
* @phys_stack: stack used during EFI Mixed Mode
* @prev_mm: store/restore stolen mm_struct while switching to/from efi_mm
*/
struct efi_scratch {
u64 phys_stack;
struct mm_struct *prev_mm;
} __packed;
#define arch_efi_call_virt_setup() \ #define arch_efi_call_virt_setup() \
({ \ ({ \
efi_sync_low_kernel_mappings(); \ efi_sync_low_kernel_mappings(); \
kernel_fpu_begin(); \ kernel_fpu_begin(); \
firmware_restrict_branch_speculation_start(); \ firmware_restrict_branch_speculation_start(); \
efi_switch_mm(&efi_mm); \ efi_enter_mm(); \
}) })
#define arch_efi_call_virt(p, f, args...) \ #define arch_efi_call_virt(p, f, args...) \
@ -117,7 +108,7 @@ struct efi_scratch {
#define arch_efi_call_virt_teardown() \ #define arch_efi_call_virt_teardown() \
({ \ ({ \
efi_switch_mm(efi_scratch.prev_mm); \ efi_leave_mm(); \
firmware_restrict_branch_speculation_end(); \ firmware_restrict_branch_speculation_end(); \
kernel_fpu_end(); \ kernel_fpu_end(); \
}) })
@ -136,7 +127,6 @@ struct efi_scratch {
#endif /* CONFIG_X86_32 */ #endif /* CONFIG_X86_32 */
extern struct efi_scratch efi_scratch;
extern int __init efi_memblock_x86_reserve_range(void); extern int __init efi_memblock_x86_reserve_range(void);
extern void __init efi_print_memmap(void); extern void __init efi_print_memmap(void);
extern void __init efi_map_region(efi_memory_desc_t *md); extern void __init efi_map_region(efi_memory_desc_t *md);
@ -149,10 +139,12 @@ extern void __init efi_dump_pagetable(void);
extern void __init efi_apply_memmap_quirks(void); extern void __init efi_apply_memmap_quirks(void);
extern int __init efi_reuse_config(u64 tables, int nr_tables); extern int __init efi_reuse_config(u64 tables, int nr_tables);
extern void efi_delete_dummy_variable(void); extern void efi_delete_dummy_variable(void);
extern void efi_switch_mm(struct mm_struct *mm);
extern void efi_recover_from_page_fault(unsigned long phys_addr); extern void efi_recover_from_page_fault(unsigned long phys_addr);
extern void efi_free_boot_services(void); extern void efi_free_boot_services(void);
void efi_enter_mm(void);
void efi_leave_mm(void);
/* kexec external ABI */ /* kexec external ABI */
struct efi_setup_data { struct efi_setup_data {
u64 fw_vendor; u64 fw_vendor;

View File

@ -54,10 +54,7 @@
* 0xffff_ffff_0000_0000 and limit EFI VA mapping space to 64G. * 0xffff_ffff_0000_0000 and limit EFI VA mapping space to 64G.
*/ */
static u64 efi_va = EFI_VA_START; static u64 efi_va = EFI_VA_START;
static struct mm_struct *efi_prev_mm;
struct efi_scratch efi_scratch;
EXPORT_SYMBOL_GPL(efi_mm);
/* /*
* We need our own copy of the higher levels of the page tables * We need our own copy of the higher levels of the page tables
@ -237,7 +234,7 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
return 1; return 1;
} }
efi_scratch.phys_stack = page_to_phys(page + 1); /* stack grows down */ efi_mixed_mode_stack_pa = page_to_phys(page + 1); /* stack grows down */
npages = (_etext - _text) >> PAGE_SHIFT; npages = (_etext - _text) >> PAGE_SHIFT;
text = __pa(_text); text = __pa(_text);
@ -462,11 +459,17 @@ void __init efi_dump_pagetable(void)
* can not change under us. * can not change under us.
* It should be ensured that there are no concurent calls to this function. * It should be ensured that there are no concurent calls to this function.
*/ */
void efi_switch_mm(struct mm_struct *mm) void efi_enter_mm(void)
{ {
efi_scratch.prev_mm = current->active_mm; efi_prev_mm = current->active_mm;
current->active_mm = mm; current->active_mm = &efi_mm;
switch_mm(efi_scratch.prev_mm, mm, NULL); switch_mm(efi_prev_mm, &efi_mm, NULL);
}
void efi_leave_mm(void)
{
current->active_mm = efi_prev_mm;
switch_mm(&efi_mm, efi_prev_mm, NULL);
} }
static DEFINE_SPINLOCK(efi_runtime_lock); static DEFINE_SPINLOCK(efi_runtime_lock);
@ -530,12 +533,12 @@ efi_thunk_set_virtual_address_map(unsigned long memory_map_size,
efi_sync_low_kernel_mappings(); efi_sync_low_kernel_mappings();
local_irq_save(flags); local_irq_save(flags);
efi_switch_mm(&efi_mm); efi_enter_mm();
status = __efi_thunk(set_virtual_address_map, memory_map_size, status = __efi_thunk(set_virtual_address_map, memory_map_size,
descriptor_size, descriptor_version, virtual_map); descriptor_size, descriptor_version, virtual_map);
efi_switch_mm(efi_scratch.prev_mm); efi_leave_mm();
local_irq_restore(flags); local_irq_restore(flags);
return status; return status;
@ -829,7 +832,7 @@ efi_set_virtual_address_map(unsigned long memory_map_size,
descriptor_size, descriptor_size,
descriptor_version, descriptor_version,
virtual_map); virtual_map);
efi_switch_mm(&efi_mm); efi_enter_mm();
kernel_fpu_begin(); kernel_fpu_begin();
@ -845,7 +848,7 @@ efi_set_virtual_address_map(unsigned long memory_map_size,
/* grab the virtually remapped EFI runtime services table pointer */ /* grab the virtually remapped EFI runtime services table pointer */
efi.runtime = READ_ONCE(systab->runtime); efi.runtime = READ_ONCE(systab->runtime);
efi_switch_mm(efi_scratch.prev_mm); efi_leave_mm();
return status; return status;
} }

View File

@ -33,7 +33,7 @@ SYM_CODE_START(__efi64_thunk)
* Switch to 1:1 mapped 32-bit stack pointer. * Switch to 1:1 mapped 32-bit stack pointer.
*/ */
movq %rsp, %rax movq %rsp, %rax
movq efi_scratch(%rip), %rsp movq efi_mixed_mode_stack_pa(%rip), %rsp
push %rax push %rax
/* /*
@ -70,3 +70,7 @@ SYM_CODE_START(__efi64_thunk)
pushl %ebp pushl %ebp
lret lret
SYM_CODE_END(__efi64_thunk) SYM_CODE_END(__efi64_thunk)
.bss
.balign 8
SYM_DATA(efi_mixed_mode_stack_pa, .quad 0)

View File

@ -61,10 +61,10 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
status = efi_get_random_bytes(sizeof(phys_seed), status = efi_get_random_bytes(sizeof(phys_seed),
(u8 *)&phys_seed); (u8 *)&phys_seed);
if (status == EFI_NOT_FOUND) { if (status == EFI_NOT_FOUND) {
efi_info("EFI_RNG_PROTOCOL unavailable, KASLR will be disabled\n"); efi_info("EFI_RNG_PROTOCOL unavailable\n");
efi_nokaslr = true; efi_nokaslr = true;
} else if (status != EFI_SUCCESS) { } else if (status != EFI_SUCCESS) {
efi_err("efi_get_random_bytes() failed (0x%lx), KASLR will be disabled\n", efi_err("efi_get_random_bytes() failed (0x%lx)\n",
status); status);
efi_nokaslr = true; efi_nokaslr = true;
} }

View File

@ -672,7 +672,7 @@ typedef union efi_tcg2_protocol efi_tcg2_protocol_t;
union efi_tcg2_protocol { union efi_tcg2_protocol {
struct { struct {
void *get_capability; void *get_capability;
efi_status_t (__efiapi *get_event_log)(efi_handle_t, efi_status_t (__efiapi *get_event_log)(efi_tcg2_protocol_t *,
efi_tcg2_event_log_format, efi_tcg2_event_log_format,
efi_physical_addr_t *, efi_physical_addr_t *,
efi_physical_addr_t *, efi_physical_addr_t *,
@ -849,4 +849,13 @@ void efi_handle_post_ebs_state(void);
enum efi_secureboot_mode efi_get_secureboot(void); enum efi_secureboot_mode efi_get_secureboot(void);
#ifdef CONFIG_RESET_ATTACK_MITIGATION
void efi_enable_reset_attack_mitigation(void);
#else
static inline void
efi_enable_reset_attack_mitigation(void) { }
#endif
void efi_retrieve_tpm2_eventlog(void);
#endif #endif

View File

@ -167,8 +167,6 @@ struct capsule_info {
int __efi_capsule_setup_info(struct capsule_info *cap_info); int __efi_capsule_setup_info(struct capsule_info *cap_info);
typedef int (*efi_freemem_callback_t) (u64 start, u64 end, void *arg);
/* /*
* Types and defines for Time Services * Types and defines for Time Services
*/ */
@ -605,10 +603,6 @@ efi_guid_to_str(efi_guid_t *guid, char *out)
} }
extern void efi_init (void); extern void efi_init (void);
extern void *efi_get_pal_addr (void);
extern void efi_map_pal_code (void);
extern void efi_memmap_walk (efi_freemem_callback_t callback, void *arg);
extern void efi_gettimeofday (struct timespec64 *ts);
#ifdef CONFIG_EFI #ifdef CONFIG_EFI
extern void efi_enter_virtual_mode (void); /* switch EFI to virtual mode, if possible */ extern void efi_enter_virtual_mode (void); /* switch EFI to virtual mode, if possible */
#else #else
@ -1110,13 +1104,6 @@ enum efi_secureboot_mode efi_get_secureboot_mode(efi_get_variable_t *get_var)
return efi_secureboot_mode_enabled; return efi_secureboot_mode_enabled;
} }
#ifdef CONFIG_RESET_ATTACK_MITIGATION
void efi_enable_reset_attack_mitigation(void);
#else
static inline void
efi_enable_reset_attack_mitigation(void) { }
#endif
#ifdef CONFIG_EFI_EMBEDDED_FIRMWARE #ifdef CONFIG_EFI_EMBEDDED_FIRMWARE
void efi_check_for_embedded_firmwares(void); void efi_check_for_embedded_firmwares(void);
#else #else
@ -1125,8 +1112,6 @@ static inline void efi_check_for_embedded_firmwares(void) { }
efi_status_t efi_random_get_seed(void); efi_status_t efi_random_get_seed(void);
void efi_retrieve_tpm2_eventlog(void);
/* /*
* Arch code can implement the following three template macros, avoiding * Arch code can implement the following three template macros, avoiding
* reptition for the void/non-void return cases of {__,}efi_call_virt(): * reptition for the void/non-void return cases of {__,}efi_call_virt():