Commit 3c17ae41 authored by Ard Biesheuvel's avatar Ard Biesheuvel

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: default avatarArd Biesheuvel <ardb@kernel.org>
parent e38abdab
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
* code doesn't get too cluttered: * code doesn't get too cluttered:
*/ */
#define efi_call_virt(f, args...) \ #define efi_call_virt(f, args...) \
efi_call_virt_pointer(efi.runtime, f, args) arch_efi_call_virt(efi.runtime, f, args)
union efi_rts_args { union efi_rts_args {
struct { struct {
...@@ -139,7 +139,7 @@ unsigned long efi_call_virt_save_flags(void) ...@@ -139,7 +139,7 @@ unsigned long efi_call_virt_save_flags(void)
return flags; return flags;
} }
void efi_call_virt_check_flags(unsigned long flags, const char *call) void efi_call_virt_check_flags(unsigned long flags, const void *caller)
{ {
unsigned long cur_flags, mismatch; unsigned long cur_flags, mismatch;
...@@ -150,8 +150,8 @@ void efi_call_virt_check_flags(unsigned long flags, const char *call) ...@@ -150,8 +150,8 @@ void efi_call_virt_check_flags(unsigned long flags, const char *call)
return; return;
add_taint(TAINT_FIRMWARE_WORKAROUND, LOCKDEP_NOW_UNRELIABLE); add_taint(TAINT_FIRMWARE_WORKAROUND, LOCKDEP_NOW_UNRELIABLE);
pr_err_ratelimited(FW_BUG "IRQ flags corrupted (0x%08lx=>0x%08lx) by EFI %s\n", pr_err_ratelimited(FW_BUG "IRQ flags corrupted (0x%08lx=>0x%08lx) by EFI call from %pS\n",
flags, cur_flags, call); flags, cur_flags, caller ?: __builtin_return_address(0));
arch_efi_restore_flags(flags); arch_efi_restore_flags(flags);
} }
...@@ -211,6 +211,10 @@ static void efi_call_rts(struct work_struct *work) ...@@ -211,6 +211,10 @@ static void efi_call_rts(struct work_struct *work)
{ {
const union efi_rts_args *args = efi_rts_work.args; const union efi_rts_args *args = efi_rts_work.args;
efi_status_t status = EFI_NOT_FOUND; efi_status_t status = EFI_NOT_FOUND;
unsigned long flags;
arch_efi_call_virt_setup();
flags = efi_call_virt_save_flags();
switch (efi_rts_work.efi_rts_id) { switch (efi_rts_work.efi_rts_id) {
case EFI_GET_TIME: case EFI_GET_TIME:
...@@ -287,6 +291,10 @@ static void efi_call_rts(struct work_struct *work) ...@@ -287,6 +291,10 @@ static void efi_call_rts(struct work_struct *work)
*/ */
pr_err("Requested executing invalid EFI Runtime Service.\n"); pr_err("Requested executing invalid EFI Runtime Service.\n");
} }
efi_call_virt_check_flags(flags, efi_rts_work.caller);
arch_efi_call_virt_teardown();
efi_rts_work.status = status; efi_rts_work.status = status;
complete(&efi_rts_work.efi_rts_comp); complete(&efi_rts_work.efi_rts_comp);
} }
...@@ -296,6 +304,7 @@ static efi_status_t __efi_queue_work(enum efi_rts_ids id, ...@@ -296,6 +304,7 @@ static efi_status_t __efi_queue_work(enum efi_rts_ids id,
{ {
efi_rts_work.efi_rts_id = id; efi_rts_work.efi_rts_id = id;
efi_rts_work.args = args; efi_rts_work.args = args;
efi_rts_work.caller = __builtin_return_address(0);
efi_rts_work.status = EFI_ABORTED; efi_rts_work.status = EFI_ABORTED;
if (!efi_enabled(EFI_RUNTIME_SERVICES)) { if (!efi_enabled(EFI_RUNTIME_SERVICES)) {
...@@ -423,8 +432,8 @@ virt_efi_set_variable_nonblocking(efi_char16_t *name, efi_guid_t *vendor, ...@@ -423,8 +432,8 @@ virt_efi_set_variable_nonblocking(efi_char16_t *name, efi_guid_t *vendor,
if (down_trylock(&efi_runtime_lock)) if (down_trylock(&efi_runtime_lock))
return EFI_NOT_READY; return EFI_NOT_READY;
status = efi_call_virt(set_variable, name, vendor, attr, data_size, status = efi_call_virt_pointer(efi.runtime, set_variable, name, vendor,
data); attr, data_size, data);
up(&efi_runtime_lock); up(&efi_runtime_lock);
return status; return status;
} }
...@@ -462,8 +471,9 @@ virt_efi_query_variable_info_nonblocking(u32 attr, ...@@ -462,8 +471,9 @@ virt_efi_query_variable_info_nonblocking(u32 attr,
if (down_trylock(&efi_runtime_lock)) if (down_trylock(&efi_runtime_lock))
return EFI_NOT_READY; return EFI_NOT_READY;
status = efi_call_virt(query_variable_info, attr, storage_space, status = efi_call_virt_pointer(efi.runtime, query_variable_info, attr,
remaining_space, max_variable_size); storage_space, remaining_space,
max_variable_size);
up(&efi_runtime_lock); up(&efi_runtime_lock);
return status; return status;
} }
......
...@@ -1129,7 +1129,7 @@ extern bool efi_runtime_disabled(void); ...@@ -1129,7 +1129,7 @@ extern bool efi_runtime_disabled(void);
static inline bool efi_runtime_disabled(void) { return true; } static inline bool efi_runtime_disabled(void) { return true; }
#endif #endif
extern void efi_call_virt_check_flags(unsigned long flags, const char *call); extern void efi_call_virt_check_flags(unsigned long flags, const void *caller);
extern unsigned long efi_call_virt_save_flags(void); extern unsigned long efi_call_virt_save_flags(void);
enum efi_secureboot_mode { enum efi_secureboot_mode {
...@@ -1196,7 +1196,7 @@ static inline void efi_check_for_embedded_firmwares(void) { } ...@@ -1196,7 +1196,7 @@ static inline void efi_check_for_embedded_firmwares(void) { }
\ \
__flags = efi_call_virt_save_flags(); \ __flags = efi_call_virt_save_flags(); \
__s = arch_efi_call_virt(p, f, args); \ __s = arch_efi_call_virt(p, f, args); \
efi_call_virt_check_flags(__flags, __stringify(f)); \ efi_call_virt_check_flags(__flags, NULL); \
\ \
arch_efi_call_virt_teardown(); \ arch_efi_call_virt_teardown(); \
\ \
...@@ -1257,6 +1257,7 @@ union efi_rts_args; ...@@ -1257,6 +1257,7 @@ union efi_rts_args;
* @status: Status of executing EFI Runtime Service * @status: Status of executing EFI Runtime Service
* @efi_rts_id: EFI Runtime Service function identifier * @efi_rts_id: EFI Runtime Service function identifier
* @efi_rts_comp: Struct used for handling completions * @efi_rts_comp: Struct used for handling completions
* @caller: The caller of the runtime service
*/ */
struct efi_runtime_work { struct efi_runtime_work {
union efi_rts_args *args; union efi_rts_args *args;
...@@ -1264,6 +1265,7 @@ struct efi_runtime_work { ...@@ -1264,6 +1265,7 @@ struct efi_runtime_work {
struct work_struct work; struct work_struct work;
enum efi_rts_ids efi_rts_id; enum efi_rts_ids efi_rts_id;
struct completion efi_rts_comp; struct completion efi_rts_comp;
const void *caller;
}; };
extern struct efi_runtime_work efi_rts_work; extern struct efi_runtime_work efi_rts_work;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment