All of lore.kernel.org
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH v2 0/8] x86: fixes for running KUT as EFI on non-QEMU KVM hosts
@ 2026-10-20 15:25 Giacomo Mazzola
  2026-10-20 15:25 ` [kvm-unit-tests PATCH v2 1/8] x86: efi: use PER_CPU_SIZE for per-CPU stack allocation Giacomo Mazzola
                   ` (7 more replies)
  0 siblings, 8 replies; 11+ messages in thread
From: Giacomo Mazzola @ 2026-10-20 15:25 UTC (permalink / raw)
  To: kvm; +Cc: Giacomo Mazzola

This series fixes several issues encountered when running KUT x86 tests
as EFI applications on a KVM-based hypervisor that lacks any ad-hoc
para-virtualized interface (e.g. fw_cfg), on arbitrary VM shapes
(variable CPU count and memory size).

Patches 1-4 fix crashes and faults:
  - Stack size mismatch between EFI and non-EFI paths
  - Memory allocator selecting regions above the 4 GiB identity map
  - #GP on systems without a PMU
  - ISR thunks using rel32 jumps that overflow beyond 2 GiB

Patches 5-6 fix SMP bringup:
  - Replace per-AP serial prints that cause watchdog timeouts on
    large systems
  - Add timeout-based AP detection when fw_cfg is unavailable

Patches 7-8 fix command line handling:
  - Correct the load_options_size byte-to-character conversion
  - Add KUT_ENV= parsing for passing environment variables via the
    command line

Regression-tested by running the full KUT suite under QEMU+KVM+OVMF,
in both ./configure and ./configure --enable-efi. Results are
identical with and without this series.

v1 -> v2:
 - 8/8: reworked per Drew's review. Moved the implementation from
   lib/efi.c to lib/argv.c so the feature is available to non-EFI
   builds as well, use a strncmp() prefix match instead of strstr(),
   shift argv down instead of swapping with the last element so
   argument order is preserved, and drop the redundant isspace()
   check and COMMAND_LINE_SIZE cap.  Retitled accordingly
   ("efi: parse KUT_ENV= from load options into environ" ->
   "lib: parse KUT_ENV= from command line into environ").
   This patch was already posted standalone as v2 and reviewed [2];
   it is included here unchanged so the series is complete.
 - 1/8 - 7/8: unchanged.
 - Picked up Andrew Jones' Reviewed-by on 7/8 and 8/8.
 - Rebased onto current master.

Patches 1-6 received no review in v1, so they are unchanged and still
need a look.  Resending the full series to make it reviewable as a
whole.

[1] v1: https://lore.kernel.org/kvm/20260609140901.95727-1-gmazz@amazon.de/
[2] v2 8/8 standalone: https://lore.kernel.org/kvm/20260625140452.24159-1-gmazz@amazon.de/

Giacomo Mazzola (8):
  x86: efi: use PER_CPU_SIZE for per-CPU stack allocation
  x86: fix EFI memory allocator to clamp regions to 4 GiB
  x86: skip PMU init when no PMU is advertised
  x86: fix ISR thunk to use absolute indirect jump
  x86: replace per-AP bringup prints with a single summary line
  x86: add timeout-based SMP bringup when fw_cfg is unavailable
  efi: fix load_options_size conversion to character count
  lib: parse KUT_ENV= from command line into environ

 lib/argv.c           | 35 +++++++++++++++++++++++++++++++++++
 lib/efi.c            |  2 +-
 lib/x86/apic.c       |  1 -
 lib/x86/isr.c        |  8 +++++---
 lib/x86/setup.c      | 24 ++++++++++++++++++++----
 lib/x86/smp.c        | 31 +++++++++++++++++++++++++++----
 x86/efi/efistart64.S |  2 +-
 7 files changed, 89 insertions(+), 14 deletions(-)


base-commit: 5a221342a025948fa7d84f0c404748f6ba57f3ad
-- 
2.47.3


^ permalink raw reply	[flat|nested] 11+ messages in thread
* [kvm-unit-tests PATCH 8/8] efi: parse KUT_ENV= from load options into environ
@ 2026-06-09 14:09 Giacomo Mazzola
  2026-06-25 14:04 ` [kvm-unit-tests PATCH v2 8/8] lib: parse KUT_ENV= from command line " Giacomo Mazzola
  0 siblings, 1 reply; 11+ messages in thread
From: Giacomo Mazzola @ 2026-06-09 14:09 UTC (permalink / raw)
  To: kvm; +Cc: Giacomo Mazzola

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

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-10-20 15:28 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-20 15:25 [kvm-unit-tests PATCH v2 0/8] x86: fixes for running KUT as EFI on non-QEMU KVM hosts Giacomo Mazzola
2026-10-20 15:25 ` [kvm-unit-tests PATCH v2 1/8] x86: efi: use PER_CPU_SIZE for per-CPU stack allocation Giacomo Mazzola
2026-10-20 15:25 ` [kvm-unit-tests PATCH v2 2/8] x86: fix EFI memory allocator to clamp regions to 4 GiB Giacomo Mazzola
2026-10-20 15:25 ` [kvm-unit-tests PATCH v2 3/8] x86: skip PMU init when no PMU is advertised Giacomo Mazzola
2026-10-20 15:25 ` [kvm-unit-tests PATCH v2 4/8] x86: fix ISR thunk to use absolute indirect jump Giacomo Mazzola
2026-10-20 15:25 ` [kvm-unit-tests PATCH v2 5/8] x86: replace per-AP bringup prints with a single summary line Giacomo Mazzola
2026-10-20 15:25 ` [kvm-unit-tests PATCH v2 6/8] x86: add timeout-based SMP bringup when fw_cfg is unavailable Giacomo Mazzola
2026-10-20 15:25 ` [kvm-unit-tests PATCH v2 7/8] efi: fix load_options_size conversion to character count Giacomo Mazzola
2026-10-20 15:25 ` [kvm-unit-tests PATCH v2 8/8] lib: parse KUT_ENV= from command line into environ Giacomo Mazzola
  -- strict thread matches above, loose matches on Subject: below --
2026-06-09 14:09 [kvm-unit-tests PATCH 8/8] efi: parse KUT_ENV= from load options " Giacomo Mazzola
2026-06-25 14:04 ` [kvm-unit-tests PATCH v2 8/8] lib: parse KUT_ENV= from command line " Giacomo Mazzola
2026-09-29 13:08   ` Andrew Jones

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.