Commit cd33a5c1 authored by Ard Biesheuvel's avatar Ard Biesheuvel Committed by Ingo Molnar
Browse files

efi/libstub: Remove 'sys_table_arg' from all function prototypes



We have a helper efi_system_table() that gives us the address of the
EFI system table in memory, so there is no longer point in passing
it around from each function to the next.

Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
Cc: Arvind Sankar <nivedita@alum.mit.edu>
Cc: Borislav Petkov <bp@alien8.de>
Cc: James Morse <james.morse@arm.com>
Cc: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-efi@vger.kernel.org
Link: https://lkml.kernel.org/r/20191224151025.32482-20-ardb@kernel.org


Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 8173ec79
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -60,8 +60,8 @@ void efi_virtmap_unload(void);
#define efi_call_proto(protocol, f, instance, ...)			\
	instance->f(instance, ##__VA_ARGS__)

struct screen_info *alloc_screen_info(efi_system_table_t *sys_table_arg);
void free_screen_info(efi_system_table_t *sys_table, struct screen_info *si);
struct screen_info *alloc_screen_info(void);
void free_screen_info(struct screen_info *si);

static inline void efifb_setup_from_dmi(struct screen_info *si, const char *opt)
{
+1 −2
Original line number Diff line number Diff line
@@ -105,8 +105,7 @@ static inline unsigned long efi_get_max_initrd_addr(unsigned long dram_base,

#define alloc_screen_info(x...)		&screen_info

static inline void free_screen_info(efi_system_table_t *sys_table_arg,
				    struct screen_info *si)
static inline void free_screen_info(struct screen_info *si)
{
}

+18 −22
Original line number Diff line number Diff line
@@ -340,7 +340,7 @@ void setup_graphics(struct boot_params *boot_params)
				EFI_LOCATE_BY_PROTOCOL,
				&graphics_proto, NULL, &size, gop_handle);
	if (status == EFI_BUFFER_TOO_SMALL)
		status = efi_setup_gop(NULL, si, &graphics_proto, size);
		status = efi_setup_gop(si, &graphics_proto, size);

	if (status != EFI_SUCCESS) {
		size = 0;
@@ -390,8 +390,7 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
		return status;
	}

	status = efi_low_alloc(sys_table, 0x4000, 1,
			       (unsigned long *)&boot_params);
	status = efi_low_alloc(0x4000, 1, (unsigned long *)&boot_params);
	if (status != EFI_SUCCESS) {
		efi_printk("Failed to allocate lowmem for boot params\n");
		return status;
@@ -416,7 +415,7 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
	hdr->type_of_loader = 0x21;

	/* Convert unicode cmdline to ascii */
	cmdline_ptr = efi_convert_cmdline(sys_table, image, &options_size);
	cmdline_ptr = efi_convert_cmdline(image, &options_size);
	if (!cmdline_ptr)
		goto fail;

@@ -434,7 +433,7 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
	if (status != EFI_SUCCESS)
		goto fail2;

	status = handle_cmdline_files(sys_table, image,
	status = handle_cmdline_files(image,
				      (char *)(unsigned long)hdr->cmd_line_ptr,
				      "initrd=", hdr->initrd_addr_max,
				      &ramdisk_addr, &ramdisk_size);
@@ -442,7 +441,7 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
	if (status != EFI_SUCCESS &&
	    hdr->xloadflags & XLF_CAN_BE_LOADED_ABOVE_4G) {
		efi_printk("Trying to load files to higher address\n");
		status = handle_cmdline_files(sys_table, image,
		status = handle_cmdline_files(image,
				      (char *)(unsigned long)hdr->cmd_line_ptr,
				      "initrd=", -1UL,
				      &ramdisk_addr, &ramdisk_size);
@@ -461,9 +460,9 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
	/* not reached */

fail2:
	efi_free(sys_table, options_size, hdr->cmd_line_ptr);
	efi_free(options_size, hdr->cmd_line_ptr);
fail:
	efi_free(sys_table, 0x4000, (unsigned long)boot_params);
	efi_free(0x4000, (unsigned long)boot_params);

	return status;
}
@@ -630,7 +629,7 @@ static efi_status_t allocate_e820(struct boot_params *params,
	boot_map.key_ptr	= NULL;
	boot_map.buff_size	= &buff_size;

	status = efi_get_memory_map(sys_table, &boot_map);
	status = efi_get_memory_map(&boot_map);
	if (status != EFI_SUCCESS)
		return status;

@@ -652,8 +651,7 @@ struct exit_boot_struct {
	struct efi_info		*efi;
};

static efi_status_t exit_boot_func(efi_system_table_t *sys_table_arg,
				   struct efi_boot_memmap *map,
static efi_status_t exit_boot_func(struct efi_boot_memmap *map,
				   void *priv)
{
	const char *signature;
@@ -663,14 +661,14 @@ static efi_status_t exit_boot_func(efi_system_table_t *sys_table_arg,
				   : EFI32_LOADER_SIGNATURE;
	memcpy(&p->efi->efi_loader_signature, signature, sizeof(__u32));

	p->efi->efi_systab		= (unsigned long)sys_table_arg;
	p->efi->efi_systab		= (unsigned long)efi_system_table();
	p->efi->efi_memdesc_size	= *map->desc_size;
	p->efi->efi_memdesc_version	= *map->desc_ver;
	p->efi->efi_memmap		= (unsigned long)*map->map;
	p->efi->efi_memmap_size		= *map->map_size;

#ifdef CONFIG_X86_64
	p->efi->efi_systab_hi		= (unsigned long)sys_table_arg >> 32;
	p->efi->efi_systab_hi		= (unsigned long)efi_system_table() >> 32;
	p->efi->efi_memmap_hi		= (unsigned long)*map->map >> 32;
#endif

@@ -702,8 +700,7 @@ static efi_status_t exit_boot(struct boot_params *boot_params, void *handle)
		return status;

	/* Might as well exit boot services now */
	status = efi_exit_boot_services(sys_table, handle, &map, &priv,
					exit_boot_func);
	status = efi_exit_boot_services(handle, &map, &priv, exit_boot_func);
	if (status != EFI_SUCCESS)
		return status;

@@ -755,14 +752,14 @@ struct boot_params *efi_main(efi_handle_t handle,
	 * otherwise we ask the BIOS.
	 */
	if (boot_params->secure_boot == efi_secureboot_mode_unset)
		boot_params->secure_boot = efi_get_secureboot(sys_table);
		boot_params->secure_boot = efi_get_secureboot();

	/* Ask the firmware to clear memory on unclean shutdown */
	efi_enable_reset_attack_mitigation(sys_table);
	efi_enable_reset_attack_mitigation();

	efi_random_get_seed(sys_table);
	efi_random_get_seed();

	efi_retrieve_tpm2_eventlog(sys_table);
	efi_retrieve_tpm2_eventlog();

	setup_graphics(boot_params);

@@ -778,8 +775,7 @@ struct boot_params *efi_main(efi_handle_t handle,
	}

	gdt->size = 0x800;
	status = efi_low_alloc(sys_table, gdt->size, 8,
			   (unsigned long *)&gdt->address);
	status = efi_low_alloc(gdt->size, 8, (unsigned long *)&gdt->address);
	if (status != EFI_SUCCESS) {
		efi_printk("Failed to allocate memory for 'gdt'\n");
		goto fail;
@@ -791,7 +787,7 @@ struct boot_params *efi_main(efi_handle_t handle,
	 */
	if (hdr->pref_address != hdr->code32_start) {
		unsigned long bzimage_addr = hdr->code32_start;
		status = efi_relocate_kernel(sys_table, &bzimage_addr,
		status = efi_relocate_kernel(&bzimage_addr,
					     hdr->init_size, hdr->init_size,
					     hdr->pref_address,
					     hdr->kernel_alignment,
+26 −29
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ __pure efi_system_table_t *efi_system_table(void)
	return sys_table;
}

static struct screen_info *setup_graphics(efi_system_table_t *sys_table_arg)
static struct screen_info *setup_graphics(void)
{
	efi_guid_t gop_proto = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
	efi_status_t status;
@@ -56,15 +56,15 @@ static struct screen_info *setup_graphics(efi_system_table_t *sys_table_arg)
	status = efi_call_early(locate_handle, EFI_LOCATE_BY_PROTOCOL,
				&gop_proto, NULL, &size, gop_handle);
	if (status == EFI_BUFFER_TOO_SMALL) {
		si = alloc_screen_info(sys_table_arg);
		si = alloc_screen_info();
		if (!si)
			return NULL;
		efi_setup_gop(sys_table_arg, si, &gop_proto, size);
		efi_setup_gop(si, &gop_proto, size);
	}
	return si;
}

void install_memreserve_table(efi_system_table_t *sys_table_arg)
void install_memreserve_table(void)
{
	struct linux_efi_memreserve *rsv;
	efi_guid_t memreserve_table_guid = LINUX_EFI_MEMRESERVE_TABLE_GUID;
@@ -95,8 +95,7 @@ void install_memreserve_table(efi_system_table_t *sys_table_arg)
 * must be reserved. On failure it is required to free all
 * all allocations it has made.
 */
efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
				 unsigned long *image_addr,
efi_status_t handle_kernel_image(unsigned long *image_addr,
				 unsigned long *image_size,
				 unsigned long *reserve_addr,
				 unsigned long *reserve_size,
@@ -135,7 +134,7 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table_arg,
	if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
		goto fail;

	status = check_platform_features(sys_table);
	status = check_platform_features();
	if (status != EFI_SUCCESS)
		goto fail;

@@ -151,7 +150,7 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table_arg,
		goto fail;
	}

	dram_base = get_dram_base(sys_table);
	dram_base = get_dram_base();
	if (dram_base == EFI_ERROR) {
		pr_efi_err("Failed to find DRAM base\n");
		goto fail;
@@ -162,7 +161,7 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table_arg,
	 * protocol. We are going to copy the command line into the
	 * device tree, so this can be allocated anywhere.
	 */
	cmdline_ptr = efi_convert_cmdline(sys_table, image, &cmdline_size);
	cmdline_ptr = efi_convert_cmdline(image, &cmdline_size);
	if (!cmdline_ptr) {
		pr_efi_err("getting command line via LOADED_IMAGE_PROTOCOL\n");
		goto fail;
@@ -178,9 +177,9 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table_arg,

	pr_efi("Booting Linux Kernel...\n");

	si = setup_graphics(sys_table);
	si = setup_graphics();

	status = handle_kernel_image(sys_table, image_addr, &image_size,
	status = handle_kernel_image(image_addr, &image_size,
				     &reserve_addr,
				     &reserve_size,
				     dram_base, image);
@@ -189,12 +188,12 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table_arg,
		goto fail_free_cmdline;
	}

	efi_retrieve_tpm2_eventlog(sys_table);
	efi_retrieve_tpm2_eventlog();

	/* Ask the firmware to clear memory on unclean shutdown */
	efi_enable_reset_attack_mitigation(sys_table);
	efi_enable_reset_attack_mitigation();

	secure_boot = efi_get_secureboot(sys_table);
	secure_boot = efi_get_secureboot();

	/*
	 * Unauthenticated device tree data is a security hazard, so ignore
@@ -206,8 +205,7 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table_arg,
		if (strstr(cmdline_ptr, "dtb="))
			pr_efi("Ignoring DTB from command line.\n");
	} else {
		status = handle_cmdline_files(sys_table, image, cmdline_ptr,
					      "dtb=",
		status = handle_cmdline_files(image, cmdline_ptr, "dtb=",
					      ~0UL, &fdt_addr, &fdt_size);

		if (status != EFI_SUCCESS) {
@@ -220,7 +218,7 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table_arg,
		pr_efi("Using DTB from command line\n");
	} else {
		/* Look for a device tree configuration table entry. */
		fdt_addr = (uintptr_t)get_fdt(sys_table, &fdt_size);
		fdt_addr = (uintptr_t)get_fdt(&fdt_size);
		if (fdt_addr)
			pr_efi("Using DTB from configuration table\n");
	}
@@ -228,7 +226,7 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table_arg,
	if (!fdt_addr)
		pr_efi("Generating empty DTB\n");

	status = handle_cmdline_files(sys_table, image, cmdline_ptr, "initrd=",
	status = handle_cmdline_files(image, cmdline_ptr, "initrd=",
				      efi_get_max_initrd_addr(dram_base,
							      *image_addr),
				      (unsigned long *)&initrd_addr,
@@ -236,7 +234,7 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table_arg,
	if (status != EFI_SUCCESS)
		pr_efi_err("Failed initrd from command line!\n");

	efi_random_get_seed(sys_table);
	efi_random_get_seed();

	/* hibernation expects the runtime regions to stay in the same place */
	if (!IS_ENABLED(CONFIG_HIBERNATION) && !nokaslr()) {
@@ -251,18 +249,17 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table_arg,
					    EFI_RT_VIRTUAL_SIZE;
		u32 rnd;

		status = efi_get_random_bytes(sys_table, sizeof(rnd),
					      (u8 *)&rnd);
		status = efi_get_random_bytes(sizeof(rnd), (u8 *)&rnd);
		if (status == EFI_SUCCESS) {
			virtmap_base = EFI_RT_VIRTUAL_BASE +
				       (((headroom >> 21) * rnd) >> (32 - 21));
		}
	}

	install_memreserve_table(sys_table);
	install_memreserve_table();

	new_fdt_addr = fdt_addr;
	status = allocate_new_fdt_and_exit_boot(sys_table, handle,
	status = allocate_new_fdt_and_exit_boot(handle,
				&new_fdt_addr, efi_get_max_fdt_addr(dram_base),
				initrd_addr, initrd_size, cmdline_ptr,
				fdt_addr, fdt_size);
@@ -277,15 +274,15 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table_arg,

	pr_efi_err("Failed to update FDT and exit boot services\n");

	efi_free(sys_table, initrd_size, initrd_addr);
	efi_free(sys_table, fdt_size, fdt_addr);
	efi_free(initrd_size, initrd_addr);
	efi_free(fdt_size, fdt_addr);

fail_free_image:
	efi_free(sys_table, image_size, *image_addr);
	efi_free(sys_table, reserve_size, reserve_addr);
	efi_free(image_size, *image_addr);
	efi_free(reserve_size, reserve_addr);
fail_free_cmdline:
	free_screen_info(sys_table, si);
	efi_free(sys_table, cmdline_size, (unsigned long)cmdline_ptr);
	free_screen_info(si);
	efi_free(cmdline_size, (unsigned long)cmdline_ptr);
fail:
	return EFI_ERROR;
}
+11 −15
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@

#include "efistub.h"

efi_status_t check_platform_features(efi_system_table_t *sys_table_arg)
efi_status_t check_platform_features(void)
{
	int block;

@@ -26,7 +26,7 @@ efi_status_t check_platform_features(efi_system_table_t *sys_table_arg)

static efi_guid_t screen_info_guid = LINUX_EFI_ARM_SCREEN_INFO_TABLE_GUID;

struct screen_info *alloc_screen_info(efi_system_table_t *sys_table_arg)
struct screen_info *alloc_screen_info(void)
{
	struct screen_info *si;
	efi_status_t status;
@@ -52,7 +52,7 @@ struct screen_info *alloc_screen_info(efi_system_table_t *sys_table_arg)
	return NULL;
}

void free_screen_info(efi_system_table_t *sys_table_arg, struct screen_info *si)
void free_screen_info(struct screen_info *si)
{
	if (!si)
		return;
@@ -61,8 +61,7 @@ void free_screen_info(efi_system_table_t *sys_table_arg, struct screen_info *si)
	efi_call_early(free_pool, si);
}

static efi_status_t reserve_kernel_base(efi_system_table_t *sys_table_arg,
					unsigned long dram_base,
static efi_status_t reserve_kernel_base(unsigned long dram_base,
					unsigned long *reserve_addr,
					unsigned long *reserve_size)
{
@@ -119,7 +118,7 @@ static efi_status_t reserve_kernel_base(efi_system_table_t *sys_table_arg,
	 * released to the OS after ExitBootServices(), the decompressor can
	 * safely overwrite them.
	 */
	status = efi_get_memory_map(sys_table_arg, &map);
	status = efi_get_memory_map(&map);
	if (status != EFI_SUCCESS) {
		pr_efi_err("reserve_kernel_base(): Unable to retrieve memory map.\n");
		return status;
@@ -190,8 +189,7 @@ out:
	return status;
}

efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
				 unsigned long *image_addr,
efi_status_t handle_kernel_image(unsigned long *image_addr,
				 unsigned long *image_size,
				 unsigned long *reserve_addr,
				 unsigned long *reserve_size,
@@ -219,8 +217,7 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
	 */
	kernel_base += TEXT_OFFSET - 5 * PAGE_SIZE;

	status = reserve_kernel_base(sys_table, kernel_base, reserve_addr,
				     reserve_size);
	status = reserve_kernel_base(kernel_base, reserve_addr, reserve_size);
	if (status != EFI_SUCCESS) {
		pr_efi_err("Unable to allocate memory for uncompressed kernel.\n");
		return status;
@@ -231,12 +228,11 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
	 * memory window.
	 */
	*image_size = image->image_size;
	status = efi_relocate_kernel(sys_table, image_addr, *image_size,
				     *image_size,
	status = efi_relocate_kernel(image_addr, *image_size, *image_size,
				     kernel_base + MAX_UNCOMP_KERNEL_SIZE, 0, 0);
	if (status != EFI_SUCCESS) {
		pr_efi_err("Failed to relocate kernel.\n");
		efi_free(sys_table, *reserve_size, *reserve_addr);
		efi_free(*reserve_size, *reserve_addr);
		*reserve_size = 0;
		return status;
	}
@@ -248,9 +244,9 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
	 */
	if (*image_addr + *image_size > dram_base + ZIMAGE_OFFSET_LIMIT) {
		pr_efi_err("Failed to relocate kernel, no low memory available.\n");
		efi_free(sys_table, *reserve_size, *reserve_addr);
		efi_free(*reserve_size, *reserve_addr);
		*reserve_size = 0;
		efi_free(sys_table, *image_size, *image_addr);
		efi_free(*image_size, *image_addr);
		*image_size = 0;
		return EFI_LOAD_ERROR;
	}
Loading