public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ardb@kernel.org>
To: linux-efi@vger.kernel.org, Ingo Molnar <mingo@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>
Cc: Ard Biesheuvel <ardb@kernel.org>,
	linux-kernel@vger.kernel.org,
	Arvind Sankar <nivedita@alum.mit.edu>
Subject: [PATCH 14/25] efi/libstub: avoid protocol wrapper for file I/O routines
Date: Tue, 24 Dec 2019 16:10:14 +0100	[thread overview]
Message-ID: <20191224151025.32482-15-ardb@kernel.org> (raw)
In-Reply-To: <20191224151025.32482-1-ardb@kernel.org>

The EFI file I/O routines built on top of the file I/O firmware
services are incompatible with mixed mode, so there is no need
to obfuscate them by using protocol wrappers whose only purpose
is to hide the mixed mode handling. So let's switch to plain
indirect calls instead.

This also means we can drop the mixed_mode aliases from the various
types involved.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 .../firmware/efi/libstub/efi-stub-helper.c    |  17 ++-
 include/linux/efi.h                           | 118 ++++++------------
 2 files changed, 46 insertions(+), 89 deletions(-)

diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c
index f91f4fdbe553..9bb74ad4b7fe 100644
--- a/drivers/firmware/efi/libstub/efi-stub-helper.c
+++ b/drivers/firmware/efi/libstub/efi-stub-helper.c
@@ -370,8 +370,7 @@ static efi_status_t efi_file_size(efi_system_table_t *sys_table_arg, void *__fh,
 	efi_guid_t info_guid = EFI_FILE_INFO_ID;
 	unsigned long info_sz;
 
-	status = efi_call_proto(efi_file_handle, open, fh, &h, filename_16,
-				EFI_FILE_MODE_READ, (u64)0);
+	status = fh->open(fh, &h, filename_16, EFI_FILE_MODE_READ, 0);
 	if (status != EFI_SUCCESS) {
 		efi_printk(sys_table_arg, "Failed to open file: ");
 		efi_char16_printk(sys_table_arg, filename_16);
@@ -382,8 +381,7 @@ static efi_status_t efi_file_size(efi_system_table_t *sys_table_arg, void *__fh,
 	*handle = h;
 
 	info_sz = 0;
-	status = efi_call_proto(efi_file_handle, get_info, h, &info_guid,
-				&info_sz, NULL);
+	status = h->get_info(h, &info_guid, &info_sz, NULL);
 	if (status != EFI_BUFFER_TOO_SMALL) {
 		efi_printk(sys_table_arg, "Failed to get file info size\n");
 		return status;
@@ -397,8 +395,7 @@ static efi_status_t efi_file_size(efi_system_table_t *sys_table_arg, void *__fh,
 		return status;
 	}
 
-	status = efi_call_proto(efi_file_handle, get_info, h, &info_guid,
-				&info_sz, info);
+	status = h->get_info(h, &info_guid, &info_sz, info);
 	if (status == EFI_BUFFER_TOO_SMALL) {
 		efi_call_early(free_pool, info);
 		goto grow;
@@ -416,12 +413,12 @@ static efi_status_t efi_file_size(efi_system_table_t *sys_table_arg, void *__fh,
 static efi_status_t efi_file_read(efi_file_handle_t *handle,
 				  unsigned long *size, void *addr)
 {
-	return efi_call_proto(efi_file_handle, read, handle, size, addr);
+	return handle->read(handle, size, addr);
 }
 
 static efi_status_t efi_file_close(efi_file_handle_t *handle)
 {
-	return efi_call_proto(efi_file_handle, close, handle);
+	return handle->close(handle);
 }
 
 static efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg,
@@ -432,7 +429,7 @@ static efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg,
 	efi_file_handle_t *fh;
 	efi_guid_t fs_proto = EFI_FILE_SYSTEM_GUID;
 	efi_status_t status;
-	void *handle = efi_table_attr(efi_loaded_image, device_handle, image);
+	efi_handle_t handle = image->device_handle;
 
 	status = efi_call_early(handle_protocol, handle,
 				&fs_proto, (void **)&io);
@@ -441,7 +438,7 @@ static efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg,
 		return status;
 	}
 
-	status = efi_call_proto(efi_file_io_interface, open_volume, io, &fh);
+	status = io->open_volume(io, &fh);
 	if (status != EFI_SUCCESS)
 		efi_printk(sys_table_arg, "Failed to open volume\n");
 	else
diff --git a/include/linux/efi.h b/include/linux/efi.h
index 2074b737aa17..14dd08ecf8a7 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -806,40 +806,21 @@ struct efi_fdt_params {
 	u32 desc_ver;
 };
 
-typedef union efi_loaded_image efi_loaded_image_t;
-
-union efi_loaded_image {
-	struct {
-		u32 revision;
-		efi_handle_t parent_handle;
-		efi_system_table_t *system_table;
-		efi_handle_t device_handle;
-		void *file_path;
-		void *reserved;
-		u32 load_options_size;
-		void *load_options;
-		void *image_base;
-		__aligned_u64 image_size;
-		unsigned int image_code_type;
-		unsigned int image_data_type;
-		efi_status_t ( __efiapi *unload)(efi_handle_t image_handle);
-	};
-	struct {
-		u32 revision;
-		u32 parent_handle;
-		u32 system_table;
-		u32 device_handle;
-		u32 file_path;
-		u32 reserved;
-		u32 load_options_size;
-		u32 load_options;
-		u32 image_base;
-		__aligned_u64 image_size;
-		unsigned int image_code_type;
-		unsigned int image_data_type;
-		u32 unload;
-	} mixed_mode;
-};
+typedef struct {
+	u32 revision;
+	efi_handle_t parent_handle;
+	efi_system_table_t *system_table;
+	efi_handle_t device_handle;
+	void *file_path;
+	void *reserved;
+	u32 load_options_size;
+	void *load_options;
+	void *image_base;
+	__aligned_u64 image_size;
+	unsigned int image_code_type;
+	unsigned int image_data_type;
+	efi_status_t ( __efiapi *unload)(efi_handle_t image_handle);
+} efi_loaded_image_t;
 
 typedef struct {
 	u64 size;
@@ -852,54 +833,33 @@ typedef struct {
 	efi_char16_t filename[1];
 } efi_file_info_t;
 
-typedef union efi_file_handle efi_file_handle_t;
-
-union efi_file_handle {
-	struct {
-		u64 revision;
-		efi_status_t (__efiapi *open)(efi_file_handle_t *,
-					      efi_file_handle_t **,
-					      efi_char16_t *, u64, u64);
-		efi_status_t (__efiapi *close)(efi_file_handle_t *);
-		void *delete;
-		efi_status_t (__efiapi *read)(efi_file_handle_t *,
-					      unsigned long *, void *);
-		void *write;
-		void *get_position;
-		void *set_position;
-		efi_status_t (__efiapi *get_info)(efi_file_handle_t *,
-						  efi_guid_t *, unsigned long *,
-						  void *);
-		void *set_info;
-		void *flush;
-	};
-	struct {
-		u64 revision;
-		u32 open;
-		u32 close;
-		u32 delete;
-		u32 read;
-		u32 write;
-		u32 get_position;
-		u32 set_position;
-		u32 get_info;
-		u32 set_info;
-		u32 flush;
-	} mixed_mode;
+typedef struct efi_file_handle efi_file_handle_t;
+
+struct efi_file_handle {
+	u64 revision;
+	efi_status_t (__efiapi *open)(efi_file_handle_t *,
+				      efi_file_handle_t **,
+				      efi_char16_t *, u64, u64);
+	efi_status_t (__efiapi *close)(efi_file_handle_t *);
+	void *delete;
+	efi_status_t (__efiapi *read)(efi_file_handle_t *,
+				      unsigned long *, void *);
+	void *write;
+	void *get_position;
+	void *set_position;
+	efi_status_t (__efiapi *get_info)(efi_file_handle_t *,
+					  efi_guid_t *, unsigned long *,
+					  void *);
+	void *set_info;
+	void *flush;
 };
 
-typedef union efi_file_io_interface efi_file_io_interface_t;
+typedef struct efi_file_io_interface efi_file_io_interface_t;
 
-union efi_file_io_interface {
-	struct {
-		u64 revision;
-		int (__efiapi *open_volume)(efi_file_io_interface_t *,
-					    efi_file_handle_t **);
-	};
-	struct {
-		u64 revision;
-		u32 open_volume;
-	} mixed_mode;
+struct efi_file_io_interface {
+	u64 revision;
+	int (__efiapi *open_volume)(efi_file_io_interface_t *,
+				    efi_file_handle_t **);
 };
 
 #define EFI_FILE_MODE_READ	0x0000000000000001
-- 
2.20.1


  parent reply	other threads:[~2019-12-24 15:11 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-24 15:10 [GIT PULL 00/25] EFI updates for v5.6 Ard Biesheuvel
2019-12-24 15:10 ` [PATCH 01/25] efi/gop: Remove bogus packed attribute from GOP structures Ard Biesheuvel
2019-12-24 15:10 ` [PATCH 02/25] efi/gop: Remove unused typedef Ard Biesheuvel
2019-12-24 15:10 ` [PATCH 03/25] efi/gop: Convert GOP structures to typedef and cleanup some types Ard Biesheuvel
2019-12-24 15:10 ` [PATCH 04/25] efi/gop: Unify 32/64-bit functions Ard Biesheuvel
2019-12-24 15:10 ` [PATCH 05/25] efi/libstub: remove unused __efi_call_early() macro Ard Biesheuvel
2019-12-24 15:10 ` [PATCH 06/25] efi/x86: rename efi_is_native() to efi_is_mixed() Ard Biesheuvel
2019-12-24 15:10 ` [PATCH 07/25] efi/libstub: use a helper to iterate over a EFI handle array Ard Biesheuvel
2019-12-24 15:10 ` [PATCH 08/25] efi/libstub: extend native protocol definitions with mixed_mode aliases Ard Biesheuvel
2019-12-24 15:10 ` [PATCH 09/25] efi/libstub: distinguish between native/mixed not 32/64 bit Ard Biesheuvel
2019-12-24 15:10 ` [PATCH 10/25] efi/libstub: drop explicit 32/64-bit protocol definitions Ard Biesheuvel
2019-12-24 15:10 ` [PATCH 11/25] efi/libstub: use stricter typing for firmware function pointers Ard Biesheuvel
2019-12-24 15:10 ` [PATCH 12/25] efi/libstub: annotate firmware routines as __efiapi Ard Biesheuvel
2019-12-24 15:10 ` [PATCH 13/25] efi/libstub/x86: avoid thunking for native firmware calls Ard Biesheuvel
2019-12-24 15:10 ` Ard Biesheuvel [this message]
2019-12-24 15:10 ` [PATCH 15/25] efi/libstub: get rid of 'sys_table_arg' macro parameter Ard Biesheuvel
2019-12-24 15:10 ` [PATCH 16/25] efi/libstub: unify the efi_char16_printk implementations Ard Biesheuvel
2019-12-24 15:10 ` [PATCH 17/25] efi/libstub/x86: drop __efi_early() export and efi_config struct Ard Biesheuvel
2019-12-24 15:10 ` [PATCH 18/25] efi/libstub: drop sys_table_arg from printk routines Ard Biesheuvel
2019-12-24 15:10 ` [PATCH 19/25] efi/libstub: remove 'sys_table_arg' from all function prototypes Ard Biesheuvel
2019-12-24 15:10 ` [PATCH 20/25] efi/libstub/x86: work around page freeing issue in mixed mode Ard Biesheuvel
2019-12-24 15:10 ` [PATCH 21/25] efi/libstub: drop protocol argument from efi_call_proto() macro Ard Biesheuvel
2019-12-24 15:10 ` [PATCH 22/25] efi/libstub: drop 'table' argument from efi_table_attr() macro Ard Biesheuvel
2019-12-24 15:10 ` [PATCH 23/25] efi/libstub: rename efi_call_early/_runtime macros to be more intuitive Ard Biesheuvel
2019-12-24 15:10 ` [PATCH 24/25] efi/libstub: tidy up types and names of global cmdline variables Ard Biesheuvel
2019-12-24 15:10 ` [PATCH 25/25] efi/libstub/x86: avoid globals to store context during mixed mode calls Ard Biesheuvel
2019-12-25  9:50 ` [GIT PULL 00/25] EFI updates for v5.6 Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191224151025.32482-15-ardb@kernel.org \
    --to=ardb@kernel.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=nivedita@alum.mit.edu \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox