efi: move noefi early param code out of x86 arch code
Subsystems (6)
PATCH 1/5 efi: move noefi early param code out of x86 arch code
noefi param can be used for arches other than X86 later, thus move it out of x86 platform code.
--- arch/x86/platform/efi/efi.c | 10 +--------- drivers/firmware/efi/efi.c | 13 +++++++++++++ include/linux/efi.h | 1 + 3 files changed, 15 insertions(+), 9 deletions(-)
arch/x86/platform/efi/efi.c +1 -9
@@ -70,14 +70,6 @@ static efi_config_table_type_t arch_tables[] __initdata = {u64 efi_setup;/* efi setup_data physical address */ -static bool disable_runtime__initdata = false; -static int __init setup_noefi (char *arg) -{ - disable_runtime = true; -return 0 ; -} -early_param ("noefi" , setup_noefi); -int add_efi_memmap;EXPORT_SYMBOL (add_efi_memmap);
@@ -492,7 +484,7 @@ void __init efi_init(void)if (!efi_runtime_supported ())pr_info ("No EFI runtime due to 32/64-bit mismatch with kernel\n" );else { -if (disable_runtime ||efi_runtime_init ()) +if (efi_runtime_disabled () ||efi_runtime_init ())return ; }if (efi_memmap_init ())
drivers/firmware/efi/efi.c +13 -0
@@ -41,6 +41,19 @@ struct efi __read_mostly efi = { };EXPORT_SYMBOL (efi); +static bool disable_runtime; +static int __init setup_noefi (char *arg) +{ + disable_runtime = true; +return 0 ; +} +early_param ("noefi" , setup_noefi); + +bool efi_runtime_disabled (void ) +{ +return disable_runtime; +} +static struct kobject *efi_kobj;static struct kobject *efivars_kobj;
include/linux/efi.h +1 -0
@@ -1227,4 +1227,5 @@ efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,unsigned long *load_addr, unsigned long *load_size); +bool efi_runtime_disabled (void );#endif /* _LINUX_EFI_H */
Signature · 1 line
1.8.3.1
PATCH 2/5 efi: add kernel param efi=noruntime
noefi kernel param means actually disabling efi runtime, Per suggestion from Leif Lindholm efi=noruntime should be better. But since noefi is already used in X86 thus just adding another param efi=noruntime for same purpose.
--- Documentation/kernel-parameters.txt | 4 +++- arch/x86/platform/efi/efi.c | 12 ------------ drivers/firmware/efi/efi.c | 22 ++++++++++++++++++++++ 3 files changed, 25 insertions(+), 13 deletions(-)
Documentation/kernel-parameters.txt +3 -1
@@ -992,11 +992,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted. Format: {"off" | "on" | "skip[mbr]"} efi= [EFI] - Format: { "old_map" } + Format: { "old_map" | "noruntime" } old_map [X86-64]: switch to the old ioremap-based EFI runtime services mapping. 32-bit still uses this one by default. + noruntime : disable EFI runtime services support + efi_no_storage_paranoia [EFI; X86] Using this parameter you can use more than 50% of your efi variable storage. Use this parameter only if
arch/x86/platform/efi/efi.c +0 -12
@@ -929,15 +929,3 @@ u64 efi_mem_attributes(unsigned long phys_addr) }return 0 ; } - -static int __init parse_efi_cmdline (char *str) -{ -if (*str =='=' ) - str++; - -if (!strncmp (str,"old_map" ,7 )) -set_bit (EFI_OLD_MEMMAP , &efi.flags); - -return 0 ; -} -early_param ("efi" , parse_efi_cmdline);
drivers/firmware/efi/efi.c +22 -0
@@ -24,6 +24,7 @@#include <linux/of_fdt.h> #include <linux/io.h> #include <linux/platform_device.h> +#include <asm/efi.h> struct efi __read_mostly efi = { .mps =EFI_INVALID_TABLE_ADDR ,
@@ -54,6 +55,27 @@ bool efi_runtime_disabled(void)return disable_runtime; } +static int __init parse_efi_cmdline (char *str) +{ +if (*str =='=' ) + str++; + +#ifdef CONFIG_X86 +if (!strncmp (str,"old_map" ,7 )) { +set_bit (EFI_OLD_MEMMAP , &efi.flags); + goto out; + } +#endif +if (!strncmp (str,"noruntime" ,9 )) { + disable_runtime = true; + goto out; + } + +out: +return 0 ; +} +early_param ("efi" , parse_efi_cmdline); +static struct kobject *efi_kobj;static struct kobject *efivars_kobj;
Signature · 1 line
1.8.3.1
Re: [PATCH 2/5] efi: add kernel param efi=noruntime
Quoted 72 lines · Dave Young
noefi kernel param means actually disabling efi runtime, Per suggestion from Leif Lindholm efi=noruntime should be better. But since noefi is already used in X86 thus just adding another param efi=noruntime for same purpose.
Signed-off-by Dave Young <[email protected]>--- Documentation/kernel-parameters.txt | 4 +++- arch/x86/platform/efi/efi.c | 12 ------------ drivers/firmware/efi/efi.c | 22 ++++++++++++++++++++++ 3 files changed, 25 insertions(+), 13 deletions(-)Documentation/kernel-parameters.txt +3
-1@@ -992,11 +992,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted. Format: {"off" | "on" | "skip[mbr]"} efi= [EFI] - Format: { "old_map" } + Format: { "old_map" | "noruntime" } old_map [X86-64]: switch to the old ioremap-based EFI runtime services mapping. 32-bit still uses this one by default. + noruntime : disable EFI runtime services support + efi_no_storage_paranoia [EFI; X86] Using this parameter you can use more than 50% of your efi variable storage. Use this parameter only ifarch/x86/platform/efi/efi.c +0
-12@@ -929,15 +929,3 @@ u64 efi_mem_attributes(unsigned long phys_addr) }return 0 ; } - -static int __init parse_efi_cmdline (char *str) -{ -if (*str =='=' ) - str++; - -if (!strncmp (str,"old_map" ,7 )) -set_bit (EFI_OLD_MEMMAP , &efi.flags); - -return 0 ; -} -early_param ("efi" , parse_efi_cmdline);drivers/firmware/efi/efi.c +7
-0@@ -24,6 +24,7 @@#include <linux/of_fdt.h> #include <linux/io.h> #include <linux/platform_device.h> +#include <asm/efi.h> struct efi __read_mostly efi = { .mps =EFI_INVALID_TABLE_ADDR ,@@ -54,6 +55,27 @@ bool efi_runtime_disabled(void)return disable_runtime; } +static int __init parse_efi_cmdline (char *str) +{ +if (*str =='=' ) + str++; + +#ifdef CONFIG_X86
drivers/firmware/efi/efi.c bool efi_runtime_disabled(void) · line 73
Quoted 10 lines
drivers/firmware/efi/efi.c +10
-0+if (!strncmp (str,"old_map" ,7 )) { +set_bit (EFI_OLD_MEMMAP , &efi.flags); + goto out; + } +#endif +if (!strncmp (str,"noruntime" ,9 )) { + disable_runtime = true; + goto out; + } +
For sharing functions I moved old_map here, but rethinking about it maybe it's better to keep it in arch code.
Matt, I see you have some code for libstub option parsing, I will rebase on your efi/next and I'm thinking to add a generic function for parsing params like below (for old_map, but libstub can not use it):
arch/x86/platform/efi/efi.c +2 -20
@@ -932,26 +932,8 @@ u64 efi_mem_attributes(unsigned long phys_addr)static int __init parse_efi_cmdline (char *str) { -if (*str =='=' ) - str++; - -while (*str) { -if (!strncmp (str,"old_map" ,7 )) { -set_bit (EFI_OLD_MEMMAP , &efi.flags); - str +=strlen ("old_map" ); - } - -/* -* Skip any options we don't understand. Presumably -* they apply to the EFI boot stub. -*/ -while (*str && *str !=',' ) - str++; - -/* If we hit a delimiter, skip it */ -if (*str ==',' ) - str++; - } +if (parse_option_str (str,"old_map" )) +set_bit (EFI_OLD_MEMMAP , &efi.flags);return 0 ; }
include/linux/kernel.h +1 -0
@@ -407,6 +407,7 @@ int vsscanf(const char *, const char *, va_list);extern int get_option (char **str,int *pint);extern char *get_options (const char *str,int nints,int *ints);extern unsigned long long memparse (const char *ptr,char **retptr); +extern bool parse_option_str (const char *str,const char *option);extern int core_kernel_text (unsigned long addr);extern int core_kernel_data (unsigned long addr);
lib/cmdline.c +29 -0
@@ -155,3 +155,32 @@ unsigned long long memparse(const char *ptr, char **retptr)return ret; }EXPORT_SYMBOL (memparse); + +/** +* parse_option_str - Parse a string and check an option is set or not +* @str: String to be parsed +* @option: the option name +* +* This function parses a string containing a comma-separated +* list of strings like a=b,c. +* +* Return true if there's such option in the string, or return false. +*/ ++bool parse_option_str(const char *str, const char *option) +{ +while (*str) { +if (!strncmp (str, option,strlen (option))) { + str +=strlen (option); +if (!*str || *str ==',' ) +return true; + } + +while (*str && *str !=',' ) + str++; + +if (*str ==',' ) + str++; + } + +return false; +}
Re: [PATCH 2/5] efi: add kernel param efi=noruntime
Quoted 7 lines · Dave Young
For sharing functions I moved
old_maphere, but rethinking about it maybe it's better to keep it in arch code.Matt, I see you have some code for libstub option parsing, I will rebase on your efi/next and I'm thinking to add a generic function for parsing params like below (for
old_map, but libstub can not use it):
Makes sense to me.
Signature · 1 line
Matt Fleming, Intel Open Source Technology Center
PATCH 3/5 efi arm64: do not enter virtual mode in case booting with efi=noruntime or noefi
In reply to Dave YoungIn case efi runtime disabled via noefi kernel cmdline arm64_enter_virtual_mode should error out.
At the same time move early_memunmap(memmap.map, mapsize) to the beginning of the function or it will leak early mem.
--- arch/arm64/kernel/efi.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
arch/arm64/kernel/efi.c +4 -3
@@ -386,7 +386,10 @@ static int __init arm64_enter_virtual_mode(void)int count =0 ;unsigned long flags; -if (!efi_enabled (EFI_BOOT )) { + mapsize = memmap.map_end - memmap.map; +early_memunmap (memmap.map, mapsize); + +if (!efi_enabled (EFI_BOOT ) ||efi_runtime_disabled ()) {pr_info ("EFI services will not be available.\n" );return -1 ; }
@@ -394,8 +397,6 @@ static int __init arm64_enter_virtual_mode(void)pr_info ("Remapping and enabling EFI services.\n" );/* replace early memmap mapping with permanent mapping */ - mapsize = memmap.map_end - memmap.map; -early_memunmap (memmap.map, mapsize); memmap.map = (__force void *)ioremap_cache ((phys_addr_t )memmap.phys_map, mapsize); memmap.map_end = memmap.map + mapsize;
Signature · 1 line
1.8.3.1
Re: [PATCH 3/5] efi arm64: do not enter virtual mode in case booting with efi=noruntime or noefi
Quoted 16 lines · Dave Young
In case efi runtime disabled via noefi kernel cmdline
arm64_enter_virtual_modeshould error out.At the same time move
early_memunmap(memmap.map, mapsize)to the beginning of the function or it will leak early mem.Signed-off-by Dave Young <[email protected]>--- arch/arm64/kernel/efi.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)arch/arm64/kernel/efi.c +0
-0
arch/arm64/kernel/efi.c static int __init arm64_enter_virtual_mode(void) · line 392
Quoted 8 lines
arch/arm64/kernel/efi.c +4
-1@@ -386,7 +386,10 @@ static int __init arm64_enter_virtual_mode(void)int count =0 ;unsigned long flags; -if (!efi_enabled (EFI_BOOT )) { + mapsize = memmap.map_end - memmap.map; +early_memunmap (memmap.map, mapsize); + +if (!efi_enabled (EFI_BOOT ) ||efi_runtime_disabled ()) {
Hmm, is this right? We only set EFI_BOOT if we find EFI parameters in the DT (see efi_init -> uefi_init), so you run the risk of unmapping something we never mapped here.
Furthermore, there seems to be a leak in uefi_init anyway, as we return -EINVAL if the signature of the EFI table doesn't match without unmapping it first.
Will
Re: [PATCH 3/5] efi arm64: do not enter virtual mode in case booting with efi=noruntime or noefi
Quoted 20 lines · Will Deacon
Quoted 19 lines · Dave Young
In case efi runtime disabled via noefi kernel cmdline
arm64_enter_virtual_modeshould error out.At the same time move
early_memunmap(memmap.map, mapsize)to the beginning of the function or it will leak early mem.Signed-off-by Dave Young <[email protected]>--- arch/arm64/kernel/efi.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)arch/arm64/kernel/efi.c +0
-0@@ -386,7 +386,10 @@ static int __init arm64_enter_virtual_mode(void)int count =0 ;unsigned long flags;
Quoted 9 lines
arch/arm64/kernel/efi.c static int __init arm64_enter_virtual_mode(void) · line 392
Quoted 5 lines
arch/arm64/kernel/efi.c +4
-1-if (!efi_enabled (EFI_BOOT )) { + mapsize = memmap.map_end - memmap.map; +early_memunmap (memmap.map, mapsize); + +if (!efi_enabled (EFI_BOOT ) ||efi_runtime_disabled ()) {Hmm, is this right? We only set
EFI_BOOTif we find EFI parameters in the DT (seeefi_init->uefi_init), so you run the risk of unmapping something we never mapped here.
Good catch, I missed the case. will fix it in next update
Quoted 4 lines
Furthermore, there seems to be a leak in
uefi_initanyway, as we return-EINVALif the signature of the EFI table doesn't match without unmapping it first.
Yes, will add a new patch to fix the error handling in uefi_init.
BTW, Matt, I forgot to cc Xen/SGI people, will send an update soon and cc them.
Thanks
Dave
PATCH 4/5 efi x86: clear EFI_RUNTIME_SERVICES bit in case failures other than SetVirtualAddressMap
In reply to Dave YoungIf enter virtual mode failed due to some reason other than the efi call the EFI_RUNTIME_SERVICES bit in efi.flags should be cleared thus users of efi runtime services can check the bit and handle the case instead of assume efi runtime is ok.
Per Matt, if efi call SetVirtualAddressMap fails we will be not sure it's safe to make any assumptions about the state of the system. so kernel panics instead of clears EFI_RUNTIME_SERVICES bit.
--- arch/x86/platform/efi/efi.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
arch/x86/platform/efi/efi.c +8 -2
@@ -724,6 +724,7 @@ static void __init kexec_enter_virtual_mode(void)*/ if (!efi_is_native ()) {efi_unmap_memmap (); +clear_bit (EFI_RUNTIME_SERVICES , &efi.flags);return ; }
@@ -797,6 +798,7 @@ static void __init __efi_enter_virtual_mode(void) new_memmap =efi_map_regions (&count, &pg_shift);if (!new_memmap) {pr_err ("Error reallocating memory, EFI runtime non-functional!\n" ); +clear_bit (EFI_RUNTIME_SERVICES , &efi.flags);return ; }
@@ -804,8 +806,10 @@ static void __init __efi_enter_virtual_mode(void)BUG_ON (!efi.systab); -if (efi_setup_page_tables (__pa (new_memmap),1 << pg_shift)) +if (efi_setup_page_tables (__pa (new_memmap),1 << pg_shift)) { +clear_bit (EFI_RUNTIME_SERVICES , &efi.flags);return ; + }efi_sync_low_kernel_mappings ();efi_dump_pagetable ();
@@ -882,8 +886,10 @@ static void __init __efi_enter_virtual_mode(void)void __init efi_enter_virtual_mode (void ) { -if (efi_enabled (EFI_PARAVIRT )) +if (efi_enabled (EFI_PARAVIRT )) { +clear_bit (EFI_RUNTIME_SERVICES , &efi.flags);return ; + }if (efi_setup)kexec_enter_virtual_mode ();
Signature · 1 line
1.8.3.1
Re: [PATCH 4/5] efi x86: clear EFI_RUNTIME_SERVICES bit in case failures other than SetVirtualAddressMap
Quoted 13 lines · Dave Young
If enter virtual mode failed due to some reason other than the efi call the
EFI_RUNTIME_SERVICESbit in efi.flags should be cleared thus users of efi runtime services can check the bit and handle the case instead of assume efi runtime is ok.Per Matt, if efi call SetVirtualAddressMap fails we will be not sure it's safe to make any assumptions about the state of the system. so kernel panics instead of clears
EFI_RUNTIME_SERVICESbit.Signed-off-by Dave Young <[email protected]>--- arch/x86/platform/efi/efi.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
[...]
arch/x86/platform/efi/efi.c static void __init __efi_enter_virtual_mode(void) · line 892
Quoted 9 lines
arch/x86/platform/efi/efi.c +3
-1@@ -882,8 +886,10 @@ static void __init __efi_enter_virtual_mode(void)void __init efi_enter_virtual_mode (void ) { -if (efi_enabled (EFI_PARAVIRT )) +if (efi_enabled (EFI_PARAVIRT )) { +clear_bit (EFI_RUNTIME_SERVICES , &efi.flags);return ; + }
The EFI_PARAVIRT folks purposely do not set this bit, so there should be no reason to clear it here.
Signature · 1 line
Matt Fleming, Intel Open Source Technology Center
PATCH 5/5 efi_rtc: probe function error out in case no efi runtime enabled
In reply to Dave Youngefi rtc depends on efi runtime services, so if efi runtime services are not usable it should error out.
Without this patch rtc-efi will panic with 'noefi' boot
--- drivers/rtc/rtc-efi.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/rtc/rtc-efi.c +3 -0
@@ -213,6 +213,9 @@ static int __init efi_rtc_probe(struct platform_device *dev) {struct rtc_device *rtc; +if (!efi_enabled (EFI_RUNTIME_SERVICES )) +return -ENODEV ; + rtc =devm_rtc_device_register (&dev->dev,"rtc-efi" , &efi_rtc_ops,THIS_MODULE );if (IS_ERR (rtc))
Signature · 1 line
1.8.3.1
Randy Dunlap
reviewerQuoted 9 lines · Dave Young
noefi param can be used for arches other than X86 later, thus move it out of x86 platform code.
Signed-off-by Dave Young <[email protected]>--- arch/x86/platform/efi/efi.c | 10 +--------- drivers/firmware/efi/efi.c | 13 +++++++++++++ include/linux/efi.h | 1 + 3 files changed, 15 insertions(+), 9 deletions(-)
This line in Documentation/kernel-parameters.txt needs to be updated:
noefi [X86] Disable EFI runtime services support.
Quoted 63 lines
arch/x86/platform/efi/efi.c +1
-9@@ -70,14 +70,6 @@ static efi_config_table_type_t arch_tables[] __initdata = {u64 efi_setup;/* efi setup_data physical address */ -static bool disable_runtime__initdata = false; -static int __init setup_noefi (char *arg) -{ - disable_runtime = true; -return 0 ; -} -early_param ("noefi" , setup_noefi); -int add_efi_memmap;EXPORT_SYMBOL (add_efi_memmap);@@ -492,7 +484,7 @@ void __init efi_init(void)if (!efi_runtime_supported ())pr_info ("No EFI runtime due to 32/64-bit mismatch with kernel\n" );else { -if (disable_runtime ||efi_runtime_init ()) +if (efi_runtime_disabled () ||efi_runtime_init ())return ; }if (efi_memmap_init ())drivers/firmware/efi/efi.c +13
-0@@ -41,6 +41,19 @@ struct efi __read_mostly efi = { };EXPORT_SYMBOL (efi); +static bool disable_runtime; +static int __init setup_noefi (char *arg) +{ + disable_runtime = true; +return 0 ; +} +early_param ("noefi" , setup_noefi); + +bool efi_runtime_disabled (void ) +{ +return disable_runtime; +} +static struct kobject *efi_kobj;static struct kobject *efivars_kobj;include/linux/efi.h +1
-0@@ -1227,4 +1227,5 @@ efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,unsigned long *load_addr, unsigned long *load_size); +bool efi_runtime_disabled (void );#endif /* _LINUX_EFI_H */
Signature · 1 line
~Randy
Quoted 11 lines · Randy Dunlap
Quoted 9 lines · Dave Young
noefi param can be used for arches other than X86 later, thus move it out of x86 platform code.
Signed-off-by Dave Young <[email protected]>--- arch/x86/platform/efi/efi.c | 10 +--------- drivers/firmware/efi/efi.c | 13 +++++++++++++ include/linux/efi.h | 1 + 3 files changed, 15 insertions(+), 9 deletions(-)
Quoted 3 lines
This line in
Documentation/kernel-parameters.txtneeds to be updated:noefi [X86] Disable EFI runtime services support.
Randy, thanks
Will update the documentation.
Dave