Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1544305 > unrolled thread

[PATCH 00/21] MIPS memblock: Remove bootmem code and switch to NO_BOOTMEM

Started bySerge Semin <fancer.lancer@gmail.com>
First post2016-12-19 03:30 +0100
Last post2016-12-19 03:30 +0100
Articles 3 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH 00/21] MIPS memblock: Remove bootmem code and switch to NO_BOOTMEM Serge Semin <fancer.lancer@gmail.com> - 2016-12-19 03:30 +0100
    [PATCH 03/21] MIPS memblock: Alter traditional add_memory_region() method Serge Semin <fancer.lancer@gmail.com> - 2016-12-19 03:30 +0100
    [PATCH 04/21] MIPS memblock: Alter user-defined memory parameter parser Serge Semin <fancer.lancer@gmail.com> - 2016-12-19 03:30 +0100

#1544305 — [PATCH 00/21] MIPS memblock: Remove bootmem code and switch to NO_BOOTMEM

FromSerge Semin <fancer.lancer@gmail.com>
Date2016-12-19 03:30 +0100
Subject[PATCH 00/21] MIPS memblock: Remove bootmem code and switch to NO_BOOTMEM
Message-ID<sPVyO-1zj-23@gated-at.bofh.it>
Most of the modern platforms supported by linux kernel have already
been cleaned up of old bootmem allocator by moving to nobootmem
interface wrapping up the memblock. This patchset is the first
attempt to do the similar improvement for MIPS for UMA systems
only.

Even though the porting was performed as much careful as possible
there still might be problem with support of some platforms,
especially Loonson3 or SGI IP27, which perform early memory manager
initialization by their self.

The patchset is split so individual patch being consistent in
functional and buildable ways. But the MIPS early memory manager
will work correctly only either with or without the whole set being
applied. For the same reason a reviewer should not pay much attention
to methods bootmem_init(), arch_mem_init(), paging_init() and
mem_init() until they are fully refactored.

The patchset is applied on top of kernel v4.9.

Signed-off-by: Serge Semin <fancer.lancer@gmail.com>

Serge Semin (21):
  MIPS memblock: Unpin dts memblock sanity check method
  MIPS memblock: Add dts mem and reserved-mem callbacks
  MIPS memblock: Alter traditional add_memory_region() method
  MIPS memblock: Alter user-defined memory parameter parser
  MIPS memblock: Alter initrd memory reservation method
  MIPS memblock: Alter kexec-crashkernel parameters parser
  MIPS memblock: Alter elfcorehdr parameters parser
  MIPS memblock: Move kernel parameters parser into individual method
  MIPS memblock: Move kernel memory reservation to individual method
  MIPS memblock: Discard bootmem allocator initialization
  MIPS memblock: Add memblock sanity check method
  MIPS memblock: Add memblock print outs in debug
  MIPS memblock: Add memblock allocator initialization
  MIPS memblock: Alter IO resources initialization method
  MIPS memblock: Alter weakened MAAR initialization method
  MIPS memblock: Alter paging initialization method
  MIPS memblock: Alter high memory freeing method
  MIPS memblock: Slightly improve buddy allocator init method
  MIPS memblock: Add print out method of kernel virtual memory layout
  MIPS memblock: Add free low memory test method call
  MIPS memblock: Deactivate old bootmem allocator

 arch/mips/Kconfig        |   2 +-
 arch/mips/kernel/prom.c  |  32 +-
 arch/mips/kernel/setup.c | 958 +++++++++++++++--------------
 arch/mips/mm/init.c      | 234 ++++---
 drivers/of/fdt.c         |  47 +-
 include/linux/of_fdt.h   |   1 +
 6 files changed, 739 insertions(+), 535 deletions(-)

-- 
2.6.6

[toc] | [next] | [standalone]


#1544306 — [PATCH 03/21] MIPS memblock: Alter traditional add_memory_region() method

FromSerge Semin <fancer.lancer@gmail.com>
Date2016-12-19 03:30 +0100
Subject[PATCH 03/21] MIPS memblock: Alter traditional add_memory_region() method
Message-ID<sPVSa-1FQ-27@gated-at.bofh.it>
In reply to#1544305
There is no safe and fast way to get rid of boot_mem_map usage in
the wide set of platform code. But it's luck, that the architecture
specific code doesn't make any direct changes in the boot_mem_map
structure. Additionally the platform specific code registers the
available memory using traditional add_memory_region() method.
It's obvious, that one needs to be modified adding regions to both
new memblock allocator and old boot_mem_map subsystem. In this way
most of architecture specific code won't be broken.

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

diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index 084ba6c..9da6f8a 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -82,10 +82,19 @@ static struct resource data_resource = { .name = "Kernel data", };
 
 static void *detect_magic __initdata = detect_memory_region;
 
