* [PATCH] pmem: emulating usable memory as persistent memory
@ 2019-09-26 3:30 Taeho Hwang
2019-09-26 3:58 ` Dan Williams
0 siblings, 1 reply; 2+ messages in thread
From: Taeho Hwang @ 2019-09-26 3:30 UTC (permalink / raw)
To: linux-nvdimm
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.
Signed-off-by: Taeho Hwang <taeho1224@gmail.com>
---
arch/x86/kernel/e820.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 55 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 76dd605..ba9115d 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -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)
--
2.7.4
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] pmem: emulating usable memory as persistent memory
2019-09-26 3:30 [PATCH] pmem: emulating usable memory as persistent memory Taeho Hwang
@ 2019-09-26 3:58 ` Dan Williams
0 siblings, 0 replies; 2+ messages in thread
From: Dan Williams @ 2019-09-26 3:58 UTC (permalink / raw)
To: Taeho Hwang; +Cc: linux-nvdimm
On Wed, Sep 25, 2019 at 8:31 PM Taeho Hwang <taeho1224@gmail.com> wrote:
>
> 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
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-09-26 3:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-26 3:30 [PATCH] pmem: emulating usable memory as persistent memory Taeho Hwang
2019-09-26 3:58 ` Dan Williams
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).