efi: x86: clean up previous struct mm switching
authorArd Biesheuvel <ardb@kernel.org>
Tue, 19 Jan 2021 14:05:40 +0000 (15:05 +0100)
committerArd Biesheuvel <ardb@kernel.org>
Tue, 19 Jan 2021 16:57:15 +0000 (17:57 +0100)
EFI on x86_64 keeps track of the process's MM pointer by storing it
in a global struct called 'efi_scratch', which also used to contain
the mixed mode stack pointer. Let's clean this up a little bit, by
getting rid of the struct, and pushing the mm handling into the
callees entirely.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
arch/x86/include/asm/efi.h
arch/x86/platform/efi/efi_64.c

index 5e37e6d..1328b79 100644 (file)
@@ -95,20 +95,12 @@ extern asmlinkage u64 __efi_call(void *fp, ...);
        __efi_call(__VA_ARGS__);                                        \
 })
 
-/*
- * struct efi_scratch - Scratch space used while switching to/from efi_mm
- * @prev_mm:    store/restore stolen mm_struct while switching to/from efi_mm
- */
-struct efi_scratch {
-       struct mm_struct        *prev_mm;
-} __packed;
-
 #define arch_efi_call_virt_setup()                                     \
 ({                                                                     \
        efi_sync_low_kernel_mappings();                                 \
        kernel_fpu_begin();                                             \
        firmware_restrict_branch_speculation_start();                   \
-       efi_switch_mm(&efi_mm);                                         \
+       efi_enter_mm();                                                 \
 })
 
 #define arch_efi_call_virt(p, f, args...)                              \
@@ -116,7 +108,7 @@ struct efi_scratch {
 
 #define arch_efi_call_virt_teardown()                                  \
 ({                                                                     \
-       efi_switch_mm(efi_scratch.prev_mm);                             \
+       efi_leave_mm();                                                 \
        firmware_restrict_branch_speculation_end();                     \
        kernel_fpu_end();                                               \
 })
@@ -135,7 +127,6 @@ struct efi_scratch {
 
 #endif /* CONFIG_X86_32 */
 
-extern struct efi_scratch efi_scratch;
 extern int __init efi_memblock_x86_reserve_range(void);
 extern void __init efi_print_memmap(void);
 extern void __init efi_map_region(efi_memory_desc_t *md);
@@ -148,10 +139,12 @@ extern void __init efi_dump_pagetable(void);
 extern void __init efi_apply_memmap_quirks(void);
 extern int __init efi_reuse_config(u64 tables, int nr_tables);
 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_free_boot_services(void);
 
+void efi_enter_mm(void);
+void efi_leave_mm(void);
+
 /* kexec external ABI */
 struct efi_setup_data {
        u64 fw_vendor;
index 1d90418..62a6c86 100644 (file)
  * 0xffff_ffff_0000_0000 and limit EFI VA mapping space to 64G.
  */
 static u64 efi_va = EFI_VA_START;
-
-struct efi_scratch efi_scratch;
-
-EXPORT_SYMBOL_GPL(efi_mm);
+static struct mm_struct *efi_prev_mm;
 
 /*
  * We need our own copy of the higher levels of the page tables
@@ -481,11 +478,17 @@ void __init efi_dump_pagetable(void)
  * can not change under us.
  * 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_prev_mm = current->active_mm;
+       current->active_mm = &efi_mm;
+       switch_mm(efi_prev_mm, &efi_mm, NULL);
+}
+
+void efi_leave_mm(void)
 {
-       efi_scratch.prev_mm = current->active_mm;
-       current->active_mm = mm;
-       switch_mm(efi_scratch.prev_mm, mm, NULL);
+       current->active_mm = efi_prev_mm;
+       switch_mm(&efi_mm, efi_prev_mm, NULL);
 }
 
 static DEFINE_SPINLOCK(efi_runtime_lock);
@@ -549,12 +552,12 @@ efi_thunk_set_virtual_address_map(unsigned long memory_map_size,
        efi_sync_low_kernel_mappings();
        local_irq_save(flags);
 
-       efi_switch_mm(&efi_mm);
+       efi_enter_mm();
 
        status = __efi_thunk(set_virtual_address_map, memory_map_size,
                             descriptor_size, descriptor_version, virtual_map);
 
-       efi_switch_mm(efi_scratch.prev_mm);
+       efi_leave_mm();
        local_irq_restore(flags);
 
        return status;
@@ -848,7 +851,7 @@ efi_set_virtual_address_map(unsigned long memory_map_size,
                                                         descriptor_size,
                                                         descriptor_version,
                                                         virtual_map);
-       efi_switch_mm(&efi_mm);
+       efi_enter_mm();
 
        kernel_fpu_begin();
 
@@ -864,7 +867,7 @@ efi_set_virtual_address_map(unsigned long memory_map_size,
        /* grab the virtually remapped EFI runtime services table pointer */
        efi.runtime = READ_ONCE(systab->runtime);
 
-       efi_switch_mm(efi_scratch.prev_mm);
+       efi_leave_mm();
 
        return status;
 }