linux-mips.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Serge Semin <fancer.lancer@gmail.com>
To: ralf@linux-mips.org, paul.burton@imgtec.com, rabinv@axis.com,
	matt.redfearn@imgtec.com, james.hogan@imgtec.com,
	alexander.sverdlin@nokia.com, robh+dt@kernel.org,
	frowand.list@gmail.com
Cc: Sergey.Semin@t-platforms.ru, linux-mips@linux-mips.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	Serge Semin <fancer.lancer@gmail.com>
Subject: [PATCH 07/21] MIPS memblock: Alter elfcorehdr parameters parser
Date: Mon, 19 Dec 2016 05:07:32 +0300	[thread overview]
Message-ID: <1482113266-13207-8-git-send-email-fancer.lancer@gmail.com> (raw)
In-Reply-To: <1482113266-13207-1-git-send-email-fancer.lancer@gmail.com>

Memblock API can be successfully used to verify whether elfcorehdr
memory region belongs to lowmemory, then it can be reserved within
memblock allocator. There is also available default method for
early parameters parser in kernel/crash_dump.c: setup_elfcorehdr(),
so it's wise to use one instead of creating our own doing actually
the same thing.

Signed-off-by: Serge Semin <fancer.lancer@gmail.com>
---
 arch/mips/kernel/setup.c | 91 +++++++++++++++++-------------
 1 file changed, 52 insertions(+), 39 deletions(-)

diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index cc6d06b..52205fb 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -426,6 +426,55 @@ static void __init mips_reserve_initrd_mem(void) { }
 
 #endif
 
+/*
+ * Reserve memory occupied by elfcorehdr
+ */
+static void __init mips_reserve_elfcorehdr(void)
+{
+#ifdef CONFIG_PROC_VMCORE
+	/*
+	 * Don't reserve anything if kernel isn't booting after a panic and
+	 * vmcore is usable (see linux/crash_dump.h for details)
+	 */
+	if (!is_vmcore_usable())
+		return;
+
+	/* Check whether the passed address belongs to low memory */
+	if (elfcorehdr_addr + elfcorehdr_size >= mips_lowmem_limit) {
+		pr_err("Elfcorehdr %08zx @ %pa doesn't belong to low memory",
+			(size_t)elfcorehdr_size, &elfcorehdr_addr);
+		return;
+	}
+
+	/*
+	 * If elfcorehdr_size hasn't been specified, then try to reserve upto
+	 * low memory limit
+	 */
+	if (!elfcorehdr_size)
+		elfcorehdr_size = mips_lowmem_limit - elfcorehdr_addr;
+
+	/* Check the region belongs to actual memory (size can be zero) */
+	if (!memblock_is_region_memory(elfcorehdr_addr, elfcorehdr_size)) {
+		pr_err("Elfcorehdr %08zx @ %pa is not a memory region",
+			(size_t)elfcorehdr_size, &elfcorehdr_addr);
+		return;
+	}
+
+	/* Check whether elfcorehdr region is free */
+	if (memblock_is_region_reserved(elfcorehdr_addr, elfcorehdr_size)) {
+		pr_err("Elfcorehdr %08zx @ %pa overlaps in-use memory",
+			(size_t)elfcorehdr_size, &elfcorehdr_addr);
+		return;
+	}
+
+	/* Reserve elfcorehdr within memblock */
+	memblock_reserve(elfcorehdr_addr, PAGE_ALIGN(elfcorehdr_size));
+
+	pr_info("Reserved memory for kdump at %08zx @ %pa\n",
+		(size_t)elfcorehdr_size, &elfcorehdr_addr);
+#endif /* CONFIG_PROC_VMCORE */
+}
+
 #ifdef CONFIG_KEXEC
 /*
  * Parse passed crashkernel parameter and reserve corresponding memory
@@ -499,6 +548,9 @@ static void __init bootmem_init(void)
 	/* Check and reserve memory occupied by initrd */
 	mips_reserve_initrd_mem();
 
+	/* Reserve memory for elfcorehdr */
+	mips_reserve_elfcorehdr();
+
 	/* Parse crashkernel parameter */
 	mips_parse_crashkernel();
 
@@ -719,37 +771,6 @@ static void __init bootmem_init(void)
  * initialization hook for anything else was introduced.
  */
 
-#ifdef CONFIG_PROC_VMCORE
-unsigned long setup_elfcorehdr, setup_elfcorehdr_size;
-static int __init early_parse_elfcorehdr(char *p)
-{
-	int i;
-
-	setup_elfcorehdr = memparse(p, &p);
-
-	for (i = 0; i < boot_mem_map.nr_map; i++) {
-		unsigned long start = boot_mem_map.map[i].addr;
-		unsigned long end = (boot_mem_map.map[i].addr +
-				     boot_mem_map.map[i].size);
-		if (setup_elfcorehdr >= start && setup_elfcorehdr < end) {
-			/*
-			 * Reserve from the elf core header to the end of
-			 * the memory segment, that should all be kdump
-			 * reserved memory.
-			 */
-			setup_elfcorehdr_size = end - setup_elfcorehdr;
-			break;
-		}
-	}
-	/*
-	 * If we don't find it in the memory map, then we shouldn't
-	 * have to worry about it, as the new kernel won't use it.
-	 */
-	return 0;
-}
-early_param("elfcorehdr", early_parse_elfcorehdr);
-#endif
-
 static void __init arch_mem_addpart(phys_addr_t mem, phys_addr_t end, int type)
 {
 	phys_addr_t size;
@@ -833,14 +854,6 @@ static void __init arch_mem_init(char **cmdline_p)
 	parse_early_param();
 
 	bootmem_init();
-#ifdef CONFIG_PROC_VMCORE
-	if (setup_elfcorehdr && setup_elfcorehdr_size) {
-		printk(KERN_INFO "kdump reserved memory at %lx-%lx\n",
-		       setup_elfcorehdr, setup_elfcorehdr_size);
-		reserve_bootmem(setup_elfcorehdr, setup_elfcorehdr_size,
-				BOOTMEM_DEFAULT);
-	}
-#endif
 
 	device_tree_init();
 	sparse_init();
-- 
2.6.6

  parent reply	other threads:[~2016-12-19  2:11 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-19  2:07 [PATCH 00/21] MIPS memblock: Remove bootmem code and switch to NO_BOOTMEM Serge Semin
2016-12-19  2:07 ` [PATCH 01/21] MIPS memblock: Unpin dts memblock sanity check method Serge Semin
2016-12-19  4:21   ` kbuild test robot
2016-12-19  4:21     ` kbuild test robot
2016-12-19  4:28   ` kbuild test robot
2016-12-19  4:28     ` kbuild test robot
2016-12-22 20:57   ` Rob Herring
2016-12-22 21:57     ` Serge Semin
2016-12-19  2:07 ` [PATCH 02/21] MIPS memblock: Add dts mem and reserved-mem callbacks Serge Semin
2016-12-19  4:13   ` kbuild test robot
2016-12-19  4:13     ` kbuild test robot
2016-12-19  2:07 ` [PATCH 03/21] MIPS memblock: Alter traditional add_memory_region() method Serge Semin
2016-12-19  2:07 ` [PATCH 04/21] MIPS memblock: Alter user-defined memory parameter parser Serge Semin
2017-01-23  7:55   ` Marcin Nowakowski
2017-01-23  7:55     ` Marcin Nowakowski
2016-12-19  2:07 ` [PATCH 05/21] MIPS memblock: Alter initrd memory reservation method Serge Semin
2016-12-19  5:08   ` kbuild test robot
2016-12-19  5:08     ` kbuild test robot
2016-12-19  2:07 ` [PATCH 06/21] MIPS memblock: Alter kexec-crashkernel parameters parser Serge Semin
2016-12-19  2:07 ` Serge Semin [this message]
2016-12-19  4:09   ` [PATCH 07/21] MIPS memblock: Alter elfcorehdr " kbuild test robot
2016-12-19  4:09     ` kbuild test robot
2016-12-19  2:07 ` [PATCH 08/21] MIPS memblock: Move kernel parameters parser into individual method Serge Semin
2016-12-19  2:07 ` [PATCH 09/21] MIPS memblock: Move kernel memory reservation to " Serge Semin
2016-12-19  2:07 ` [PATCH 10/21] MIPS memblock: Discard bootmem allocator initialization Serge Semin
2016-12-19  4:28   ` kbuild test robot
2016-12-19  4:28     ` kbuild test robot
2017-01-23  7:55   ` Marcin Nowakowski
2017-01-23  7:55     ` Marcin Nowakowski
2016-12-19  2:07 ` [PATCH 11/21] MIPS memblock: Add memblock sanity check method Serge Semin
2016-12-19  2:07 ` [PATCH 12/21] MIPS memblock: Add memblock print outs in debug Serge Semin
2016-12-19  2:07 ` [PATCH 13/21] MIPS memblock: Add memblock allocator initialization Serge Semin
2016-12-19  2:07 ` [PATCH 14/21] MIPS memblock: Alter IO resources initialization method Serge Semin
2016-12-19  2:07 ` [PATCH 15/21] MIPS memblock: Alter weakened MAAR " Serge Semin
2016-12-19  2:07 ` [PATCH 16/21] MIPS memblock: Alter paging " Serge Semin
2016-12-19  2:07 ` [PATCH 17/21] MIPS memblock: Alter high memory freeing method Serge Semin
2016-12-19  2:07 ` [PATCH 18/21] MIPS memblock: Slightly improve buddy allocator init method Serge Semin
2016-12-19  2:07 ` [PATCH 19/21] MIPS memblock: Add print out method of kernel virtual memory layout Serge Semin
2016-12-19 12:04   ` Matt Redfearn
2016-12-19 12:04     ` Matt Redfearn
2016-12-19 12:09     ` Serge Semin
2016-12-19 13:02     ` James Hogan
2016-12-19 13:02       ` James Hogan
2016-12-19 13:15       ` Serge Semin
2016-12-19  2:07 ` [PATCH 20/21] MIPS memblock: Add free low memory test method call Serge Semin
2016-12-19  2:07 ` [PATCH 21/21] MIPS memblock: Deactivate old bootmem allocator Serge Semin
2017-01-23  7:55 ` [PATCH 00/21] MIPS memblock: Remove bootmem code and switch to NO_BOOTMEM Marcin Nowakowski
2017-01-23  7:55   ` Marcin Nowakowski
2017-03-02  3:06   ` Florian Fainelli
2017-01-23 14:51 ` Joshua Kinard
2017-05-22  9:48 ` Marcin Nowakowski
2017-05-22  9:48   ` Marcin Nowakowski
2017-05-22 10:26   ` Serge Semin
2017-05-22 12:19     ` Marcin Nowakowski
2017-05-22 12:19       ` Marcin Nowakowski
2017-05-22 12:47     ` Joshua Kinard
2017-05-22 13:03       ` Serge Semin
2017-05-22 13:20         ` Alexander Sverdlin
2017-05-22 13:20           ` Alexander Sverdlin
2017-05-22 13:29           ` Serge Semin

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=1482113266-13207-8-git-send-email-fancer.lancer@gmail.com \
    --to=fancer.lancer@gmail.com \
    --cc=Sergey.Semin@t-platforms.ru \
    --cc=alexander.sverdlin@nokia.com \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=james.hogan@imgtec.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@linux-mips.org \
    --cc=matt.redfearn@imgtec.com \
    --cc=paul.burton@imgtec.com \
    --cc=rabinv@axis.com \
    --cc=ralf@linux-mips.org \
    --cc=robh+dt@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).