From: Cong Wang <xiyou.wangcong@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: jiri@resnulli.us, stefanha@redhat.com,
multikernel@lists.linux.dev, pasha.tatashin@soleen.com,
Cong Wang <cwang@multikernel.io>,
Andrew Morton <akpm@linux-foundation.org>,
Baoquan He <bhe@redhat.com>, Alexander Graf <graf@amazon.com>,
Mike Rapoport <rppt@kernel.org>,
Changyuan Lyu <changyuanl@google.com>,
kexec@lists.infradead.org, linux-mm@kvack.org
Subject: [RFC Patch v2 11/16] kexec: Add /proc/kimage interface for kimage tracking
Date: Sat, 18 Oct 2025 23:16:25 -0700 [thread overview]
Message-ID: <20251019061631.2235405-12-xiyou.wangcong@gmail.com> (raw)
In-Reply-To: <20251019061631.2235405-1-xiyou.wangcong@gmail.com>
From: Cong Wang <cwang@multikernel.io>
Add a dedicated /proc/kimage file to provide read-only access to
all loaded kernel images in the system, for both regular kexec kernel
images and multikernel images.
The interface displays kernel images in a tabular format showing:
- Type: kexec type (default, crash, multikernel)
- Start Address: entry point in hexadecimal format
- Segments: number of memory segments
This interface is particularly useful for inspecting kimages, debugging
kexec, and verifying that kernel images are loaded correctly.
Signed-off-by: Cong Wang <cwang@multikernel.io>
---
kernel/kexec_core.c | 63 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+)
diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
index ed5c97b4531e..7db755e64dd6 100644
--- a/kernel/kexec_core.c
+++ b/kernel/kexec_core.c
@@ -13,6 +13,8 @@
#include <linux/slab.h>
#include <linux/fs.h>
#include <linux/kexec.h>
+#include <linux/proc_fs.h>
+#include <linux/seq_file.h>
#include <linux/mutex.h>
#include <linux/list.h>
#include <linux/highmem.h>
@@ -1214,6 +1216,52 @@ struct kimage *kexec_image;
struct kimage *kexec_crash_image;
static int kexec_load_disabled;
+/*
+ * Proc interface for /proc/kimage
+ */
+static int kimage_proc_show(struct seq_file *m, void *v)
+{
+ struct kimage *image;
+ const char *type_names[] = {
+ [KEXEC_TYPE_DEFAULT] = "default",
+ [KEXEC_TYPE_CRASH] = "crash",
+ [KEXEC_TYPE_MULTIKERNEL] = "multikernel"
+ };
+
+ seq_printf(m, "MK_ID Type Start Address Segments\n");
+ seq_printf(m, "----- ---------- -------------- --------\n");
+
+ kimage_list_lock();
+ if (list_empty(&kexec_image_list)) {
+ seq_printf(m, "No kimages loaded\n");
+ } else {
+ list_for_each_entry(image, &kexec_image_list, list) {
+ const char *type_name = "unknown";
+
+ if (image->type < ARRAY_SIZE(type_names) && type_names[image->type])
+ type_name = type_names[image->type];
+
+ seq_printf(m, "%5d %-10s 0x%012lx %8lu\n",
+ image->mk_id, type_name, image->start, image->nr_segments);
+ }
+ }
+ kimage_list_unlock();
+
+ return 0;
+}
+
+static int kimage_proc_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, kimage_proc_show, NULL);
+}
+
+static const struct proc_ops kimage_proc_ops = {
+ .proc_open = kimage_proc_open,
+ .proc_read = seq_read,
+ .proc_lseek = seq_lseek,
+ .proc_release = single_release,
+};
+
#ifdef CONFIG_SYSCTL
static int kexec_limit_handler(const struct ctl_table *table, int write,
void *buffer, size_t *lenp, loff_t *ppos)
@@ -1285,6 +1333,21 @@ static int __init kexec_core_sysctl_init(void)
late_initcall(kexec_core_sysctl_init);
#endif
+static int __init kimage_proc_init(void)
+{
+ struct proc_dir_entry *entry;
+
+ entry = proc_create("kimage", 0444, NULL, &kimage_proc_ops);
+ if (!entry) {
+ pr_err("Failed to create /proc/kimage\n");
+ return -ENOMEM;
+ }
+
+ pr_debug("Created /proc/kimage interface\n");
+ return 0;
+}
+late_initcall(kimage_proc_init);
+
bool kexec_load_permitted(int kexec_image_type)
{
struct kexec_load_limit *limit;
--
2.34.1
next prev parent reply other threads:[~2025-10-19 6:17 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-19 6:16 [RFC Patch v2 00/16] kernel: Introduce multikernel architecture support Cong Wang
2025-10-19 6:16 ` [RFC Patch v2 01/16] kexec: Introduce multikernel support via kexec Cong Wang
2025-10-19 6:16 ` [RFC Patch v2 02/16] x86: Introduce SMP INIT trampoline for multikernel CPU bootstrap Cong Wang
2025-10-19 6:16 ` [RFC Patch v2 03/16] multikernel: Introduce basic multikernel subsystem infrastructure Cong Wang
2025-10-19 6:16 ` [RFC Patch v2 04/16] x86: Introduce MULTIKERNEL_VECTOR for inter-kernel communication Cong Wang
2025-10-19 6:16 ` [RFC Patch v2 05/16] x86: Introduce arch_cpu_physical_id() to obtain physical CPU ID Cong Wang
2025-10-19 6:16 ` [RFC Patch v2 06/16] multikernel: Introduce physical memory reservation and allocation Cong Wang
2025-10-19 6:16 ` [RFC Patch v2 07/16] kexec: Implement dynamic kimage tracking Cong Wang
2025-10-19 6:16 ` [RFC Patch v2 08/16] multikernel: Introduce device-tree based kernfs interface Cong Wang
2025-10-19 6:16 ` [RFC Patch v2 09/16] kexec: Integrate multikernel instance management with kexec subsystem Cong Wang
2025-10-19 6:16 ` [RFC Patch v2 10/16] Documentation: Add multikernel usage Cong Wang
2025-10-19 6:16 ` Cong Wang [this message]
2025-10-19 6:16 ` [RFC Patch v2 12/16] multikernel: Introduce per-instance memory allocation interface Cong Wang
2025-10-19 6:16 ` [RFC Patch v2 13/16] kernel: Introduce generic multikernel IPI communication framework Cong Wang
2025-10-19 6:16 ` [RFC Patch v2 14/16] multikernel: Add messaging layer for inter-kernel communication Cong Wang
2025-10-19 6:16 ` [RFC Patch v2 15/16] kexec: Integrate multikernel support with kexec_file_load() Cong Wang
2025-10-19 6:16 ` [RFC Patch v2 16/16] multikernel: Integrate Kexec HandOver framework for DTB preservation Cong Wang
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=20251019061631.2235405-12-xiyou.wangcong@gmail.com \
--to=xiyou.wangcong@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=bhe@redhat.com \
--cc=changyuanl@google.com \
--cc=cwang@multikernel.io \
--cc=graf@amazon.com \
--cc=jiri@resnulli.us \
--cc=kexec@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=multikernel@lists.linux.dev \
--cc=pasha.tatashin@soleen.com \
--cc=rppt@kernel.org \
--cc=stefanha@redhat.com \
/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