From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64BE960A6F79 for ; Wed, 2 Dec 2026 00:40:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=I62YRYw7; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=mlK8SKfm DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=U651M90jEu63AlWIR0flG6QTCHixAieee6f+6tuQN4Q=; b=I62YRYw7mM/1DEjqvmTtDsMpwm rAR/uYhhkZfYBhRwzVbk6qgbxnxaqlHEKYdtZ/S9QsqdfEPKjyX8UgW6W9JsZIfkEDSrgo9PbSd03 utE/3M2NVDQwzqnTICGfvR+pKsuZOLayYiXgxX0PKF3sAhcBwzs8PWyvJySm19tEp5MclJQf/tryy euaIBP47aaXtFbjbg6FeTv5HxmboHnsdrblOdK95R76wK1bUQC4LO3Wi0tV1unvkbvpuqo30XrfRJ Qhyhglw80O7YWc7GRTobM78Y1URdftGEJtDLpSS14m31Wf/E6woebIp0uv5SpwhYUhBKKnSXr40RD IEogB9RQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYYOR-00000009mGV-1vBj; Wed, 02 Dec 2026 00:40:19 +0000 Received: from mail-oi1-x247.google.com ([2607:f8b0:4864:20::247]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYYOJ-00000009lyR-3nuB for kexec@lists.infradead.org; Wed, 02 Dec 2026 00:40:14 +0000 Received: by mail-oi1-x247.google.com with SMTP id 5614622812f47-4b2d1eb484aso13208821b6e.2 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=lists.infradead.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=mlK8SKfmaihpXVaMqY6bouLcBT95AWN6Z+Unvl5o55rZHQpSgPInB6wNgOFNvakNwI C/hMJdWb7CRowGJ+e2gtGEID8Xlme9s4wlCr7g20F2TLKwl3VhdXijarKNMkoO3Ai8PX 28VedaXNT2WNFmVQIC3pryQfl20bFk7exiVeOcErS9+Us6meRjzWDFjXOeD9O9WLsl54 uMBDiKdAwa1oVjPpQGVXHSPecIKUKo0mLU4y4Mz5Bd9Kv+ldsXWgTsgev9Kafi/H9ZPp RRszPqxpnOSrTN5yFTeSxWnd0XoVaMd9dnou2JnkPKga+k9WCvO3CAiykRZ6l2/6ywxa decQ== 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=nFlFKm6Wyz8h6pV7Gg6HvdCXpVNJzliSn/F3c4DBdsnllqo75EVz2oLOk8mhnJsBJH reZjGMqF142/NAPz/yQ5eB6BXLLAc8QoetRFIZ1SoyWAh6bbJL7oy0kqwpFaIkzQLJli s+0rVPsfh7aeFQOgg7jBOillsiIPSu6R4Q7pWl+o/lXRcovnlf0wAY7JRylf4L/WaOQk pDiaS2FtKL1ts8JEHWIPRsEsmgK103P7F2zZWRmD4MvX3KXARiVBNLybypREGtZfIItD wlyLg4nte2HXtw6F35Be6oTrLWtqYi65lxhbSVfMzieJERzBgcxj1hX0bhsEPAH+/J1u GHNw== X-Gm-Message-State: APuU4Z8jZr3b0djlVbPepHHDvEsgsVV8PNbTrHJVfFiWydzsrEqHztcq E5fYe587bIZSwIR59WxvdtuZE4LKrOnkW7fSTMPaKP1Bg7kBSHASMYdKf4kKDhusZ6KSzntJGZT gWEauGlKAi5aJiTLKJoYis+4EOkHN719s3RsuoP8z9Mu1o3g0v2sQjVod34qfwgo1LG85glIEUY F1ilGANcDNITtbJ1BHcNB9JFWpfEhOMuDx+JtTdP9FX+aEM9bhIHM= 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-Archived-By: 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" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261201_164012_207154_0500D98D X-CRM114-Status: GOOD ( 20.14 ) X-Spam-Score: -9.5 (---------) X-BeenThere: kexec@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kexec" X-Spam-Status: No, score=-26.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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