From 37d467125ef20ba87d25041b3eefbea7c69446c6 Mon Sep 17 00:00:00 2001 From: Ilias Apalodimas Date: Mon, 24 May 2021 17:34:10 +0300 Subject: efi: Use alternative functions for variable runtime services So let's install the alternative functions if the firmware install the configuration table and indicates it can't handle the variables natively. Signed-off-by: Ilias Apalodimas --- drivers/firmware/efi/efi.c | 19 ++++++++++++++++++- include/linux/efi.h | 8 +++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 4b7ee3fa9224..25f7e3d22d1c 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -52,6 +52,9 @@ EXPORT_SYMBOL(efi); unsigned long __ro_after_init efi_rng_seed = EFI_INVALID_TABLE_ADDR; static unsigned long __initdata mem_reserve = EFI_INVALID_TABLE_ADDR; static unsigned long __initdata rt_prop = EFI_INVALID_TABLE_ADDR; +#ifdef CONFIG_OPTEE_EFI_VARS +static unsigned long __initdata tee_var = EFI_INVALID_TABLE_ADDR; +#endif struct mm_struct efi_mm = { .mm_rb = RB_ROOT, @@ -179,6 +182,17 @@ static struct efivar_operations generic_ops; static int generic_ops_register(void) { +#ifdef CONFIG_OPTEE_EFI_VARS + if (tee_var != EFI_INVALID_TABLE_ADDR ) { + efi_status_t ret; + + pr_err("EFI variable ops swapped\n"); + ret = optee_efi_ops_init(&generic_ops); + if (ret == EFI_SUCCESS) + return efivars_register(&generic_efivars, &generic_ops, efi_kobj); + } +#endif + generic_ops.get_variable = efi.get_variable; generic_ops.get_next_variable = efi.get_next_variable; generic_ops.query_variable_store = efi_query_variable_store; @@ -519,7 +533,10 @@ static const efi_config_table_type_t common_tables[] __initconst = { {LINUX_EFI_TPM_EVENT_LOG_GUID, &efi.tpm_log, "TPMEventLog" }, {LINUX_EFI_TPM_FINAL_LOG_GUID, &efi.tpm_final_log, "TPMFinalLog" }, {LINUX_EFI_MEMRESERVE_TABLE_GUID, &mem_reserve, "MEMRESERVE" }, - {EFI_RT_PROPERTIES_TABLE_GUID, &rt_prop, "RTPROP" }, + {EFI_RT_PROPERTIES_TABLE_GUID, &rt_prop, "RTPROPS" }, +#ifdef CONFIG_OPTEE_EFI_VARS + {EFI_INT_VARIABLES_TABLE_GUID, &tee_var, "INTVAR" }, +#endif #ifdef CONFIG_EFI_RCI2_TABLE {DELLEMC_EFI_RCI2_TABLE_GUID, &rci2_table_phys }, #endif diff --git a/include/linux/efi.h b/include/linux/efi.h index 6b5d36babfcc..3ecb0df8c44f 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -39,6 +39,7 @@ #define EFI_WRITE_PROTECTED ( 8 | (1UL << (BITS_PER_LONG-1))) #define EFI_OUT_OF_RESOURCES ( 9 | (1UL << (BITS_PER_LONG-1))) #define EFI_NOT_FOUND (14 | (1UL << (BITS_PER_LONG-1))) +#define EFI_ACCESS_DENIED (15 | (1UL << (BITS_PER_LONG-1))) #define EFI_TIMEOUT (18 | (1UL << (BITS_PER_LONG-1))) #define EFI_ABORTED (21 | (1UL << (BITS_PER_LONG-1))) #define EFI_SECURITY_VIOLATION (26 | (1UL << (BITS_PER_LONG-1))) @@ -238,7 +239,7 @@ typedef efi_status_t efi_get_variable_t (efi_char16_t *name, efi_guid_t *vendor, unsigned long *data_size, void *data); typedef efi_status_t efi_get_next_variable_t (unsigned long *name_size, efi_char16_t *name, efi_guid_t *vendor); -typedef efi_status_t efi_set_variable_t (efi_char16_t *name, efi_guid_t *vendor, +typedef efi_status_t efi_set_variable_t (efi_char16_t *name, efi_guid_t *vendor, u32 attr, unsigned long data_size, void *data); typedef efi_status_t efi_get_next_high_mono_count_t (u32 *count); @@ -337,6 +338,9 @@ void efi_native_runtime_setup(void); #define EFI_LOAD_FILE_PROTOCOL_GUID EFI_GUID(0x56ec3091, 0x954c, 0x11d2, 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b) #define EFI_LOAD_FILE2_PROTOCOL_GUID EFI_GUID(0x4006c0c1, 0xfcb3, 0x403e, 0x99, 0x6d, 0x4a, 0x6c, 0x87, 0x24, 0xe0, 0x6d) #define EFI_RT_PROPERTIES_TABLE_GUID EFI_GUID(0xeb66918a, 0x7eef, 0x402a, 0x84, 0x2e, 0x93, 0x1d, 0x21, 0xc3, 0x8a, 0xe9) +#define EFI_INT_VARIABLES_TABLE_GUID EFI_GUID(0x1e2ed096, 0x30e2, 0x4254, 0xbd, 0x89, 0x86, 0x3b, 0xbe, 0xf8, 0x23, 0x26) + + #define EFI_IMAGE_SECURITY_DATABASE_GUID EFI_GUID(0xd719b2cb, 0x3d3a, 0x4596, 0xa3, 0xbc, 0xda, 0xd0, 0x0e, 0x67, 0x65, 0x6f) #define EFI_SHIM_LOCK_GUID EFI_GUID(0x605dab50, 0xe046, 0x4300, 0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23) @@ -1282,4 +1286,6 @@ static inline struct efi_mokvar_table_entry *efi_mokvar_entry_find( } #endif +efi_status_t optee_efi_ops_init(struct efivar_operations *ops); + #endif /* _LINUX_EFI_H */ -- cgit v1.2.3