mbox series

[v2,dwarves,0/2] Check DW_OP_[GNU_]entry_value for possible parameter matching

Message ID 20241114155822.898466-1-alan.maguire@oracle.com (mailing list archive)
Headers show
Series Check DW_OP_[GNU_]entry_value for possible parameter matching | expand

Message

Alan Maguire Nov. 14, 2024, 3:58 p.m. UTC
Currently, pahole relies on DWARF to find whether a particular func
has its parameter mismatched with standard or optimized away.
In both these cases, the func will not be put in BTF and this
will prevent fentry/fexit tracing for these functions.

The current parameter checking focuses on the first location/expression
to match intended parameter register. But in some cases, the first
location/expression does not have expected matching information,
but further location like DW_OP_[GNU_]entry_value can provide
information which matches the expected parameter register.

Patch 1 supports this; patch 2 adds locking around dwarf_getlocation*
as it is unsafe in a multithreaded environment.

Run ~4000 times without observing a segmentation fault (as compared
to without patch 2, where a segmentation fault is observed approximately
every 200 invokations).

Changes since v1:

- used Eduard's approach of using a __dwarf_getlocations()
  internal wrapper (Eduard, patch 1).
- renamed function to parameter__reg(); did not rename
  __dwarf_getlocations() since its functionality is based around
  retrieving DWARF location info rather than parameter register
  indices (Yonghong, patch 2)
- added locking around dwarf_getlocation*() usage in dwarf_loader
  to avoid segmentation faults reported by Eduard (Jiri, Arnaldo,
  patch 2)

Alan Maguire (1):
  dwarf_loader: use libdw__lock for dwarf_getlocation(s)

Eduard Zingerman (1):
  dwarf_loader: Check DW_OP_[GNU_]entry_value for possible parameter
    matching

 dwarf_loader.c | 121 +++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 96 insertions(+), 25 deletions(-)

Comments

Jiri Olsa Nov. 15, 2024, 9:34 a.m. UTC | #1
On Thu, Nov 14, 2024 at 03:58:20PM +0000, Alan Maguire wrote:
> Currently, pahole relies on DWARF to find whether a particular func
> has its parameter mismatched with standard or optimized away.
> In both these cases, the func will not be put in BTF and this
> will prevent fentry/fexit tracing for these functions.
> 
> The current parameter checking focuses on the first location/expression
> to match intended parameter register. But in some cases, the first
> location/expression does not have expected matching information,
> but further location like DW_OP_[GNU_]entry_value can provide
> information which matches the expected parameter register.
> 
> Patch 1 supports this; patch 2 adds locking around dwarf_getlocation*
> as it is unsafe in a multithreaded environment.
> 
> Run ~4000 times without observing a segmentation fault (as compared
> to without patch 2, where a segmentation fault is observed approximately
> every 200 invokations).
> 
> Changes since v1:
> 
> - used Eduard's approach of using a __dwarf_getlocations()
>   internal wrapper (Eduard, patch 1).
> - renamed function to parameter__reg(); did not rename
>   __dwarf_getlocations() since its functionality is based around
>   retrieving DWARF location info rather than parameter register
>   indices (Yonghong, patch 2)
> - added locking around dwarf_getlocation*() usage in dwarf_loader
>   to avoid segmentation faults reported by Eduard (Jiri, Arnaldo,
>   patch 2)

looks good, I got 95 more functions in clang build including perf_event_read
and there's no change in generated functions with gcc build

Acked-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka

