Bug 230846

Summary: dtrace FBT doesn't know about ifuncs
Product: Base System Reporter: Mark Johnston <markj>
Component: kernAssignee: Mark Johnston <markj>
Status: Closed FIXED    
Severity: Affects Many People CC: avg, dtrace, emaste
Priority: ---    
Version: CURRENT   
Hardware: Any   
OS: Any   

Description Mark Johnston freebsd_committer freebsd_triage 2018-08-23 15:53:25 UTC
FBT creates entry/return probes for functions which have a corresponding ELF symbol.  For e.g., copyout(), we'll get fbt::copyout{,_smap,_nosmap}:entry.  Now users need to know which one to select.  In particular, fbt::copyout:entry never fires now.

I think FBT should be made to treat STT_GNU_IFUNC symbols specially: when enabling a probe on such a function, invoke the resolver to find the true address, and put a probe there instead.
Comment 1 Mark Johnston freebsd_committer freebsd_triage 2018-08-27 14:42:34 UTC
Hmm, it looks like we're already patching the right instruction since linker_file_function_listall() returns the resolved ifunc address for each ifunc.  But the probe isn't firing for some reason.
Comment 2 Mark Johnston freebsd_committer freebsd_triage 2018-08-27 15:11:16 UTC
The real problem is that with ifuncs we create multiple probes with the same tracepoint, and fbt_invop() just returns after the first probe.
Comment 3 Mark Johnston freebsd_committer freebsd_triage 2018-08-27 16:16:29 UTC
https://reviews.freebsd.org/D16921
Comment 4 commit-hook freebsd_committer freebsd_triage 2018-08-28 20:22:20 UTC
A commit references this bug:

Author: markj
Date: Tue Aug 28 20:21:38 UTC 2018
New revision: 338359
URL: https://svnweb.freebsd.org/changeset/base/338359

Log:
  Allow multiple FBT probes to share a tracepoint.

  With GNU ifuncs, multiple FBT probes may correspond to the same
  instruction.  fbt_invop() assumed that this could not happen and
  would return after the first probe found in the global FBT hash
  table, which might not be the one that's enabled.  Fix the problem
  on x86 by linking probes that share a tracepoint and having each
  linked probe fire when the tracepoint is hit.

  PR:		230846
  Approved by:	re (gjb)
  Sponsored by:	The FreeBSD Foundation
  Differential Revision:	https://reviews.freebsd.org/D16921

Changes:
  head/sys/cddl/dev/fbt/aarch64/fbt_isa.c
  head/sys/cddl/dev/fbt/arm/fbt_isa.c
  head/sys/cddl/dev/fbt/fbt.c
  head/sys/cddl/dev/fbt/fbt.h
  head/sys/cddl/dev/fbt/mips/fbt_isa.c
  head/sys/cddl/dev/fbt/powerpc/fbt_isa.c
  head/sys/cddl/dev/fbt/riscv/fbt_isa.c
  head/sys/cddl/dev/fbt/x86/fbt_isa.c