Skip to contentSkip to conversation

pmem: emulating usable memory as persistent memory

PATCH In review Taeho Hwang 2 participants 2 messages Sep 26, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pmem: emulating usable memory as persistent memory

This patch checks whether the specified memory (memmap) is userable or not. This patch prevents non-existing memory from being emulated as persistent memory.
If non-existing memory is specified by memmap without this patch, struct nd_namespace_io and struct pmem_device will have invalid values.

---
 arch/x86/kernel/e820.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 55 insertions(+), 1 deletion(-)
arch/x86/kernel/e820.c +55 -1
index 76dd605..ba9115d 100644
@@ -178,9 +178,63 @@ static void __init __e820__range_add(struct e820_table *table, u64 start, u64 si
 	table->nr_entries++;
 }
 
+static void __init __e820__range_add_pram(struct e820_table *table, u64 start,
+					  u64 size)
+{
+	int nr_entries = table->nr_entries;
+	int new_nr_entries = nr_entries;
+	u64 range_start, range_end;
+	u64 end = start + size;
+	bool flag;
+	int i;
+
+	if (nr_entries >= ARRAY_SIZE(table->entries)) {
+		pr_err("too many entries; ignoring [mem %#010llx-%#010llx]\n",
+		       start, start + size - 1);
+		return;
+	}
+
+	for (i = 0; i < nr_entries; i++) {
+		if (table->entries[i].type != E820_TYPE_RESERVED_KERN &&
+				table->entries[i].type != E820_TYPE_RAM)
+			continue;
+
+		range_start = table->entries[i].addr;
+		range_end = table->entries[i].addr + table->entries[i].size;
+		flag = false;
+		if (range_start <= start && start < range_end) {
+			table->entries[new_nr_entries].addr = start;
+			if (end <= range_end)
+				table->entries[new_nr_entries].size = size;
+			else
+				table->entries[new_nr_entries].size =
+					range_end - start;
+			flag = true;
+		} else if (range_start < end && end <= range_end) {
+			table->entries[new_nr_entries].addr = range_start;
+			table->entries[new_nr_entries].size = end - range_end;
+			flag = true;
+		} else if (start <= range_start && range_end <= end) {
+			table->entries[new_nr_entries].addr = range_start;
+			table->entries[new_nr_entries].size =
+				range_end - range_start;
+			flag = true;
+		}
+		if (flag) {
+			table->entries[new_nr_entries].type = E820_TYPE_PRAM;
+			if (++new_nr_entries >= ARRAY_SIZE(table->entries))
+				break;
+		}
+	}
+	table->nr_entries = new_nr_entries;
+}
+
 void __init e820__range_add(u64 start, u64 size, enum e820_type type)
 {
-	__e820__range_add(e820_table, start, size, type);
+	if (type == E820_TYPE_PRAM || type == E820_TYPE_PMEM)
+		__e820__range_add_pram(e820_table, start, size);
+	else
+		__e820__range_add(e820_table, start, size, type);
 }
 
 static void __init e820_print_type(enum e820_type type)
Signature · 6 lines
2.7.4

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
#1 lore raw
Quoted 7 lines · Taeho Hwang

This patch checks whether the specified memory (memmap) is userable or not. This patch prevents non-existing memory from being emulated as persistent memory.
If non-existing memory is specified by memmap without this patch, struct nd_namespace_io and struct pmem_device will have invalid values.

The whole point of the memmap= option is that the person specifying it knows more about the memory map than either the kernel or the platform BIOS. Validating the memmap= parameter against the very same memory map that is trying to be overridden violates that assumption. So memmap= is a dangerous interface on purpose. Now, if you want to define a new option that requires the base type to be E820_RAM that might be defensible, but at this point given the age of the memmap=ss!nn option and the wikis available to picking a valid value, I'd advocate leaving it as is.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm