From: Ard Biesheuvel Date: Mon, 7 Nov 2022 08:17:16 +0000 (+0100) Subject: efi: x86: Move EFI runtime map sysfs code to arch/x86 X-Git-Tag: v6.6.7~3922^2~12 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1fff234de2b6047ee311c6bf88f31ad5008f2889;p=platform%2Fkernel%2Flinux-starfive.git efi: x86: Move EFI runtime map sysfs code to arch/x86 The EFI runtime map code is only wired up on x86, which is the only architecture that has a need for it in its implementation of kexec. So let's move this code under arch/x86 and drop all references to it from generic code. To ensure that the efi_runtime_map_init() is invoked at the appropriate time use a 'sync' subsys_initcall() that will be called right after the EFI initcall made from generic code where the original invocation of efi_runtime_map_init() resided. Signed-off-by: Ard Biesheuvel Reviewed-by: Dave Young --- diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index e2f89a7..eaf8475 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -2014,6 +2014,17 @@ config EFI_MAX_FAKE_MEM Ranges can be set up to this value using comma-separated list. The default value is 8. +config EFI_RUNTIME_MAP + bool "Export EFI runtime maps to sysfs" if EXPERT + depends on EFI + default KEXEC_CORE + help + Export EFI runtime memory regions to /sys/firmware/efi/runtime-map. + That memory map is required by the 2nd kernel to set up EFI virtual + mappings after kexec, but can also be used for debugging purposes. + + See also Documentation/ABI/testing/sysfs-firmware-efi-runtime-map. + source "kernel/Kconfig.hz" config KEXEC diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h index f29d145..a63154e 100644 --- a/arch/x86/include/asm/efi.h +++ b/arch/x86/include/asm/efi.h @@ -432,4 +432,26 @@ extern void __init efi_memmap_insert(struct efi_memory_map *old_memmap, #define arch_ima_efi_boot_mode \ ({ extern struct boot_params boot_params; boot_params.secure_boot; }) +#ifdef CONFIG_EFI_RUNTIME_MAP +int efi_get_runtime_map_size(void); +int efi_get_runtime_map_desc_size(void); +int efi_runtime_map_copy(void *buf, size_t bufsz); +#else +static inline int efi_get_runtime_map_size(void) +{ + return 0; +} + +static inline int efi_get_runtime_map_desc_size(void) +{ + return 0; +} + +static inline int efi_runtime_map_copy(void *buf, size_t bufsz) +{ + return 0; +} + +#endif + #endif /* _ASM_X86_EFI_H */ diff --git a/arch/x86/platform/efi/Makefile b/arch/x86/platform/efi/Makefile index ed5502a5..543df9a 100644 --- a/arch/x86/platform/efi/Makefile +++ b/arch/x86/platform/efi/Makefile @@ -6,3 +6,4 @@ obj-$(CONFIG_EFI) += memmap.o quirks.o efi.o efi_$(BITS).o \ efi_stub_$(BITS).o obj-$(CONFIG_EFI_MIXED) += efi_thunk_$(BITS).o obj-$(CONFIG_EFI_FAKE_MEMMAP) += fake_mem.o +obj-$(CONFIG_EFI_RUNTIME_MAP) += runtime-map.o diff --git a/drivers/firmware/efi/runtime-map.c b/arch/x86/platform/efi/runtime-map.c similarity index 96% rename from drivers/firmware/efi/runtime-map.c rename to arch/x86/platform/efi/runtime-map.c index 92a3d45..bbee682 100644 --- a/drivers/firmware/efi/runtime-map.c +++ b/arch/x86/platform/efi/runtime-map.c @@ -1,6 +1,5 @@ // SPDX-License-Identifier: GPL-2.0 /* - * linux/drivers/efi/runtime-map.c * Copyright (C) 2013 Red Hat, Inc., Dave Young */ @@ -11,6 +10,7 @@ #include #include +#include #include struct efi_runtime_map_entry { @@ -157,13 +157,13 @@ int efi_runtime_map_copy(void *buf, size_t bufsz) return 0; } -int __init efi_runtime_map_init(struct kobject *efi_kobj) +static int __init efi_runtime_map_init(void) { int i, j, ret = 0; struct efi_runtime_map_entry *entry; efi_memory_desc_t *md; - if (!efi_enabled(EFI_MEMMAP)) + if (!efi_enabled(EFI_MEMMAP) || !efi_kobj) return 0; map_entries = kcalloc(efi.memmap.nr_map, sizeof(entry), GFP_KERNEL); @@ -191,3 +191,4 @@ out_add_entry: out: return ret; } +subsys_initcall_sync(efi_runtime_map_init); diff --git a/drivers/firmware/efi/Kconfig b/drivers/firmware/efi/Kconfig index 552512f..08ed88e4 100644 --- a/drivers/firmware/efi/Kconfig +++ b/drivers/firmware/efi/Kconfig @@ -26,17 +26,6 @@ config EFI_VARS_PSTORE_DEFAULT_DISABLE backend for pstore by default. This setting can be overridden using the efivars module's pstore_disable parameter. -config EFI_RUNTIME_MAP - bool "Export EFI runtime maps to sysfs" if EXPERT - depends on X86 && EFI - default KEXEC_CORE - help - Export EFI runtime memory regions to /sys/firmware/efi/runtime-map. - That memory map is required by the 2nd kernel to set up EFI virtual - mappings after kexec, but can also be used for debugging purposes. - - See also Documentation/ABI/testing/sysfs-firmware-efi-runtime-map. - config EFI_SOFT_RESERVE bool "Reserve EFI Specific Purpose Memory" depends on EFI && EFI_STUB && ACPI_HMAT diff --git a/drivers/firmware/efi/Makefile b/drivers/firmware/efi/Makefile index 8e4f0d5..7d3b08c 100644 --- a/drivers/firmware/efi/Makefile +++ b/drivers/firmware/efi/Makefile @@ -20,7 +20,6 @@ obj-$(CONFIG_EFI_PARAMS_FROM_FDT) += fdtparams.o obj-$(CONFIG_EFI_ESRT) += esrt.o obj-$(CONFIG_EFI_VARS_PSTORE) += efi-pstore.o obj-$(CONFIG_UEFI_CPER) += cper.o -obj-$(CONFIG_EFI_RUNTIME_MAP) += runtime-map.o obj-$(CONFIG_EFI_RUNTIME_WRAPPERS) += runtime-wrappers.o subdir-$(CONFIG_EFI_STUB) += libstub obj-$(CONFIG_EFI_BOOTLOADER_CONTROL) += efibc.o diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 951a42d..dfdbbc7 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -396,10 +396,6 @@ static int __init efisubsys_init(void) goto err_unregister; } - error = efi_runtime_map_init(efi_kobj); - if (error) - goto err_remove_group; - /* and the standard mountpoint for efivarfs */ error = sysfs_create_mount_point(efi_kobj, "efivars"); if (error) { @@ -425,6 +421,7 @@ err_unregister: generic_ops_unregister(); err_put: kobject_put(efi_kobj); + efi_kobj = NULL; destroy_workqueue(efi_rts_wq); return error; } diff --git a/include/linux/efi.h b/include/linux/efi.h index 6a0bdef..400edf7 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1089,34 +1089,6 @@ extern int efi_capsule_update(efi_capsule_header_t *capsule, static inline bool efi_capsule_pending(int *reset_type) { return false; } #endif -#ifdef CONFIG_EFI_RUNTIME_MAP -int efi_runtime_map_init(struct kobject *); -int efi_get_runtime_map_size(void); -int efi_get_runtime_map_desc_size(void); -int efi_runtime_map_copy(void *buf, size_t bufsz); -#else -static inline int efi_runtime_map_init(struct kobject *kobj) -{ - return 0; -} - -static inline int efi_get_runtime_map_size(void) -{ - return 0; -} - -static inline int efi_get_runtime_map_desc_size(void) -{ - return 0; -} - -static inline int efi_runtime_map_copy(void *buf, size_t bufsz) -{ - return 0; -} - -#endif - #ifdef CONFIG_EFI extern bool efi_runtime_disabled(void); #else