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