Re: [PATCH v2 1/4] ftrace: Add print_function_args()

Steven Rostedt
2025-01-08T15:23:14Z

On Wed, 8 Jan 2025 11:19:11 +0000
Alan Maguire <alan.maguire@oracle.com> wrote:

> >>> + trace_seq_printf(s, "(");
> >>> +
> >>> + if (!args)
> >>> + goto out;
> >>> + if (lookup_symbol_name(func, name))
> >>> + goto out;
> >>> +
> >>> + btf = bpf_get_btf_vmlinux();
> >>> + if (IS_ERR_OR_NULL(btf))
> >>> + goto out;
> >>
> >>
> >> There is no need to the retrieve the BTF of vmlinux, as btf_find_func_proto
> >> will return the correct BTF via its second parameter.
> >
> > Good catch! The second parameter of btf_find_func_proto() is output.
> >
>
> One thought here - with btf_find_func_proto(), we will try kernel BTF
> and then proceed to module BTF, iterating over all modules to find the
> function prototype. So where we are tracing module functions this could
> get expensive if such a function is frequently encountered, and it also
> opens up the risk that we end up using the wrong function prototype from
> the wrong module that just happens to match on function name.
>
> So I wonder if we could use the function address to do a more guided
> lookup. Perhaps we could use kallsyms_lookup(), retrieving the
> (potential) module name. Then maybe modify the signature of
> btf_find_func_proto() to take an optional module name parameter to avoid
> iteration? None of this is strictly needed, but it may speed things up a
> bit and give us more accurate parameter info for those few cases with
> name clashes, so could be done as a follow-up if needed. Thanks!

Well, every place this is called, we first get the function name from
kallsyms. Perhaps I can modify the code to get the module name as well, and
if it exists, we can pass that too?

-- Steve