public inbox for linux-efi@vger.kernel.org
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ardb@kernel.org>
To: linux-efi@vger.kernel.org
Cc: linux-acpi@vger.kernel.org, rafael@kernel.org, lenb@kernel.org,
	Ard Biesheuvel <ardb@kernel.org>
Subject: [PATCH 3/4] efi/runtime-wrappers: Remove duplicated macro for service returning void
Date: Fri,  4 Aug 2023 18:03:58 +0200	[thread overview]
Message-ID: <20230804160359.228901-4-ardb@kernel.org> (raw)
In-Reply-To: <20230804160359.228901-1-ardb@kernel.org>

__efi_call_virt() exists as an alternative for efi_call_virt() for the
sole reason that ResetSystem() returns void, and so we cannot use a call
to it in the RHS of an assignment.

Now that we support the use of _Generic, this is no longer needed, and
we can handle this by emitting a comma expression inside the default
branch of a _Generic() switch.

As a bonus, this ensures that the runtime service call is always
constructed and type checked by the compiler, as it is passed to
_Generic() to infer the return type. (both x86 and arm64 override
arch_efi_call_virt() to invoke a type unsafe variadic wrapper function
implemented in assembler)

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 drivers/firmware/efi/runtime-wrappers.c |  4 +---
 include/linux/efi.h                     | 24 ++++----------------
 2 files changed, 6 insertions(+), 22 deletions(-)

diff --git a/drivers/firmware/efi/runtime-wrappers.c b/drivers/firmware/efi/runtime-wrappers.c
index 158685e26f430ac9..b3ef208299ae591e 100644
--- a/drivers/firmware/efi/runtime-wrappers.c
+++ b/drivers/firmware/efi/runtime-wrappers.c
@@ -41,8 +41,6 @@
  */
 #define efi_call_virt(f, args...)   \
 	efi_call_virt_pointer(efi.runtime, f, args)
-#define __efi_call_virt(f, args...) \
-	__efi_call_virt_pointer(efi.runtime, f, args)
 
 struct efi_runtime_work efi_rts_work;
 
@@ -422,7 +420,7 @@ static void virt_efi_reset_system(int reset_type,
 		return;
 	}
 	efi_rts_work.efi_rts_id = EFI_RESET_SYSTEM;
-	__efi_call_virt(reset_system, reset_type, status, data_size, data);
+	efi_call_virt(reset_system, reset_type, status, data_size, data);
 	up(&efi_runtime_lock);
 }
 
diff --git a/include/linux/efi.h b/include/linux/efi.h
index b34e11a5e969282c..c72715821016851b 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -1171,8 +1171,7 @@ static inline void efi_check_for_embedded_firmwares(void) { }
 #define arch_efi_call_virt(p, f, args...)	((p)->f(args))
 
 /*
- * Arch code can implement the following three template macros, avoiding
- * reptition for the void/non-void return cases of {__,}efi_call_virt():
+ * Arch code must implement the following three template macros:
  *
  *  * arch_efi_call_virt_setup()
  *
@@ -1181,9 +1180,7 @@ static inline void efi_check_for_embedded_firmwares(void) { }
  *
  *  * arch_efi_call_virt()
  *
- *    Performs the call. The last expression in the macro must be the call
- *    itself, allowing the logic to be shared by the void and non-void
- *    cases.
+ *    Performs the call.
  *
  *  * arch_efi_call_virt_teardown()
  *
@@ -1198,7 +1195,9 @@ static inline void efi_check_for_embedded_firmwares(void) { }
 	arch_efi_call_virt_setup();					\
 									\
 	__flags = efi_call_virt_save_flags();				\
-	__s = arch_efi_call_virt(p, f, args);				\
+	__s = _Generic((p)->f(args),					\
+	       efi_status_t: arch_efi_call_virt((p), f, args),		\
+	       default: (arch_efi_call_virt((p), f, args), EFI_ABORTED));\
 	efi_call_virt_check_flags(__flags, __stringify(f));		\
 									\
 	arch_efi_call_virt_teardown();					\
@@ -1206,19 +1205,6 @@ static inline void efi_check_for_embedded_firmwares(void) { }
 	__s;								\
 })
 
-#define __efi_call_virt_pointer(p, f, args...)				\
-({									\
-	unsigned long __flags;						\
-									\
-	arch_efi_call_virt_setup();					\
-									\
-	__flags = efi_call_virt_save_flags();				\
-	arch_efi_call_virt(p, f, args);					\
-	efi_call_virt_check_flags(__flags, __stringify(f));		\
-									\
-	arch_efi_call_virt_teardown();					\
-})
-
 #define EFI_RANDOM_SEED_SIZE		32U // BLAKE2S_HASH_SIZE
 
 struct linux_efi_random_seed {
-- 
2.39.2


  parent reply	other threads:[~2023-08-04 16:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-04 16:03 [PATCH 0/4] efi: Clean up runtime wrapper and wire it up for PRM Ard Biesheuvel
2023-08-04 16:03 ` [PATCH 1/4] efi/runtime-wrappers: Use type safe encapsulation of call arguments Ard Biesheuvel
2023-08-04 16:03 ` [PATCH 2/4] efi/runtime-wrapper: Move workqueue manipulation out of line Ard Biesheuvel
2023-08-04 16:03 ` Ard Biesheuvel [this message]
2023-08-04 16:03 ` [PATCH 4/4] acpi/prmt: Use EFI runtime sandbox to invoke PRM handlers Ard Biesheuvel
2023-08-17 17:55   ` Rafael J. Wysocki

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=20230804160359.228901-4-ardb@kernel.org \
    --to=ardb@kernel.org \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=rafael@kernel.org \
    /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