Re: [PATCH 1/2] tracing/probes: Add symstr type for dynamic events
From: Google
Date: Wed Oct 26 2022 - 11:42:44 EST
On Sat, 22 Oct 2022 15:38:50 +0900
"Masami Hiramatsu (Google)" <mhiramat@xxxxxxxxxx> wrote:
> From: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>
>
> Add 'symstr' type for storing the kernel symbol as a string data
> instead of the symbol address. This allows us to filter the
> events by wildcard symbol name.
>
> e.g.
> # echo 'e:wqfunc workqueue.workqueue_execute_start symname=$function:symstr' >> dynamic_events
> # cat events/eprobes/wqfunc/format
> name: wqfunc
> ID: 2110
> format:
> field:unsigned short common_type; offset:0; size:2; signed:0;
> field:unsigned char common_flags; offset:2; size:1; signed:0;
> field:unsigned char common_preempt_count; offset:3; size:1; signed:0;
> field:int common_pid; offset:4; size:4; signed:1;
>
> field:__data_loc char[] symname; offset:8; size:4; signed:1;
>
> print fmt: " symname=\"%s\"", __get_str(symname)
>
> Note that there is already 'symbol' type which just change the
> print format (so it still stores the symbol address in the tracing
> ring buffer.) On the other hand, 'symstr' type stores the actual
> "symbol+offset/size" data as a string.
>
> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>
> ---
[...]
> diff --git a/kernel/trace/trace_probe_tmpl.h b/kernel/trace/trace_probe_tmpl.h
> index b3bdb8ddb862..d57a3143929a 100644
> --- a/kernel/trace/trace_probe_tmpl.h
> +++ b/kernel/trace/trace_probe_tmpl.h
> @@ -67,6 +67,37 @@ probe_mem_read(void *dest, void *src, size_t size);
> static nokprobe_inline int
> probe_mem_read_user(void *dest, void *src, size_t size);
>
> +static nokprobe_inline int
> +fetch_store_symstrlen(unsigned long addr)
> +{
> + char namebuf[KSYM_SYMBOL_LEN];
> + int ret;
> +
> + ret = sprint_symbol(namebuf, addr);
> + if (ret < 0)
> + return 0;
> +
> + return strlen(namebuf) + 1;
Ah, sprint_symbol() returns the length. This strlen() is redundant.
Let me update the patch.
Thank you,
--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>