From: Giacomo Mazzola <gmazz@amazon.de>
To: <kvm@vger.kernel.org>
Cc: Giacomo Mazzola <gmazz@amazon.de>
Subject: [kvm-unit-tests PATCH 8/8] efi: parse KUT_ENV= from load options into environ
Date: Tue, 9 Jun 2026 14:09:00 +0000 [thread overview]
Message-ID: <20260609140901.95727-9-gmazz@amazon.de> (raw)
In-Reply-To: <20260609140901.95727-1-gmazz@amazon.de>
Allow EFI applications to receive environment variables via the UEFI
load options string. If any argv element contains 'KUT_ENV=', the
value after the '=' is parsed as a comma-separated list of KEY=VAL
pairs and fed to setup_env(). The KUT_ENV= argument is then removed
from argv so tests do not see it as a spurious positional argument.
This lets a UEFI boot manager pass runtime configuration (e.g.
KUT_ENV=PARAM_1=VALUE_1,PARAM_2=VALUE_2) without needing an initrd
environ file — useful in EFI environments where no filesystem is
available to the test.
Signed-off-by: Giacomo Mazzola <gmazz@amazon.de>
---
lib/efi.c | 37 ++++++++++++++++++++++++++++++++++++-
1 file changed, 36 insertions(+), 1 deletion(-)
diff --git a/lib/efi.c b/lib/efi.c
index d1be2bfc..650671e9 100644
--- a/lib/efi.c
+++ b/lib/efi.c
@@ -13,6 +13,8 @@
#include <asm/setup.h>
#include "efi.h"
+#define COMMAND_LINE_SIZE 2048
+
/* From each arch */
extern char *initrd;
extern u32 initrd_size;
@@ -139,7 +141,6 @@ static char *efi_convert_cmdline(struct efi_loaded_image_64 *image, int *cmd_lin
int options_bytes = 0, safe_options_bytes = 0; /* UTF-8 bytes */
bool in_quote = false;
efi_status_t status;
- const int COMMAND_LINE_SIZE = 2048;
if (options) {
s2 = options;
@@ -397,6 +398,39 @@ static void efi_load_initrd(void)
}
}
+#define ENV_STR "KUT_ENV"
+
+static void efi_setup_env(void)
+{
+ char *env = NULL, *p;
+ int i, size = 0;
+
+ for (i = 0; i < __argc && !env; i++)
+ env = strstr(__argv[i], ENV_STR "=");
+
+ if (!env)
+ return;
+
+ /* Remove the KUT_ENV= argument from argv. */
+ __argv[i - 1] = __argv[__argc - 1];
+ __argv[__argc - 1] = NULL;
+ __argc -= 1;
+
+ env += strlen(ENV_STR) + 1; /* skip past 'KUT_ENV=' */
+ p = env;
+ while (*p && !isspace(*p) && size < COMMAND_LINE_SIZE) {
+ if (*p == ',')
+ *p = '\n';
+ size++;
+ p++;
+ }
+
+ if (size >= COMMAND_LINE_SIZE)
+ report_abort("Cmdline arguments too long, or bad format");
+
+ setup_env(env, size);
+}
+
efi_status_t efi_main(efi_handle_t handle, efi_system_table_t *sys_tab)
{
int ret;
@@ -434,6 +468,7 @@ efi_status_t efi_main(efi_handle_t handle, efi_system_table_t *sys_tab)
goto efi_main_error;
}
setup_args(cmdline_ptr);
+ efi_setup_env();
efi_load_initrd();
--
2.47.3
Amazon Web Services Development Center Germany GmbH
Tamara-Danz-Str. 13
10243 Berlin
Geschaeftsfuehrung: Christof Hellmis, Andreas Stieger
Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B
Sitz: Berlin
Ust-ID: DE 365 538 597
next prev parent reply other threads:[~2026-06-09 14:13 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-09 14:08 [kvm-unit-tests PATCH 0/8] x86: fixes for running KUT as EFI on non-QEMU KVM hosts Giacomo Mazzola
2026-06-09 14:08 ` [kvm-unit-tests PATCH 1/8] x86: efi: use PER_CPU_SIZE for per-CPU stack allocation Giacomo Mazzola
2026-06-09 14:08 ` [kvm-unit-tests PATCH 2/8] x86: fix EFI memory allocator to clamp regions to 4 GiB Giacomo Mazzola
2026-06-09 14:08 ` [kvm-unit-tests PATCH 3/8] x86: skip PMU init when no PMU is advertised Giacomo Mazzola
2026-06-09 14:08 ` [kvm-unit-tests PATCH 4/8] x86: fix ISR thunk to use absolute indirect jump Giacomo Mazzola
2026-06-09 14:08 ` [kvm-unit-tests PATCH 5/8] x86: replace per-AP bringup prints with a single summary line Giacomo Mazzola
2026-06-09 14:08 ` [kvm-unit-tests PATCH 6/8] x86: add timeout-based SMP bringup when fw_cfg is unavailable Giacomo Mazzola
2026-06-09 14:08 ` [kvm-unit-tests PATCH 7/8] efi: fix load_options_size conversion to character count Giacomo Mazzola
2026-06-10 16:09 ` Andrew Jones
2026-06-09 14:09 ` Giacomo Mazzola [this message]
2026-06-10 18:18 ` [kvm-unit-tests PATCH 8/8] efi: parse KUT_ENV= from load options into environ Andrew Jones
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=20260609140901.95727-9-gmazz@amazon.de \
--to=gmazz@amazon.de \
--cc=kvm@vger.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