more EFI changes for v4.14
The following changes since commit f1a5b53570001b1bcbf890ac6c4be1db99f8cc28:
firmware/efi/esrt: Constify attribute_group structures (2017-08-21 09:43:51 +0200)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/efi/efi.git tags/efi-next
for you to fetch changes up to c4d2793e5a07d5e63d91715a4393fe47c8345112:
efi: bgrt: use efi_mem_type() (2017-08-25 10:35:23 +0100)
----------------------------------------------------------------
More EFI changes for v4.14:
- add support for requesting the firmware to wipe RAM at warm reboot
- increase the size of the random seed obtained from UEFI so crng fast init can complete earlier
- add 'static' to local function pointer
- move efi_mem_type() to common code and replace an open coded instance with it in the BGRT driver
----------------------------------------------------------------
Ard Biesheuvel (1):
efi/random: Increase size of firmware supplied randomness
Colin Ian King (1):
efi/reboot: Make function pointer orig_pm_power_off static
Jan Beulich (2):
efi: move efi_mem_type() to common code
efi: bgrt: use efi_mem_type()
Matthew Garrett (1):
efi/libstub: Enable reset attack mitigation
arch/x86/boot/compressed/eboot.c | 3 ++ arch/x86/platform/efi/efi.c | 19 ----------- drivers/firmware/efi/Kconfig | 10 ++++++ drivers/firmware/efi/efi-bgrt.c | 22 +------------ drivers/firmware/efi/efi.c | 40 +++++++++++++++++++---- drivers/firmware/efi/libstub/Makefile | 1 + drivers/firmware/efi/libstub/arm-stub.c | 3 ++ drivers/firmware/efi/libstub/random.c | 10 +++--- drivers/firmware/efi/libstub/tpm.c | 58 +++++++++++++++++++++++++++++++++ drivers/firmware/efi/reboot.c | 2 +- include/linux/efi.h | 9 +++++ 11 files changed, 123 insertions(+), 54 deletions(-) create mode 100644 drivers/firmware/efi/libstub/tpm.c
PATCH 1/5 efi/libstub: Enable reset attack mitigation
From: Matthew Garrett <[email protected]>
If a machine is reset while secrets are present in RAM, it may be possible for code executed after the reboot to extract those secrets from untouched memory. The Trusted Computing Group specified a mechanism for requesting that the firmware clear all RAM on reset before booting another OS. This is done by setting the MemoryOverwriteRequestControl variable at startup. If userspace can ensure that all secrets are removed as part of a controlled shutdown, it can reset this variable to 0 before triggering a hardware reboot.
--- arch/x86/boot/compressed/eboot.c | 3 ++ drivers/firmware/efi/Kconfig | 10 ++++++ drivers/firmware/efi/libstub/Makefile | 1 + drivers/firmware/efi/libstub/arm-stub.c | 3 ++ drivers/firmware/efi/libstub/tpm.c | 58 +++++++++++++++++++++++++++++++++ include/linux/efi.h | 7 ++++ 6 files changed, 82 insertions(+) create mode 100644 drivers/firmware/efi/libstub/tpm.c
arch/x86/boot/compressed/eboot.c +3 -0
@@ -997,6 +997,9 @@ struct boot_params *efi_main(struct efi_config *c,if (boot_params->secure_boot == efi_secureboot_mode_unset) boot_params->secure_boot =efi_get_secureboot (sys_table); +/* Ask the firmware to clear memory on unclean shutdown */ +efi_enable_reset_attack_mitigation (sys_table); +setup_graphics (boot_params);setup_efi_pci (boot_params);
drivers/firmware/efi/Kconfig +10 -0
@@ -151,6 +151,16 @@ config APPLE_PROPERTIES If unsure, say Y if you have a Mac. Otherwise N. +config RESET_ATTACK_MITIGATION + bool "Reset memory attack mitigation" + depends on EFI_STUB + help + Request that the firmware clear the contents of RAM after a reboot + using the TCG Platform Reset Attack Mitigation specification. This + protects against an attacker forcibly rebooting the system while it + still contains secrets in RAM, booting another OS and extracting the + secrets. + endmenu config UEFI_CPER
drivers/firmware/efi/libstub/Makefile +1 -0
@@ -30,6 +30,7 @@ OBJECT_FILES_NON_STANDARD := y KCOV_INSTRUMENT := n lib-y := efi-stub-helper.o gop.o secureboot.o +lib-$(CONFIG_RESET_ATTACK_MITIGATION) += tpm.o # include the stub's generic dependencies from lib/ when building for ARM/arm64 arm-deps := fdt_rw.c fdt_ro.c fdt_wip.c fdt.c fdt_empty_tree.c fdt_sw.c sort.c
drivers/firmware/efi/libstub/arm-stub.c +3 -0
@@ -192,6 +192,9 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table, goto fail_free_cmdline; } +/* Ask the firmware to clear memory on unclean shutdown */ +efi_enable_reset_attack_mitigation (sys_table); + secure_boot =efi_get_secureboot (sys_table);/*
drivers/firmware/efi/libstub/tpm.c new file +58 -0
58 lines not on this page · raw message
include/linux/efi.h +7 -0
@@ -1497,6 +1497,13 @@ enum efi_secureboot_mode { };enum efi_secureboot_mode efi_get_secureboot (efi_system_table_t *sys_table); +#ifdef CONFIG_RESET_ATTACK_MITIGATION +void efi_enable_reset_attack_mitigation (efi_system_table_t *sys_table_arg); +#else +static inline void +efi_enable_reset_attack_mitigation (efi_system_table_t *sys_table_arg) { } +#endif +/* * Arch code can implement the following three template macros, avoiding * reptition for the void/non-void return cases of {__,}efi_call_virt():
Signature · 1 line
2.11.0
tip-bot for Matthew Garrett
merge bot[tip:efi/core] efi/libstub: Enable reset attack mitigation
efi/libstub: Enable reset attack mitigation
Commit-ID: ccc829ba3624beb9a703fc995d016b836d9eead8 Gitweb: http://git.kernel.org/tip/ccc829ba3624beb9a703fc995d016b836d9eead8 Author: Matthew Garrett <[email protected]> AuthorDate: Fri, 25 Aug 2017 16:50:15 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 26 Aug 2017 09:20:33 +0200
efi/libstub: Enable reset attack mitigation
If a machine is reset while secrets are present in RAM, it may be possible for code executed after the reboot to extract those secrets from untouched memory. The Trusted Computing Group specified a mechanism for requesting that the firmware clear all RAM on reset before booting another OS. This is done by setting the MemoryOverwriteRequestControl variable at startup. If userspace can ensure that all secrets are removed as part of a controlled shutdown, it can reset this variable to 0 before triggering a hardware reboot.
--- arch/x86/boot/compressed/eboot.c | 3 ++ drivers/firmware/efi/Kconfig | 10 ++++++ drivers/firmware/efi/libstub/Makefile | 1 + drivers/firmware/efi/libstub/arm-stub.c | 3 ++ drivers/firmware/efi/libstub/tpm.c | 58 +++++++++++++++++++++++++++++++++ include/linux/efi.h | 7 ++++ 6 files changed, 82 insertions(+)
arch/x86/boot/compressed/eboot.c +3 -0
@@ -997,6 +997,9 @@ struct boot_params *efi_main(struct efi_config *c,if (boot_params->secure_boot == efi_secureboot_mode_unset) boot_params->secure_boot =efi_get_secureboot (sys_table); +/* Ask the firmware to clear memory on unclean shutdown */ +efi_enable_reset_attack_mitigation (sys_table); +setup_graphics (boot_params);setup_efi_pci (boot_params);
drivers/firmware/efi/Kconfig +10 -0
@@ -151,6 +151,16 @@ config APPLE_PROPERTIES If unsure, say Y if you have a Mac. Otherwise N. +config RESET_ATTACK_MITIGATION + bool "Reset memory attack mitigation" + depends on EFI_STUB + help + Request that the firmware clear the contents of RAM after a reboot + using the TCG Platform Reset Attack Mitigation specification. This + protects against an attacker forcibly rebooting the system while it + still contains secrets in RAM, booting another OS and extracting the + secrets. + endmenu config UEFI_CPER
drivers/firmware/efi/libstub/Makefile +1 -0
@@ -30,6 +30,7 @@ OBJECT_FILES_NON_STANDARD := y KCOV_INSTRUMENT := n lib-y := efi-stub-helper.o gop.o secureboot.o +lib-$(CONFIG_RESET_ATTACK_MITIGATION) += tpm.o # include the stub's generic dependencies from lib/ when building for ARM/arm64 arm-deps := fdt_rw.c fdt_ro.c fdt_wip.c fdt.c fdt_empty_tree.c fdt_sw.c sort.c
drivers/firmware/efi/libstub/arm-stub.c +3 -0
@@ -192,6 +192,9 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table, goto fail_free_cmdline; } +/* Ask the firmware to clear memory on unclean shutdown */ +efi_enable_reset_attack_mitigation (sys_table); + secure_boot =efi_get_secureboot (sys_table);/*
drivers/firmware/efi/libstub/tpm.c new file +58 -0
58 lines not on this page · raw message
include/linux/efi.h +7 -0
@@ -1504,6 +1504,13 @@ enum efi_secureboot_mode { };enum efi_secureboot_mode efi_get_secureboot (efi_system_table_t *sys_table); +#ifdef CONFIG_RESET_ATTACK_MITIGATION +void efi_enable_reset_attack_mitigation (efi_system_table_t *sys_table_arg); +#else +static inline void +efi_enable_reset_attack_mitigation (efi_system_table_t *sys_table_arg) { } +#endif +/* * Arch code can implement the following three template macros, avoiding * reptition for the void/non-void return cases of {__,}efi_call_virt():
PATCH 2/5 efi/random: Increase size of firmware supplied randomness
In reply to Ard BiesheuvelThe crng code requires at least 64 bytes (2 * CHACHA20_BLOCK_SIZE) to complete the fast boot-time init, so provide that many bytes when invoking UEFI protocols to seed the entropy pool. Also, add a notice so we can tell from the boot log when the seeding actually took place.
--- drivers/firmware/efi/efi.c | 3 ++- drivers/firmware/efi/libstub/random.c | 10 ++++------ include/linux/efi.h | 2 ++ 3 files changed, 8 insertions(+), 7 deletions(-)
drivers/firmware/efi/efi.c +2 -1
@@ -522,6 +522,7 @@ int __init efi_config_parse_tables(void *config_tables, int count, int sz,if (seed !=NULL ) {add_device_randomness (seed->bits, seed->size);early_memunmap (seed,sizeof (*seed) + size); +pr_notice ("seeding entropy pool\n" ); }else {pr_err ("Could not map UEFI random seed!\n" ); }
@@ -867,7 +868,7 @@ static int update_efi_random_seed(struct notifier_block *nb, seed =memremap (efi.rng_seed,sizeof (*seed),MEMREMAP_WB );if (seed !=NULL ) { - size =min (seed->size,32U ); + size =min (seed->size,EFI_RANDOM_SEED_SIZE );memunmap (seed); }else {pr_err ("Could not map UEFI random seed!\n" );
drivers/firmware/efi/libstub/random.c +4 -6
@@ -145,8 +145,6 @@ efi_status_t efi_random_alloc(efi_system_table_t *sys_table_arg,return status; } -#define RANDOM_SEED_SIZE 32 -efi_status_t efi_random_get_seed (efi_system_table_t *sys_table_arg) {efi_guid_t rng_proto =EFI_RNG_PROTOCOL_GUID ;
@@ -162,25 +160,25 @@ efi_status_t efi_random_get_seed(efi_system_table_t *sys_table_arg)return status; status =efi_call_early (allocate_pool,EFI_RUNTIME_SERVICES_DATA , -sizeof (*seed) +RANDOM_SEED_SIZE , +sizeof (*seed) +EFI_RANDOM_SEED_SIZE , (void **)&seed);if (status !=EFI_SUCCESS )return status; - status = rng->get_rng (rng, &rng_algo_raw,RANDOM_SEED_SIZE , + status = rng->get_rng (rng, &rng_algo_raw,EFI_RANDOM_SEED_SIZE , seed->bits);if (status ==EFI_UNSUPPORTED )/* * Use whatever algorithm we have available if the raw algorithm * is not implemented. */ - status = rng->get_rng (rng,NULL ,RANDOM_SEED_SIZE , + status = rng->get_rng (rng,NULL ,EFI_RANDOM_SEED_SIZE , seed->bits);if (status !=EFI_SUCCESS ) goto err_freepool; - seed->size =RANDOM_SEED_SIZE ; + seed->size =EFI_RANDOM_SEED_SIZE ; status =efi_call_early (install_configuration_table, &rng_table_guid, seed);if (status !=EFI_SUCCESS )
include/linux/efi.h +2 -0
@@ -1564,6 +1564,8 @@ efi_status_t efi_exit_boot_services(efi_system_table_t *sys_table,void *priv, efi_exit_boot_map_processing priv_func); +#define EFI_RANDOM_SEED_SIZE 64U +struct linux_efi_random_seed {u32 size;u8 bits[];
Signature · 1 line
2.11.0
tip-bot for Ard Biesheuvel
merge bot[tip:efi/core] efi/random: Increase size of firmware supplied randomness
efi/random: Increase size of firmware supplied randomness
Commit-ID: c2ceb5fd4e921506e86208b82fca716a2c3aad59 Gitweb: http://git.kernel.org/tip/c2ceb5fd4e921506e86208b82fca716a2c3aad59 Author: Ard Biesheuvel <[email protected]> AuthorDate: Fri, 25 Aug 2017 16:50:16 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 26 Aug 2017 09:20:33 +0200
efi/random: Increase size of firmware supplied randomness
The crng code requires at least 64 bytes (2 * CHACHA20_BLOCK_SIZE) to complete the fast boot-time init, so provide that many bytes when invoking UEFI protocols to seed the entropy pool. Also, add a notice so we can tell from the boot log when the seeding actually took place.
--- drivers/firmware/efi/efi.c | 3 ++- drivers/firmware/efi/libstub/random.c | 10 ++++------ include/linux/efi.h | 2 ++ 3 files changed, 8 insertions(+), 7 deletions(-)
drivers/firmware/efi/efi.c +2 -1
@@ -541,6 +541,7 @@ int __init efi_config_parse_tables(void *config_tables, int count, int sz,if (seed !=NULL ) {add_device_randomness (seed->bits, seed->size);early_memunmap (seed,sizeof (*seed) + size); +pr_notice ("seeding entropy pool\n" ); }else {pr_err ("Could not map UEFI random seed!\n" ); }
@@ -900,7 +901,7 @@ static int update_efi_random_seed(struct notifier_block *nb, seed =memremap (efi.rng_seed,sizeof (*seed),MEMREMAP_WB );if (seed !=NULL ) { - size =min (seed->size,32U ); + size =min (seed->size,EFI_RANDOM_SEED_SIZE );memunmap (seed); }else {pr_err ("Could not map UEFI random seed!\n" );
drivers/firmware/efi/libstub/random.c +4 -6
@@ -145,8 +145,6 @@ efi_status_t efi_random_alloc(efi_system_table_t *sys_table_arg,return status; } -#define RANDOM_SEED_SIZE 32 -efi_status_t efi_random_get_seed (efi_system_table_t *sys_table_arg) {efi_guid_t rng_proto =EFI_RNG_PROTOCOL_GUID ;
@@ -162,25 +160,25 @@ efi_status_t efi_random_get_seed(efi_system_table_t *sys_table_arg)return status; status =efi_call_early (allocate_pool,EFI_RUNTIME_SERVICES_DATA , -sizeof (*seed) +RANDOM_SEED_SIZE , +sizeof (*seed) +EFI_RANDOM_SEED_SIZE , (void **)&seed);if (status !=EFI_SUCCESS )return status; - status = rng->get_rng (rng, &rng_algo_raw,RANDOM_SEED_SIZE , + status = rng->get_rng (rng, &rng_algo_raw,EFI_RANDOM_SEED_SIZE , seed->bits);if (status ==EFI_UNSUPPORTED )/* * Use whatever algorithm we have available if the raw algorithm * is not implemented. */ - status = rng->get_rng (rng,NULL ,RANDOM_SEED_SIZE , + status = rng->get_rng (rng,NULL ,EFI_RANDOM_SEED_SIZE , seed->bits);if (status !=EFI_SUCCESS ) goto err_freepool; - seed->size =RANDOM_SEED_SIZE ; + seed->size =EFI_RANDOM_SEED_SIZE ; status =efi_call_early (install_configuration_table, &rng_table_guid, seed);if (status !=EFI_SUCCESS )
include/linux/efi.h +2 -0
@@ -1571,6 +1571,8 @@ efi_status_t efi_exit_boot_services(efi_system_table_t *sys_table,void *priv, efi_exit_boot_map_processing priv_func); +#define EFI_RANDOM_SEED_SIZE 64U +struct linux_efi_random_seed {u32 size;u8 bits[];
PATCH 3/5 efi/reboot: Make function pointer orig_pm_power_off static
In reply to Ard BiesheuvelFrom: Colin Ian King <[email protected]>
The function pointer orig_pm_power_off is local to the source and does not need to be in global scope, so make it static.
Cleans up sparse warning:
symbol 'orig_pm_power_off' was not declared. Should it be static?
--- drivers/firmware/efi/reboot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/efi/reboot.c +1 -1
@@ -5,7 +5,7 @@#include <linux/efi.h> #include <linux/reboot.h> -void (*orig_pm_power_off)(void ); +static void (*orig_pm_power_off)(void );int efi_reboot_quirk_mode =-1 ;
Signature · 1 line
2.11.0
tip-bot for Colin Ian King
merge bot[tip:efi/core] efi/reboot: Make function pointer orig_pm_power_off static
efi/reboot: Make function pointer orig_pm_power_off static
Commit-ID: 68ee51cb773bed81f9ff7144eca0a08550e1f9a1 Gitweb: http://git.kernel.org/tip/68ee51cb773bed81f9ff7144eca0a08550e1f9a1 Author: Colin Ian King <[email protected]> AuthorDate: Fri, 25 Aug 2017 16:50:17 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 26 Aug 2017 09:20:33 +0200
efi/reboot: Make function pointer orig_pm_power_off static
The function pointer orig_pm_power_off is local to the source and does not need to be in global scope, so make it static.
Cleans up sparse warning:
symbol 'orig_pm_power_off' was not declared. Should it be static?
--- drivers/firmware/efi/reboot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/efi/reboot.c +1 -1
@@ -5,7 +5,7 @@#include <linux/efi.h> #include <linux/reboot.h> -void (*orig_pm_power_off)(void ); +static void (*orig_pm_power_off)(void );int efi_reboot_quirk_mode =-1 ;
PATCH 4/5 efi: move efi_mem_type() to common code
In reply to Ard BiesheuvelFrom: Jan Beulich <JBeulich-IBi9RG/[email protected]>
This follows efi_mem_attributes(), as it's similarly generic. Drop __weak from that one though (and don't introduce it for efi_mem_type() in the first place) to make clear that other overrides to these functions are really not intended.
--- arch/x86/platform/efi/efi.c | 19 ------------------- drivers/firmware/efi/efi.c | 37 +++++++++++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 25 deletions(-)
arch/x86/platform/efi/efi.c +0 -19
@@ -1032,25 +1032,6 @@ void __init efi_enter_virtual_mode(void)efi_dump_pagetable (); } -/* -* Convenience functions to obtain memory types and attributes -*/ -u32 efi_mem_type (unsigned long phys_addr) -{ -efi_memory_desc_t *md; - -if (!efi_enabled (EFI_MEMMAP )) -return 0 ; - -for_each_efi_memory_desc (md) { -if ((md->phys_addr <= phys_addr) && - (phys_addr < (md->phys_addr + - (md->num_pages <<EFI_PAGE_SHIFT )))) -return md->type; - } -return 0 ; -} -static int __init arch_parse_efi_cmdline (char *str) {if (!str) {
drivers/firmware/efi/efi.c +31 -6
@@ -792,19 +792,19 @@ char * __init efi_md_typeattr_format(char *buf, size_t size, }/* +* IA64 has a funky EFI memory map that doesn't work the same way as +* other architectures. +*/ +#ifndef CONFIG_IA64 +/* * efi_mem_attributes - lookup memmap attributes for physical address * @phys_addr: the physical address to lookup * * Search in the EFI memory map for the region covering * @phys_addr. Returns the EFI memory attributes if the region * was found in the memory map, 0 otherwise. -* -* Despite being marked __weak, most architectures should *not* -* override this function. It is __weak solely for the benefit -* of ia64 which has a funky EFI memory map that doesn't work -* the same way as other architectures. */ -u64 __weak efi_mem_attributes (unsigned long phys_addr) +u64 efi_mem_attributes (unsigned long phys_addr) {efi_memory_desc_t *md;
@@ -820,6 +820,31 @@ u64 __weak efi_mem_attributes(unsigned long phys_addr) return 0; } +/* +* efi_mem_type - lookup memmap type for physical address +* @phys_addr: the physical address to lookup +* +* Search in the EFI memory map for the region covering @phys_addr. +* Returns the EFI memory type if the region was found in the memory +* map, EFI_RESERVED_TYPE (zero) otherwise. +*/ +u32 efi_mem_type (unsigned long phys_addr) +{ +const efi_memory_desc_t *md; + +if (!efi_enabled (EFI_MEMMAP )) +return 0 ; + +for_each_efi_memory_desc (md) { +if ((md->phys_addr <= phys_addr) && + (phys_addr < (md->phys_addr + + (md->num_pages <<EFI_PAGE_SHIFT )))) +return md->type; + } +return EFI_RESERVED_TYPE ; +} +#endif +int efi_status_to_err (efi_status_t status) {int err;
Signature · 1 line
2.11.0
tip-bot for Jan Beulich
merge bot[tip:efi/core] efi: Move efi_mem_type() to common code
efi: Move efi_mem_type() to common code
Commit-ID: 23f0571c9fd184504f7a2f27011750e0ad99bb73 Gitweb: http://git.kernel.org/tip/23f0571c9fd184504f7a2f27011750e0ad99bb73 Author: Jan Beulich <[email protected]> AuthorDate: Fri, 25 Aug 2017 16:50:18 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 26 Aug 2017 09:20:33 +0200
efi: Move efi_mem_type() to common code
This follows efi_mem_attributes(), as it's similarly generic. Drop __weak from that one though (and don't introduce it for efi_mem_type() in the first place) to make clear that other overrides to these functions are really not intended.
--- arch/x86/platform/efi/efi.c | 19 ------------------- drivers/firmware/efi/efi.c | 37 +++++++++++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 25 deletions(-)
arch/x86/platform/efi/efi.c +0 -19
@@ -1032,25 +1032,6 @@ void __init efi_enter_virtual_mode(void)efi_dump_pagetable (); } -/* -* Convenience functions to obtain memory types and attributes -*/ -int efi_mem_type (unsigned long phys_addr) -{ -efi_memory_desc_t *md; - -if (!efi_enabled (EFI_MEMMAP )) -return -ENOTSUPP ; - -for_each_efi_memory_desc (md) { -if ((md->phys_addr <= phys_addr) && - (phys_addr < (md->phys_addr + - (md->num_pages <<EFI_PAGE_SHIFT )))) -return md->type; - } -return -EINVAL ; -} -static int __init arch_parse_efi_cmdline (char *str) {if (!str) {
drivers/firmware/efi/efi.c +31 -6
@@ -811,19 +811,19 @@ char * __init efi_md_typeattr_format(char *buf, size_t size, }/* +* IA64 has a funky EFI memory map that doesn't work the same way as +* other architectures. +*/ +#ifndef CONFIG_IA64 +/* * efi_mem_attributes - lookup memmap attributes for physical address * @phys_addr: the physical address to lookup * * Search in the EFI memory map for the region covering * @phys_addr. Returns the EFI memory attributes if the region * was found in the memory map, 0 otherwise. -* -* Despite being marked __weak, most architectures should *not* -* override this function. It is __weak solely for the benefit -* of ia64 which has a funky EFI memory map that doesn't work -* the same way as other architectures. */ -u64 __weak efi_mem_attributes (unsigned long phys_addr) +u64 efi_mem_attributes (unsigned long phys_addr) {efi_memory_desc_t *md;
@@ -839,6 +839,31 @@ u64 __weak efi_mem_attributes(unsigned long phys_addr) return 0; } +/* +* efi_mem_type - lookup memmap type for physical address +* @phys_addr: the physical address to lookup +* +* Search in the EFI memory map for the region covering @phys_addr. +* Returns the EFI memory type if the region was found in the memory +* map, EFI_RESERVED_TYPE (zero) otherwise. +*/ +int efi_mem_type (unsigned long phys_addr) +{ +const efi_memory_desc_t *md; + +if (!efi_enabled (EFI_MEMMAP )) +return -ENOTSUPP ; + +for_each_efi_memory_desc (md) { +if ((md->phys_addr <= phys_addr) && + (phys_addr < (md->phys_addr + + (md->num_pages <<EFI_PAGE_SHIFT )))) +return md->type; + } +return -EINVAL ; +} +#endif +int efi_status_to_err (efi_status_t status) {int err;
PATCH 5/5 efi: bgrt: use efi_mem_type()
In reply to Ard BiesheuvelFrom: Jan Beulich <[email protected]>
Avoid effectively open-coding the function.
--- drivers/firmware/efi/efi-bgrt.c | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-)
drivers/firmware/efi/efi-bgrt.c +1 -21
@@ -27,26 +27,6 @@ struct bmp_header {u32 size; } __packed; -static bool efi_bgrt_addr_valid (u64 addr) -{ -efi_memory_desc_t *md; - -for_each_efi_memory_desc (md) { -u64 size; -u64 end; - -if (md->type !=EFI_BOOT_SERVICES_DATA ) -continue ; - - size = md->num_pages <<EFI_PAGE_SHIFT ; - end = md->phys_addr + size; -if (addr >= md->phys_addr && addr < end) -return true; - } - -return false; -} -void __init efi_bgrt_init (struct acpi_table_header *table) {void *image;
@@ -85,7 +65,7 @@ void __init efi_bgrt_init(struct acpi_table_header *table) goto out; } -if (!efi_bgrt_addr_valid (bgrt->image_address)) { +if (efi_mem_type (bgrt->image_address) !=EFI_BOOT_SERVICES_DATA ) {pr_notice ("Ignoring BGRT: invalid image address\n" ); goto out; }
Signature · 1 line
2.11.0
tip-bot for Jan Beulich
merge bot[tip:efi/core] efi/bgrt: Use efi_mem_type()
efi/bgrt: Use efi_mem_type()
Commit-ID: 6de47a5e371f75f80544986e6c9636211a2ae8af Gitweb: http://git.kernel.org/tip/6de47a5e371f75f80544986e6c9636211a2ae8af Author: Jan Beulich <[email protected]> AuthorDate: Fri, 25 Aug 2017 16:50:19 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 26 Aug 2017 09:20:33 +0200
efi/bgrt: Use efi_mem_type()
Avoid effectively open-coding the function.
--- drivers/firmware/efi/efi-bgrt.c | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-)
drivers/firmware/efi/efi-bgrt.c +1 -21
@@ -27,26 +27,6 @@ struct bmp_header {u32 size; } __packed; -static bool efi_bgrt_addr_valid (u64 addr) -{ -efi_memory_desc_t *md; - -for_each_efi_memory_desc (md) { -u64 size; -u64 end; - -if (md->type !=EFI_BOOT_SERVICES_DATA ) -continue ; - - size = md->num_pages <<EFI_PAGE_SHIFT ; - end = md->phys_addr + size; -if (addr >= md->phys_addr && addr < end) -return true; - } - -return false; -} -void __init efi_bgrt_init (struct acpi_table_header *table) {void *image;
@@ -85,7 +65,7 @@ void __init efi_bgrt_init(struct acpi_table_header *table) goto out; } -if (!efi_bgrt_addr_valid (bgrt->image_address)) { +if (efi_mem_type (bgrt->image_address) !=EFI_BOOT_SERVICES_DATA ) {pr_notice ("Ignoring BGRT: invalid image address\n" ); goto out; }