Skip to content

Commit ccc27ae

Browse files
committed
efi/libstub: Drop __pure getter for efi_system_table
The practice of using __pure getter functions to access global variables in the EFI stub dates back to the time when we had to carefully prevent GOT entries from being emitted, because we could not rely on the toolchain to do this for us. Today, we use the hidden visibility pragma for all EFI stub source files, which now all live in the same subdirectory, and we apply a sanity check on the objects, so we can get rid of these getter functions and simply refer to global data objects directly. Start with efi_system_table(), and convert it into a global variable. While at it, make it a pointer-to-const, because we can. Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent 5443937 commit ccc27ae

File tree

6 files changed

+30
-38
lines changed

6 files changed

+30
-38
lines changed

arch/x86/include/asm/efi.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,15 +339,17 @@ static inline u32 efi64_convert_status(efi_status_t status)
339339

340340
#define efi_bs_call(func, ...) \
341341
(efi_is_native() \
342-
? efi_system_table()->boottime->func(__VA_ARGS__) \
343-
: __efi64_thunk_map(efi_table_attr(efi_system_table(), \
344-
boottime), func, __VA_ARGS__))
342+
? efi_system_table->boottime->func(__VA_ARGS__) \
343+
: __efi64_thunk_map(efi_table_attr(efi_system_table, \
344+
boottime), \
345+
func, __VA_ARGS__))
345346

346347
#define efi_rt_call(func, ...) \
347348
(efi_is_native() \
348-
? efi_system_table()->runtime->func(__VA_ARGS__) \
349-
: __efi64_thunk_map(efi_table_attr(efi_system_table(), \
350-
runtime), func, __VA_ARGS__))
349+
? efi_system_table->runtime->func(__VA_ARGS__) \
350+
: __efi64_thunk_map(efi_table_attr(efi_system_table, \
351+
runtime), \
352+
func, __VA_ARGS__))
351353

352354
extern bool efi_reboot_required(void);
353355
extern bool efi_is_table_address(unsigned long phys_addr);

