Skip to contentSkip to conversation

sparc64: Support reserving memory with memmap=xxx$yyy

PATCH In review Larry Bassel 2 participants 2 messages Dec 21, 2016 – Dec 26, 2016 SPARC + UltraSPARC (sparc/sparc64)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sparc64: Support reserving memory with memmap=xxx$yyy

The kernel commandline parameter memmap= was supported on several other architectures but not on SPARC (it was being ignored on SPARC).

Add support for the memmap=xxx$yyy commandline parameter (sparc64 only). The patch is based on the existing code for the "tile" architecture.

There are other types of memmap= commandlines which are only supported on x86 that are e820-specific. These were not implemented.

---
 arch/sparc/mm/init_64.c |   83 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 83 insertions(+), 0 deletions(-)
arch/sparc/mm/init_64.c +82 -0
index 65457c9..cbd905d 100644
@@ -744,6 +744,58 @@ do {	if (numa_debug) \
 		printk(KERN_INFO f, ## a); \
 } while (0)
 
+struct memmap_entry {
+	u64 addr;	/* start of memory segment */
+	u64 size;	/* size of memory segment */
+};
+static struct memmap_entry memmap_map[64];
+static int memmap_nr;
+
+static void add_memmap_region(u64 addr, u64 size)
+{
+	if (memmap_nr >= ARRAY_SIZE(memmap_map)) {
+		pr_err("Too many entries in the memory map!\n");
+		return;
+	}
+	memmap_map[memmap_nr].addr = addr;
+	memmap_map[memmap_nr].size = size;
+	memmap_nr++;
+}
+
+static int __init setup_memmap(char *p)
+{
+	char *oldp;
+	u64 start_at, mem_size;
+
+	if (!p)
+		return -EINVAL;
+
+	if (!strncmp(p, "exactmap", 8)) {
+		pr_err("\"memmap=exactmap\" not valid on SPARC\n");
+		return 0;
+	}
+
+	oldp = p;
+	mem_size = memparse(p, &p);
+	if (p = oldp)
+		return -EINVAL;
+
+	if (*p = '@') {
+		pr_err("\"memmap=nn@ss\" (force RAM) invalid on SPARC\n");
+	} else if (*p = '#') {
+		pr_err("\"memmap=nn#ss\" (force ACPI data) invalid on SPARC\n");
+	} else if (*p = '!') {
+		pr_err("\"memmap=nn!ss\" (mark as protected) invalid on SPARC\n");
+	} else if (*p = '$') {
+		start_at = memparse(p+1, &p);
+		add_memmap_region(start_at, mem_size);
+	} else {
+		pr_err("unsupported memmap option\n");
+	}
+	return *p = '\0' ? 0 : -EINVAL;
+}
+early_param("memmap", setup_memmap);
+
 static void __init find_ramdisk(unsigned long phys_base)
 {
 #ifdef CONFIG_BLK_DEV_INITRD
@@ -2179,6 +2231,12 @@ void __init paging_init(void)
 	if (cmdline_memory_size)
 		reduce_memory(cmdline_memory_size);
 
+	/* Reserve any memory excluded by "memmap" arguments. */
+	for (i = 0; i < memmap_nr; ++i) {
+		struct memmap_entry *m = &memmap_map[i];
+		memblock_remove(m->addr, m->size);
+	}
+
 	memblock_allow_resize();
 	memblock_dump_all();
 
@@ -2887,6 +2945,24 @@ static void __init kernel_lds_init(void)
 	bss_resource.end    = compute_kern_paddr(_end - 1);
 }
 
+static struct resource* __init
+insert_ram_resource(u64 start_pfn, u64 end_pfn, bool reserved)
+{
+	struct resource *res +		kzalloc(sizeof(struct resource), GFP_ATOMIC);
+	if (!res)
+		return NULL;
+	res->name = reserved ? "Reserved" : "System RAM";
+	res->start = start_pfn << PAGE_SHIFT;
+	res->end = (end_pfn << PAGE_SHIFT) - 1;
+	res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
+	if (insert_resource(&iomem_resource, res)) {
+		kfree(res);
+		return NULL;
+	}
+	return res;
+}
+
 static int __init report_memory(void)
 {
 	int i;
@@ -2917,6 +2993,13 @@ static int __init report_memory(void)
 		insert_resource(res, &bss_resource);
 	}
 
+	/* Mark any "memmap" regions busy for the resource manager. */
+	for (i = 0; i < memmap_nr; ++i) {
+		struct memmap_entry *m = &memmap_map[i];
+		insert_ram_resource(PFN_DOWN(m->addr),
+				    PFN_UP(m->addr + m->size - 1), 1);
+	}
+
 	return 0;
 }
 arch_initcall(report_memory);
Signature · 1 line
1.7.1
maintainer
#1 lore raw

From: Larry Bassel <[email protected]>
Date: Wed, 21 Dec 2016 14:24:16 -0800

Quoted 8 lines

The kernel commandline parameter memmap= was supported on several other architectures but not on SPARC (it was being ignored on SPARC).

Add support for the memmap=xxx$yyy commandline parameter (sparc64 only). The patch is based on the existing code for the "tile" architecture.

Quoted 5 lines

There are other types of memmap= commandlines which are only supported on x86 that are e820-specific. These were not implemented.

Are you adding this purely to achieve feature parity with other architectures, or do you have an actual use case for this?

Nobody has asked for this for two decades, so I don't see why adding it now has any real value without an actual user request.

And it's going to eat 1K of unswappable kernel space for something almost nobody will actually use.

Thanks.