|
|
Subscribe / Log in / New account

function_graph: Rewrite to allow multiple users

From:  Steven Rostedt <rostedt-AT-goodmis.org>
To:  linux-kernel-AT-vger.kernel.org
Subject:  [RFC][PATCH 00/14 v2] function_graph: Rewrite to allow multiple users
Date:  Mon, 20 May 2019 10:20:01 -0400
Message-ID:  <20190520142001.270067280@goodmis.org>
Cc:  Ingo Molnar <mingo-AT-kernel.org>, Andrew Morton <akpm-AT-linux-foundation.org>, Thomas Gleixner <tglx-AT-linutronix.de>, Peter Zijlstra <peterz-AT-infradead.org>, Masami Hiramatsu <mhiramat-AT-kernel.org>, Josh Poimboeuf <jpoimboe-AT-redhat.com>, Frederic Weisbecker <frederic-AT-kernel.org>, Joel Fernandes <joel-AT-joelfernandes.org>, Andy Lutomirski <luto-AT-kernel.org>, Mark Rutland <mark.rutland-AT-arm.com>, Namhyung Kim <namhyung-AT-kernel.org>, "Frank Ch. Eigler" <fche-AT-redhat.com>
Archive-link:  Article


The background for this is explained in the V1 version found here:

 http://lkml.kernel.org/r/20181122012708.491151844@goodmis...

The TL;DR; is this:

 The function graph tracer required a rewrite, mainly because it
 can only allow one callback registered at a time. The main motivation
 for this change is to allow kretprobes to use the code of function
 graph tracer, which should allow all archs that have function graph
 tracing to also have kretprobes with no extra work.

Masami told me that one requirement was to allow the function entry
callback to store data on the shadow stack that can be retrieved by
the the function return callback. I added this, as well as a per-task
variable (used by one of the function graph users).

The two functions to allow the storing of data on the stack and
retrieval of it are:

 void *fgraph_reserve_data(int size_in_bytes)

    Allows the entry function to reserve up to 4 words of data on
    the shadow stack. On success, a pointer to the contents is returned.
    This may be only called once per entry function.

 void *fgraph_retrieve_data(void)

    Allows the return function to retrieve the reserved data that was
    allocated by the entry function.

Note, this code has passed my full test suite.

Changes since v1:

  - Well, the first part of that series was already merged.
    But that was just the preparation for this part.

  - Allocate a page for the shadow stack split it up that way.
    When the stack is full, we stop allowing more to be added (stop tracing).

  - Added the reserve and retrieve of private data on the shadow stack
    for individual entry/return callbacks to pass data to each other.

  - Added a "per task" data that can be used by a fgraph_ops for all
    function callbacks for a specific task.

Steven Rostedt (VMware) (14):
      function_graph: Convert ret_stack to a series of longs
      function_graph: Add an array structure that will allow multiple callbacks
      function_graph: Allow multiple users to attach to function graph
      function_graph: Remove logic around ftrace_graph_entry and return
      ftrace/function_graph: Pass fgraph_ops to function graph callbacks
      ftrace: Allow function_graph tracer to be enabled in instances
      ftrace: Allow ftrace startup flags exist without dynamic ftrace
      function_graph: Have the instances use their own ftrace_ops for filtering
      function_graph: Add "task variables" per task for fgraph_ops
      function_graph: Move set_graph_function tests to shadow stack global var
      function_graph: Move graph depth stored data to shadow stack global var
      function_graph: Move graph notrace bit to shadow stack global var
      function_graph: Implement fgraph_reserve_data() and fgraph_retrieve_data()
      function_graph: Add selftest for passing local variables

----
 include/linux/ftrace.h               |  37 +-
 include/linux/sched.h                |   2 +-
 kernel/trace/fgraph.c                | 862 ++++++++++++++++++++++++++++-------
 kernel/trace/ftrace.c                |  13 +-
 kernel/trace/ftrace_internal.h       |   2 -
 kernel/trace/trace.h                 | 132 +++---
 kernel/trace/trace_functions.c       |   7 +
 kernel/trace/trace_functions_graph.c |  96 ++--
 kernel/trace/trace_irqsoff.c         |  10 +-
 kernel/trace/trace_sched_wakeup.c    |  10 +-
 kernel/trace/trace_selftest.c        | 168 ++++++-
 11 files changed, 1048 insertions(+), 291 deletions(-)


Copyright © 2019, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds