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 v3 4/8] Implement kernel modules' btf resolving
Date: Tue, 20 Jan 2026 15:54:56 +1300 [thread overview]
Message-ID: <20260120025500.25095-5-ltao@redhat.com> (raw)
In-Reply-To: <20260120025500.25095-1-ltao@redhat.com>
Same as the previous patch, with kernel's kallsyms and btf ready,
we can locate and iterate all kernel modules' btf data.
Signed-off-by: Tao Liu <ltao@redhat.com>
---
btf_info.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
btf_info.h | 2 ++
2 files changed, 76 insertions(+)
diff --git a/btf_info.c b/btf_info.c
index e7f8d9a..752661c 100644
--- a/btf_info.c
+++ b/btf_info.c
@@ -184,3 +184,77 @@ out:
free(buf);
return ret;
}
+
+#define MEMBER_OFF(S, M) \
+ GET_STRUCT_MEMBER_MOFF(S, M) / 8
+
+bool init_module_btf(void)
+{
+ struct btf *btf_mod;
+ uint64_t btf_modules, list;
+ struct struct_member_info smi;
+ uint64_t btf = 0, data = 0, module = 0;
+ int data_size = 0;
+ bool ret = false;
+ char *btf_buf = NULL;
+ char *modname = NULL;
+
+ btf_modules = get_kallsyms_value_by_name("btf_modules");
+ if (!btf_modules)
+ /* Maybe module is not enabled, this is not an error */
+ return true;
+
+ INIT_STRUCT_MEMBER(btf_module, list);
+ INIT_STRUCT_MEMBER(btf_module, btf);
+ INIT_STRUCT_MEMBER(btf_module, module);
+ INIT_STRUCT_MEMBER(module, name);
+ INIT_STRUCT_MEMBER(btf, data);
+ INIT_STRUCT_MEMBER(btf, data_size);
+ modname = (char *)malloc(GET_STRUCT_MEMBER_MSIZE(module, name));
+ if (!modname)
+ goto no_mem;
+
+ for (list = next_list(btf_modules); list != btf_modules; list = next_list(list)) {
+ readmem(VADDR, list - MEMBER_OFF(btf_module, list) +
+ MEMBER_OFF(btf_module, btf),
+ &btf, GET_STRUCT_MEMBER_MSIZE(btf_module, btf));
+ readmem(VADDR, list - MEMBER_OFF(btf_module, list) +
+ MEMBER_OFF(btf_module, module),
+ &module, GET_STRUCT_MEMBER_MSIZE(btf_module, module));
+ readmem(VADDR, module + MEMBER_OFF(module, name),
+ modname, GET_STRUCT_MEMBER_MSIZE(module, name));
+ readmem(VADDR, btf + MEMBER_OFF(btf, data),
+ &data, GET_STRUCT_MEMBER_MSIZE(btf, data));
+ readmem(VADDR, btf + MEMBER_OFF(btf, data_size),
+ &data_size, GET_STRUCT_MEMBER_MSIZE(btf, data_size));
+ btf_buf = (char *)malloc(data_size);
+ if (!btf_buf)
+ goto no_mem;
+ readmem(VADDR, data, btf_buf, data_size);
+ btf_mod = btf__new_split(btf_buf, data_size, btf_arr[0].btf);
+ free(btf_buf);
+ if (libbpf_get_error(btf_mod) != 0 ||
+ add_to_btf_arr(btf_mod, strdup(modname)) == false) {
+ fprintf(stderr, "%s: init %s btf fail\n", __func__, modname);
+ goto out;
+ }
+ }
+ ret = true;
+ goto out;
+
+no_mem:
+ fprintf(stderr, "%s: Not enough memory!\n", __func__);
+out:
+ if (modname)
+ free(modname);
+ return ret;
+}
+
+void cleanup_btf(void)
+{
+ for (int i = 0; i < btf_arr_len; i++) {
+ free(btf_arr[i].module);
+ btf__free(btf_arr[i].btf);
+ }
+ free(btf_arr);
+}
diff --git a/btf_info.h b/btf_info.h
index 1fc6829..d4408c3 100644
--- a/btf_info.h
+++ b/btf_info.h
@@ -16,7 +16,9 @@ struct struct_member_info {
};
bool init_kernel_btf(void);
+bool init_module_btf(void);
bool get_struct_member_by_name(struct struct_member_info *smi);
+void cleanup_btf(void);
struct member_off_size {
int m_off;
--
2.47.0
next prev parent reply other threads:[~2026-01-20 3:39 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-20 2:54 [PATCH v3 0/8] btf/kallsyms based makedumpfile extension for mm page filtering Tao Liu
2026-01-20 2:54 ` [PATCH v3 1/8] Implement kernel kallsyms resolving Tao Liu
2026-01-24 1:09 ` Stephen Brennan
2026-01-24 5:52 ` Tao Liu
2026-01-20 2:54 ` [PATCH v3 2/8] Implement kernel btf resolving Tao Liu
2026-01-20 2:54 ` [PATCH v3 3/8] Implement kernel modules' kallsyms resolving Tao Liu
2026-01-20 2:54 ` Tao Liu [this message]
2026-01-20 2:54 ` [PATCH v3 5/8] Add makedumpfile extension support Tao Liu
2026-01-22 0:51 ` Stephen Brennan
2026-01-22 13:43 ` Tao Liu
2026-02-04 8:40 ` Tao Liu
2026-03-11 0:38 ` Stephen Brennan
2026-03-11 14:41 ` Tao Liu
2026-03-12 22:24 ` Stephen Brennan
2026-03-17 15:31 ` Tao Liu
2026-01-20 2:54 ` [PATCH v3 6/8] Add page filtering function Tao Liu
2026-01-23 0:54 ` Stephen Brennan
2026-01-27 3:21 ` Tao Liu
2026-01-20 2:54 ` [PATCH v3 7/8] Add maple tree support to makedumpfile extension Tao Liu
2026-01-20 2:55 ` [PATCH v3 8/8] Filter amdgpu mm pages Tao Liu
2026-01-20 4:39 ` [PATCH v3 0/8] btf/kallsyms based makedumpfile extension for mm page filtering Tao Liu
2026-01-29 10:19 ` YAMAZAKI MASAMITSU(山崎 真光)
2026-02-04 8:50 ` 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=20260120025500.25095-5-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