mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] kho: make sure scratch size is always aligned by CMA_MIN_ALIGNMENT_BYTES
@ 2026-05-19 16:05 Pratyush Yadav
  2026-05-21 18:54 ` Pasha Tatashin
  0 siblings, 1 reply; 2+ messages in thread
From: Pratyush Yadav @ 2026-05-19 16:05 UTC (permalink / raw)
  To: Mike Rapoport, Pasha Tatashin, Pratyush Yadav, Alexander Graf,
	Andrew Morton, Changyuan Lyu
  Cc: kexec, linux-mm, linux-kernel

From: "Pratyush Yadav (Google)" <pratyush@kernel.org>

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) <pratyush@kernel.org>
---
 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_handover.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);
 
 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;
 
-	if (!scratch_scale)
-		return;
+		size = memblock_reserved_kern_size(ARCH_LOW_ADDRESS_LIMIT,
+						   NUMA_NO_NODE);
+		size = size * scratch_scale / 100;
+		scratch_size_lowmem = size;
 
-	size = memblock_reserved_kern_size(ARCH_LOW_ADDRESS_LIMIT,
-					   NUMA_NO_NODE);
-	size = size * scratch_scale / 100;
-	scratch_size_lowmem = round_up(size, CMA_MIN_ALIGNMENT_BYTES);
+		size = memblock_reserved_kern_size(MEMBLOCK_ALLOC_ANYWHERE,
+						   NUMA_NO_NODE);
+		size = size * scratch_scale / 100 - scratch_size_lowmem;
+		scratch_size_global = size;
+	}
 
-	size = memblock_reserved_kern_size(MEMBLOCK_ALLOC_ANYWHERE,
-					   NUMA_NO_NODE);
-	size = size * scratch_scale / 100 - scratch_size_lowmem;
-	scratch_size_global = round_up(size, CMA_MIN_ALIGNMENT_BYTES);
+	/*
+	 * Scratch areas are released as MIGRATE_CMA. Round them up to the right
+	 * size.
+	 */
+	scratch_size_lowmem = round_up(scratch_size_lowmem, CMA_MIN_ALIGNMENT_BYTES);
+	scratch_size_global = round_up(scratch_size_global, CMA_MIN_ALIGNMENT_BYTES);
 }
 
 static phys_addr_t __init scratch_size_node(int nid)

base-commit: b1378127003b61930ce30064328640503ad3ef6d
-- 
2.54.0.563.g4f69b47b94-goog


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

* Re: [PATCH] kho: make sure scratch size is always aligned by CMA_MIN_ALIGNMENT_BYTES
  2026-05-19 16:05 [PATCH] kho: make sure scratch size is always aligned by CMA_MIN_ALIGNMENT_BYTES Pratyush Yadav
@ 2026-05-21 18:54 ` Pasha Tatashin
  0 siblings, 0 replies; 2+ messages in thread
From: Pasha Tatashin @ 2026-05-21 18:54 UTC (permalink / raw)
  To: Mike Rapoport, Alexander Graf, Andrew Morton, Changyuan Lyu,
	Pratyush Yadav
  Cc: kexec, linux-mm, linux-kernel


On Tue, 19 May 2026 18:05:49 +0200, Pratyush Yadav wrote:
> 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().
> 
> [...]

Applied, thanks!

[1/1] kho: make sure scratch size is always aligned by CMA_MIN_ALIGNMENT_BYTES
      commit: 4129715f7ac5b71183350f1983023caf0464cb9b

Best regards,
-- 
Pasha Tatashin <pasha.tatashin@soleen.com>


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

end of thread, other threads:[~2026-05-21 18:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-19 16:05 [PATCH] kho: make sure scratch size is always aligned by CMA_MIN_ALIGNMENT_BYTES Pratyush Yadav
2026-05-21 18:54 ` Pasha Tatashin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®