All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arvind Sankar <nivedita@alum.mit.edu>
To: Ard Biesheuvel <ardb@kernel.org>
Cc: linux-efi@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 08/11] efi/x86: Move command-line initrd loading to efi_main
Date: Thu, 30 Apr 2020 14:28:40 -0400	[thread overview]
Message-ID: <20200430182843.2510180-9-nivedita@alum.mit.edu> (raw)
In-Reply-To: <20200430182843.2510180-1-nivedita@alum.mit.edu>

Consolidate the initrd loading in efi_main.

The command line options now need to be parsed only once.

Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
---
 drivers/firmware/efi/libstub/x86-stub.c | 64 ++++++++++---------------
 1 file changed, 25 insertions(+), 39 deletions(-)

diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c
index 3800eb22232e..defeb6035109 100644
--- a/drivers/firmware/efi/libstub/x86-stub.c
+++ b/drivers/firmware/efi/libstub/x86-stub.c
@@ -22,6 +22,7 @@
 
 const efi_system_table_t *efi_system_table;
 extern u32 image_offset;
+static efi_loaded_image_t *image = NULL;
 
 static efi_status_t
 preserve_pci_rom_image(efi_pci_io_protocol_t *pci, struct pci_setup_rom **__rom)
@@ -355,7 +356,6 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
 {
 	struct boot_params *boot_params;
 	struct setup_header *hdr;
-	efi_loaded_image_t *image;
 	void *image_base;
 	efi_guid_t proto = LOADED_IMAGE_PROTOCOL_GUID;
 	int options_size = 0;
@@ -414,30 +414,9 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
 	hdr->ramdisk_image = 0;
 	hdr->ramdisk_size = 0;
 
-	if (efi_is_native()) {
-		status = efi_parse_options(cmdline_ptr);
-		if (status != EFI_SUCCESS)
-			goto fail2;
-
-		if (!efi_noinitrd) {
-			status = efi_load_initrd(image, &ramdisk_addr,
-						 &ramdisk_size,
-						 hdr->initrd_addr_max,
-						 ULONG_MAX);
-			if (status != EFI_SUCCESS)
-				goto fail2;
-			efi_set_u64_split(ramdisk_addr, &hdr->ramdisk_image,
-					  &boot_params->ext_ramdisk_image);
-			efi_set_u64_split(ramdisk_size, &hdr->ramdisk_size,
-					  &boot_params->ext_ramdisk_size);
-		}
-	}
-
 	efi_stub_entry(handle, sys_table_arg, boot_params);
 	/* not reached */
 
-fail2:
-	efi_free(options_size, (unsigned long)cmdline_ptr);
 fail:
 	efi_free(sizeof(struct boot_params), (unsigned long)boot_params);
 
@@ -760,35 +739,42 @@ unsigned long efi_main(efi_handle_t handle,
 		image_offset = 0;
 	}
 
-	/*
-	 * efi_pe_entry() may have been called before efi_main(), in which
-	 * case this is the second time we parse the cmdline. This is ok,
-	 * parsing the cmdline multiple times does not have side-effects.
-	 */
 	cmdline_paddr = ((u64)hdr->cmd_line_ptr |
 			 ((u64)boot_params->ext_cmd_line_ptr << 32));
 	efi_parse_options((char *)cmdline_paddr);
 
 	/*
-	 * At this point, an initrd may already have been loaded, either by
-	 * the bootloader and passed via bootparams, or loaded from a initrd=
-	 * command line option by efi_pe_entry() above. In either case, we
-	 * permit an initrd loaded from the LINUX_EFI_INITRD_MEDIA_GUID device
-	 * path to supersede it.
+	 * At this point, an initrd may already have been loaded by the
+	 * bootloader and passed via bootparams. We permit an initrd loaded
+	 * from the LINUX_EFI_INITRD_MEDIA_GUID device path to supersede it.
+	 *
+	 * If the device path is not present, any command-line initrd=
+	 * arguments will be processed only if image is not NULL, which will be
+	 * the case only if we were loaded via the PE entry point.
 	 */
 	if (!efi_noinitrd) {
 		unsigned long addr, size;
 
 		status = efi_load_initrd_dev_path(&addr, &size, ULONG_MAX);
-		if (status == EFI_SUCCESS) {
-			efi_set_u64_split(addr, &hdr->ramdisk_image,
-					  &boot_params->ext_ramdisk_image);
-			efi_set_u64_split(size, &hdr->ramdisk_size,
-					  &boot_params->ext_ramdisk_size);
-		} else if (status != EFI_NOT_FOUND) {
-			efi_err("efi_load_initrd_dev_path() failed!\n");
+		if (status == EFI_NOT_FOUND) {
+			if (efi_is_native() && image != NULL) {
+				status = efi_load_initrd(image, &addr, &size,
+							 hdr->initrd_addr_max,
+							 ULONG_MAX);
+			} else {
+				addr = size = 0;
+				status = EFI_SUCCESS;
+			}
+		}
+
+		if (status != EFI_SUCCESS) {
+			efi_err("Failed to load initrd!\n");
 			goto fail;
 		}
+		efi_set_u64_split(addr, &hdr->ramdisk_image,
+				  &boot_params->ext_ramdisk_image);
+		efi_set_u64_split(size, &hdr->ramdisk_size,
+				  &boot_params->ext_ramdisk_size);
 	}
 
 	/*
-- 
2.26.2


  parent reply	other threads:[~2020-04-30 18:28 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-29 17:41 [PATCH 00/10] efi: some cleanups/refactoring for efi/next Arvind Sankar
2020-04-29 17:41 ` [PATCH 01/10] efi/x86: Use correct size for boot_params Arvind Sankar
2020-04-29 17:41 ` [PATCH 02/10] efi: Add a helper function to split 64-bit values Arvind Sankar
2020-04-29 23:51   ` kbuild test robot
2020-04-29 23:51     ` kbuild test robot
2020-04-29 17:41 ` [PATCH 02/10] efi/libstub: " Arvind Sankar
2020-04-29 17:41 ` [PATCH 03/10] efi/x86: Use pr_efi_err for error messages Arvind Sankar
2020-04-29 18:47   ` Joe Perches
2020-04-29 18:49     ` Ard Biesheuvel
2020-04-29 18:57       ` Joe Perches
2020-04-29 18:59         ` Ard Biesheuvel
2020-04-29 19:47           ` Joe Perches
2020-04-29 19:48             ` Ard Biesheuvel
2020-04-29 21:43       ` Arvind Sankar
2020-04-29 21:45         ` Ard Biesheuvel
2020-04-29 21:51           ` Arvind Sankar
2020-04-29 21:53         ` Joe Perches
2020-04-29 21:55           ` Ard Biesheuvel
2020-04-29 22:20             ` Arvind Sankar
2020-04-30 15:14               ` Ard Biesheuvel
2020-04-29 17:41 ` [PATCH 04/10] efi/gop: " Arvind Sankar
2020-04-29 17:41 ` [PATCH 05/10] efi/tpm: " Arvind Sankar
2020-04-29 17:41 ` [PATCH 06/10] efi/x86: Move command-line initrd loading to efi_main Arvind Sankar
2020-04-29 17:41 ` [PATCH 07/10] efi/libstub: Unify initrd loading across architectures Arvind Sankar
2020-04-29 17:41 ` [PATCH 08/10] efi/x86: Drop soft_limit for x86 initrd loading Arvind Sankar
2020-04-29 19:05   ` Ard Biesheuvel
2020-04-29 21:33     ` Arvind Sankar
2020-04-29 17:41 ` [PATCH 09/10] efi/x86: Support builtin command line Arvind Sankar
2020-04-29 19:07   ` Ard Biesheuvel
2020-04-29 21:39     ` Arvind Sankar
2020-04-29 21:40       ` Ard Biesheuvel
2020-04-29 21:48         ` Arvind Sankar
2020-04-29 21:51           ` Ard Biesheuvel
2020-04-29 17:41 ` [PATCH 10/10] efi/libstub: Check return value of efi_parse_options Arvind Sankar
2020-04-30  4:31   ` kbuild test robot
2020-04-30  4:31     ` kbuild test robot
2020-04-30 18:28 ` [PATCH v2 00/11] efi: some cleanups/refactoring for efi/next Arvind Sankar
2020-04-30 18:28   ` [PATCH v2 01/11] efi/x86: Use correct size for boot_params Arvind Sankar
2020-04-30 18:28   ` [PATCH v2 02/11] efi/libstub: Add a helper function to split 64-bit values Arvind Sankar
2020-04-30 18:28   ` [PATCH v2 03/11] efi/libstub: Move pr_efi/pr_efi_err into efi namespace Arvind Sankar
2020-04-30 18:28   ` [PATCH v2 04/11] efi/x86: Use efi_err for error messages Arvind Sankar
2020-04-30 18:28   ` [PATCH v2 05/11] efi/gop: " Arvind Sankar
2020-04-30 18:28   ` [PATCH v2 06/11] efi/tpm: " Arvind Sankar
2020-04-30 18:28   ` [PATCH v2 07/11] efi/libstub: Upgrade ignored dtb= argument message to error Arvind Sankar
2020-04-30 18:28   ` Arvind Sankar [this message]
2020-04-30 18:28   ` [PATCH v2 09/11] efi/libstub: Unify initrd loading across architectures Arvind Sankar
2020-04-30 18:28   ` [PATCH v2 10/11] efi/x86: Support builtin command line Arvind Sankar
2020-04-30 18:28   ` [PATCH v2 11/11] efi/libstub: Check return value of efi_parse_options Arvind Sankar
2020-04-30 19:12   ` [PATCH 1/2] efi/libstub: efi_info/efi_err message neatening Joe Perches
2020-04-30 19:12     ` [PATCH 2/2] efi/libstub: Correct comment typos Joe Perches
2020-04-30 19:30       ` Ard Biesheuvel
2020-05-04 18:29         ` [trivial PATCH] efi/libstub: Reduce efi_printk object size Joe Perches
2020-05-05  7:50           ` Ard Biesheuvel
2020-05-05  8:01             ` Joe Perches
2020-04-30 19:29     ` [PATCH 1/2] efi/libstub: efi_info/efi_err message neatening Ard Biesheuvel
2020-04-30 19:38       ` Joe Perches
2020-04-30 20:40       ` Arvind Sankar
2020-04-30 20:42         ` Ard Biesheuvel
2020-05-04  8:17   ` [PATCH v2 00/11] efi: some cleanups/refactoring for efi/next Ard Biesheuvel

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=20200430182843.2510180-9-nivedita@alum.mit.edu \
    --to=nivedita@alum.mit.edu \
    --cc=ardb@kernel.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=x86@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.