Skip to content

Commit 762f169

Browse files
committed
efi/x86: Move EFI runtime call setup/teardown helpers out of line
Only the arch_efi_call_virt() macro that some architectures override needs to be a macro, given that it is variadic and encapsulates calls via function pointers that have different prototypes. The associated setup and teardown code are not special in this regard, and don't need to be instantiated at each call site. So turn them into ordinary C functions and move them out of line. Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
1 parent 0bb80ec commit 762f169

File tree

3 files changed

+31
-32
lines changed

3 files changed

+31
-32
lines changed

arch/x86/include/asm/efi.h

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,6 @@ static inline void efi_fpu_end(void)
9191

9292
#ifdef CONFIG_X86_32
9393
#define EFI_X86_KERNEL_ALLOC_LIMIT (SZ_512M - 1)
94-
95-
#define arch_efi_call_virt_setup() \
96-
({ \
97-
efi_fpu_begin(); \
98-
firmware_restrict_branch_speculation_start(); \
99-
})
100-
101-
#define arch_efi_call_virt_teardown() \
102-
({ \
103-
firmware_restrict_branch_speculation_end(); \
104-
efi_fpu_end(); \
105-
})
106-
10794
#else /* !CONFIG_X86_32 */
10895
#define EFI_X86_KERNEL_ALLOC_LIMIT EFI_ALLOC_LIMIT
10996

@@ -116,14 +103,6 @@ extern bool efi_disable_ibt_for_runtime;
116103
__efi_call(__VA_ARGS__); \
117104
})
118105

119-
#define arch_efi_call_virt_setup() \
120-
({ \
121-
efi_sync_low_kernel_mappings(); \
122-
efi_fpu_begin(); \
123-
firmware_restrict_branch_speculation_start(); \
124-
efi_enter_mm(); \
125-
})
126-
127106
#undef arch_efi_call_virt
128107
#define arch_efi_call_virt(p, f, args...) ({ \
129108
u64 ret, ibt = ibt_save(efi_disable_ibt_for_runtime); \
@@ -132,13 +111,6 @@ extern bool efi_disable_ibt_for_runtime;
132111
ret; \
133112
})
134113

135-
#define arch_efi_call_virt_teardown() \
136-
({ \
137-
efi_leave_mm(); \
138-
firmware_restrict_branch_speculation_end(); \
139-
efi_fpu_end(); \
140-
})
141-
142114
#ifdef CONFIG_KASAN
143115
/*
144116
* CONFIG_KASAN may redefine memset to __memset. __memset function is present
@@ -168,8 +140,8 @@ extern void efi_delete_dummy_variable(void);
168140
extern void efi_crash_gracefully_on_page_fault(unsigned long phys_addr);
169141
extern void efi_free_boot_services(void);
170142

171-
void efi_enter_mm(void);
172-
void efi_leave_mm(void);
143+
void arch_efi_call_virt_setup(void);
144+
void arch_efi_call_virt_teardown(void);
173145

174146
/* kexec external ABI */
175147
struct efi_setup_data {

arch/x86/platform/efi/efi_32.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,15 @@ void __init efi_runtime_update_mappings(void)
140140
}
141141
}
142142
}
143+
144+
void arch_efi_call_virt_setup(void)
145+
{
146+
efi_fpu_begin();
147+
firmware_restrict_branch_speculation_start();
148+
}
149+
150+
void arch_efi_call_virt_teardown(void)
151+
{
152+
firmware_restrict_branch_speculation_end();
153+
efi_fpu_end();
154+
}

arch/x86/platform/efi/efi_64.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,19 +474,34 @@ void __init efi_dump_pagetable(void)
474474
* can not change under us.
475475
* It should be ensured that there are no concurrent calls to this function.
476476
*/
477-
void efi_enter_mm(void)
477+
static void efi_enter_mm(void)
478478
{
479479
efi_prev_mm = current->active_mm;
480480
current->active_mm = &efi_mm;
481481
switch_mm(efi_prev_mm, &efi_mm, NULL);
482482
}
483483

484-
void efi_leave_mm(void)
484+
static void efi_leave_mm(void)
485485
{
486486
current->active_mm = efi_prev_mm;
487487
switch_mm(&efi_mm, efi_prev_mm, NULL);
488488
}
489489

490+
void arch_efi_call_virt_setup(void)
491+
{
492+
efi_sync_low_kernel_mappings();
493+
efi_fpu_begin();
494+
firmware_restrict_branch_speculation_start();
495+
efi_enter_mm();
496+
}
497+
498+
void arch_efi_call_virt_teardown(void)
499+
{
500+
efi_leave_mm();
501+
firmware_restrict_branch_speculation_end();
502+
efi_fpu_end();
503+
}
504+
490505
static DEFINE_SPINLOCK(efi_runtime_lock);
491506

492507
/*

0 commit comments

Comments
 (0)