Skip to content

ftrace: Add access to function arguments for all callbacks

Steven Rostedt (VMware) live-patching lkml 5 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v7 Latest3 patches 6 repliesIn review
  2. v63 patches 4 repliesSuperseded
  3. v53 patches 5 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v43 patches4 repliesSuperseded
v3 RFC3 patches2 repliesSuperseded

Changes in v7 from the cover letter

- Use the new name ftrace_instruction_pointer_set() in the live patching code.

Patches in v7 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3ftrace: Have the callbacks receive a struct ftrace_regs instead of pt_regsarch/csky/kernel/probes/ftrace.c arch/nds32/kernel/ftrace.c arch/parisc/kernel/ftrace.c +15 more+71 -453 replies
2/3ftrace/x86: Allow for arguments to be passed in to ftrace_regs by defaultarch/x86/Kconfig arch/x86/include/asm/ftrace.h arch/x86/kernel/ftrace_64.S +2 more+40 -30 replies
3/3livepatch: Use the default ftrace_ops instead of REGS when ARGS is availablearch/powerpc/include/asm/livepatch.h arch/s390/include/asm/livepatch.h arch/x86/include/asm/ftrace.h +5 more+29 -93 replies

Reviews trailers per patch

All 3 patches have a Reviewed-by or Acked-by.

PatchPeter Zijlstra (Intel)Miroslav BenesMasami HiramatsuPetr Mladek
1/3A-b R-b A-b
2/3A-b
3/3A-b A-b A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.

Read the v7 thread

Cover letter [PATCH 0/3 v7] ftrace: Add access to function arguments for all callbacks

This is something I wanted to implement a long time ago, but held off until there was a good reason to do so. Now it appears that having access to the arguments of the function by default is very useful. As a bonus, because arguments must be saved regardless before calling a callback, because they need to be restored before returning back to the start of the traced function, there's not much work to do to have them always be there for normal function callbacks.

The basic idea is that if CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS is set, then all callbacks registered to ftrace can use the regs parameter for the stack and arguments (kernel_stack_pointer(regs), regs_get_kernel_argument(regs, n)), without the need to set REGS that causes overhead by saving all registers as REGS simulates a breakpoint.

This could be extended to move the REGS portion to kprobes itself, and remove the SAVE_REGS flag completely, but for now, kprobes still uses the full SAVE_REGS support.

The last patch extends the WITH_ARGS to allow default function tracing to modify the instruction pointer, where livepatching for x86 no longer needs to save all registers.

The idea of this approach is to give enough information to a callback that it could retrieve all arguments, which includes the stack pointer and instruction pointer.

This can also be extended to modify the function graph tracer to use the function tracer instead of having a separate trampoline.

Changes since v6:
- Use the new name ftrace_instruction_pointer_set() in the live patching code.

Steven Rostedt (VMware) (3):
ftrace: Have the callbacks receive a struct ftrace_regs instead of pt_regs ftrace/x86: Allow for arguments to be passed in to ftrace_regs by default
livepatch: Use the default ftrace_ops instead of REGS when ARGS is available

----

 arch/csky/kernel/probes/ftrace.c     |  4 +++-
 arch/nds32/kernel/ftrace.c           |  4 ++--
 arch/parisc/kernel/ftrace.c          |  8 +++++---
 arch/powerpc/include/asm/livepatch.h |  4 +++-
 arch/powerpc/kernel/kprobes-ftrace.c |  4 +++-
 arch/s390/include/asm/livepatch.h    |  5 ++++-
 arch/s390/kernel/ftrace.c            |  4 +++-
 arch/x86/Kconfig                     |  1 +
 arch/x86/include/asm/ftrace.h        | 18 ++++++++++++++++++
 arch/x86/include/asm/livepatch.h     |  4 ++--
 arch/x86/kernel/ftrace_64.S          | 15 +++++++++++++--
 arch/x86/kernel/kprobes/ftrace.c     |  3 ++-
 fs/pstore/ftrace.c                   |  2 +-
 include/linux/ftrace.h               | 28 ++++++++++++++++++++++++++--
 include/linux/kprobes.h              |  2 +-
 kernel/livepatch/Kconfig             |  2 +-
 kernel/livepatch/patch.c             | 10 ++++++----
 kernel/trace/Kconfig                 |  9 +++++++++
 kernel/trace/ftrace.c                | 27 +++++++++++++++------------
 kernel/trace/trace_event_perf.c      |  2 +-
 kernel/trace/trace_events.c          |  2 +-
 kernel/trace/trace_functions.c       |  9 ++++-----
 kernel/trace/trace_irqsoff.c         |  2 +-
 kernel/trace/trace_sched_wakeup.c    |  2 +-
 kernel/trace/trace_selftest.c        | 20 +++++++++++---------
 kernel/trace/trace_stack.c           |  2 +-
 26 files changed, 138 insertions(+), 55 deletions(-)