aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86
diff options
context:
space:
mode:
authorMatt Fleming <matt.fleming@intel.com>2013-03-25 05:14:30 -0400
committerMatt Fleming <matt.fleming@intel.com>2013-04-09 06:34:05 -0400
commita6e4d5a03e9e3587e88aba687d8f225f4f04c792 (patch)
tree5159dd594f8c70ef964ec0fef74a6e8482f2606e /arch/x86
parentca0ba26fbbd2d81c43085df49ce0abfe34535a90 (diff)
x86, efivars: firmware bug workarounds should be in platform code
Let's not burden ia64 with checks in the common efivars code that we're not writing too much data to the variable store. That kind of thing is an x86 firmware bug, plain and simple. efi_query_variable_store() provides platforms with a wrapper in which they can perform checks and workarounds for EFI variable storage bugs. Cc: H. Peter Anvin <hpa@zytor.com> Cc: Matthew Garrett <mjg59@srcf.ucam.org> Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Diffstat (limited to 'arch/x86')
-rw-r--r--arch/x86/platform/efi/efi.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
index 5f2ecaf3f9d8..c89c245eff40 100644
--- a/arch/x86/platform/efi/efi.c
+++ b/arch/x86/platform/efi/efi.c
@@ -999,3 +999,28 @@ u64 efi_mem_attributes(unsigned long phys_addr)
999 } 999 }
1000 return 0; 1000 return 0;
1001} 1001}
1002
1003/*
1004 * Some firmware has serious problems when using more than 50% of the EFI
1005 * variable store, i.e. it triggers bugs that can brick machines. Ensure that
1006 * we never use more than this safe limit.
1007 *
1008 * Return EFI_SUCCESS if it is safe to write 'size' bytes to the variable
1009 * store.
1010 */
1011efi_status_t efi_query_variable_store(u32 attributes, unsigned long size)
1012{
1013 efi_status_t status;
1014 u64 storage_size, remaining_size, max_size;
1015
1016 status = efi.query_variable_info(attributes, &storage_size,
1017 &remaining_size, &max_size);
1018 if (status != EFI_SUCCESS)
1019 return status;
1020
1021 if (!storage_size || size > remaining_size || size > max_size ||
1022 (remaining_size - size) < (storage_size / 2))
1023 return EFI_OUT_OF_RESOURCES;
1024
1025 return EFI_SUCCESS;
1026}