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 09/21] MIPS memblock: Move kernel memory reservation to individual method
Date: Mon, 19 Dec 2016 05:07:34 +0300 [thread overview]
Message-ID: <1482113266-13207-10-git-send-email-fancer.lancer@gmail.com> (raw)
In-Reply-To: <1482113266-13207-1-git-send-email-fancer.lancer@gmail.com>
The whole kernel text/data/bss must be reserved to prevent sudden
kernel crashes, for instance, due to unexpected non-zero default static
variables initializations.
Signed-off-by: Serge Semin <fancer.lancer@gmail.com>
---
arch/mips/kernel/setup.c | 117 +++++++++++++++--------------
1 file changed, 59 insertions(+), 58 deletions(-)
diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index 9c1a60d..e746793 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -472,6 +472,62 @@ static void __init mips_reserve_initrd_mem(void) { }
#endif
/*
+ * Reserve kernel code and data within memblock allocator
+ */
+static void __init mips_reserve_kernel_mem(void)
+{
+ phys_addr_t start, size;
+
+ /*
+ * Add kernel _text, _data, _bss, __init*, upto __end sections to
+ * boot_mem_map and memblock. We must reserve all of them!
+ */
+ start = __pa_symbol(&_text);
+ size = __pa_symbol(&_end) - start;
+ add_memory_region(start, size, BOOT_MEM_RAM);
+ /*
+ * It needs to be reserved within memblock as well. It's ok if memory
+ * has already been reserved with previous method
+ */
+ memblock_reserve(start, size);
+
+ /* Reserve nosave region for hibernation */
+ start = __pa_symbol(&__nosave_begin);
+ size = __pa_symbol(&__nosave_end) - start;
+ add_memory_region(start, size, BOOT_MEM_RAM);
+ memblock_reserve(start, size);
+
+ /* Initialize some init_mm fieldis. We may not need this? */
+ init_mm.start_code = (unsigned long)&_text;
+ init_mm.end_code = (unsigned long)&_etext;
+ init_mm.end_data = (unsigned long)&_edata;
+ init_mm.brk = (unsigned long)&_end;
+
+ /*
+ * The kernel reserves all memory below its _end symbol as bootmem,
+ * but the kernel may now be at a much higher address. The memory
+ * between the original and new locations may be returned to the system.
+ */
+#ifdef CONFIG_RELOCATABLE
+ if (__pa_symbol(&_text) > __pa_symbol(VMLINUX_LOAD_ADDRESS)) {
+ phys_addr_t offset;
+ extern void show_kernel_relocation(const char *level);
+
+ offset = __pa_symbol(_text) - __pa_symbol(VMLINUX_LOAD_ADDRESS);
+ memblock_free(__pa_symbol(VMLINUX_LOAD_ADDRESS), offset);
+
+#if defined(CONFIG_DEBUG_KERNEL) && defined(CONFIG_DEBUG_INFO)
+ /*
+ * This information is necessary when debugging the kernel
+ * But is a security vulnerability otherwise!
+ */
+ show_kernel_relocation(KERN_INFO);
+#endif
+ }
+#endif
+}
+
+/*
* Reserve memory occupied by elfcorehdr
*/
static void __init mips_reserve_elfcorehdr(void)
@@ -590,6 +646,9 @@ static void __init bootmem_init(void)
unsigned long bootmap_size;
int i;
+ /* Reserve kernel code/data memory */
+ mips_reserve_kernel_mem();
+
/* Check and reserve memory occupied by initrd */
mips_reserve_initrd_mem();
@@ -766,29 +825,6 @@ static void __init bootmem_init(void)
* Reserve the bootmap memory.
*/
reserve_bootmem(PFN_PHYS(mapstart), bootmap_size, BOOTMEM_DEFAULT);
-
-#ifdef CONFIG_RELOCATABLE
- /*
- * The kernel reserves all memory below its _end symbol as bootmem,
- * but the kernel may now be at a much higher address. The memory
- * between the original and new locations may be returned to the system.
- */
- if (__pa_symbol(_text) > __pa_symbol(VMLINUX_LOAD_ADDRESS)) {
- unsigned long offset;
- extern void show_kernel_relocation(const char *level);
-
- offset = __pa_symbol(_text) - __pa_symbol(VMLINUX_LOAD_ADDRESS);
- free_bootmem(__pa_symbol(VMLINUX_LOAD_ADDRESS), offset);
-
-#if defined(CONFIG_DEBUG_KERNEL) && defined(CONFIG_DEBUG_INFO)
- /*
- * This information is necessary when debugging the kernel
- * But is a security vulnerability otherwise!
- */
- show_kernel_relocation(KERN_INFO);
-#endif
- }
-#endif
}
#endif /* CONFIG_SGI_IP27 */
@@ -816,25 +852,6 @@ static void __init bootmem_init(void)
* initialization hook for anything else was introduced.
*/
-static void __init arch_mem_addpart(phys_addr_t mem, phys_addr_t end, int type)
-{
- phys_addr_t size;
- int i;
-
- size = end - mem;
- if (!size)
- return;
-
- /* Make sure it is in the boot_mem_map */
- for (i = 0; i < boot_mem_map.nr_map; i++) {
- if (mem >= boot_mem_map.map[i].addr &&
- mem < (boot_mem_map.map[i].addr +
- boot_mem_map.map[i].size))
- return;
- }
- add_memory_region(mem, size, type);
-}
-
static void __init arch_mem_init(char **cmdline_p)
{
struct memblock_region *reg;
@@ -846,19 +863,6 @@ static void __init arch_mem_init(char **cmdline_p)
/* Parse passed parameters */
mips_parse_param(cmdline_p);
- /*
- * Make sure all kernel memory is in the maps. The "UP" and
- * "DOWN" are opposite for initdata since if it crosses over
- * into another memory section you don't want that to be
- * freed when the initdata is freed.
- */
- arch_mem_addpart(PFN_DOWN(__pa_symbol(&_text)) << PAGE_SHIFT,
- PFN_UP(__pa_symbol(&_edata)) << PAGE_SHIFT,
- BOOT_MEM_RAM);
- arch_mem_addpart(PFN_UP(__pa_symbol(&__init_begin)) << PAGE_SHIFT,
- PFN_DOWN(__pa_symbol(&__init_end)) << PAGE_SHIFT,
- BOOT_MEM_INIT_RAM);
-
pr_info("Determined physical RAM map:\n");
print_memory_map();
@@ -873,9 +877,6 @@ static void __init arch_mem_init(char **cmdline_p)
for_each_memblock(reserved, reg)
if (reg->size != 0)
reserve_bootmem(reg->base, reg->size, BOOTMEM_DEFAULT);
-
- reserve_bootmem_region(__pa_symbol(&__nosave_begin),
- __pa_symbol(&__nosave_end)); /* Reserve for hibernation */
}
static void __init resource_init(void)
--
2.6.6
next prev parent reply other threads:[~2016-12-19 2:12 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 ` [PATCH 07/21] MIPS memblock: Alter elfcorehdr " Serge Semin
2016-12-19 4:09 ` 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 ` Serge Semin [this message]
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-10-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).