drivers/firmware/efi/libstub/efi-stub-helper.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,8 @@ efi_status_t efi_exit_boot_services(void *handle,
287287

288288
void *get_efi_config_table(efi_guid_t guid)
289289
{
290-
unsigned long tables = efi_table_attr(efi_system_table(), tables);
291-
int nr_tables = efi_table_attr(efi_system_table(), nr_tables);
290+
unsigned long tables = efi_table_attr(efi_system_table, tables);
291+
int nr_tables = efi_table_attr(efi_system_table, nr_tables);
292292
int i;
293293

294294
for (i = 0; i < nr_tables; i++) {
@@ -305,7 +305,7 @@ void *get_efi_config_table(efi_guid_t guid)
305305

306306
void efi_char16_printk(efi_char16_t *str)
307307
{
308-
efi_call_proto(efi_table_attr(efi_system_table(), con_out),
308+
efi_call_proto(efi_table_attr(efi_system_table, con_out),
309309
output_string, str);
310310
}
311311

drivers/firmware/efi/libstub/efi-stub.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,7 @@
3838
static u64 virtmap_base = EFI_RT_VIRTUAL_BASE;
3939
static bool flat_va_mapping;
4040

41-
static efi_system_table_t *sys_table;
42-
43-
__pure efi_system_table_t *efi_system_table(void)
44-
{
45-
return sys_table;
46-
}
41+
const efi_system_table_t *efi_system_table;
4742

4843
static struct screen_info *setup_graphics(void)
4944
{
@@ -167,10 +162,10 @@ efi_status_t efi_entry(efi_handle_t handle, efi_system_table_t *sys_table_arg)
167162
efi_properties_table_t *prop_tbl;
168163
unsigned long max_addr;
169164

170-
sys_table = sys_table_arg;
165+
efi_system_table = sys_table_arg;
171166

172167
/* Check if we were booted by the EFI firmware */
173-
if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) {
168+
if (efi_system_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) {
174169
status = EFI_INVALID_PARAMETER;
175170
goto fail;
176171
}
@@ -184,7 +179,7 @@ efi_status_t efi_entry(efi_handle_t handle, efi_system_table_t *sys_table_arg)
184179
* information about the running image, such as size and the command
185180
* line.
186181
*/
187-
status = sys_table->boottime->handle_protocol(handle,
182+
status = efi_system_table->boottime->handle_protocol(handle,
188183
&loaded_image_proto, (void *)&image);
189184
if (status != EFI_SUCCESS) {
190185
pr_efi_err("Failed to get loaded image protocol\n");

drivers/firmware/efi/libstub/efistub.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ extern bool __pure noinitrd(void);
3131
extern bool __pure is_quiet(void);
3232
extern bool __pure novamap(void);
3333

34-
extern __pure efi_system_table_t *efi_system_table(void);
34+
extern const efi_system_table_t *efi_system_table;
3535

3636
#ifndef efi_bs_call
37-
#define efi_bs_call(func, ...) efi_system_table()->boottime->func(__VA_ARGS__)
37+
#define efi_bs_call(func, ...) efi_system_table->boottime->func(__VA_ARGS__)
3838
#endif
3939
#ifndef efi_rt_call
40-
#define efi_rt_call(func, ...) efi_system_table()->runtime->func(__VA_ARGS__)
40+
#define efi_rt_call(func, ...) efi_system_table->runtime->func(__VA_ARGS__)
4141
#endif
4242
#ifndef efi_is_native
4343
#define efi_is_native() (true)

drivers/firmware/efi/libstub/fdt.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static efi_status_t update_fdt(void *orig_fdt, unsigned long orig_fdt_size,
110110

111111
/* Add FDT entries for EFI runtime services in chosen node. */
112112
node = fdt_subnode_offset(fdt, 0, "chosen");
113-
fdt_val64 = cpu_to_fdt64((u64)(unsigned long)efi_system_table());
113+
fdt_val64 = cpu_to_fdt64((u64)(unsigned long)efi_system_table);
114114

115115
status = fdt_setprop_var(fdt, node, "linux,uefi-system-table", fdt_val64);
116116
if (status)
@@ -314,7 +314,7 @@ efi_status_t allocate_new_fdt_and_exit_boot(void *handle,
314314
return EFI_SUCCESS;
315315

316316
/* Install the new virtual address map */
317-
svam = efi_system_table()->runtime->set_virtual_address_map;
317+
svam = efi_system_table->runtime->set_virtual_address_map;
318318
status = svam(runtime_entry_count * desc_size, desc_size,
319319
desc_ver, runtime_map);
320320

@@ -348,7 +348,7 @@ efi_status_t allocate_new_fdt_and_exit_boot(void *handle,
348348
efi_free(MAX_FDT_SIZE, *new_fdt_addr);
349349

350350
fail:
351-
efi_system_table()->boottime->free_pool(runtime_map);
351+
efi_system_table->boottime->free_pool(runtime_map);
352352

353353
return EFI_LOAD_ERROR;
354354
}

drivers/firmware/efi/libstub/x86-stub.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,10 @@
2020
/* Maximum physical address for 64-bit kernel with 4-level paging */
2121
#define MAXMEM_X86_64_4LEVEL (1ull << 46)
2222

23-
static efi_system_table_t *sys_table;
23+
const efi_system_table_t *efi_system_table;
2424
extern const bool efi_is64;
2525
extern u32 image_offset;
2626

27-
__pure efi_system_table_t *efi_system_table(void)
28-
{
29-
return sys_table;
30-
}
31-
3227
__attribute_const__ bool efi_is_64bit(void)
3328
{
3429
if (IS_ENABLED(CONFIG_EFI_MIXED))
@@ -227,7 +222,7 @@ static const efi_char16_t apple[] = L"Apple";
227222
static void setup_quirks(struct boot_params *boot_params)
228223
{
229224
efi_char16_t *fw_vendor = (efi_char16_t *)(unsigned long)
230-
efi_table_attr(efi_system_table(), fw_vendor);
225+
efi_table_attr(efi_system_table, fw_vendor);
231226

232227
if (!memcmp(fw_vendor, apple, sizeof(apple))) {
233228
if (IS_ENABLED(CONFIG_APPLE_PROPERTIES))
@@ -377,10 +372,10 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
377372
unsigned long ramdisk_addr;
378373
unsigned long ramdisk_size;
379374

380-
sys_table = sys_table_arg;
375+
efi_system_table = sys_table_arg;
381376

382377
/* Check if we were booted by the EFI firmware */
383-
if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
378+
if (efi_system_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
384379
efi_exit(handle, EFI_INVALID_PARAMETER);
385380

386381
status = efi_bs_call(handle_protocol, handle, &proto, (void **)&image);
@@ -446,7 +441,7 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
446441
}
447442
}
448443

449-
efi_stub_entry(handle, sys_table, boot_params);
444+
efi_stub_entry(handle, sys_table_arg, boot_params);
450445
/* not reached */
451446

452447
fail2:
@@ -651,14 +646,14 @@ static efi_status_t exit_boot_func(struct efi_boot_memmap *map,
651646
: EFI32_LOADER_SIGNATURE;
652647
memcpy(&p->efi->efi_loader_signature, signature, sizeof(__u32));
653648

654-
p->efi->efi_systab = (unsigned long)efi_system_table();
649+
p->efi->efi_systab = (unsigned long)efi_system_table;
655650
p->efi->efi_memdesc_size = *map->desc_size;
656651
p->efi->efi_memdesc_version = *map->desc_ver;
657652
p->efi->efi_memmap = (unsigned long)*map->map;
658653
p->efi->efi_memmap_size = *map->map_size;
659654

660655
#ifdef CONFIG_X86_64
661-
p->efi->efi_systab_hi = (unsigned long)efi_system_table() >> 32;
656+
p->efi->efi_systab_hi = (unsigned long)efi_system_table >> 32;
662657
p->efi->efi_memmap_hi = (unsigned long)*map->map >> 32;
663658
#endif
664659

@@ -719,10 +714,10 @@ unsigned long efi_main(efi_handle_t handle,
719714
efi_status_t status;
720715
unsigned long cmdline_paddr;
721716

722-
sys_table = sys_table_arg;
717+
efi_system_table = sys_table_arg;
723718

724719
/* Check if we were booted by the EFI firmware */
725-
if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
720+
if (efi_system_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
726721
efi_exit(handle, EFI_INVALID_PARAMETER);
727722

728723
/*

0 commit comments

Comments
 (0)