Skip to content

Commit f4b603e

Browse files
committed
efi/runtime-wrappers: Don't duplicate setup/teardown code
JIRA: https://issues.redhat.com/browse/RHEL-22695 Tested: sanity commit 3c17ae4 Author: Ard Biesheuvel <[email protected]> Date: Tue Aug 8 12:47:51 2023 +0200 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 <[email protected]> Signed-off-by: Aristeu Rozanski <[email protected]>
1 parent 6a6bc5e commit f4b603e

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
@@ -1182,7 +1182,7 @@ extern bool efi_runtime_disabled(void);
11821182
static inline bool efi_runtime_disabled(void) { return true; }
11831183
#endif
11841184

1185-
extern void efi_call_virt_check_flags(unsigned long flags, const char *call);
1185+
extern void efi_call_virt_check_flags(unsigned long flags, const void *caller);
11861186
extern unsigned long efi_call_virt_save_flags(void);
11871187

11881188
static inline
@@ -1242,7 +1242,7 @@ static inline void efi_check_for_embedded_firmwares(void) { }
12421242
\
12431243
__flags = efi_call_virt_save_flags(); \
12441244
__s = arch_efi_call_virt(p, f, args); \
1245-
efi_call_virt_check_flags(__flags, __stringify(f)); \
1245+
efi_call_virt_check_flags(__flags, NULL); \
12461246
\
12471247
arch_efi_call_virt_teardown(); \
12481248
\
@@ -1303,13 +1303,15 @@ union efi_rts_args;
13031303
* @status: Status of executing EFI Runtime Service
13041304
* @efi_rts_id: EFI Runtime Service function identifier
13051305
* @efi_rts_comp: Struct used for handling completions
1306+
* @caller: The caller of the runtime service
13061307
*/
13071308
struct efi_runtime_work {
13081309
union efi_rts_args *args;
13091310
efi_status_t status;
13101311
struct work_struct work;
13111312
enum efi_rts_ids efi_rts_id;
13121313
struct completion efi_rts_comp;
1314+
const void *caller;
13131315
};
13141316

13151317
extern struct efi_runtime_work efi_rts_work;

0 commit comments

Comments
 (0)