efi: Use more granular check for availability for variable services
authorArd Biesheuvel <ardb@kernel.org>
Thu, 23 Jan 2020 08:12:00 +0000 (09:12 +0100)
committerArd Biesheuvel <ardb@kernel.org>
Sun, 23 Feb 2020 20:59:42 +0000 (21:59 +0100)
The UEFI spec rev 2.8 permits firmware implementations to support only
a subset of EFI runtime services at OS runtime (i.e., after the call to
ExitBootServices()), so let's take this into account in the drivers that
rely specifically on the availability of the EFI variable services.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
drivers/firmware/efi/efi-pstore.c
drivers/firmware/efi/efi.c
drivers/firmware/efi/efivars.c
fs/efivarfs/super.c

index 9ea13e8d12ec252455c10cf923c24bfb09f9f191..d2f6855d205bb469ff191cb016e856ed9e0c6905 100644 (file)
@@ -356,7 +356,7 @@ static struct pstore_info efi_pstore_info = {
 
 static __init int efivars_pstore_init(void)
 {
-       if (!efi_enabled(EFI_RUNTIME_SERVICES))
+       if (!efi_rt_services_supported(EFI_RT_SUPPORTED_VARIABLE_SERVICES))
                return 0;
 
        if (!efivars_kobject())
index a35230517f9c7e9699a45c53d43264c8a29dde0b..abf4c02e020110bde98b67322a068e96ac50e544 100644 (file)
@@ -328,12 +328,13 @@ static int __init efisubsys_init(void)
                return -ENOMEM;
        }
 
-       error = generic_ops_register();
-       if (error)
-               goto err_put;
-
-       if (efi_enabled(EFI_RUNTIME_SERVICES))
+       if (efi_rt_services_supported(EFI_RT_SUPPORTED_VARIABLE_SERVICES)) {
                efivar_ssdt_load();
+               error = generic_ops_register();
+               if (error)
+                       goto err_put;
+               platform_device_register_simple("efivars", 0, NULL, 0);
+       }
 
        error = sysfs_create_group(efi_kobj, &efi_subsys_attr_group);
        if (error) {
@@ -358,7 +359,8 @@ static int __init efisubsys_init(void)
 err_remove_group:
        sysfs_remove_group(efi_kobj, &efi_subsys_attr_group);
 err_unregister:
-       generic_ops_unregister();
+       if (efi_rt_services_supported(EFI_RT_SUPPORTED_VARIABLE_SERVICES))
+               generic_ops_unregister();
 err_put:
        kobject_put(efi_kobj);
        return error;
@@ -650,20 +652,6 @@ void __init efi_systab_report_header(const efi_table_hdr_t *systab_hdr,
                vendor);
 }
 
-#ifdef CONFIG_EFI_VARS_MODULE
-static int __init efi_load_efivars(void)
-{
-       struct platform_device *pdev;
-
-       if (!efi_enabled(EFI_RUNTIME_SERVICES))
-               return 0;
-
-       pdev = platform_device_register_simple("efivars", 0, NULL, 0);
-       return PTR_ERR_OR_ZERO(pdev);
-}
-device_initcall(efi_load_efivars);
-#endif
-
 static __initdata char memory_type_name[][20] = {
        "Reserved",
        "Loader Code",
index 7576450c8254b8cc8c1cada05a1c9ac61922ea1f..d309abca509185fd86ad757abafb9218eb372cfa 100644 (file)
@@ -664,7 +664,7 @@ int efivars_sysfs_init(void)
        struct kobject *parent_kobj = efivars_kobject();
        int error = 0;
 
-       if (!efi_enabled(EFI_RUNTIME_SERVICES))
+       if (!efi_rt_services_supported(EFI_RT_SUPPORTED_VARIABLE_SERVICES))
                return -ENODEV;
 
        /* No efivars has been registered yet */
index fa4f6447ddad690f04cc6d4fddef833e39ff45ac..12c66f5d92dd2e5e1de7fc4d733bed11871adfa0 100644 (file)
@@ -252,7 +252,7 @@ static struct file_system_type efivarfs_type = {
 
 static __init int efivarfs_init(void)
 {
-       if (!efi_enabled(EFI_RUNTIME_SERVICES))
+       if (!efi_rt_services_supported(EFI_RT_SUPPORTED_VARIABLE_SERVICES))
                return -ENODEV;
 
        if (!efivars_kobject())