Skip to content

Commit 3c17ae4

Browse files
committed
efi/runtime-wrappers: Don't duplicate setup/teardown code
Avoid duplicating the EFI arch setup and teardown routine calls numerous times in efi_call_rts(). Instead, expand the efi_call_virt_pointer() macro into efi_call_rts(), taking the pre and post parts out of the switch. Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
1 parent e38abda commit 3c17ae4

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

drivers/firmware/efi/runtime-wrappers.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
* code doesn't get too cluttered:
4141
*/
4242
#define efi_call_virt(f, args...) \
43-
efi_call_virt_pointer(efi.runtime, f, args)
43+
arch_efi_call_virt(efi.runtime, f, args)
4444

4545
union efi_rts_args {
4646
struct {
@@ -139,7 +139,7 @@ unsigned long efi_call_virt_save_flags(void)
139139
return flags;
140140
}
141141

142-
void efi_call_virt_check_flags(unsigned long flags, const char *call)
142+
void efi_call_virt_check_flags(unsigned long flags, const void *caller)
143143
{
144144
unsigned long cur_flags, mismatch;
145145

@@ -150,8 +150,8 @@ void efi_call_virt_check_flags(unsigned long flags, const char *call)
150150
return;
151151

152152
add_taint(TAINT_FIRMWARE_WORKAROUND, LOCKDEP_NOW_UNRELIABLE);
153-
pr_err_ratelimited(FW_BUG "IRQ flags corrupted (0x%08lx=>0x%08lx) by EFI %s\n",
154-
flags, cur_flags, call);
153+
pr_err_ratelimited(FW_BUG "IRQ flags corrupted (0x%08lx=>0x%08lx) by EFI call from %pS\n",
154+
flags, cur_flags, caller ?: __builtin_return_address(0));
155155
arch_efi_restore_flags(flags);
156156
}
157157

@@ -211,6 +211,10 @@ static void efi_call_rts(struct work_struct *work)
211211
{
212212
const union efi_rts_args *args = efi_rts_work.args;
213213
efi_status_t status = EFI_NOT_FOUND;
214+
unsigned long flags;
215+
216+
arch_efi_call_virt_setup();
217+
flags = efi_call_virt_save_flags();
214218

215219
switch (efi_rts_work.efi_rts_id) {
216220
case EFI_GET_TIME:
@@ -287,6 +291,10 @@ static void efi_call_rts(struct work_struct *work)
287291
*/
288292
pr_err("Requested executing invalid EFI Runtime Service.\n");
289293
}
294+
295+
efi_call_virt_check_flags(flags, efi_rts_work.caller);
296+
arch_efi_call_virt_teardown();
297+
290298
efi_rts_work.status = status;
291299
complete(&efi_rts_work.efi_rts_comp);
292300
}
@@ -296,6 +304,7 @@ static efi_status_t __efi_queue_work(enum efi_rts_ids id,
296304
{
297305
efi_rts_work.efi_rts_id = id;
298306
efi_rts_work.args = args;
307+
efi_rts_work.caller = __builtin_return_address(0);
299308
efi_rts_work.status = EFI_ABORTED;
300309

301310
if (!efi_enabled(EFI_RUNTIME_SERVICES)) {
@@ -423,8 +432,8 @@ virt_efi_set_variable_nonblocking(efi_char16_t *name, efi_guid_t *vendor,
423432
if (down_trylock(&efi_runtime_lock))
424433
return EFI_NOT_READY;
425434

426-
status = efi_call_virt(set_variable, name, vendor, attr, data_size,
427-
data);
435+
status = efi_call_virt_pointer(efi.runtime, set_variable, name, vendor,
436+
attr, data_size, data);
428437
up(&efi_runtime_lock);
429438
return status;
430439
}
@@ -462,8 +471,9 @@ virt_efi_query_variable_info_nonblocking(u32 attr,
462471
if (down_trylock(&efi_runtime_lock))
463472
return EFI_NOT_READY;
464473

465-
status = efi_call_virt(query_variable_info, attr, storage_space,
466-
remaining_space, max_variable_size);
474+
status = efi_call_virt_pointer(efi.runtime, query_variable_info, attr,
475+
storage_space, remaining_space,
476+
max_variable_size);
467477
up(&efi_runtime_lock);
468478
return status;
469479
}

include/linux/efi.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ extern bool efi_runtime_disabled(void);
11291129
static inline bool efi_runtime_disabled(void) { return true; }
11301130
#endif
11311131

1132-
extern void efi_call_virt_check_flags(unsigned long flags, const char *call);
1132+
extern void efi_call_virt_check_flags(unsigned long flags, const void *caller);
11331133
extern unsigned long efi_call_virt_save_flags(void);
11341134

11351135
enum efi_secureboot_mode {
@@ -1196,7 +1196,7 @@ static inline void efi_check_for_embedded_firmwares(void) { }
11961196
\
11971197
__flags = efi_call_virt_save_flags(); \
11981198
__s = arch_efi_call_virt(p, f, args); \
1199-
efi_call_virt_check_flags(__flags, __stringify(f)); \
1199+
efi_call_virt_check_flags(__flags, NULL); \
12001200
\
12011201
arch_efi_call_virt_teardown(); \
12021202
\
@@ -1257,13 +1257,15 @@ union efi_rts_args;
12571257
* @status: Status of executing EFI Runtime Service
12581258
* @efi_rts_id: EFI Runtime Service function identifier
12591259
* @efi_rts_comp: Struct used for handling completions
1260+
* @caller: The caller of the runtime service
12601261
*/
12611262
struct efi_runtime_work {
12621263
union efi_rts_args *args;
12631264
efi_status_t status;
12641265
struct work_struct work;
12651266
enum efi_rts_ids efi_rts_id;
12661267
struct completion efi_rts_comp;
1268+
const void *caller;
12671269
};
12681270

12691271
extern struct efi_runtime_work efi_rts_work;

0 commit comments

Comments
 (0)