mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mikhail Zaslonko <zaslonko@linux.ibm.com>
To: Heiko Carstens <hca@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Ilya Leoshkevich <iii@linux.ibm.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Baoquan He <baoquan.he@linux.dev>,
	Mike Rapoport <rppt@kernel.org>,
	Pasha Tatashin <pasha.tatashin@soleen.com>,
	Pratyush Yadav <pratyush@kernel.org>,
	Dave Young <ruirui.yang@linux.dev>, Jiri Bohac <jbohac@suse.cz>,
	Jonathan Corbet <corbet@lwn.net>,
	Usama Arif <usama.arif@linux.dev>,
	linux-s390@vger.kernel.org, kexec@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH v1 5/8] s390/kdump: Exclude crashkernel CMA memory from vmcore
Date: Thu, 12 Nov 2026 12:21:02 +0100	[thread overview]
Message-ID: <20261112112105.1169118-6-zaslonko@linux.ibm.com> (raw)
In-Reply-To: <20261112112105.1169118-1-zaslonko@linux.ibm.com>

The kdump kernel will be using the crashkernel CMA memory of the
crashed kernel, so it must not be a part of the dump.

Keep the CMA ranges handed over by the crashed kernel in oldmem_data.
Add them to oldmem_type next to the crashkernel memory, so that no
PT_LOAD headers are created for them.

Merge adjacent regions, such as CMA areas placed back to back or next
to the crashkernel memory. Otherwise for_each_physmem_range() returns an
empty range between them, which ends up as an empty PT_LOAD header.

Use the original ranges even if mem= limits usable memory in the kdump
kernel. Build the list without depending on CONFIG_CMA in that kernel.

Co-developed-by: Vasily Gorbik <gor@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
---
 arch/s390/boot/startup.c      |  1 +
 arch/s390/include/asm/setup.h |  1 +
 arch/s390/kernel/crash_dump.c | 48 ++++++++++++++++++++++++++++-------
 3 files changed, 41 insertions(+), 9 deletions(-)

diff --git a/arch/s390/boot/startup.c b/arch/s390/boot/startup.c
index 95543656d1b8..111b146a3332 100644
--- a/arch/s390/boot/startup.c
+++ b/arch/s390/boot/startup.c
@@ -529,6 +529,7 @@ void startup_kernel(void)
 		physmem_reserve(RR_INITRD, parmarea.initrd_start, parmarea.initrd_size);
 	oldmem_data.start = parmarea.oldmem_base;
 	oldmem_data.size = parmarea.oldmem_size;
+	memcpy(oldmem_data.crashk_cma, parmarea.crashk_cma, sizeof(oldmem_data.crashk_cma));
 
 	read_ipl_report();
 	sclp_early_read_info();
diff --git a/arch/s390/include/asm/setup.h b/arch/s390/include/asm/setup.h
index 7e992f3953b1..7048985ec014 100644
--- a/arch/s390/include/asm/setup.h
+++ b/arch/s390/include/asm/setup.h
@@ -100,6 +100,7 @@ extern void (*_machine_power_off)(void);
 struct oldmem_data {
 	unsigned long start;
 	unsigned long size;
+	struct crashk_cma_range crashk_cma[CRASHK_CMA_ENTRIES];
 };
 extern struct oldmem_data oldmem_data;
 
diff --git a/arch/s390/kernel/crash_dump.c b/arch/s390/kernel/crash_dump.c
index d4839de8ce9d..f2f4a5f40d60 100644
--- a/arch/s390/kernel/crash_dump.c
+++ b/arch/s390/kernel/crash_dump.c
@@ -19,6 +19,7 @@
 #include <linux/uio.h>
 #include <asm/asm-offsets.h>
 #include <asm/os_info.h>
+#include <asm/setup.h>
 #include <asm/elf.h>
 #include <asm/ipl.h>
 #include <asm/sclp.h>
@@ -29,13 +30,14 @@
 #define PTR_SUB(x, y) (((char *) (x)) - ((unsigned long) (y)))
 #define PTR_DIFF(x, y) ((unsigned long)(((char *) (x)) - ((unsigned long) (y))))
 
-static struct memblock_region oldmem_region;
+/* crashkernel memory and crashkernel CMA memory, sorted by address */
+static struct memblock_region oldmem_regions[1 + CRASHK_CMA_ENTRIES];
 
 static struct memblock_type oldmem_type = {
 	.cnt = 1,
-	.max = 1,
+	.max = ARRAY_SIZE(oldmem_regions),
 	.total_size = 0,
-	.regions = &oldmem_region,
+	.regions = oldmem_regions,
 	.name = "oldmem",
 };
 
