Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

efi/x86: Make fw_vendor, config_table and runtime sysfs nodes x86 specific

There is some code that exposes physical addresses of certain parts of
the EFI firmware implementation via sysfs nodes. These nodes are only
used on x86, and are of dubious value to begin with, so let's move
their handling into the x86 arch code.

Tested-by: Tony Luck <tony.luck@intel.com> # arch/ia64
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>

+59 -55
+2
arch/x86/include/asm/efi.h
··· 10 10 #include <asm/mmu_context.h> 11 11 #include <linux/build_bug.h> 12 12 13 + extern unsigned long efi_fw_vendor, efi_config_table; 14 + 13 15 /* 14 16 * We map the EFI regions needed for runtime services non-contiguously, 15 17 * with preserved alignment on virtual addresses starting from -4G down
+2 -2
arch/x86/kernel/kexec-bzimage64.c
··· 141 141 struct setup_data *sd = (void *)params + efi_setup_data_offset; 142 142 struct efi_setup_data *esd = (void *)sd + sizeof(struct setup_data); 143 143 144 - esd->fw_vendor = efi.fw_vendor; 145 - esd->tables = efi.config_table; 144 + esd->fw_vendor = efi_fw_vendor; 145 + esd->tables = efi_config_table; 146 146 esd->smbios = efi.smbios; 147 147 148 148 sd->type = SETUP_EFI;
+48 -12
arch/x86/platform/efi/efi.c
··· 59 59 60 60 static unsigned long prop_phys = EFI_INVALID_TABLE_ADDR; 61 61 static unsigned long uga_phys = EFI_INVALID_TABLE_ADDR; 62 + static unsigned long efi_runtime, efi_nr_tables; 63 + 64 + unsigned long efi_fw_vendor, efi_config_table; 62 65 63 66 static const efi_config_table_type_t arch_tables[] __initconst = { 64 67 {EFI_PROPERTIES_TABLE_GUID, "PROP", &prop_phys}, ··· 81 78 #ifdef CONFIG_X86_UV 82 79 &uv_systab_phys, 83 80 #endif 84 - &efi.fw_vendor, 85 - &efi.runtime, 86 - &efi.config_table, 81 + &efi_fw_vendor, 82 + &efi_runtime, 83 + &efi_config_table, 87 84 &efi.esrt, 88 85 &prop_phys, 89 86 &efi_mem_attr_table, ··· 437 434 void *config_tables; 438 435 int sz, ret; 439 436 440 - if (efi.systab->nr_tables == 0) 437 + if (efi_nr_tables == 0) 441 438 return 0; 442 439 443 440 if (efi_enabled(EFI_64BIT)) ··· 448 445 /* 449 446 * Let's see what config tables the firmware passed to us. 450 447 */ 451 - config_tables = early_memremap(efi.systab->tables, 452 - efi.systab->nr_tables * sz); 448 + config_tables = early_memremap(efi_config_table, efi_nr_tables * sz); 453 449 if (config_tables == NULL) { 454 450 pr_err("Could not map Configuration table!\n"); 455 451 return -ENOMEM; 456 452 } 457 453 458 - ret = efi_config_parse_tables(config_tables, efi.systab->nr_tables, 454 + ret = efi_config_parse_tables(config_tables, efi_nr_tables, 459 455 arch_tables); 460 456 461 - early_memunmap(config_tables, efi.systab->nr_tables * sz); 457 + early_memunmap(config_tables, efi_nr_tables * sz); 462 458 return ret; 463 459 } 464 460 ··· 476 474 if (efi_systab_init(efi_systab_phys)) 477 475 return; 478 476 479 - efi.config_table = (unsigned long)efi.systab->tables; 480 - efi.fw_vendor = (unsigned long)efi.systab->fw_vendor; 481 - efi.runtime = (unsigned long)efi.systab->runtime; 477 + efi_config_table = (unsigned long)efi.systab->tables; 478 + efi_nr_tables = efi.systab->nr_tables; 479 + efi_fw_vendor = (unsigned long)efi.systab->fw_vendor; 480 + efi_runtime = (unsigned long)efi.systab->runtime; 482 481 483 - if (efi_reuse_config(efi.systab->tables, efi.systab->nr_tables)) 482 + if (efi_reuse_config(efi_config_table, efi_nr_tables)) 484 483 return; 485 484 486 485 if (efi_config_init(arch_tables)) ··· 1025 1022 if (uga_phys != EFI_INVALID_TABLE_ADDR) 1026 1023 str += sprintf(str, "UGA=0x%lx\n", uga_phys); 1027 1024 return str; 1025 + } 1026 + 1027 + #define EFI_FIELD(var) efi_ ## var 1028 + 1029 + #define EFI_ATTR_SHOW(name) \ 1030 + static ssize_t name##_show(struct kobject *kobj, \ 1031 + struct kobj_attribute *attr, char *buf) \ 1032 + { \ 1033 + return sprintf(buf, "0x%lx\n", EFI_FIELD(name)); \ 1034 + } 1035 + 1036 + EFI_ATTR_SHOW(fw_vendor); 1037 + EFI_ATTR_SHOW(runtime); 1038 + EFI_ATTR_SHOW(config_table); 1039 + 1040 + struct kobj_attribute efi_attr_fw_vendor = __ATTR_RO(fw_vendor); 1041 + struct kobj_attribute efi_attr_runtime = __ATTR_RO(runtime); 1042 + struct kobj_attribute efi_attr_config_table = __ATTR_RO(config_table); 1043 + 1044 + umode_t efi_attr_is_visible(struct kobject *kobj, struct attribute *attr, int n) 1045 + { 1046 + if (attr == &efi_attr_fw_vendor.attr) { 1047 + if (efi_enabled(EFI_PARAVIRT) || 1048 + efi_fw_vendor == EFI_INVALID_TABLE_ADDR) 1049 + return 0; 1050 + } else if (attr == &efi_attr_runtime.attr) { 1051 + if (efi_runtime == EFI_INVALID_TABLE_ADDR) 1052 + return 0; 1053 + } else if (attr == &efi_attr_config_table.attr) { 1054 + if (efi_config_table == EFI_INVALID_TABLE_ADDR) 1055 + return 0; 1056 + } 1057 + return attr->mode; 1028 1058 }
+1 -1
arch/x86/platform/efi/quirks.c
··· 537 537 goto out_memremap; 538 538 } 539 539 540 - for (i = 0; i < efi.systab->nr_tables; i++) { 540 + for (i = 0; i < nr_tables; i++) { 541 541 efi_guid_t guid; 542 542 543 543 guid = ((efi_config_table_64_t *)p)->guid;
-3
drivers/firmware/efi/arm-init.c
··· 120 120 retval = efi_config_parse_tables(config_tables, efi.systab->nr_tables, 121 121 arch_tables); 122 122 123 - if (!retval) 124 - efi.config_table = (unsigned long)efi.systab->tables; 125 - 126 123 early_memunmap(config_tables, table_size); 127 124 out: 128 125 early_memunmap(efi.systab, sizeof(efi_system_table_t));
+6 -34
drivers/firmware/efi/efi.c
··· 39 39 .acpi20 = EFI_INVALID_TABLE_ADDR, 40 40 .smbios = EFI_INVALID_TABLE_ADDR, 41 41 .smbios3 = EFI_INVALID_TABLE_ADDR, 42 - .fw_vendor = EFI_INVALID_TABLE_ADDR, 43 - .runtime = EFI_INVALID_TABLE_ADDR, 44 - .config_table = EFI_INVALID_TABLE_ADDR, 45 42 .esrt = EFI_INVALID_TABLE_ADDR, 46 43 .tpm_log = EFI_INVALID_TABLE_ADDR, 47 44 .tpm_final_log = EFI_INVALID_TABLE_ADDR, ··· 139 142 140 143 static struct kobj_attribute efi_attr_systab = __ATTR_RO_MODE(systab, 0400); 141 144 142 - #define EFI_FIELD(var) efi.var 143 - 144 - #define EFI_ATTR_SHOW(name) \ 145 - static ssize_t name##_show(struct kobject *kobj, \ 146 - struct kobj_attribute *attr, char *buf) \ 147 - { \ 148 - return sprintf(buf, "0x%lx\n", EFI_FIELD(name)); \ 149 - } 150 - 151 - EFI_ATTR_SHOW(fw_vendor); 152 - EFI_ATTR_SHOW(runtime); 153 - EFI_ATTR_SHOW(config_table); 154 - 155 145 static ssize_t fw_platform_size_show(struct kobject *kobj, 156 146 struct kobj_attribute *attr, char *buf) 157 147 { 158 148 return sprintf(buf, "%d\n", efi_enabled(EFI_64BIT) ? 64 : 32); 159 149 } 160 150 161 - static struct kobj_attribute efi_attr_fw_vendor = __ATTR_RO(fw_vendor); 162 - static struct kobj_attribute efi_attr_runtime = __ATTR_RO(runtime); 163 - static struct kobj_attribute efi_attr_config_table = __ATTR_RO(config_table); 151 + extern __weak struct kobj_attribute efi_attr_fw_vendor; 152 + extern __weak struct kobj_attribute efi_attr_runtime; 153 + extern __weak struct kobj_attribute efi_attr_config_table; 164 154 static struct kobj_attribute efi_attr_fw_platform_size = 165 155 __ATTR_RO(fw_platform_size); 166 156 167 157 static struct attribute *efi_subsys_attrs[] = { 168 158 &efi_attr_systab.attr, 159 + &efi_attr_fw_platform_size.attr, 169 160 &efi_attr_fw_vendor.attr, 170 161 &efi_attr_runtime.attr, 171 162 &efi_attr_config_table.attr, 172 - &efi_attr_fw_platform_size.attr, 173 163 NULL, 174 164 }; 175 165 176 - static umode_t efi_attr_is_visible(struct kobject *kobj, 177 - struct attribute *attr, int n) 166 + umode_t __weak efi_attr_is_visible(struct kobject *kobj, struct attribute *attr, 167 + int n) 178 168 { 179 - if (attr == &efi_attr_fw_vendor.attr) { 180 - if (efi_enabled(EFI_PARAVIRT) || 181 - efi.fw_vendor == EFI_INVALID_TABLE_ADDR) 182 - return 0; 183 - } else if (attr == &efi_attr_runtime.attr) { 184 - if (efi.runtime == EFI_INVALID_TABLE_ADDR) 185 - return 0; 186 - } else if (attr == &efi_attr_config_table.attr) { 187 - if (efi.config_table == EFI_INVALID_TABLE_ADDR) 188 - return 0; 189 - } 190 - 191 169 return attr->mode; 192 170 } 193 171
-3
include/linux/efi.h
··· 535 535 unsigned long acpi20; /* ACPI table (ACPI 2.0) */ 536 536 unsigned long smbios; /* SMBIOS table (32 bit entry point) */ 537 537 unsigned long smbios3; /* SMBIOS table (64 bit entry point) */ 538 - unsigned long fw_vendor; /* fw_vendor */ 539 - unsigned long runtime; /* runtime table */ 540 - unsigned long config_table; /* config tables */ 541 538 unsigned long esrt; /* ESRT table */ 542 539 unsigned long tpm_log; /* TPM2 Event Log table */ 543 540 unsigned long tpm_final_log; /* TPM2 Final Events Log table */