History

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.

Ard Biesheuvel committed 6 years ago

Commit 9cd437a1 parent 0a673617 files · +59 −55Browse files

Unified · Split

7 files
  1. arch/x86/include/asm/efi.h +2 −0
  2. arch/x86/kernel/kexec-bzimage64.c +2 −2
  3. arch/x86/platform/efi/efi.c +48 −12
  4. arch/x86/platform/efi/quirks.c +1 −1
  5. drivers/firmware/efi/arm-init.c +0 −3
  6. drivers/firmware/efi/efi.c +6 −34
  7. include/linux/efi.h +0 −3
arch/x86/include/asm/efi.h+2−0
@@ -10,6 +10,8 @@ · 9 unmodified lines
1010 #include <asm/mmu_context.h>
1111 #include <linux/build_bug.h>
1212
13+extern unsigned long efi_fw_vendor, efi_config_table;
14+
1315 /*
1416 * We map the EFI regions needed for runtime services non-contiguously,
1517 * with preserved alignment on virtual addresses starting from -4G down
arch/x86/kernel/kexec-bzimage64.c+2−2
@@ -141,8 +141,8 @@ prepare_add_efi_setup_data(struct boot_params *params, · 140 unmodified lines
141141 struct setup_data *sd = (void *)params + efi_setup_data_offset;
142142 struct efi_setup_data *esd = (void *)sd + sizeof(struct setup_data);
143143
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;
146146 esd->smbios = efi.smbios;
147147
148148 sd->type = SETUP_EFI;
arch/x86/platform/efi/efi.c+48−12
@@ -59,6 +59,9 @@ static u64 efi_systab_phys __initdata; · 58 unmodified lines
5959
6060 static unsigned long prop_phys = EFI_INVALID_TABLE_ADDR;
6161 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;
6265
6366 static const efi_config_table_type_t arch_tables[] __initconst = {
6467 {EFI_PROPERTIES_TABLE_GUID, "PROP", &prop_phys},
@@ -78,9 +81,9 @@ static const unsigned long * const efi_tables[] = { · 13 unmodified lines
7881 #ifdef CONFIG_X86_UV
7982 &uv_systab_phys,
8083 #endif
81− &efi.fw_vendor,
82− &efi.runtime,
83− &efi.config_table,
84+ &efi_fw_vendor,
85+ &efi_runtime,
86+ &efi_config_table,
8487 &efi.esrt,
8588 &prop_phys,
8689 &efi_mem_attr_table,
@@ -434,7 +437,7 @@ static int __init efi_config_init(const efi_config_table_type_t *arch_tables) · 347 unmodified lines
434437 void *config_tables;
435438 int sz, ret;
436439
437− if (efi.systab->nr_tables == 0)
440+ if (efi_nr_tables == 0)
438441 return 0;
439442
440443 if (efi_enabled(EFI_64BIT))
@@ -445,17 +448,16 @@ static int __init efi_config_init(const efi_config_table_type_t *arch_tables) · 4 unmodified lines
445448 /*
446449 * Let's see what config tables the firmware passed to us.
447450 */
448− config_tables = early_memremap(efi.systab->tables,
449− efi.systab->nr_tables * sz);
451+ config_tables = early_memremap(efi_config_table, efi_nr_tables * sz);
450452 if (config_tables == NULL) {
451453 pr_err("Could not map Configuration table!\n");
452454 return -ENOMEM;
453455 }
454456
455− ret = efi_config_parse_tables(config_tables, efi.systab->nr_tables,
457+ ret = efi_config_parse_tables(config_tables, efi_nr_tables,
456458 arch_tables);
457459
458− early_memunmap(config_tables, efi.systab->nr_tables * sz);
460+ early_memunmap(config_tables, efi_nr_tables * sz);
459461 return ret;
460462 }
461463
@@ -474,11 +476,12 @@ void __init efi_init(void) · 12 unmodified lines
474476 if (efi_systab_init(efi_systab_phys))
475477 return;
476478
477− efi.config_table = (unsigned long)efi.systab->tables;
478− efi.fw_vendor = (unsigned long)efi.systab->fw_vendor;
479− efi.runtime = (unsigned long)efi.systab->runtime;
479+ efi_config_table = (unsigned long)efi.systab->tables;
480+ efi_nr_tables = efi.systab->nr_tables;
481+ efi_fw_vendor = (unsigned long)efi.systab->fw_vendor;
482+ efi_runtime = (unsigned long)efi.systab->runtime;
480483
481− if (efi_reuse_config(efi.systab->tables, efi.systab->nr_tables))
484+ if (efi_reuse_config(efi_config_table, efi_nr_tables))
482485 return;
483486
484487 if (efi_config_init(arch_tables))
@@ -1023,3 +1026,36 @@ char *efi_systab_show_arch(char *str) · 538 unmodified lines
10231026 str += sprintf(str, "UGA=0x%lx\n", uga_phys);
10241027 return str;
10251028 }
1029+
1030+#define EFI_FIELD(var) efi_ ## var
1031+
1032+#define EFI_ATTR_SHOW(name) \
1033+static ssize_t name##_show(struct kobject *kobj, \
1034+ struct kobj_attribute *attr, char *buf) \
1035+{ \
1036+ return sprintf(buf, "0x%lx\n", EFI_FIELD(name)); \
1037+}
1038+
1039+EFI_ATTR_SHOW(fw_vendor);
1040+EFI_ATTR_SHOW(runtime);
1041+EFI_ATTR_SHOW(config_table);
1042+
1043+struct kobj_attribute efi_attr_fw_vendor = __ATTR_RO(fw_vendor);
1044+struct kobj_attribute efi_attr_runtime = __ATTR_RO(runtime);
1045+struct kobj_attribute efi_attr_config_table = __ATTR_RO(config_table);
1046+
1047+umode_t efi_attr_is_visible(struct kobject *kobj, struct attribute *attr, int n)
1048+{
1049+ if (attr == &efi_attr_fw_vendor.attr) {
1050+ if (efi_enabled(EFI_PARAVIRT) ||
1051+ efi_fw_vendor == EFI_INVALID_TABLE_ADDR)
1052+ return 0;
1053+ } else if (attr == &efi_attr_runtime.attr) {
1054+ if (efi_runtime == EFI_INVALID_TABLE_ADDR)
1055+ return 0;
1056+ } else if (attr == &efi_attr_config_table.attr) {
1057+ if (efi_config_table == EFI_INVALID_TABLE_ADDR)
1058+ return 0;
1059+ }
1060+ return attr->mode;
1061+}
arch/x86/platform/efi/quirks.c+1−1
@@ -537,7 +537,7 @@ int __init efi_reuse_config(u64 tables, int nr_tables) · 536 unmodified lines
537537 goto out_memremap;
538538 }
539539
540− for (i = 0; i < efi.systab->nr_tables; i++) {
540+ for (i = 0; i < nr_tables; i++) {
541541 efi_guid_t guid;
542542
543543 guid = ((efi_config_table_64_t *)p)->guid;
drivers/firmware/efi/arm-init.c+0−3
@@ -120,9 +120,6 @@ static int __init uefi_init(void) · 119 unmodified lines
120120 retval = efi_config_parse_tables(config_tables, efi.systab->nr_tables,
121121 arch_tables);
122122
123− if (!retval)
124− efi.config_table = (unsigned long)efi.systab->tables;
125−
126123 early_memunmap(config_tables, table_size);
127124 out:
128125 early_memunmap(efi.systab, sizeof(efi_system_table_t));
drivers/firmware/efi/efi.c+6−34
@@ -39,9 +39,6 @@ struct efi __read_mostly efi = { · 38 unmodified lines
3939 .acpi20 = EFI_INVALID_TABLE_ADDR,
4040 .smbios = EFI_INVALID_TABLE_ADDR,
4141 .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,
4542 .esrt = EFI_INVALID_TABLE_ADDR,
4643 .tpm_log = EFI_INVALID_TABLE_ADDR,
4744 .tpm_final_log = EFI_INVALID_TABLE_ADDR,
@@ -142,55 +139,30 @@ static ssize_t systab_show(struct kobject *kobj, · 94 unmodified lines
142139
143140 static struct kobj_attribute efi_attr_systab = __ATTR_RO_MODE(systab, 0400);
144141
145−#define EFI_FIELD(var) efi.var
146−
147−#define EFI_ATTR_SHOW(name) \
148−static ssize_t name##_show(struct kobject *kobj, \
149− struct kobj_attribute *attr, char *buf) \
150−{ \
151− return sprintf(buf, "0x%lx\n", EFI_FIELD(name)); \
152−}
153−
154−EFI_ATTR_SHOW(fw_vendor);
155−EFI_ATTR_SHOW(runtime);
156−EFI_ATTR_SHOW(config_table);
157−
158142 static ssize_t fw_platform_size_show(struct kobject *kobj,
159143 struct kobj_attribute *attr, char *buf)
160144 {
161145 return sprintf(buf, "%d\n", efi_enabled(EFI_64BIT) ? 64 : 32);
162146 }
163147
164−static struct kobj_attribute efi_attr_fw_vendor = __ATTR_RO(fw_vendor);
165−static struct kobj_attribute efi_attr_runtime = __ATTR_RO(runtime);
166−static struct kobj_attribute efi_attr_config_table = __ATTR_RO(config_table);
148+extern __weak struct kobj_attribute efi_attr_fw_vendor;
149+extern __weak struct kobj_attribute efi_attr_runtime;
150+extern __weak struct kobj_attribute efi_attr_config_table;
167151 static struct kobj_attribute efi_attr_fw_platform_size =
168152 __ATTR_RO(fw_platform_size);
169153
170154 static struct attribute *efi_subsys_attrs[] = {
171155 &efi_attr_systab.attr,
156+ &efi_attr_fw_platform_size.attr,
172157 &efi_attr_fw_vendor.attr,
173158 &efi_attr_runtime.attr,
174159 &efi_attr_config_table.attr,
175− &efi_attr_fw_platform_size.attr,
176160 NULL,
177161 };
178162
179−static umode_t efi_attr_is_visible(struct kobject *kobj,
180− struct attribute *attr, int n)
163+umode_t __weak efi_attr_is_visible(struct kobject *kobj, struct attribute *attr,
164+ int n)
181165 {
182− if (attr == &efi_attr_fw_vendor.attr) {
183− if (efi_enabled(EFI_PARAVIRT) ||
184− efi.fw_vendor == EFI_INVALID_TABLE_ADDR)
185− return 0;
186− } else if (attr == &efi_attr_runtime.attr) {
187− if (efi.runtime == EFI_INVALID_TABLE_ADDR)
188− return 0;
189− } else if (attr == &efi_attr_config_table.attr) {
190− if (efi.config_table == EFI_INVALID_TABLE_ADDR)
191− return 0;
192− }
193−
194166 return attr->mode;
195167 }
196168
include/linux/efi.h+0−3
@@ -535,9 +535,6 @@ extern struct efi { · 534 unmodified lines
535535 unsigned long acpi20; /* ACPI table (ACPI 2.0) */
536536 unsigned long smbios; /* SMBIOS table (32 bit entry point) */
537537 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 */
541538 unsigned long esrt; /* ESRT table */
542539 unsigned long tpm_log; /* TPM2 Event Log table */
543540 unsigned long tpm_final_log; /* TPM2 Final Events Log table */