+/*
+ * General method to add RAM regions to the system
+ *
+ * NOTE Historically this method has been used to register memory blocks within
+ *      MIPS kernel code in the boot_mem_map array. So we need to support it
+ * up until it's discarded from platform-depended code.
+ * On the other hand it might be good to have it, since we can check regions
+ * before actually adding them
+ */
 void __init add_memory_region(phys_addr_t start, phys_addr_t size, long type)
 {
 	int x = boot_mem_map.nr_map;
-	int i;
+	int ret, i;
 
 	/*
 	 * If the region reaches the top of the physical address space, adjust
@@ -94,15 +103,51 @@ void __init add_memory_region(phys_addr_t start, phys_addr_t size, long type)
 	if (start + size - 1 == (phys_addr_t)ULLONG_MAX)
 		--size;
 
-	/* Sanity check */
+	/* Sanity check the region */
 	if (start + size < start) {
 		pr_warn("Trying to add an invalid memory region, skipped\n");
 		return;
 	}
 
+	/* Make sure the type is supported */
+	if (type != BOOT_MEM_RAM && type != BOOT_MEM_INIT_RAM &&
+	    type != BOOT_MEM_ROM_DATA && type != BOOT_MEM_RESERVED) {
+		pr_warn("Invalid type of memory region, skipped\n");
+		return;
+	}
+
 	/*
-	 * Try to merge with existing entry, if any.
+	 * According to the request_resource logic RAM, INIT and ROM shouldn't
+	 * intersect each other but being subset of one memory space
 	 */
+	if (type != BOOT_MEM_RESERVED && memblock_is_memory(start)) {
+		pr_warn("Drop already added memory region %08zx @ %pa\n",
+			(size_t)size, &start);
+		return;
+	}
+
+	/*
+	 * Add the region to the memblock allocator. Reserved regions should be
+	 * in the memory as well to be actually reserved.
+	 */
+	ret = memblock_add_node(start, size, 0);
+	if (ret < 0) {
+		pr_err("Could't add memblock %08zx @ %pa\n",
+			(size_t)size, &start);
+		return;
+	}
+
+	/* Reserve memory region passed with the corresponding flags */
+	if (type != BOOT_MEM_RAM) {
+		ret = memblock_reserve(start, size);
+		if (ret < 0) {
+			pr_err("Could't reserve memblock %08zx @ %pa\n",
+				(size_t)size, &start);
+			return;
+		}
+	}
+
+	/* Try to combine with existing entry, if any. */
 	for (i = 0; i < boot_mem_map.nr_map; i++) {
 		struct boot_mem_map_entry *entry = boot_mem_map.map + i;
 		unsigned long top;
-- 
2.6.6

[toc] | [prev] | [next] | [standalone]


#1544307 — [PATCH 04/21] MIPS memblock: Alter user-defined memory parameter parser

FromSerge Semin <fancer.lancer@gmail.com>
Date2016-12-19 03:30 +0100
Subject[PATCH 04/21] MIPS memblock: Alter user-defined memory parameter parser
Message-ID<sPVSa-1FQ-23@gated-at.bofh.it>
In reply to#1544305
Both new memblock and boot_mem_map subsystems need to be fully
cleared before a new memory region is added. So the early parser is
correspondingly modified.

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

diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index 9da6f8a..789aafe 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -229,6 +229,43 @@ static void __init print_memory_map(void)
 }
 
 /*
+ * Parse "mem=size@start" parameter rewriting a defined memory map
+ * We look for mem=size@start, where start and size are "value[KkMm]"
+ */
+static int __init early_parse_mem(char *p)
+{
+	static int usermem;
+	phys_addr_t start, size;
+
+	start = PHYS_OFFSET;
+	size = memparse(p, &p);
+	if (*p == '@')
+		start = memparse(p + 1, &p);
+
+	/*
+	 * If a user specifies memory size, we blow away any automatically
+	 * generated regions.
+	 */
+	if (usermem == 0) {
+		phys_addr_t ram_start = memblock_start_of_DRAM();
+		phys_addr_t ram_end = memblock_end_of_DRAM() - ram_start;
+
+		pr_notice("Discard memory layout %pa - %pa",
+			  &ram_start, &ram_end);
+
+		memblock_remove(ram_start, ram_end - ram_start);
+		boot_mem_map.nr_map = 0;
+		usermem = 1;
+	}
+	pr_notice("Add userdefined memory region %08zx @ %pa",
+		  (size_t)size, &start);
+
+	add_memory_region(start, size, BOOT_MEM_RAM);
+	return 0;
+}
+early_param("mem", early_parse_mem);
+
+/*
  * Manage initrd
  */
 #ifdef CONFIG_BLK_DEV_INITRD
@@ -613,31 +650,6 @@ static void __init bootmem_init(void)
  * initialization hook for anything else was introduced.
  */
 
-static int usermem __initdata;
-
-static int __init early_parse_mem(char *p)
-{
-	phys_addr_t start, size;
-
-	/*
-	 * If a user specifies memory size, we
-	 * blow away any automatically generated
-	 * size.
-	 */
-	if (usermem == 0) {
-		boot_mem_map.nr_map = 0;
-		usermem = 1;
-	}
-	start = 0;
-	size = memparse(p, &p);
-	if (*p == '@')
-		start = memparse(p + 1, &p);
-
-	add_memory_region(start, size, BOOT_MEM_RAM);
-	return 0;
-}
-early_param("mem", early_parse_mem);
-
 #ifdef CONFIG_PROC_VMCORE
 unsigned long setup_elfcorehdr, setup_elfcorehdr_size;
 static int __init early_parse_elfcorehdr(char *p)
@@ -797,11 +809,6 @@ static void __init arch_mem_init(char **cmdline_p)
 
 	parse_early_param();
 
-	if (usermem) {
-		pr_info("User-defined physical RAM map:\n");
-		print_memory_map();
-	}
-
 	bootmem_init();
 #ifdef CONFIG_PROC_VMCORE
 	if (setup_elfcorehdr && setup_elfcorehdr_size) {
-- 
2.6.6

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web