From nobody Sun Oct 5 01:46:19 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B9B882D8DAA; Mon, 11 Aug 2025 08:25:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754900729; cv=none; b=BXvFvInAT0Ir+OifWwe/PkD2LxAqAWoTqW4acs9k7rQfyQ9pLIQC6KFCAH6aAPIBirbt3JaMcjOk/Ik2KhJWKaeEmKEcCOWO6c5zuG7WZp2OHDvaVgtdAKd/pTgxhtDSwrqGsrxLXtgCrSU3kdHMHZH2JXncGjoKxD1NKRmT9TU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754900729; c=relaxed/simple; bh=GD0CZJPipj/scvOiwO86D4QvWu2bhvyPoPfEPeM7R1g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EShq22+XHaH2ScD01Hau97M4hqDGBdo70RMFXTvDgDjXS5HzN3xfCh7Plt5HBZZBSSD0jmerqTsZJ1SOEyp7dtmzk76GgHeZT7gtdoGFJEQGcYUMuU1j5nf/de4PBiU6Vv5foOI3i4rzCTP06A9ePbNCEK4LybPRgRPFUN2tk4o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mVk5V2vX; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mVk5V2vX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC748C4CEF7; Mon, 11 Aug 2025 08:25:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1754900729; bh=GD0CZJPipj/scvOiwO86D4QvWu2bhvyPoPfEPeM7R1g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mVk5V2vX3KTa6TTrst2P85RRH05lSqF0XHkEtbdHC7XoprqtDZ1clLzEoeeQ8KLuR U6PvynDjMIG3Eo9QnHWbTT+EKN9IVGPnwNaBEfjSi/uckjWPQn7KJFqgA4CacMTKw6 9wUZQVsVqwXh5eewwvehW8hxHCT52OMZG72LMZ8T9+490eIS1WoY9Rp1p+4OcK6hqn Mzc/g6UG3olKoudsttAg9N2gc/ZMiXq445iE0fnbZLPRIy/im7Pd+LUShSAu+DHdfu ep2YrMSWxgbIEqnKPB/RMVav5E7YKyX8IPyz7mVX+c1mKshftSmB3rxoI1wNbJ3ddY PWpdlLQJ294vw== From: Mike Rapoport To: Andrew Morton Cc: Alexander Graf , Baoquan He , Changyuan Lyu , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Shuah Khan , =?UTF-8?q?Thomas=20Wei=DFschuh?= , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 1/3] kho: allow scratch areas with zero size Date: Mon, 11 Aug 2025 11:25:08 +0300 Message-ID: <20250811082510.4154080-2-rppt@kernel.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250811082510.4154080-1-rppt@kernel.org> References: <20250811082510.4154080-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" Parsing of kho_scratch parameter treats zero size as an invalid value, although it should be fine for user to request zero sized scratch area for some types if scratch memory, when for example there is no need to create scratch area in the low memory. Treat zero as a valid value for a scratch area size but reject kho_scratch parameter that defines no scratch memory at all. Signed-off-by: Mike Rapoport (Microsoft) Reviewed-by: Pratyush Yadav --- kernel/kexec_handover.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kernel/kexec_handover.c b/kernel/kexec_handover.c index e49743ae52c5..c6ac5a5e51cb 100644 --- a/kernel/kexec_handover.c +++ b/kernel/kexec_handover.c @@ -385,6 +385,7 @@ static int __init kho_parse_scratch_size(char *p) { size_t len; unsigned long sizes[3]; + size_t total_size =3D 0; int i; =20 if (!p) @@ -421,11 +422,15 @@ static int __init kho_parse_scratch_size(char *p) } =20 sizes[i] =3D memparse(p, &endp); - if (!sizes[i] || endp =3D=3D p) + if (endp =3D=3D p) return -EINVAL; p =3D endp; + total_size +=3D sizes[i]; } =20 + if (!total_size) + return -EINVAL; + scratch_size_lowmem =3D sizes[0]; scratch_size_global =3D sizes[1]; scratch_size_pernode =3D sizes[2]; --=20 2.47.2 From nobody Sun Oct 5 01:46:19 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D1F42DAFC3; Mon, 11 Aug 2025 08:25:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754900733; cv=none; b=hpjQfpkOHmQMUZjRYKkk4udgGot5Or9QYKj3cJJ6kEbRMoXUtPta8dfXJ5He+jhnL22wIqyRngJvCMK+11m2Cq0GRBpH2uwR7RzVhPtvBP0KLMsDTOegV5gWMhqxp9sfMC4aP3ctNATiKCjAyNZ7aaLY7lLg0Nj5XbmrYjee94s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754900733; c=relaxed/simple; bh=AX4qbF1XwwQU81rpLwIDoyjLFeF3rSGWbifPTbjdHrg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Zg0uI+QriZP0JtieG0k/8w1GdR/oBPf3WiIGimtSp4zV3CQFXg4+9C+WyCsxX7BYb1irSRkTp6+oVuQIiVXeXWr1aM7vTkIa47dzGiMxb4LdgON/UQSETof5eeJp8DOE35/4QJt4z2SjZbY4McLkDvMUEQEsQhqlRhiL8wRCc5Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BBu0tV7S; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BBu0tV7S" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6E4DC4CEED; Mon, 11 Aug 2025 08:25:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1754900733; bh=AX4qbF1XwwQU81rpLwIDoyjLFeF3rSGWbifPTbjdHrg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BBu0tV7SisZJigpGLwfJlV2DUdG+zG1xMTy9xi/TIyeMR5QWWzL0vrHVWTDRyETLf 9wif8JusDG/lncKaw75hHOvcdqYqn/hmr+fqPbslLarR0lND4TxrjqOXleCy0VgHww GueKwq1d+VQbbVudmODDZr+IKPx3dEjguWd30pfO49xBo595IUSrVNKUlqaptMEDm9 KP31uI9G5AP37tXrvaMBfcsjXU1W0CCSlWIXI4CgqU7P5fOOJ/Xo7AU7E4ynb4fCqu n34r44Dg10BdzEJjqjj3L+enf9CPz3opBOem/pEGx2qDAobHWQmPbtyV9jD4PbU+67 7mhcCWzujOfug== From: Mike Rapoport To: Andrew Morton Cc: Alexander Graf , Baoquan He , Changyuan Lyu , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Shuah Khan , =?UTF-8?q?Thomas=20Wei=DFschuh?= , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 2/3] lib/test_kho: fixes for error handling Date: Mon, 11 Aug 2025 11:25:09 +0300 Message-ID: <20250811082510.4154080-3-rppt@kernel.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250811082510.4154080-1-rppt@kernel.org> References: <20250811082510.4154080-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" * Update kho_test_save() so that folios array won't be freed when returning from the function and the fdt will be freed on error * Reset state->nr_folios to 0 in kho_test_generate_data() on error * Simplify allocation of folios info in fdt. Reported-by: Pratyush Yadav Closes: https://lore.kernel.org/all/mafs0zfcjcepf.fsf@kernel.org Fixes: b753522bed0b ("kho: add test for kexec handover") Signed-off-by: Mike Rapoport (Microsoft) Reviewed-by: Pratyush Yadav --- lib/test_kho.c | 52 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/lib/test_kho.c b/lib/test_kho.c index c2eb899c3b45..fe8504e3407b 100644 --- a/lib/test_kho.c +++ b/lib/test_kho.c @@ -67,13 +67,20 @@ static struct notifier_block kho_test_nb =3D { =20 static int kho_test_save_data(struct kho_test_state *state, void *fdt) { - phys_addr_t *folios_info __free(kvfree) =3D NULL; + phys_addr_t *folios_info; int err =3D 0; =20 - folios_info =3D kvmalloc_array(state->nr_folios, sizeof(*folios_info), - GFP_KERNEL); - if (!folios_info) - return -ENOMEM; + err |=3D fdt_begin_node(fdt, "data"); + err |=3D fdt_property(fdt, "nr_folios", &state->nr_folios, + sizeof(state->nr_folios)); + err |=3D fdt_property_placeholder(fdt, "folios_info", + state->nr_folios * sizeof(*folios_info), + (void **)&folios_info); + err |=3D fdt_property(fdt, "csum", &state->csum, sizeof(state->csum)); + err |=3D fdt_end_node(fdt); + + if (err) + return err; =20 for (int i =3D 0; i < state->nr_folios; i++) { struct folio *folio =3D state->folios[i]; @@ -83,17 +90,9 @@ static int kho_test_save_data(struct kho_test_state *sta= te, void *fdt) =20 err =3D kho_preserve_folio(folio); if (err) - return err; + break; } =20 - err |=3D fdt_begin_node(fdt, "data"); - err |=3D fdt_property(fdt, "nr_folios", &state->nr_folios, - sizeof(state->nr_folios)); - err |=3D fdt_property(fdt, "folios_info", folios_info, - state->nr_folios * sizeof(*folios_info)); - err |=3D fdt_property(fdt, "csum", &state->csum, sizeof(state->csum)); - err |=3D fdt_end_node(fdt); - return err; } =20 @@ -140,7 +139,10 @@ static int kho_test_generate_data(struct kho_test_stat= e *state) unsigned int size; void *addr; =20 - /* cap allocation so that we won't exceed max_mem */ + /* + * Since get_order() rounds up, make sure that actual + * allocation is smaller so that we won't exceed max_mem + */ if (alloc_size + (PAGE_SIZE << order) > max_mem) { order =3D get_order(max_mem - alloc_size); if (order) @@ -165,13 +167,14 @@ static int kho_test_generate_data(struct kho_test_sta= te *state) err_free_folios: for (int i =3D 0; i < state->nr_folios; i++) folio_put(state->folios[i]); + state->nr_folios =3D 0; return -ENOMEM; } =20 static int kho_test_save(void) { struct kho_test_state *state =3D &kho_test_state; - struct folio **folios __free(kvfree) =3D NULL; + struct folio **folios; unsigned long max_nr; int err; =20 @@ -185,13 +188,23 @@ static int kho_test_save(void) =20 err =3D kho_test_generate_data(state); if (err) - return err; + goto err_free_folios; =20 err =3D kho_test_prepare_fdt(state); if (err) - return err; + goto err_free_folios; =20 - return register_kho_notifier(&kho_test_nb); + err =3D register_kho_notifier(&kho_test_nb); + if (err) + goto err_free_fdt; + + return 0; + +err_free_fdt: + folio_put(state->fdt); +err_free_folios: + kvfree(folios); + return err; } =20 static int kho_test_restore_data(const void *fdt, int node) @@ -291,6 +304,7 @@ static void kho_test_cleanup(void) folio_put(kho_test_state.folios[i]); =20 kvfree(kho_test_state.folios); + folio_put(kho_test_state.fdt); } =20 static void __exit kho_test_exit(void) --=20 2.47.2 From nobody Sun Oct 5 01:46:19 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F5832DC33B; Mon, 11 Aug 2025 08:25:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754900737; cv=none; b=cyHVlZk8YBXl9DNZh9Js6iOj+m0RLzLGLqcL9ZpT9KAlDsP3/LHuEW/8wRgd3Cs8TH1Yp/eho5zJK2dZRD+U+pGxSrdrTaIIlTseDTXIGx8v7pMfX4L9whfBB/M8OdLtR4pukOAXs4uG3ZnSwMUDo5QwtVKeLQok0d4Nc9TWdg8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754900737; c=relaxed/simple; bh=x9yDF0ETg1DZV483jmCAS7zdZyJxfX8QtrhsIOYLE3w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PICFhfeTCy1Ln0bqEFCLyR5h/RFstlNi6GvmL5aATvsgCzVTTjiJ6jI9pKOPs2lCqlLCZELi+j5xrXLcioajcr2/gRYK4lP/4sgsycEokoxp0xjJOll2WPSqXxa4AsSjcf+LRVJ8y5tAWTd5PtUJG3lXmlaZYrFPeZoTR5C91Ro= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=J+xamGjR; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="J+xamGjR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C0AADC4CEF8; Mon, 11 Aug 2025 08:25:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1754900737; bh=x9yDF0ETg1DZV483jmCAS7zdZyJxfX8QtrhsIOYLE3w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J+xamGjRj0qBZ8f+MKHSAySNijepwnYwt5H+o27/gEbgnXE3KQltdcbB0iHOqwdja e3uxwJ+w5yxH41yVobpeGbK+tifeiohOed1kRfcIgZnRmaI0/zJph8jQ5jZVoQmEeA SF8HdzQuD9/keUQlz5XLJhcPyyioXMA19Oobp3ATZm0iBRUf4g+5zifCSJpt16V6ae aZW1oBggKLDmPu7m2OsuFxhT2HtyISgt7vOI/0pde2gNl2gwyV7EtRwVfP6dGR1CnN VBZIFHyuTocPG+JYnv9+2PApCwJFsdR/g/PfEDfrLK1MTZdRF9ha1opuD5ix9iZ9en HgZmIqifpPCkg== From: Mike Rapoport To: Andrew Morton Cc: Alexander Graf , Baoquan He , Changyuan Lyu , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Shuah Khan , =?UTF-8?q?Thomas=20Wei=DFschuh?= , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 3/3] selftest/kho: update generation of initrd Date: Mon, 11 Aug 2025 11:25:10 +0300 Message-ID: <20250811082510.4154080-4-rppt@kernel.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250811082510.4154080-1-rppt@kernel.org> References: <20250811082510.4154080-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: "Mike Rapoport (Microsoft)" Use nolibc include directory rather than include a cumulative nolibc.h on the compiler command line and replace use of 'sudo cpio' with usr/gen_init_cpio. While on it fix spelling of KHO_FINALIZE Suggested-by: Thomas Wei=C3=9Fschuh Signed-off-by: Mike Rapoport (Microsoft) --- tools/testing/selftests/kho/init.c | 13 ++++--------- tools/testing/selftests/kho/vmtest.sh | 28 ++++++++++++++------------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/tools/testing/selftests/kho/init.c b/tools/testing/selftests/k= ho/init.c index 8034e24c6bf6..6d9e91d55d68 100644 --- a/tools/testing/selftests/kho/init.c +++ b/tools/testing/selftests/kho/init.c @@ -1,22 +1,17 @@ // SPDX-License-Identifier: GPL-2.0 =20 -#ifndef NOLIBC -#include #include #include #include -#include +#include #include #include -#endif +#include =20 /* from arch/x86/include/asm/setup.h */ #define COMMAND_LINE_SIZE 2048 =20 -/* from include/linux/kexex.h */ -#define KEXEC_FILE_NO_INITRAMFS 0x00000004 - -#define KHO_FINILIZE "/debugfs/kho/out/finalize" +#define KHO_FINALIZE "/debugfs/kho/out/finalize" #define KERNEL_IMAGE "/kernel" =20 static int mount_filesystems(void) @@ -32,7 +27,7 @@ static int kho_enable(void) const char enable[] =3D "1"; int fd; =20 - fd =3D open(KHO_FINILIZE, O_RDWR); + fd =3D open(KHO_FINALIZE, O_RDWR); if (fd < 0) return -1; =20 diff --git a/tools/testing/selftests/kho/vmtest.sh b/tools/testing/selftest= s/kho/vmtest.sh index ec70a17bd476..3f6c17166846 100755 --- a/tools/testing/selftests/kho/vmtest.sh +++ b/tools/testing/selftests/kho/vmtest.sh @@ -10,7 +10,6 @@ kernel_dir=3D$(realpath "$test_dir/../../../..") =20 tmp_dir=3D$(mktemp -d /tmp/kho-test.XXXXXXXX) headers_dir=3D"$tmp_dir/usr" -initrd_dir=3D"$tmp_dir/initrd" initrd=3D"$tmp_dir/initrd.cpio" =20 source "$test_dir/../kselftest/ktap_helpers.sh" @@ -81,19 +80,22 @@ EOF function mkinitrd() { local kernel=3D$1 =20 - mkdir -p "$initrd_dir"/{dev,debugfs,proc} - sudo mknod "$initrd_dir/dev/console" c 5 1 - - "$CROSS_COMPILE"gcc -s -static -Os -nostdinc -I"$headers_dir/include" \ - -fno-asynchronous-unwind-tables -fno-ident -nostdlib \ - -include "$test_dir/../../../include/nolibc/nolibc.h" \ - -o "$initrd_dir/init" "$test_dir/init.c" \ - - cp "$kernel" "$initrd_dir/kernel" + "$CROSS_COMPILE"gcc -s -static -Os -nostdinc -nostdlib \ + -fno-asynchronous-unwind-tables -fno-ident \ + -I "$headers_dir/include" \ + -I "$kernel_dir/tools/include/nolibc" \ + -o "$tmp_dir/init" "$test_dir/init.c" + + cat > "$tmp_dir/cpio_list" </dev/null - find . | cpio -H newc --create > "$initrd" 2>/dev/null - popd &>/dev/null + "$build_dir/usr/gen_init_cpio" "$tmp_dir/cpio_list" > "$initrd" } =20 function run_qemu() { --=20 2.47.2