@@ -478,6 +480,37 @@ static int get_cpu_cnt(void)
 	return cpus;
 }
 
+/* Exclude the original crashkernel and CMA reservations, independent of mem=. */
+static void oldmem_type_init(void)
+{
+	struct memblock_region *regions = oldmem_regions;
+	unsigned long base, size;
+	int i, j;
+
+	regions[0].base = oldmem_data.start;
+	regions[0].size = oldmem_data.size;
+	oldmem_type.cnt = 1;
+	oldmem_type.total_size = oldmem_data.size;
+	for (i = 0; i < ARRAY_SIZE(oldmem_data.crashk_cma) && oldmem_data.crashk_cma[i].size; i++) {
+		base = oldmem_data.crashk_cma[i].start;
+		size = oldmem_data.crashk_cma[i].size;
+		for (j = oldmem_type.cnt; j > 0 && regions[j - 1].base > base; j--)
+			regions[j] = regions[j - 1];
+		regions[j].base = base;
+		regions[j].size = size;
+		oldmem_type.cnt++;
+		oldmem_type.total_size += size;
+	}
+	/* memblock iterators expect separate regions, merge adjacent ones */
+	for (i = 1, j = 0; i < oldmem_type.cnt; i++) {
+		if (regions[j].base + regions[j].size == regions[i].base)
+			regions[j].size += regions[i].size;
+		else
+			regions[++j] = regions[i];
+	}
+	oldmem_type.cnt = j + 1;
+}
+
 /*
  * Return memory chunk count for ELF header (new kernel)
  */
@@ -626,12 +659,9 @@ int elfcorehdr_alloc(unsigned long long *addr, unsigned long long *size)
 	if (is_ipl_type_dump() && !sclp.hsa_size)
 		return -ENODEV;
 
-	/* For kdump, exclude previous crashkernel memory */
-	if (oldmem_data.start) {
-		oldmem_region.base = oldmem_data.start;
-		oldmem_region.size = oldmem_data.size;
-		oldmem_type.total_size = oldmem_data.size;
-	}
+	/* For kdump, exclude memory used by the kdump kernel */
+	if (oldmem_data.start)
+		oldmem_type_init();
 
 	mem_chunk_cnt = get_mem_chunk_cnt();
 	phdr_text_cnt = os_info_has_vm() ? 1 : 0;
-- 
2.55.0


  parent reply	other threads:[~2026-11-12 11:21 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 11:20 [PATCH v1 0/8] s390/kdump: Add crashkernel CMA support Mikhail Zaslonko
2026-11-12 11:20 ` [PATCH v1 1/8] s390/kdump: Enable crashkernel CMA infrastructure Mikhail Zaslonko
2026-11-12 11:20 ` [PATCH v1 2/8] s390/kdump: Reserve crashkernel CMA memory Mikhail Zaslonko
2026-11-12 11:21 ` [PATCH v1 3/8] s390/kexec: Pass crashkernel CMA ranges to the kdump kernel Mikhail Zaslonko
2026-11-12 11:21 ` [PATCH v1 4/8] s390/boot: Allow additional usable memory ranges Mikhail Zaslonko
2026-11-12 11:21 ` Mikhail Zaslonko [this message]
2026-11-12 11:21 ` [PATCH v1 6/8] s390/kdump: Use crashkernel CMA memory in the kdump kernel Mikhail Zaslonko
2026-11-12 11:21 ` [PATCH v1 7/8] s390/kdump: Skip the crashkernel CMA DMA wait Mikhail Zaslonko
2026-11-12 11:21 ` [PATCH v1 8/8] Documentation: kdump: Add s390 to crashkernel CMA Mikhail Zaslonko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261112112105.1169118-6-zaslonko@linux.ibm.com \
    --to=zaslonko@linux.ibm.com \
    --cc=agordeev@linux.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=baoquan.he@linux.dev \
    --cc=corbet@lwn.net \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=iii@linux.ibm.com \
    --cc=jbohac@suse.cz \
    --cc=kexec@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=pasha.tatashin@soleen.com \
    --cc=pratyush@kernel.org \
    --cc=rppt@kernel.org \
    --cc=ruirui.yang@linux.dev \
    --cc=usama.arif@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®