public inbox for kexec@lists.infradead.org
 help / color / mirror / Atom feed
From: Stephen Brennan <stephen.s.brennan@oracle.com>
To: Tao Liu <ltao@redhat.com>,
	yamazaki-msmt@nec.com, k-hagio-ab@nec.com,
	kexec@lists.infradead.org
Cc: aravinda@linux.vnet.ibm.com, Tao Liu <ltao@redhat.com>
Subject: Re: [PATCH v4][makedumpfile 5/7] Implement kernel module's btf resolving
Date: Thu, 02 Apr 2026 16:56:20 -0700	[thread overview]
Message-ID: <87tstsex23.fsf@oracle.com> (raw)
In-Reply-To: <20260317150743.69590-6-ltao@redhat.com>

Tao Liu <ltao@redhat.com> writes:

> Same as the previous patch, with kernel's kallsyms and btf ready,
> we can locate and iterate all kernel modules' btf data. So kernel
> modules' types specified within .init_ksyms section will be resolved.
>
> Suggested-by: Stephen Brennan <stephen.s.brennan@oracle.com>
> Signed-off-by: Tao Liu <ltao@redhat.com>

Reviewed-by: Stephen Brennan <stephen.s.brennan@oracle.com>

> ---
>  btf_info.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
>  btf_info.h |   2 +
>  2 files changed, 115 insertions(+), 1 deletion(-)
>
> diff --git a/btf_info.c b/btf_info.c
> index 1cb66e2..7682a82 100644
> --- a/btf_info.c
> +++ b/btf_info.c
> @@ -230,4 +230,116 @@ out:
>  	if (buf)
>  		free(buf);
>  	return ret;
> -}
> \ No newline at end of file
> +}
> +
> +INIT_KERN_SYM(btf_modules);
> +
> +INIT_KERN_STRUCT_MEMBER(btf_module, list);
> +INIT_KERN_STRUCT_MEMBER(btf_module, btf);
> +INIT_KERN_STRUCT_MEMBER(btf_module, module);
> +DECLARE_KERN_STRUCT_MEMBER(module, name);
> +INIT_KERN_STRUCT_MEMBER(btf, data);
> +INIT_KERN_STRUCT_MEMBER(btf, data_size);
> +
> +#define MEMBER_OFF(S, M) \
> +	GET_KERN_STRUCT_MEMBER_MOFF(S, M) / 8
> +
> +bool init_module_btf(void)
> +{
> +	struct btf *btf_mod;
> +	uint64_t btf_modules, list;
> +	uint64_t btf = 0, data = 0, module = 0;
> +	int data_size = 0;
> +	bool ret = false;
> +	char *btf_buf = NULL;
> +	char *modname = NULL;
> +	struct ktype_info **p;
> +
> +	btf_modules = GET_KERN_SYM(btf_modules);
> +	if (!KERN_SYM_EXIST(btf_modules))
> +		/* Maybe module is not enabled, this is not an error */
> +		return true;
> +
> +	if (!KERN_STRUCT_MEMBER_EXIST(btf_module, list) ||
> +	    !KERN_STRUCT_MEMBER_EXIST(btf_module, btf) ||
> +	    !KERN_STRUCT_MEMBER_EXIST(btf_module, module) ||
> +	    !KERN_STRUCT_MEMBER_EXIST(btf, data) ||
> +	    !KERN_STRUCT_MEMBER_EXIST(btf, data_size)) {
> +		/* Fail when module enabled but any required types not found */
> +		fprintf(stderr, "%s: Missing required btf syms/types!", __func__);
> +		goto out;
> +	}
> +
> +	modname = (char *)malloc(GET_KERN_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_KERN_STRUCT_MEMBER_MSIZE(btf_module, btf));
> +		readmem(VADDR, list - MEMBER_OFF(btf_module, list) +
> +				MEMBER_OFF(btf_module, module),
> +			&module, GET_KERN_STRUCT_MEMBER_MSIZE(btf_module, module));
> +		readmem(VADDR, module + MEMBER_OFF(module, name),
> +			modname, GET_KERN_STRUCT_MEMBER_MSIZE(module, name));
> +		if (!check_ktypes_require_modname(modname, NULL)) {
> +			continue;
> +		}
> +		readmem(VADDR, btf + MEMBER_OFF(btf, data),
> +			&data, GET_KERN_STRUCT_MEMBER_MSIZE(btf, data));
> +		readmem(VADDR, btf + MEMBER_OFF(btf, data_size),
> +			&data_size, GET_KERN_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;
> +		}
> +	}
> +
> +	/* OK, we have loaded all needed modules's btf, now resolve the types */
> +	for (int i = 0; i < sr_len; i++) {
> +		for (p = (struct ktype_info **)(sr[i]->start);
> +		     p < (struct ktype_info **)(sr[i]->stop);
> +		     p++)
> +			get_ktype_info(*p, NULL);
> +	}
> +
> +	ret = true;
> +	goto out;
> +
> +no_mem:
> +	fprintf(stderr, "%s: Not enough memory!\n", __func__);
> +out:
> +	if (modname)
> +		free(modname);
> +	return ret;
> +}
> +
> +static void cleanup_btf_arr(void)
> +{
> +	for (int i = 0; i < btf_arr_len; i++) {
> +		free(btf_arr[i]->module);
> +		btf__free(btf_arr[i]->btf);
> +		free(btf_arr[i]);
> +	}
> +	if (btf_arr) {
> +		free(btf_arr);
> +		btf_arr = NULL;
> +	}
> +	btf_arr_len = 0;
> +	btf_arr_cap = 0;
> +}
> +
> +void cleanup_btf(void)
> +{
> +	cleanup_btf_arr();
> +	cleanup_ktypes_section_range();
> +	cleanup_ktypes_modname();
> +}
> diff --git a/btf_info.h b/btf_info.h
> index 2cf6b07..b7f6810 100644
> --- a/btf_info.h
> +++ b/btf_info.h
> @@ -22,6 +22,8 @@ struct ktype_info {
>  bool check_ktypes_require_modname(char *modname, int *total);
>  bool register_ktype_section(char *start, char *stop);
>  bool init_kernel_btf(void);
> +bool init_module_btf(void);
> +void cleanup_btf(void);
>  
>  #define QUATE(x) #x
>  #define INIT_MOD_STRUCT_MEMBER_RQD(MOD, S, M, R)			\
> -- 
> 2.47.0


  reply	other threads:[~2026-04-02 23:56 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-17 15:07 [PATCH v4][makedumpfile 0/7] btf/kallsyms based makedumpfile extension for mm page filtering Tao Liu
2026-03-17 15:07 ` [PATCH v4][makedumpfile 1/7] Reserve sections for makedumpfile and extenions Tao Liu
2026-04-02 23:31   ` Stephen Brennan
2026-04-03  8:10   ` HAGIO KAZUHITO(萩尾 一仁)
2026-03-17 15:07 ` [PATCH v4][makedumpfile 2/7] Implement kernel kallsyms resolving Tao Liu
2026-04-02 23:32   ` Stephen Brennan
2026-04-03  8:12   ` HAGIO KAZUHITO(萩尾 一仁)
2026-03-17 15:07 ` [PATCH v4][makedumpfile 3/7] Implement kernel btf resolving Tao Liu
2026-04-02 23:41   ` Stephen Brennan
2026-04-03  8:13   ` HAGIO KAZUHITO(萩尾 一仁)
2026-03-17 15:07 ` [PATCH v4][makedumpfile 4/7] Implement kernel module's kallsyms resolving Tao Liu
2026-04-02 23:54   ` Stephen Brennan
2026-03-17 15:07 ` [PATCH v4][makedumpfile 5/7] Implement kernel module's btf resolving Tao Liu
2026-04-02 23:56   ` Stephen Brennan [this message]
2026-03-17 15:07 ` [PATCH v4][makedumpfile 6/7] Add makedumpfile extensions support Tao Liu
2026-04-03  0:11   ` Stephen Brennan
2026-04-03  8:14   ` HAGIO KAZUHITO(萩尾 一仁)
2026-03-17 15:07 ` [PATCH v4][makedumpfile 7/7] Filter amdgpu mm pages Tao Liu
2026-04-03  0:16   ` Stephen Brennan
2026-04-03  8:06 ` [PATCH v4][makedumpfile 0/7] btf/kallsyms based makedumpfile extension for mm page filtering HAGIO KAZUHITO(萩尾 一仁)
2026-04-03 18:26 ` Stephen Brennan

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=87tstsex23.fsf@oracle.com \
    --to=stephen.s.brennan@oracle.com \
    --cc=aravinda@linux.vnet.ibm.com \
    --cc=k-hagio-ab@nec.com \
    --cc=kexec@lists.infradead.org \
    --cc=ltao@redhat.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