From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.71 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796172009; b=s5yuzjHh5ukRdM711pddVgJlZz06HkySgwhx8uLmdc8gFM4UNwyNiXl1sh25OrgAGdGC JgAAy6sDgQ4kN5ZqQepUsQh1kwCEDL8GAuMtLu2lgoqcLhf8Ma0SGlBOSPXrxgASaIaGu LVWigyiM4ubU8xZATDHCFqC+oSeYwm/mNUWkH5Cp0zNcUoj2CMSOZZnusXn0T16++DdMY SKrkFfB+Vlp1HrOCvKjwbvhzr8dGdzcH5nP5gLeKOe2ElcYC7/6dncwEIuRfYtQ/xaNxN abtf/p+AhXJX4Kg8wXPJfXCQqb8xK6xxDXvwHM0lblYstRFatAn3q+4cbGpXIsTPJdw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796172009; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=U651M90jEu63AlWIR0flG6QTCHixAieee6f+6tuQN4Q=; b=gFTlAFycaYeEH3qKkAjoPB2JZpxhTtPeIM9DFlYBvkCJtGrteynBr0SxrhEXjJ4qCeR1 m1U8WfX4INiGYscT+CSk0/Avsq7ZydegLFfltfifu/OWoBg2kLoMoCSWRzlBTZRPjIuSL ELYHLfgNL+TCeeD0bnmUCHOOSQdl2iEbhTEhCcgL7eCXoc1+oQNd5ppF+ae3RdvzRUPpH rBJrPHey4RoyZ7mgdNOEv+15ve3Utu6Fv4SDqcHKtqcI6zcXmqjaUwECynyIOkDVrLXNw KYpr+iQlzs11vl4IHOC3e3H8GInsFHbr1hT7XRQz1NzSE/QIygmpOHh4dzP9mM60XAA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=FPTGOTYn; arc=none smtp.remote-ip=209.85.210.71 Received: from mail-ot1-f71.google.com (mail-ot1-f71.google.com [209.85.210.71]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6D3760A2633 for ; Wed, 2 Dec 2026 00:40:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C6D3760A2633 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=FPTGOTYn Received: by mail-ot1-f71.google.com with SMTP id 46e09a7af769-86285932977so12453551a34.0 for ; Tue, 01 Dec 2026 16:40:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796172008; x=1796776808; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=U651M90jEu63AlWIR0flG6QTCHixAieee6f+6tuQN4Q=; b=FPTGOTYnRk56XS1ezM/zFJ+1PqwXjl3y7LDN44hFQf9LHZPZoCjTS81aC1u45v6/r6 kmwGOMNyEQDEuH+nEUhd0Qzw3bA7MPo7ErwQrrCqXluUGtFRzdGhUxubRIdPrjI3DYCB MjgaHDbtcXZ8YWZPwbtfxerDq8SB+BoodbBA/7GTpEl3uN62RXceEo25bIkxydX8Qi4x vq/VokYk2b8df09oSgD/meZetRoZaS0I7AS5riFSXf8oikR4hn8O16SpHh4jahoDHzBr Y2zKEISGXsf2nAYflakHQxPmLbkdOQ8eljsYX2mqzAu3EQAB8+s7K+UHdlAu96ypwLy6 gzBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796172008; x=1796776808; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=U651M90jEu63AlWIR0flG6QTCHixAieee6f+6tuQN4Q=; b=fNq46ka1GDs8OLK8lnMWS2HbZxrk3zxTX9deZ7f7/QinRqfoHI49ZniU1up5yWAgOi FzRBKbNYzlPB8K4UMLKBiyZKPYMpaw0PgLei5B/QljRy+rQly/2RwYY0qa3rCaedVQ+e g1WQ3sqw1Y58ZxWSbAv7KexgwG1cUqvB2frJ+7QvRHE0zjZMx4n9ntDnlQdsaVvGeigi MTyT5k1iakmj8liuWzUbmGN9V7T7nwxcQFS4KnyQBpyBmHHOz+A9tYKQofFjpj/gKijl XN1dkiIfdu/D5VY8AuoROUW6JjxyYs2XckC/3ov2epdoA6edrEAgERlDSHbtbJl0uvwx rOlg== X-Forwarded-Encrypted: i=1; AL+hErEN3wuYlNv5YM3c+veKnn1nCW44fZW7F8zdBDE7dl9X4Yht7zir/flTThlYKwlAPXlSJ4MDH/FKAgY=@vger.kernel.org X-Gm-Message-State: APuU4Z8x73rgtMRboC+If7TXxXrOUIPoYA21QhLameOkjRyD+0BUg0X4 nWjVr5YgK7/Kf/OYqTpB0D/LXHXeXEfrH+9f00L4Rzq5/sP/6mNiwKj24xkTnZj1hrtLV/dksZL revZoirW4Ij2sig== X-Received: from ilbec2.prod.google.com ([2002:a05:6e02:4702:b0:54f:4b24:f5d9]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6808:4f4f:b0:539:dfe8:9953 with SMTP id 5614622812f47-57a0a20cfe6mr42402189b6e.50.1796172007558; Tue, 01 Dec 2026 16:40:07 -0800 (PST) Date: Wed, 2 Dec 2026 00:39:45 +0000 In-Reply-To: <20261202003955.3607156-1-dmatlack@google.com> X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261202003955.3607156-1-dmatlack@google.com> X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog Message-ID: <20261202003955.3607156-9-dmatlack@google.com> Subject: [PATCH 08/18] selftests/liveupdate: Support a different command line for each kernel From: David Matlack To: kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-pci@vger.kernel.org, linux-riscv@lists.infradead.org Cc: Albert Ou , Alexandre Ghiti , Alex Williamson , Bjorn Helgaas , David Matlack , Jacob Pan , Jason Gunthorpe , Josh Hilke , Lukas Wunner , Mike Rapoport , Palmer Dabbelt , Parav Pandit , Pasha Tatashin , Paul Walmsley , Pranjal Shrivastava , Pratyush Yadav , Samiullah Khawaja , Shuah Khan , Vipin Sharma Content-Type: text/plain; charset="UTF-8" Add TEST_CMDLINE_STAGE1 and TEST_CMDLINE_STAGE2 to vmtest.sh test definitions, which are only passed to the first and the kexec'd kernel respectively. When either is set, vmtest.sh writes the kexec'd kernel's full command line to /cmdline_stage2 in the first kernel's initrd, and init uses it instead of the current command line. This lets tests check how the next kernel handles preserved state that was set up under a different configuration. Signed-off-by: David Matlack --- tools/testing/selftests/liveupdate/init.c | 33 ++++++++++++++------ tools/testing/selftests/liveupdate/vmtest.sh | 26 ++++++++++++--- 2 files changed, 46 insertions(+), 13 deletions(-) diff --git a/tools/testing/selftests/liveupdate/init.c b/tools/testing/selftests/liveupdate/init.c index bcb401295801..45abf45c206c 100644 --- a/tools/testing/selftests/liveupdate/init.c +++ b/tools/testing/selftests/liveupdate/init.c @@ -21,6 +21,7 @@ #define TEST_BINARY "/test_binary" #define TEST_ARGS "/test_args" #define MAX_TEST_ARGS 32 +#define CMDLINE_STAGE2 "/cmdline_stage2" static int mount_filesystems(void) { @@ -50,21 +51,22 @@ static long kexec_file_load(int kernel_fd, int initrd_fd, cmdline, flags); } -static int kexec_load(void) +/* + * Read the kexec'd kernel's command line from CMDLINE_STAGE2 if it exists, or + * reuse the current command line otherwise. + */ +static int read_cmdline_stage2(char *cmdline, size_t size) { - char cmdline[COMMAND_LINE_SIZE]; - int kernel_fd, initrd_fd, err; ssize_t len; int fd; - fd = open("/proc/cmdline", O_RDONLY); - if (fd < 0) { - fprintf(stderr, "INIT: Failed to read /proc/cmdline\n"); - + fd = open(CMDLINE_STAGE2, O_RDONLY); + if (fd < 0) + fd = open("/proc/cmdline", O_RDONLY); + if (fd < 0) return -1; - } - len = read(fd, cmdline, sizeof(cmdline) - 1); + len = read(fd, cmdline, size - 1); close(fd); if (len < 0) return -1; @@ -73,6 +75,19 @@ static int kexec_load(void) if (len > 0 && cmdline[len - 1] == '\n') cmdline[len - 1] = 0; + return 0; +} + +static int kexec_load(void) +{ + char cmdline[COMMAND_LINE_SIZE]; + int kernel_fd, initrd_fd, err; + + if (read_cmdline_stage2(cmdline, sizeof(cmdline))) { + fprintf(stderr, "INIT: Failed to read the command line\n"); + return -1; + } + strncat(cmdline, " luo_stage=2", sizeof(cmdline) - strlen(cmdline) - 1); kernel_fd = open(KERNEL_IMAGE, O_RDONLY); diff --git a/tools/testing/selftests/liveupdate/vmtest.sh b/tools/testing/selftests/liveupdate/vmtest.sh index 937f10fc9592..102261892829 100755 --- a/tools/testing/selftests/liveupdate/vmtest.sh +++ b/tools/testing/selftests/liveupdate/vmtest.sh @@ -24,11 +24,15 @@ KEEP_WORKSPACE=0 # TEST_MODULES Kernel modules to place at /.ko in the # initrd, built from the Makefile's TEST_GEN_MODS_DIR # TEST_QEMU_ARGS Extra QEMU arguments +# TEST_CMDLINE_STAGE1 Extra command line for the first kernel only +# TEST_CMDLINE_STAGE2 Extra command line for the kexec'd kernel only # TEST_TIMEOUT Timeout for the QEMU run # test_check() Host-side check, run after the test passes in the VM TEST_ARGS=() TEST_MODULES=() TEST_QEMU_ARGS=() +TEST_CMDLINE_STAGE1="" +TEST_CMDLINE_STAGE2="" TEST_TIMEOUT="30s" function test_check() { @@ -166,6 +170,7 @@ function mkinitrd() { local build_dir=$1 local kernel_path=$2 local make_cmd=$3 + local cmdline_stage2=$4 local output="$workspace_dir/build" local init="$output/init" local test_binary="$output/$TEST_BINARY" @@ -219,6 +224,13 @@ file /initrd.img $workspace_dir/inner_initrd.cpio 0644 0 0 EOF cat "$extra_files" >> "$workspace_dir/cpio_list" + # Only the first kernel needs the command line for the kexec'd kernel + if [ -n "$cmdline_stage2" ]; then + echo "$cmdline_stage2" > "$workspace_dir/cmdline_stage2" + echo "file /cmdline_stage2 $workspace_dir/cmdline_stage2 0644 0 0" \ + >> "$workspace_dir/cpio_list" + fi + # Generate the final initrd "$build_dir/scripts/gen_init_cpio" "$workspace_dir/cpio_list" > "$initrd" } @@ -229,8 +241,6 @@ function run_qemu() { local kernel_path=$3 local serial="$workspace_dir/qemu.serial" - cmdline="$cmdline liveupdate=on panic=-1" - echo "# Serial Log: $serial" timeout "$TEST_TIMEOUT" \ $qemu_cmd -m 1G -smp 2 -no-reboot -nographic -nodefaults \ @@ -316,9 +326,17 @@ function main() { build_kernel "$build_dir" "$make_cmd_build" "$KERNEL_IMAGE" "$target" local final_kernel="$build_dir/arch/$arch/boot/$KERNEL_IMAGE" - mkinitrd "$build_dir" "$final_kernel" "$make_cmd" + local cmdline="$KERNEL_CMDLINE liveupdate=on panic=-1" + local cmdline_stage2="" + + # By default, the kexec'd kernel reuses the first kernel's command line + if [ -n "$TEST_CMDLINE_STAGE1$TEST_CMDLINE_STAGE2" ]; then + cmdline_stage2="$cmdline $TEST_CMDLINE_STAGE2" + fi + + mkinitrd "$build_dir" "$final_kernel" "$make_cmd" "$cmdline_stage2" - run_qemu "$QEMU_CMD" "$KERNEL_CMDLINE" "$final_kernel" + run_qemu "$QEMU_CMD" "$cmdline $TEST_CMDLINE_STAGE1" "$final_kernel" ktap_test_pass "$test_name succeeded" } -- 2.56.1.911.g883d8bcb20-goog