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 2/7] x86: kexec: Transfer existing fdt to the new kernel
Date: Mon, 25 Sep 2023 14:27:54 -0700 [thread overview]
Message-ID: <169567727460.19708.8733721379247990958.stgit@skinsburskii.> (raw)
In-Reply-To: <169567722094.19708.3583735425859054859.stgit@skinsburskii.>
From: Stanislav Kinsburskii <stanislav.kinsburskii@gmail.com>
Enable passing of the Flattened Device Tree (fdt) over kexec for x86
architecture, as outlined in Documentation/x86/booting-dt.rst.
Signed-off-by: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
---
arch/x86/Kconfig | 8 +++++
arch/x86/kernel/kexec-bzimage64.c | 58 +++++++++++++++++++++++++++++++++++++
2 files changed, 66 insertions(+)
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index e36261b4ea14..efb472e267ec 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -2070,6 +2070,14 @@ config KEXEC_FILE
for kernel and initramfs as opposed to list of segments as
accepted by previous system call.
+config KEXEC_FILE_FDT
+ bool "Pass fdt over kexec"
+ depends on KEXEC_FILE && X86_64
+ depends on OF_FLATTREE
+ help
+ This option enables passing existent Flattened Device Tree to the new
+ kernel when kexec is invoked by the file based system call.
+
config ARCH_HAS_KEXEC_PURGATORY
def_bool KEXEC_FILE
diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c
index a61c12c01270..ab9ae02c9a5f 100644
--- a/arch/x86/kernel/kexec-bzimage64.c
+++ b/arch/x86/kernel/kexec-bzimage64.c
@@ -18,6 +18,8 @@
#include <linux/mm.h>
#include <linux/efi.h>
#include <linux/random.h>
+#include <linux/of_fdt.h>
+#include <linux/libfdt.h>
#include <asm/bootparam.h>
#include <asm/setup.h>
@@ -381,7 +383,59 @@ static int bzImage64_probe(const char *buf, unsigned long len)
return ret;
}
+#ifdef CONFIG_KEXEC_FILE_FDT
+static void *fdt_get_runtime(void)
+{
+ return initial_boot_params;
+}
+
+static int kexec_setup_fdt(struct kexec_buf *kbuf, struct boot_params *params)
+{
+ void *fdt;
+ struct setup_data *sd;
+ unsigned long fdt_load_addr, fdt_sz;
+ int ret;
+
+ fdt = fdt_get_runtime();
+ if (!fdt)
+ return 0;
+
+ fdt_sz = fdt_totalsize(fdt);
+
+ kbuf->bufsz = kbuf->memsz = sizeof(struct setup_data) + fdt_sz;
+
+ sd = kzalloc(kbuf->bufsz, GFP_KERNEL);
+ if (!sd)
+ return -ENOMEM;
+
+ kbuf->buffer = sd;
+ kbuf->buf_align = PAGE_SIZE;
+ kbuf->buf_min = MIN_INITRD_LOAD_ADDR;
+ kbuf->mem = KEXEC_BUF_MEM_UNKNOWN;
+ ret = kexec_add_buffer(kbuf);
+ if (ret)
+ return ret;
+
+ fdt_load_addr = kbuf->mem;
+ pr_debug("Loaded fdt at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
+ fdt_load_addr, fdt_sz, fdt_sz);
+
+ sd->type = SETUP_DTB;
+ sd->len = fdt_sz;
+ memcpy(sd->data, fdt, fdt_sz);
+
+ sd->next = params->hdr.setup_data;
+ params->hdr.setup_data = fdt_load_addr;
+
+ return 0;
+}
+#else
+static int kexec_setup_fdt(struct kexec_buf *kbuf, struct boot_params *params)
+{
+ return 0;
+}
+#endif
static void *bzImage64_load(struct kimage *image, char *kernel,
unsigned long kernel_len, char *initrd,
unsigned long initrd_len, char *cmdline,
@@ -561,6 +615,10 @@ static void *bzImage64_load(struct kimage *image, char *kernel,
if (ret)
goto out_free_params;
+ ret = kexec_setup_fdt(&kbuf, params);
+ if (ret)
+ goto out_free_params;
+
/* Allocate loader specific data */
ldata = kzalloc(sizeof(struct bzimage64_data), GFP_KERNEL);
if (!ldata) {
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 ` Stanislav Kinsburskii [this message]
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 ` [RFC PATCH v2 5/7] pmpool: Update device tree on kexec Stanislav Kinsburskii
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=169567727460.19708.8733721379247990958.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