From: Tao Liu <ltao@redhat.com>
To: yamazaki-msmt@nec.com, k-hagio-ab@nec.com, kexec@lists.infradead.org
Cc: aravinda@linux.vnet.ibm.com, stephen.s.brennan@oracle.com,
Tao Liu <ltao@redhat.com>
Subject: [PATCH v5][makedumpfile 7/9] Add sample extension as an example reference
Date: Tue, 14 Apr 2026 22:26:54 +1200 [thread overview]
Message-ID: <20260414102656.55200-8-ltao@redhat.com> (raw)
In-Reply-To: <20260414102656.55200-1-ltao@redhat.com>
This patch will add a sample.c as an example extension for code
reference. The extension will do nothing related to page filtering,
but print a few kernel symbol/type information.
Suggested-by: Kazuhito Hagio <k-hagio-ab@nec.com>
Signed-off-by: Tao Liu <ltao@redhat.com>
---
extensions/Makefile | 2 +-
extensions/sample.c | 69 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 70 insertions(+), 1 deletion(-)
create mode 100644 extensions/sample.c
diff --git a/extensions/Makefile b/extensions/Makefile
index b23f346..dbaec4e 100644
--- a/extensions/Makefile
+++ b/extensions/Makefile
@@ -1,5 +1,5 @@
CC ?= gcc
-CONTRIB_SO :=
+CONTRIB_SO := sample.so
all: $(CONTRIB_SO)
diff --git a/extensions/sample.c b/extensions/sample.c
new file mode 100644
index 0000000..e4938d1
--- /dev/null
+++ b/extensions/sample.c
@@ -0,0 +1,69 @@
+#include "../makedumpfile.h"
+#include "../btf_info.h"
+#include "../kallsyms.h"
+#include "../extension.h"
+
+/*
+ * Declare the kernel symbols/types that will be used by the extension later.
+ * The btf/kallsyms component of makedumpfile will resolve these requested
+ * info automatically during extension loading.
+ *
+ * The symbol/types declared by non-OPT macros as INIT_MOD_XX are must-have for
+ * the extension, any missing of these will lead to load-fail of the extension.
+ * This is useful to skip one extension as early. E.g. exit the amdgpu mm filtering
+ * extension when filtering against a vmcore dumpped by a machine which have
+ * no amdgpu hardware.
+ *
+ * The symbol/types declared by OPT macros as INIT_OPT_MOD_XX are optional,
+ * meaning the existence of these are checked during extension runtime. This
+ * is useful to cover different kernel versions where some of the data structure
+ * are slightly different.
+ */
+/* All kernel will have init_task and task_struct.mm */
+INIT_MOD_SYM(vmlinux, init_task);
+INIT_MOD_STRUCT_MEMBER(vmlinux, task_struct, mm);
+/*
+ * Older kernels use mm_struct.mm_rb,
+ * later ones use mm_struct.mm_mt
+ */
+INIT_OPT_MOD_STRUCT_MEMBER(vmlinux, mm_struct, mm_mt);
+INIT_OPT_MOD_STRUCT_MEMBER(vmlinux, mm_struct, mm_rb);
+
+/*
+ * Extension callback when makedumpfile is doing page filtering,
+ * extension should decide whether the given page should be kept(PG_INCLUDE),
+ * discarded(PG_EXCLUDE) or undecided(PG_UNDECID). Here we simply return
+ * PG_UNDECID to let every page fallbacks to traditinal page-flags
+ * check routine or let other extensions make the decision.
+ */
+int extension_callback(unsigned long pfn, const void *pcache)
+{
+ return PG_UNDECID;
+}
+
+/* Entry of extension */
+void extension_init(void)
+{
+ MSG("sample.so: The address of init_task is: %lx\n",
+ GET_MOD_SYM(vmlinux, init_task));
+ MSG("sample.so: The size of task_struct is: %d bytes\n",
+ GET_MOD_STRUCT_MEMBER_SSIZE(vmlinux, task_struct, mm));
+ MSG("sample.so: The offset of member mm within task_struct is: %d bytes\n",
+ GET_MOD_STRUCT_MEMBER_MOFF(vmlinux, task_struct, mm) / 8 );
+ MSG("sample.so: The size of member mm within task_struct is: %d bytes\n",
+ GET_MOD_STRUCT_MEMBER_MSIZE(vmlinux, task_struct, mm));
+ if (MOD_STRUCT_MEMBER_EXIST(vmlinux, mm_struct, mm_mt)) {
+ MSG("sample.so: Your kernel is using maple tree in mm_struct\n");
+ }
+ if (MOD_STRUCT_MEMBER_EXIST(vmlinux, mm_struct, mm_rb)) {
+ MSG("sample.so: Your kernel is using rb tree in mm_struct\n");
+ }
+}
+
+/*
+ * This function is called when the extension is unloaded.
+ * If desired, perform any cleanups here.
+ */
+__attribute__((destructor))
+void extension_cleanup(void) { }
+
--
2.47.0
next prev parent reply other threads:[~2026-04-14 10:27 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-14 10:26 [PATCH v5][makedumpfile 0/9] btf/kallsyms based makedumpfile extension for mm page filtering Tao Liu
2026-04-14 10:26 ` [PATCH v5][makedumpfile 1/9] Reserve sections for makedumpfile and extenions Tao Liu
2026-04-14 10:26 ` [PATCH v5][makedumpfile 2/9] Implement kernel kallsyms resolving Tao Liu
2026-04-14 10:26 ` [PATCH v5][makedumpfile 3/9] Implement kernel btf resolving Tao Liu
2026-04-14 10:26 ` [PATCH v5][makedumpfile 4/9] Implement kernel module's kallsyms resolving Tao Liu
2026-04-14 10:26 ` [PATCH v5][makedumpfile 5/9] Implement kernel module's btf resolving Tao Liu
2026-04-14 10:26 ` [PATCH v5][makedumpfile 6/9] Add makedumpfile extensions support Tao Liu
2026-04-14 10:26 ` Tao Liu [this message]
2026-04-14 10:26 ` [PATCH v5][makedumpfile 8/9] Doc: Add --extension option to makedumpfile manual Tao Liu
2026-04-14 10:26 ` [PATCH v5][makedumpfile 9/9] Add amdgpu mm pages filtering extension Tao Liu
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=20260414102656.55200-8-ltao@redhat.com \
--to=ltao@redhat.com \
--cc=aravinda@linux.vnet.ibm.com \
--cc=k-hagio-ab@nec.com \
--cc=kexec@lists.infradead.org \
--cc=stephen.s.brennan@oracle.com \
--cc=yamazaki-msmt@nec.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