> 
> Alan Maguire (1):
>   dwarf_loader: use libdw__lock for dwarf_getlocation(s)
> 
> Eduard Zingerman (1):
>   dwarf_loader: Check DW_OP_[GNU_]entry_value for possible parameter
>     matching
> 
>  dwarf_loader.c | 121 +++++++++++++++++++++++++++++++++++++++----------
>  1 file changed, 96 insertions(+), 25 deletions(-)
> 
> -- 
> 2.31.1
>
Arnaldo Carvalho de Melo Nov. 15, 2024, 2:52 p.m. UTC | #2
On Fri, Nov 15, 2024 at 10:34:35AM +0100, Jiri Olsa wrote:
> On Thu, Nov 14, 2024 at 03:58:20PM +0000, Alan Maguire wrote:
> > Currently, pahole relies on DWARF to find whether a particular func
> > has its parameter mismatched with standard or optimized away.
> > In both these cases, the func will not be put in BTF and this
> > will prevent fentry/fexit tracing for these functions.
> > 
> > The current parameter checking focuses on the first location/expression
> > to match intended parameter register. But in some cases, the first
> > location/expression does not have expected matching information,
> > but further location like DW_OP_[GNU_]entry_value can provide
> > information which matches the expected parameter register.
> > 
> > Patch 1 supports this; patch 2 adds locking around dwarf_getlocation*
> > as it is unsafe in a multithreaded environment.
> > 
> > Run ~4000 times without observing a segmentation fault (as compared
> > to without patch 2, where a segmentation fault is observed approximately
> > every 200 invokations).
> > 
> > Changes since v1:
> > 
> > - used Eduard's approach of using a __dwarf_getlocations()
> >   internal wrapper (Eduard, patch 1).
> > - renamed function to parameter__reg(); did not rename
> >   __dwarf_getlocations() since its functionality is based around
> >   retrieving DWARF location info rather than parameter register
> >   indices (Yonghong, patch 2)
> > - added locking around dwarf_getlocation*() usage in dwarf_loader
> >   to avoid segmentation faults reported by Eduard (Jiri, Arnaldo,
> >   patch 2)
> 
> looks good, I got 95 more functions in clang build including perf_event_read
> and there's no change in generated functions with gcc build
> 
> Acked-by: Jiri Olsa <jolsa@kernel.org>

I think since you tested it we can stick this, right?

Tested-by: Jiri Olsa <jolsa@kernel.org>
 
> thanks,
> jirka
> 
> > 
> > Alan Maguire (1):
> >   dwarf_loader: use libdw__lock for dwarf_getlocation(s)
> > 
> > Eduard Zingerman (1):
> >   dwarf_loader: Check DW_OP_[GNU_]entry_value for possible parameter
> >     matching
> > 
> >  dwarf_loader.c | 121 +++++++++++++++++++++++++++++++++++++++----------
> >  1 file changed, 96 insertions(+), 25 deletions(-)
> > 
> > -- 
> > 2.31.1
> >
Jiri Olsa Nov. 15, 2024, 3 p.m. UTC | #3
On Fri, Nov 15, 2024 at 11:52:38AM -0300, Arnaldo Carvalho de Melo wrote:
> On Fri, Nov 15, 2024 at 10:34:35AM +0100, Jiri Olsa wrote:
> > On Thu, Nov 14, 2024 at 03:58:20PM +0000, Alan Maguire wrote:
> > > Currently, pahole relies on DWARF to find whether a particular func
> > > has its parameter mismatched with standard or optimized away.
> > > In both these cases, the func will not be put in BTF and this
> > > will prevent fentry/fexit tracing for these functions.
> > > 
> > > The current parameter checking focuses on the first location/expression
> > > to match intended parameter register. But in some cases, the first
> > > location/expression does not have expected matching information,
> > > but further location like DW_OP_[GNU_]entry_value can provide
> > > information which matches the expected parameter register.
> > > 
> > > Patch 1 supports this; patch 2 adds locking around dwarf_getlocation*
> > > as it is unsafe in a multithreaded environment.
> > > 
> > > Run ~4000 times without observing a segmentation fault (as compared
> > > to without patch 2, where a segmentation fault is observed approximately
> > > every 200 invokations).
> > > 
> > > Changes since v1:
> > > 
> > > - used Eduard's approach of using a __dwarf_getlocations()
> > >   internal wrapper (Eduard, patch 1).
> > > - renamed function to parameter__reg(); did not rename
> > >   __dwarf_getlocations() since its functionality is based around
> > >   retrieving DWARF location info rather than parameter register
> > >   indices (Yonghong, patch 2)
> > > - added locking around dwarf_getlocation*() usage in dwarf_loader
> > >   to avoid segmentation faults reported by Eduard (Jiri, Arnaldo,
> > >   patch 2)
> > 
> > looks good, I got 95 more functions in clang build including perf_event_read
> > and there's no change in generated functions with gcc build
> > 
> > Acked-by: Jiri Olsa <jolsa@kernel.org>
> 
> I think since you tested it we can stick this, right?
> 
> Tested-by: Jiri Olsa <jolsa@kernel.org>

yep, sure

jirka

>  
> > thanks,
> > jirka
> > 
> > > 
> > > Alan Maguire (1):
> > >   dwarf_loader: use libdw__lock for dwarf_getlocation(s)
> > > 
> > > Eduard Zingerman (1):
> > >   dwarf_loader: Check DW_OP_[GNU_]entry_value for possible parameter
> > >     matching
> > > 
> > >  dwarf_loader.c | 121 +++++++++++++++++++++++++++++++++++++++----------
> > >  1 file changed, 96 insertions(+), 25 deletions(-)
> > > 
> > > -- 
> > > 2.31.1
> > >