[PATCH 69/93] efi: Make 'efi_enabled' a function to query EFI facilities
3.5.7.5 -stable review patch. If anyone has any objections, please let me know. -- From: Matt Fleming commit 83e68189745ad931c2afd45d8ee3303929233e7f upstream. Originally 'efi_enabled' indicated whether a kernel was booted from EFI firmware. Over time its semantics have changed, and it now indicates whether or not we are booted on an EFI machine with bit-native firmware, e.g. 64-bit kernel with 64-bit firmware. The immediate motivation for this patch is the bug report at, https://bugs.launchpad.net/ubuntu-cdimage/+bug/1040557 which details how running a platform driver on an EFI machine that is designed to run under BIOS can cause the machine to become bricked. Also, the following report, https://bugzilla.kernel.org/show_bug.cgi?id=47121 details how running said driver can also cause Machine Check Exceptions. Drivers need a new means of detecting whether they're running on an EFI machine, as sadly the expression, if (!efi_enabled) hasn't been a sufficient condition for quite some time. Users actually want to query 'efi_enabled' for different reasons - what they really want access to is the list of available EFI facilities. For instance, the x86 reboot code needs to know whether it can invoke the ResetSystem() function provided by the EFI runtime services, while the ACPI OSL code wants to know whether the EFI config tables were mapped successfully. There are also checks in some of the platform driver code to simply see if they're running on an EFI machine (which would make it a bad idea to do BIOS-y things). This patch is a prereq for the samsung-laptop fix patch. Cc: David Airlie Cc: Corentin Chary Cc: Matthew Garrett Cc: Dave Jiang Cc: Olof Johansson Cc: Peter Jones Cc: Colin Ian King Cc: Steve Langasek Cc: Tony Luck Cc: Konrad Rzeszutek Wilk Cc: Rafael J. Wysocki Signed-off-by: Matt Fleming Signed-off-by: H. Peter Anvin [ herton: adjust efi_enabled check at start_kernel ] Signed-off-by: Herton Ronaldo Krzesinski --- arch/x86/include/asm/efi.h |1 + arch/x86/kernel/reboot.c |2 +- arch/x86/kernel/setup.c| 28 arch/x86/platform/efi/efi.c| 57 +++- drivers/acpi/osl.c |2 +- drivers/firmware/dmi_scan.c|2 +- drivers/firmware/efivars.c |4 +-- drivers/firmware/iscsi_ibft_find.c |2 +- drivers/gpu/drm/radeon/radeon_device.c |3 +- drivers/platform/x86/ibm_rtl.c |2 +- drivers/scsi/isci/init.c |2 +- include/linux/efi.h| 24 ++ init/main.c|4 +-- 13 files changed, 79 insertions(+), 54 deletions(-) diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h index 029189d..da37433 100644 --- a/arch/x86/include/asm/efi.h +++ b/arch/x86/include/asm/efi.h @@ -94,6 +94,7 @@ extern void __iomem *efi_ioremap(unsigned long addr, unsigned long size, #endif /* CONFIG_X86_32 */ extern int add_efi_memmap; +extern unsigned long x86_efi_facility; extern void efi_set_executable(efi_memory_desc_t *md, bool executable); extern int efi_memblock_x86_reserve_range(void); extern void efi_call_phys_prelog(void); diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c index 5de92f1..2a29384 100644 --- a/arch/x86/kernel/reboot.c +++ b/arch/x86/kernel/reboot.c @@ -598,7 +598,7 @@ static void native_machine_emergency_restart(void) break; case BOOT_EFI: - if (efi_enabled) + if (efi_enabled(EFI_RUNTIME_SERVICES)) efi.reset_system(reboot_mode ? EFI_RESET_WARM : EFI_RESET_COLD, diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index a0ee620..36cf7fa 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -808,15 +808,15 @@ void __init setup_arch(char **cmdline_p) #ifdef CONFIG_EFI if (!strncmp((char *)_params.efi_info.efi_loader_signature, "EL32", 4)) { - efi_enabled = 1; - efi_64bit = false; + set_bit(EFI_BOOT, _efi_facility); } else if (!strncmp((char *)_params.efi_info.efi_loader_signature, "EL64", 4)) { - efi_enabled = 1; - efi_64bit = true; + set_bit(EFI_BOOT, _efi_facility); + set_bit(EFI_64BIT, _efi_facility); } - if (efi_enabled && efi_memblock_x86_reserve_range()) - efi_enabled = 0; + + if (efi_enabled(EFI_BOOT)) + efi_memblock_x86_reserve_range(); #endif x86_init.oem.arch_setup(); @@ -889,7 +889,7 @@ void __init setup_arch(char **cmdline_p) finish_e820_parsing(); - if (efi_enabled) + if
[PATCH 69/93] efi: Make 'efi_enabled' a function to query EFI facilities
3.5.7.5 -stable review patch. If anyone has any objections, please let me know. -- From: Matt Fleming matt.flem...@intel.com commit 83e68189745ad931c2afd45d8ee3303929233e7f upstream. Originally 'efi_enabled' indicated whether a kernel was booted from EFI firmware. Over time its semantics have changed, and it now indicates whether or not we are booted on an EFI machine with bit-native firmware, e.g. 64-bit kernel with 64-bit firmware. The immediate motivation for this patch is the bug report at, https://bugs.launchpad.net/ubuntu-cdimage/+bug/1040557 which details how running a platform driver on an EFI machine that is designed to run under BIOS can cause the machine to become bricked. Also, the following report, https://bugzilla.kernel.org/show_bug.cgi?id=47121 details how running said driver can also cause Machine Check Exceptions. Drivers need a new means of detecting whether they're running on an EFI machine, as sadly the expression, if (!efi_enabled) hasn't been a sufficient condition for quite some time. Users actually want to query 'efi_enabled' for different reasons - what they really want access to is the list of available EFI facilities. For instance, the x86 reboot code needs to know whether it can invoke the ResetSystem() function provided by the EFI runtime services, while the ACPI OSL code wants to know whether the EFI config tables were mapped successfully. There are also checks in some of the platform driver code to simply see if they're running on an EFI machine (which would make it a bad idea to do BIOS-y things). This patch is a prereq for the samsung-laptop fix patch. Cc: David Airlie airl...@linux.ie Cc: Corentin Chary corenti...@iksaif.net Cc: Matthew Garrett mj...@srcf.ucam.org Cc: Dave Jiang dave.ji...@intel.com Cc: Olof Johansson o...@lixom.net Cc: Peter Jones pjo...@redhat.com Cc: Colin Ian King colin.k...@canonical.com Cc: Steve Langasek steve.langa...@canonical.com Cc: Tony Luck tony.l...@intel.com Cc: Konrad Rzeszutek Wilk kon...@kernel.org Cc: Rafael J. Wysocki r...@sisk.pl Signed-off-by: Matt Fleming matt.flem...@intel.com Signed-off-by: H. Peter Anvin h...@linux.intel.com [ herton: adjust efi_enabled check at start_kernel ] Signed-off-by: Herton Ronaldo Krzesinski herton.krzesin...@canonical.com --- arch/x86/include/asm/efi.h |1 + arch/x86/kernel/reboot.c |2 +- arch/x86/kernel/setup.c| 28 arch/x86/platform/efi/efi.c| 57 +++- drivers/acpi/osl.c |2 +- drivers/firmware/dmi_scan.c|2 +- drivers/firmware/efivars.c |4 +-- drivers/firmware/iscsi_ibft_find.c |2 +- drivers/gpu/drm/radeon/radeon_device.c |3 +- drivers/platform/x86/ibm_rtl.c |2 +- drivers/scsi/isci/init.c |2 +- include/linux/efi.h| 24 ++ init/main.c|4 +-- 13 files changed, 79 insertions(+), 54 deletions(-) diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h index 029189d..da37433 100644 --- a/arch/x86/include/asm/efi.h +++ b/arch/x86/include/asm/efi.h @@ -94,6 +94,7 @@ extern void __iomem *efi_ioremap(unsigned long addr, unsigned long size, #endif /* CONFIG_X86_32 */ extern int add_efi_memmap; +extern unsigned long x86_efi_facility; extern void efi_set_executable(efi_memory_desc_t *md, bool executable); extern int efi_memblock_x86_reserve_range(void); extern void efi_call_phys_prelog(void); diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c index 5de92f1..2a29384 100644 --- a/arch/x86/kernel/reboot.c +++ b/arch/x86/kernel/reboot.c @@ -598,7 +598,7 @@ static void native_machine_emergency_restart(void) break; case BOOT_EFI: - if (efi_enabled) + if (efi_enabled(EFI_RUNTIME_SERVICES)) efi.reset_system(reboot_mode ? EFI_RESET_WARM : EFI_RESET_COLD, diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index a0ee620..36cf7fa 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -808,15 +808,15 @@ void __init setup_arch(char **cmdline_p) #ifdef CONFIG_EFI if (!strncmp((char *)boot_params.efi_info.efi_loader_signature, EL32, 4)) { - efi_enabled = 1; - efi_64bit = false; + set_bit(EFI_BOOT, x86_efi_facility); } else if (!strncmp((char *)boot_params.efi_info.efi_loader_signature, EL64, 4)) { - efi_enabled = 1; - efi_64bit = true; + set_bit(EFI_BOOT, x86_efi_facility); + set_bit(EFI_64BIT, x86_efi_facility); } - if (efi_enabled efi_memblock_x86_reserve_range())