Re: [PATCH] tracing/fgraph: support recording function return values

From: Changbin Du
Date: Tue Jul 16 2019 - 10:08:33 EST


On Mon, Jul 15, 2019 at 12:12:31PM +0200, Peter Zijlstra wrote:
> On Mon, Jul 15, 2019 at 09:29:30AM +0100, Will Deacon wrote:
> > On Sat, Jul 13, 2019 at 08:10:26PM +0800, Changbin Du wrote:
> > > This patch adds a new trace option 'funcgraph-retval' and is disabled by
> > > default. When this option is enabled, fgraph tracer will show the return
> > > value of each function. This is useful to find/analyze a original error
> > > source in a call graph.
> > >
> > > One limitation is that the kernel doesn't know the prototype of functions.
> > > So fgraph assumes all functions have a retvalue of type int. You must ignore
> > > the value of *void* function. And if the retvalue looks like an error code
> > > then both hexadecimal and decimal number are displayed.
> >
> > This seems like quite a significant drawback and I think it could be pretty
> > confusing if you have to filter out bogus return values from the trace.
> >
> > For example, in your snippet:
> >
> > > 3) | kvm_vm_ioctl() {
> > > 3) | mutex_lock() {
> > > 3) | _cond_resched() {
> > > 3) 0.234 us | rcu_all_qs(); /* ret=0x80000000 */
> > > 3) 0.704 us | } /* ret=0x0 */
> > > 3) 1.226 us | } /* ret=0x0 */
> > > 3) 0.247 us | mutex_unlock(); /* ret=0xffff8880738ed040 */
> >
> > mutex_unlock() is wrongly listed as returning something.
> >
> > How much of this could be achieved from userspace by placing kretprobes on
> > non-void functions instead?
>
> Alternatively, we can have recordmcount (or objtool) mark all functions
> with a return value when the build has DEBUG_INFO on. The dwarves know
> the function signature.
>
We can extend the recordmcount tool to search 'subprogram' tag in the DIE tree.
In below example, the 'DW_AT_type' is the type of function pidfd_create().

$ readelf -w kernel/pid.o
[...]
<1><1b914>: Abbrev Number: 232 (DW_TAG_subprogram)
<1b916> DW_AT_name : (indirect string, offset: 0x415e): pidfd_create
<1b91a> DW_AT_decl_file : 1
<1b91b> DW_AT_decl_line : 471
<1b91d> DW_AT_decl_column : 12
<1b91e> DW_AT_prototyped : 1
<1b91e> DW_AT_type : <0xcc>
<1b922> DW_AT_low_pc : 0x450
<1b92a> DW_AT_high_pc : 0x50
<1b932> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
<1b934> DW_AT_GNU_all_call_sites: 1
<1b934> DW_AT_sibling : <0x1b9d9>
[...]

To that end, we need to introduce libdw library for recordmcount. I will have a
try this week.

And probably, we can also record the parameters?

--
Cheers,
Changbin Du