From: Taeho Hwang <taeho1224@gmail.com>
To: linux-nvdimm@lists.01.org
Subject: [PATCH] pmem: emulating usable memory as persistent memory
Date: Thu, 26 Sep 2019 12:30:53 +0900 [thread overview]
Message-ID: <1569468653-3489-1-git-send-email-taeho1224@gmail.com> (raw)
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
next reply other threads:[~2019-09-26 3:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-26 3:30 Taeho Hwang [this message]
2019-09-26 3:58 ` [PATCH] pmem: emulating usable memory as persistent memory Dan Williams
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=1569468653-3489-1-git-send-email-taeho1224@gmail.com \
--to=taeho1224@gmail.com \
--cc=linux-nvdimm@lists.01.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).