From nobody Mon May 25 02:43:15 2026 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 39C882EACEF for ; Tue, 19 May 2026 16:06:05 +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=1779206765; cv=none; b=N3A5TTfdjAbeWvIZdKEC2+0opUv5ghaTfOcBvSzuLqF01mW3aFpuE2Fnx9PK8DBKd0XihfCWOuog7JQEhVvBGPQ1Ez0oCb0egOn4vPGRNb4XPaYrXKNyp+WSAZl23WuQNVuiBiG4+KpY18gdg/sLweRr/bGfmplnMR4TJ9GliEQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779206765; c=relaxed/simple; bh=3G28d0TOyfNRinSp659QFq62b49e9yvwWyjT8rXN4fw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=DCtetSi/Al46mj4Si+Y0kUGrsAh8C0Mxmjmucr2542ei8ucsnqaqxJZmYd908WH50BgMt6pXrMcgXpkkNZe9vTZyg2P5gz7QLnYkjmiI9daEi5C1rXY8Q1uqAyaYknvHy74JoMqTOruXZEirWwcDcJmo6QscF7owzqPyI4tamGA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qY9x92Pr; 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="qY9x92Pr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65C34C2BCB3; Tue, 19 May 2026 16:06:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1779206764; bh=3G28d0TOyfNRinSp659QFq62b49e9yvwWyjT8rXN4fw=; h=From:To:Cc:Subject:Date:From; b=qY9x92PrTGloGMB4sUwDGgLF5j6PDvzeOQDKL4aKnBN+UdjLDRJLp8M4OhkH0o0f/ v34wNqWmM/VimJEDe5e1axaWRWXocyGKR6cWpMAs+hfake/ZMolhuYIdXauXdv6Z43 C9Lf46v9wMzUX2HBhfo4vkdIRUEcBwCmzArpc0DXnR9W5Ehv07QpSAfM7VSHqFlGmC 6gZ8RmjgSn5/KzNcnP/8Ov/aRKVGkBBrQNTHa2OnMgj78lNa1N1uF/WMyVaoX0d7Ac atazB59bpZ1DxNW8juJScVZDXLqjM3PRxw1QOQ1HwEMYzwriQ8HkQ4WwF9X/1pLTuQ KFtCIzvbMnZCg== From: Pratyush Yadav To: Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Alexander Graf , Andrew Morton , Changyuan Lyu Cc: kexec@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] kho: make sure scratch size is always aligned by CMA_MIN_ALIGNMENT_BYTES Date: Tue, 19 May 2026 18:05:49 +0200 Message-ID: <20260519160554.2713361-1-pratyush@kernel.org> X-Mailer: git-send-email 2.54.0.563.g4f69b47b94-goog 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: "Pratyush Yadav (Google)" When using scratch_scale, the scratch sizes are rounded up to CMA_MIN_ALIGNMENT_BYTES since they will be released as MIGRATE_CMA. This is not done when using fixed scratch sizes via command line. This can result in user specifying a size which is not aligned, and thus kernel releasing a pageblock that is only partially scratch. Do the rounding up for both cases in scratch_size_update(). Fixes: 3dc92c311498 ("kexec: add Kexec HandOver (KHO) generation helpers") Signed-off-by: Pratyush Yadav (Google) --- kernel/liveupdate/kexec_handover.c | 32 ++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_h= andover.c index 4fde8325c49f..c26e4df37479 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -607,20 +607,30 @@ early_param("kho_scratch", kho_parse_scratch_size); =20 static void __init scratch_size_update(void) { - phys_addr_t size; + /* + * If fixed sizes are not provided via command line, calculate them + * now. + */ + if (scratch_scale) { + phys_addr_t size; =20 - if (!scratch_scale) - return; + size =3D memblock_reserved_kern_size(ARCH_LOW_ADDRESS_LIMIT, + NUMA_NO_NODE); + size =3D size * scratch_scale / 100; + scratch_size_lowmem =3D size; =20 - size =3D memblock_reserved_kern_size(ARCH_LOW_ADDRESS_LIMIT, - NUMA_NO_NODE); - size =3D size * scratch_scale / 100; - scratch_size_lowmem =3D round_up(size, CMA_MIN_ALIGNMENT_BYTES); + size =3D memblock_reserved_kern_size(MEMBLOCK_ALLOC_ANYWHERE, + NUMA_NO_NODE); + size =3D size * scratch_scale / 100 - scratch_size_lowmem; + scratch_size_global =3D size; + } =20 - size =3D memblock_reserved_kern_size(MEMBLOCK_ALLOC_ANYWHERE, - NUMA_NO_NODE); - size =3D size * scratch_scale / 100 - scratch_size_lowmem; - scratch_size_global =3D round_up(size, CMA_MIN_ALIGNMENT_BYTES); + /* + * Scratch areas are released as MIGRATE_CMA. Round them up to the right + * size. + */ + scratch_size_lowmem =3D round_up(scratch_size_lowmem, CMA_MIN_ALIGNMENT_B= YTES); + scratch_size_global =3D round_up(scratch_size_global, CMA_MIN_ALIGNMENT_B= YTES); } =20 static phys_addr_t __init scratch_size_node(int nid) base-commit: b1378127003b61930ce30064328640503ad3ef6d --=20 2.54.0.563.g4f69b47b94-goog