From: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com,
ebiederm@xmission.com, akpm@linux-foundation.org,
stanislav.kinsburskii@gmail.com, corbet@lwn.net,
linux-kernel@vger.kernel.org, kexec@lists.infradead.org,
linux-mm@kvack.org, kys@microsoft.com, jgowans@amazon.com,
wei.liu@kernel.org, arnd@arndb.de, gregkh@linuxfoundation.org,
graf@amazon.de, pbonzini@redhat.com
Subject: [RFC PATCH v2 5/7] pmpool: Update device tree on kexec
Date: Mon, 25 Sep 2023 14:28:16 -0700 [thread overview]
Message-ID: <169567729602.19708.7544090989330715724.stgit@skinsburskii.> (raw)
In-Reply-To: <169567722094.19708.3583735425859054859.stgit@skinsburskii.>
From: Stanislav Kinsburskii <stanislav.kinsburskii@gmail.com>
Introduce a pmpool kexec fdt notifier that enables pmpool to pass its
metadata, including the bitmap address, to the new kernel during kexec.
Signed-off-by: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
---
mm/Kconfig | 1 +
mm/pmpool.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 64 insertions(+), 1 deletion(-)
diff --git a/mm/Kconfig b/mm/Kconfig
index e7c10094fb10..1eefdd4c82ba 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -925,6 +925,7 @@ config CMA_AREAS
config PMPOOL
bool "Persistent memory pool support"
select CMA
+ select LIBFDT
help
This option adds support for CMA-based persistent memory pool
feature, which provides pages allocation and freeing from a set of
diff --git a/mm/pmpool.c b/mm/pmpool.c
index 12a8cac75558..f2173db782d6 100644
--- a/mm/pmpool.c
+++ b/mm/pmpool.c
@@ -6,6 +6,7 @@
#include <linux/cma.h>
#include <linux/io.h>
#include <linux/kexec.h>
+#include <linux/libfdt.h>
#include <linux/memblock.h>
#include <linux/mm.h>
#include <linux/pmpool.h>
@@ -58,6 +59,59 @@ static int __init default_pmpool_fixup_cma(void)
}
postcore_initcall(default_pmpool_fixup_cma);
+static int pmpool_fdt_update(struct notifier_block *nb, unsigned long val,
+ void *data)
+{
+ void *fdt = data;
+ int node, status;
+
+ if (!fdt)
+ goto err;
+
+ node = fdt_subnode_offset(fdt, 0, "chosen");
+ if (node < 0) {
+ node = fdt_add_subnode(fdt, 0, "chosen");
+ if (node < 0)
+ goto err;
+ }
+
+ node = fdt_add_subnode(fdt, node, "default_pmpool");
+ if (node == -FDT_ERR_EXISTS)
+ return 0;
+ if (node < 0)
+ goto err;
+
+ status = fdt_setprop(fdt, node, "compatible",
+ "pmpool", sizeof("pmpool"));
+ if (status)
+ goto err;
+
+ status = fdt_setprop_u64(fdt, node, "bitmap",
+ virt_to_phys(default_pmpool->cma->bitmap));
+ if (status)
+ goto err;
+
+ status = fdt_setprop_u64(fdt, node, "size",
+ default_pmpool->cma->count << PAGE_SHIFT);
+ if (status)
+ goto err;
+
+ status = fdt_setprop_u64(fdt, node, "base",
+ default_pmpool->cma->base_pfn << PAGE_SHIFT);
+ if (status)
+ goto err;
+
+ return NOTIFY_DONE;
+
+err:
+ pr_err("failed to update fdt\n");
+ return NOTIFY_DONE;
+}
+
+static struct notifier_block pmpool_kexec_fdt_nb = {
+ .notifier_call = pmpool_fdt_update,
+};
+
static int __init parse_pmpool_opt(char *str)
{
static struct pmpool pmpool;
@@ -80,10 +134,16 @@ static int __init parse_pmpool_opt(char *str)
return 0;
}
+ err = register_kexec_fdt_notifier(&pmpool_kexec_fdt_nb);
+ if (err) {
+ pr_err("failed to register kexec fdt notifier: %d\n", err);
+ goto free_memblock;
+ }
+
err = cma_init_reserved_mem(base, size, 0, "pmpool", &pmpool.cma);
if (err) {
pr_err("failed to initialize CMA: %d\n", err);
- goto free_memblock;
+ goto notifier_unregister;
}
pr_info("default memory pool is created: %#llx-%#llx\n",
@@ -93,6 +153,8 @@ static int __init parse_pmpool_opt(char *str)
return 0;
+notifier_unregister:
+ unregister_kexec_fdt_notifier(&pmpool_kexec_fdt_nb);
free_memblock:
memblock_phys_free(base, size);
return 0;
next prev parent reply other threads:[~2023-09-25 21:28 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-25 21:27 [RFC PATCH v2 0/7] Introduce persistent memory pool Stanislav Kinsburskii
2023-09-25 21:27 ` [RFC PATCH v2 1/7] kexec_file: Add fdt modification callback support Stanislav Kinsburskii
2023-09-25 21:27 ` [RFC PATCH v2 2/7] x86: kexec: Transfer existing fdt to the new kernel Stanislav Kinsburskii
2023-09-25 21:28 ` [RFC PATCH v2 3/7] x86: kexec: Enable fdt modification in callbacks Stanislav Kinsburskii
2023-09-25 21:28 ` [RFC PATCH v2 4/7] pmpool: Introduce persistent memory pool Stanislav Kinsburskii
2023-09-25 21:28 ` Stanislav Kinsburskii [this message]
2023-09-25 21:28 ` [RFC PATCH v2 6/7] pmpool: Restore state from device tree post-kexec Stanislav Kinsburskii
2023-09-25 21:28 ` [RFC PATCH v2 7/7] Drivers: hv: Allocate persistent pages for root partition Stanislav Kinsburskii
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=169567729602.19708.7544090989330715724.stgit@skinsburskii. \
--to=skinsburskii@linux.microsoft.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=bp@alien8.de \
--cc=corbet@lwn.net \
--cc=dave.hansen@linux.intel.com \
--cc=ebiederm@xmission.com \
--cc=graf@amazon.de \
--cc=gregkh@linuxfoundation.org \
--cc=hpa@zytor.com \
--cc=jgowans@amazon.com \
--cc=kexec@lists.infradead.org \
--cc=kys@microsoft.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=stanislav.kinsburskii@gmail.com \
--cc=tglx@linutronix.de \
--cc=wei.liu@kernel.org \
--cc=x86@kernel.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