mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>,
	Chali Anis <chalianis1@gmail.com>
Subject: [PATCH 1/2] efi: payload: image: exit if kernel image returned
Date: Tue, 14 Apr 2026 16:26:29 +0200	[thread overview]
Message-ID: <20260414142634.744542-1-a.fatoum@pengutronix.de> (raw)

EFI applications can exit and return to the EFI application that started
them and barebox can handle that, except for the case that it was a
EFI-stubbed kernel and barebox has already called shutdown_barebox().

In that case, the safest way is to just propagate the exit code instead
of attempting to execute code as if nothing happened.

Starting EFI applications via bin format continues to work as before.

Cc: Chali Anis <chalianis1@gmail.com>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 efi/payload/image.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/efi/payload/image.c b/efi/payload/image.c
index 83094cda6d89..378709b6de95 100644
--- a/efi/payload/image.c
+++ b/efi/payload/image.c
@@ -104,7 +104,7 @@ int efi_execute_image(efi_handle_t handle,
 {
 	efi_status_t efiret;
 	const char *options;
-	bool is_driver;
+	bool is_driver, is_kernel = false;
 
 	is_driver = (loaded_image->image_code_type == EFI_BOOT_SERVICES_CODE) ||
 		(loaded_image->image_code_type == EFI_RUNTIME_SERVICES_CODE);
@@ -123,17 +123,24 @@ int efi_execute_image(efi_handle_t handle,
 		efi_set_variable_usec("LoaderTimeExecUSec", &efi_systemd_vendor_guid,
 				      ktime_to_us(ktime_get()));
 
+		is_kernel = true;
 		shutdown_barebox();
 	}
 
 	efi_pause_devices();
 
 	efiret = BS->start_image(handle, NULL, NULL);
-	if (EFI_ERROR(efiret))
-		pr_err("failed to StartImage: %s\n", efi_strerror(efiret));
 
 	efi_continue_devices();
 
+	if (is_kernel) {
+		pr_emerg("Kernel image has unexpectedly returned\n");
+		BS->exit(efi_parent_image, efiret, 0, NULL);
+	}
+
+	if (EFI_ERROR(efiret))
+		pr_err("failed to StartImage: %s\n", efi_strerror(efiret));
+
 	if (!is_driver)
 		BS->unload_image(handle);
 
-- 
2.47.3




             reply	other threads:[~2026-04-14 14:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-14 14:26 Ahmad Fatoum [this message]
2026-04-14 14:26 ` [PATCH 2/2] efi: payload: bootm: fix potential double-unload for image Ahmad Fatoum
2026-04-15  6:29 ` [PATCH 1/2] efi: payload: image: exit if kernel image returned Sascha Hauer

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=20260414142634.744542-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=chalianis1@gmail.com \
    /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