[PATCH] tracing: Fix possible memory leak in ftrace_regsiter_direct()

2023-12-27 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) If ftrace_register_direct() called with a large number of target functions (e.g. 65), the free_hash can be updated twice or more in the ftrace_add_rec_direct() without freeing the previous hash memory. Thus this can cause a memory leak. Fix this issue by

[PATCH] ftrace: Fix DIRECT_CALLS to use SAVE_REGS by default

2024-01-09 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) The commit 60c8971899f3 ("ftrace: Make DIRECT_CALLS work WITH_ARGS and !WITH_REGS") changed DIRECT_CALLS to use SAVE_ARGS when there are multiple ftrace_ops at the same function, but since the x86 only support to jump to direct_call from ftrace_regs_ca

[PATCH v6 00/36] tracing: fprobe: function_graph: Multi-function graph and fprobe on fgraph

2024-01-12 Thread Masami Hiramatsu (Google)
e given 'fprobe' data structure pointer is still valid. Note that it is possible to unregister fprobe before the return callback runs. Thus the address validation must be done before using it in the return callback. This series can be applied against the v6.7 kernel. This series can also be

[PATCH v6 01/36] ftrace: Fix DIRECT_CALLS to use SAVE_REGS by default

2024-01-12 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) The commit 60c8971899f3 ("ftrace: Make DIRECT_CALLS work WITH_ARGS and !WITH_REGS") changed DIRECT_CALLS to use SAVE_ARGS when there are multiple ftrace_ops at the same function, but since the x86 only support to jump to direct_call from ftrace_regs_ca

[PATCH v6 02/36] tracing: Add a comment about ftrace_regs definition

2024-01-12 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) To clarify what will be expected on ftrace_regs, add a comment to the architecture independent definition of the ftrace_regs. Signed-off-by: Masami Hiramatsu (Google) Acked-by: Mark Rutland --- Changes in v3: - Add instruction pointer Changes in v2

[PATCH v6 03/36] tracing: Rename ftrace_regs_return_value to ftrace_regs_get_return_value

2024-01-12 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Rename ftrace_regs_return_value to ftrace_regs_get_return_value as same as other ftrace_regs_get/set_* APIs. Signed-off-by: Masami Hiramatsu (Google) Acked-by: Mark Rutland --- Changes in v6: - Moved to top of the series. Changes in v3: - Newly added

[PATCH v6 04/36] x86: tracing: Add ftrace_regs definition in the header

2024-01-12 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Add ftrace_regs definition for x86_64 in the ftrace header to clarify what register will be accessible from ftrace_regs. Signed-off-by: Masami Hiramatsu (Google) --- Changes in v3: - Add rip to be saved. Changes in v2: - Newly added. --- arch/x86/include

[PATCH v6 05/36] function_graph: Convert ret_stack to a series of longs

2024-01-12 Thread Masami Hiramatsu (Google)
the return side of the functions. Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- include/linux/sched.h |2 - kernel/trace/fgraph.c | 124 - 2 files changed, 71 insertions(+), 55 deletions(-) diff --git a

[PATCH v6 06/36] fgraph: Use BUILD_BUG_ON() to make sure we have structures divisible by long

2024-01-12 Thread Masami Hiramatsu (Google)
dt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- kernel/trace/fgraph.c |9 ++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c index 30edeb6d4aa9..837daf929d2a 100644 --- a/kernel/trace/fgraph.c +++ b/kernel/trac

[PATCH v6 07/36] function_graph: Add an array structure that will allow multiple callbacks

2024-01-12 Thread Masami Hiramatsu (Google)
n the shadow stack. We need to only save the index, because this will allow the fgraph_ops to be freed before the function returns (which may happen if the function call schedule for a long time). Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- Changes in v2: - R

[PATCH v6 08/36] function_graph: Allow multiple users to attach to function graph

2024-01-12 Thread Masami Hiramatsu (Google)
s when both are called is not completely handled yet, but that shouldn't be too hard to manage. Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- Changes in v2: - Check return value of the ftrace_pop_return_trace() instead of 'ret' since '

[PATCH v6 09/36] function_graph: Remove logic around ftrace_graph_entry and return

2024-01-12 Thread Masami Hiramatsu (Google)
function_graph tracer. Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- Changes in v2: - Fix typo and make lines shorter than 76 chars in the description. - Remove unneeded return from return_run() function. --- kernel/trace/fgraph.c | 71

[PATCH v6 10/36] ftrace/function_graph: Pass fgraph_ops to function graph callbacks

2024-01-12 Thread Masami Hiramatsu (Google)
to the function graph tracer. Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- Changes in v2: - cleanup to set argument name on function prototype. --- include/linux/ftrace.h | 10 +++--- kernel/trace/fgraph.c| 16

[PATCH v6 11/36] ftrace: Allow function_graph tracer to be enabled in instances

2024-01-12 Thread Masami Hiramatsu (Google)
: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- Changes in v2: - Fix to remove set_graph_array() completely. --- include/linux/ftrace.h |1 + kernel/trace/ftrace.c|1 + kernel/trace/trace.h | 13 ++- kernel

[PATCH v6 12/36] ftrace: Allow ftrace startup flags exist without dynamic ftrace

2024-01-12 Thread Masami Hiramatsu (Google)
compile because dynamic ftrace is disabled. This change is needed to move some of the logic of what is passed to ftrace_startup() out of the parameters of ftrace_startup(). Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- include/linux/ftrace.h | 18

[PATCH v6 13/36] function_graph: Have the instances use their own ftrace_ops for filtering

2024-01-12 Thread Masami Hiramatsu (Google)
t is not enough for the self- recursive tail-call case. Thus fgraph uses the bitmap entry to find it is already set (this means that entry is for previous tail call). Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- Changes in v6: - Fix to check whether the fg

[PATCH v6 14/36] function_graph: Use a simple LRU for fgraph_array index number

2024-01-12 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Since the fgraph_array index is used for the bitmap on the shadow stack, it may leave some entries after a function_graph instance is removed. Thus if another instance reuses the fgraph_array index soon after releasing it, the fgraph may confuse to call the newer

[PATCH v6 15/36] function_graph: Add "task variables" per task for fgraph_ops

2024-01-12 Thread Masami Hiramatsu (Google)
atures on a per task basis having a way to maintain state for each task. Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- Changes in v3: - Move fgraph_ops::idx to previous patch in the series. Changes in v2: - Make description lines shorter than 76 char

[PATCH v6 16/36] function_graph: Move set_graph_function tests to shadow stack global var

2024-01-12 Thread Masami Hiramatsu (Google)
are) Signed-off-by: Masami Hiramatsu (Google) --- include/linux/trace_recursion.h |5 + kernel/trace/trace.h | 32 +--- kernel/trace/trace_functions_graph.c |6 +++--- kernel/trace/trace_irqsoff.c |4 ++-- kernel/tr

[PATCH v6 17/36] function_graph: Move graph depth stored data to shadow stack global var

2024-01-12 Thread Masami Hiramatsu (Google)
are) Signed-off-by: Masami Hiramatsu (Google) --- include/linux/trace_recursion.h | 29 - kernel/trace/trace.h| 34 -- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/include/linux/trace_recursion.h b/incl

[PATCH v6 18/36] function_graph: Move graph notrace bit to shadow stack global var

2024-01-12 Thread Masami Hiramatsu (Google)
are) Signed-off-by: Masami Hiramatsu (Google) --- Changes in v2: - Make description lines shorter than 76 chars. --- include/linux/trace_recursion.h |7 --- kernel/trace/trace.h |9 + kernel/trace/trace_functions_graph.c | 10 ++ 3 files chan

[PATCH v6 19/36] function_graph: Implement fgraph_reserve_data() and fgraph_retrieve_data()

2024-01-12 Thread Masami Hiramatsu (Google)
x27;s shadow ret_stack and this then can be retrieved by fgraph_retrieve_data() called by the corresponding retfunc(). Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- Changes in v3: - Store fgraph_array index to the data entry. - Both function req

[PATCH v6 20/36] function_graph: Improve push operation for several interrupts

2024-01-12 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Improve push and data reserve operation on the shadow stack for several sequencial interrupts. To push a ret_stack or data entry on the shadow stack, we need to prepare an index (offset) entry before updating the stack pointer (curr_ret_stack) so that unwinder

[PATCH v6 21/36] function_graph: Add selftest for passing local variables

2024-01-12 Thread Masami Hiramatsu (Google)
From: Steven Rostedt (VMware) Add boot up selftest that passes variables from a function entry to a function exit, and make sure that they do get passed around. Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- Changes in v2: - Add reserved size test

[PATCH v6 22/36] function_graph: Add a new entry handler with parent_ip and ftrace_regs

2024-01-12 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Add a new entry handler to fgraph_ops as 'entryregfunc' which takes parent_ip and ftrace_regs. Note that the 'entryfunc' and 'entryregfunc' are mutual exclusive. You can set only one of them. Signed-off-by: Masami Hiramats

[PATCH v6 23/36] function_graph: Add a new exit handler with parent_ip and ftrace_regs

2024-01-12 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Add a new return handler to fgraph_ops as 'retregfunc' which takes parent_ip and ftrace_regs instead of ftrace_graph_ret. This handler is available only if the arch support CONFIG_HAVE_FUNCTION_GRAPH_FREGS. Note that the 'retfunc' and &#

[PATCH v6 24/36] x86/ftrace: Enable HAVE_FUNCTION_GRAPH_FREGS

2024-01-12 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Support HAVE_FUNCTION_GRAPH_FREGS on x86-64, which saves ftrace_regs on the stack in ftrace_graph return trampoline so that the callbacks can access registers via ftrace_regs APIs. Note that this only recovers 'rax' and 'rdx' registers because

[PATCH v6 25/36] arm64: ftrace: Enable HAVE_FUNCTION_GRAPH_FREGS

2024-01-12 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Enable CONFIG_HAVE_FUNCTION_GRAPH_FREGS on arm64. Note that this depends on HAVE_DYNAMIC_FTRACE_WITH_ARGS which is enabled if the compiler supports "-fpatchable-function-entry=2". If not, it continue to use ftrace_ret_regs. Signed-off-by: Masami Hiramat

[PATCH v6 26/36] fprobe: Use ftrace_regs in fprobe entry handler

2024-01-12 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) This allows fprobes to be available with CONFIG_DYNAMIC_FTRACE_WITH_ARGS instead of CONFIG_DYNAMIC_FTRACE_WITH_REGS, then we can enable fprobe on arm64. Signed-off-by: Masami Hiramatsu (Google) Acked-by: Florent Revest --- Changes in v6: - Keep using

[PATCH v6 27/36] fprobe: Use ftrace_regs in fprobe exit handler

2024-01-12 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Change the fprobe exit handler to use ftrace_regs structure instead of pt_regs. This also introduce HAVE_PT_REGS_TO_FTRACE_REGS_CAST which means the ftrace_regs's memory layout is equal to the pt_regs so that those are able to cast. Fprobe introduces

[PATCH v6 28/36] tracing: Add ftrace_partial_regs() for converting ftrace_regs to pt_regs

2024-01-12 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Add ftrace_partial_regs() which converts the ftrace_regs to pt_regs. If the architecture defines its own ftrace_regs, this copies partial registers to pt_regs and returns it. If not, ftrace_regs is the same as pt_regs and ftrace_partial_regs() will return

[PATCH v6 29/36] tracing: Add ftrace_fill_perf_regs() for perf event

2024-01-12 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Add ftrace_fill_perf_regs() which should be compatible with the perf_fetch_caller_regs(). In other words, the pt_regs returned from the ftrace_fill_perf_regs() must satisfy 'user_mode(regs) == false' and can be used for stack tracing. Signed-off-

[PATCH v6 30/36] tracing/fprobe: Enable fprobe events with CONFIG_DYNAMIC_FTRACE_WITH_ARGS

2024-01-12 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Allow fprobe events to be enabled with CONFIG_DYNAMIC_FTRACE_WITH_ARGS. With this change, fprobe events mostly use ftrace_regs instead of pt_regs. Note that if the arch doesn't enable HAVE_PT_REGS_COMPAT_FTRACE_REGS, fprobe events will not be able to be used

[PATCH v6 31/36] bpf: Enable kprobe_multi feature if CONFIG_FPROBE is enabled

2024-01-12 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Enable kprobe_multi feature if CONFIG_FPROBE is enabled. The pt_regs is converted from ftrace_regs by ftrace_partial_regs(), thus some registers may always returns 0. But it should be enough for function entry (access arguments) and exit (access return value

[PATCH v6 32/36] fprobe: Rewrite fprobe on function-graph tracer

2024-01-12 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Rewrite fprobe implementation on function-graph tracer. Major API changes are: - 'nr_maxactive' field is deprecated. - This depends on CONFIG_DYNAMIC_FTRACE_WITH_ARGS or !CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS, and CONFIG_HAVE_FUNCTION_GRAPH

[PATCH v6 33/36] tracing/fprobe: Remove nr_maxactive from fprobe

2024-01-12 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Remove depercated fprobe::nr_maxactive. This involves fprobe events to rejects the maxactive number. Signed-off-by: Masami Hiramatsu (Google) --- Changes in v2: - Newly added. --- include/linux/fprobe.h |2 -- kernel/trace/trace_fprobe.c | 44

[PATCH v6 34/36] selftests: ftrace: Remove obsolate maxactive syntax check

2024-01-12 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Since the fprobe event does not support maxactive anymore, stop testing the maxactive syntax error checking. Signed-off-by: Masami Hiramatsu (Google) --- .../ftrace/test.d/dynevent/fprobe_syntax_errors.tc |4 +--- 1 file changed, 1 insertion(+), 3 deletions

[PATCH v6 35/36] selftests/ftrace: Add a test case for repeating register/unregister fprobe

2024-01-12 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) This test case repeats define and undefine the fprobe dynamic event to ensure that the fprobe does not cause any issue with such operations. Signed-off-by: Masami Hiramatsu (Google) --- .../test.d/dynevent/add_remove_fprobe_repeat.tc| 19

[PATCH v6 36/36] Documentation: probes: Update fprobe on function-graph tracer

2024-01-12 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Update fprobe documentation for the new fprobe on function-graph tracer. This includes some bahvior changes and pt_regs to ftrace_regs interface change. Signed-off-by: Masami Hiramatsu (Google) --- Changes in v2: - Update @fregs parameter explanation

[PATCH 0/2] tracing/probes: Fix probe event argument parser

2024-01-23 Thread Masami Hiramatsu (Google)
y BTF. Thank you, --- Masami Hiramatsu (Google) (2): tracing/probes: Fix to show a parse error for bad type for $comm tracing/probes: Fix to set arg size and fmt after setting type from BTF kernel/trace/trace_probe.c | 32 ++-- kernel/trace/trace_pr

[PATCH 1/2] tracing/probes: Fix to show a parse error for bad type for $comm

2024-01-23 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Fix to show a parse error for bad type (non-string) for $comm/$COMM and immediate-string. With this fix, error_log file shows appropriate error message as below. /sys/kernel/tracing # echo 'p vfs_read $comm:u32' >> kprobe_events sh: write error:

[PATCH 2/2] tracing/probes: Fix to set arg size and fmt after setting type from BTF

2024-01-23 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Since the BTF type setting updates probe_arg::type, the type size calculation and setting print-fmt should be done after that. Without this fix, the argument size and print-fmt can be wrong. Fixes: b576e09701c7 ("tracing/probes: Support function parameters i

[PATCH] tracing/trigger: Fix to return error if failed to alloc snapshot

2024-01-25 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Fix register_snapshot_trigger() to return error code if it failed to allocate a snapshot instead of 0 (success). Unless that, it will register snapshot trigger without an error. Fixes: 0bbe7f719985 ("tracing: Fix the race between registering 'snapsh

[PATCH v7 00/36] tracing: fprobe: function_graph: Multi-function graph and fprobe on fgraph

2024-02-06 Thread Masami Hiramatsu (Google)
an be applied against the linux-trace/trace/urgent (based on v6.8-rc1) kernel. This series can also be found below branch. https://git.kernel.org/pub/scm/linux/kernel/git/mhiramat/linux.git/log/?h=topic/fprobe-on-fgraph Thank you, --- Masami Hiramatsu (Google) (21): ftrace: Fix DIRECT_CA

[PATCH v7 01/36] ftrace: Fix DIRECT_CALLS to use SAVE_REGS by default

2024-02-06 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) The commit 60c8971899f3 ("ftrace: Make DIRECT_CALLS work WITH_ARGS and !WITH_REGS") changed DIRECT_CALLS to use SAVE_ARGS when there are multiple ftrace_ops at the same function, but since the x86 only support to jump to direct_call from ftrace_regs_ca

[PATCH v7 02/36] tracing: Add a comment about ftrace_regs definition

2024-02-06 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) To clarify what will be expected on ftrace_regs, add a comment to the architecture independent definition of the ftrace_regs. Signed-off-by: Masami Hiramatsu (Google) Acked-by: Mark Rutland --- Changes in v3: - Add instruction pointer Changes in v2

[PATCH v7 03/36] tracing: Rename ftrace_regs_return_value to ftrace_regs_get_return_value

2024-02-06 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Rename ftrace_regs_return_value to ftrace_regs_get_return_value as same as other ftrace_regs_get/set_* APIs. Signed-off-by: Masami Hiramatsu (Google) Acked-by: Mark Rutland --- Changes in v6: - Moved to top of the series. Changes in v3: - Newly added

[PATCH v7 04/36] x86: tracing: Add ftrace_regs definition in the header

2024-02-06 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Add ftrace_regs definition for x86_64 in the ftrace header to clarify what register will be accessible from ftrace_regs. Signed-off-by: Masami Hiramatsu (Google) --- Changes in v3: - Add rip to be saved. Changes in v2: - Newly added. --- arch/x86/include

[PATCH v7 05/36] function_graph: Convert ret_stack to a series of longs

2024-02-06 Thread Masami Hiramatsu (Google)
the return side of the functions. Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- include/linux/sched.h |2 - kernel/trace/fgraph.c | 124 - 2 files changed, 71 insertions(+), 55 deletions(-) diff --git a

[PATCH v7 06/36] fgraph: Use BUILD_BUG_ON() to make sure we have structures divisible by long

2024-02-06 Thread Masami Hiramatsu (Google)
dt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- Changes in v7: - Use DIV_ROUND_UP() to calculate FGRAPH_RET_INDEX --- kernel/trace/fgraph.c |9 ++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c index 30

[PATCH v7 07/36] function_graph: Add an array structure that will allow multiple callbacks

2024-02-06 Thread Masami Hiramatsu (Google)
n the shadow stack. We need to only save the index, because this will allow the fgraph_ops to be freed before the function returns (which may happen if the function call schedule for a long time). Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- Changes in v2: - R

[PATCH v7 08/36] function_graph: Allow multiple users to attach to function graph

2024-02-06 Thread Masami Hiramatsu (Google)
s when both are called is not completely handled yet, but that shouldn't be too hard to manage. Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- Changes in v7: - Fix max limitation check in ftrace_graph_push_return(). - Rewrite the shadow stack impleme

[PATCH v7 09/36] function_graph: Remove logic around ftrace_graph_entry and return

2024-02-06 Thread Masami Hiramatsu (Google)
function_graph tracer. Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- Changes in v2: - Fix typo and make lines shorter than 76 chars in the description. - Remove unneeded return from return_run() function. --- kernel/trace/fgraph.c | 67

[PATCH v7 11/36] ftrace: Allow function_graph tracer to be enabled in instances

2024-02-06 Thread Masami Hiramatsu (Google)
: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- Changes in v2: - Fix to remove set_graph_array() completely. --- include/linux/ftrace.h |1 + kernel/trace/ftrace.c|1 + kernel/trace/trace.h | 13 ++- kernel

[PATCH v7 10/36] ftrace/function_graph: Pass fgraph_ops to function graph callbacks

2024-02-06 Thread Masami Hiramatsu (Google)
to the function graph tracer. Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- Changes in v2: - cleanup to set argument name on function prototype. --- include/linux/ftrace.h | 10 +++--- kernel/trace/fgraph.c| 14

[PATCH v7 12/36] ftrace: Allow ftrace startup flags exist without dynamic ftrace

2024-02-06 Thread Masami Hiramatsu (Google)
compile because dynamic ftrace is disabled. This change is needed to move some of the logic of what is passed to ftrace_startup() out of the parameters of ftrace_startup(). Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- include/linux/ftrace.h | 18

[PATCH v7 14/36] function_graph: Use a simple LRU for fgraph_array index number

2024-02-06 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Since the fgraph_array index is used for the bitmap on the shadow stack, it may leave some entries after a function_graph instance is removed. Thus if another instance reuses the fgraph_array index soon after releasing it, the fgraph may confuse to call the newer

[PATCH v7 15/36] function_graph: Add "task variables" per task for fgraph_ops

2024-02-06 Thread Masami Hiramatsu (Google)
atures on a per task basis having a way to maintain state for each task. Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- Changes in v3: - Move fgraph_ops::idx to previous patch in the series. Changes in v2: - Make description lines shorter than 76 char

[PATCH v7 16/36] function_graph: Move set_graph_function tests to shadow stack global var

2024-02-06 Thread Masami Hiramatsu (Google)
are) Signed-off-by: Masami Hiramatsu (Google) --- include/linux/trace_recursion.h |5 + kernel/trace/trace.h | 32 +--- kernel/trace/trace_functions_graph.c |6 +++--- kernel/trace/trace_irqsoff.c |4 ++-- kernel/tr

[PATCH v7 17/36] function_graph: Move graph depth stored data to shadow stack global var

2024-02-06 Thread Masami Hiramatsu (Google)
are) Signed-off-by: Masami Hiramatsu (Google) --- include/linux/trace_recursion.h | 29 - kernel/trace/trace.h| 34 -- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/include/linux/trace_recursion.h b/incl

[PATCH v7 18/36] function_graph: Move graph notrace bit to shadow stack global var

2024-02-06 Thread Masami Hiramatsu (Google)
are) Signed-off-by: Masami Hiramatsu (Google) --- Changes in v2: - Make description lines shorter than 76 chars. --- include/linux/trace_recursion.h |7 --- kernel/trace/trace.h |9 + kernel/trace/trace_functions_graph.c | 10 ++ 3 files chan

[PATCH v7 19/36] function_graph: Implement fgraph_reserve_data() and fgraph_retrieve_data()

2024-02-06 Thread Masami Hiramatsu (Google)
x27;s shadow ret_stack and this then can be retrieved by fgraph_retrieve_data() called by the corresponding retfunc(). Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- Changes in v3: - Store fgraph_array index to the data entry. - Both function req

[PATCH v7 22/36] function_graph: Add a new entry handler with parent_ip and ftrace_regs

2024-02-06 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Add a new entry handler to fgraph_ops as 'entryregfunc' which takes parent_ip and ftrace_regs. Note that the 'entryfunc' and 'entryregfunc' are mutual exclusive. You can set only one of them. Signed-off-by: Masami Hiramats

[PATCH v7 23/36] function_graph: Add a new exit handler with parent_ip and ftrace_regs

2024-02-06 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Add a new return handler to fgraph_ops as 'retregfunc' which takes parent_ip and ftrace_regs instead of ftrace_graph_ret. This handler is available only if the arch support CONFIG_HAVE_FUNCTION_GRAPH_FREGS. Note that the 'retfunc' and &#

[PATCH v7 24/36] x86/ftrace: Enable HAVE_FUNCTION_GRAPH_FREGS

2024-02-06 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Support HAVE_FUNCTION_GRAPH_FREGS on x86-64, which saves ftrace_regs on the stack in ftrace_graph return trampoline so that the callbacks can access registers via ftrace_regs APIs. Note that this only recovers 'rax' and 'rdx' registers because

[PATCH v7 25/36] arm64: ftrace: Enable HAVE_FUNCTION_GRAPH_FREGS

2024-02-06 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Enable CONFIG_HAVE_FUNCTION_GRAPH_FREGS on arm64. Note that this depends on HAVE_DYNAMIC_FTRACE_WITH_ARGS which is enabled if the compiler supports "-fpatchable-function-entry=2". If not, it continue to use ftrace_ret_regs. Signed-off-by: Masami Hiramat

[PATCH v7 26/36] fprobe: Use ftrace_regs in fprobe entry handler

2024-02-06 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) This allows fprobes to be available with CONFIG_DYNAMIC_FTRACE_WITH_ARGS instead of CONFIG_DYNAMIC_FTRACE_WITH_REGS, then we can enable fprobe on arm64. Signed-off-by: Masami Hiramatsu (Google) Acked-by: Florent Revest --- Changes in v6: - Keep using

[PATCH v7 27/36] fprobe: Use ftrace_regs in fprobe exit handler

2024-02-06 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Change the fprobe exit handler to use ftrace_regs structure instead of pt_regs. This also introduce HAVE_PT_REGS_TO_FTRACE_REGS_CAST which means the ftrace_regs's memory layout is equal to the pt_regs so that those are able to cast. Fprobe introduces

[PATCH v7 28/36] tracing: Add ftrace_partial_regs() for converting ftrace_regs to pt_regs

2024-02-06 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Add ftrace_partial_regs() which converts the ftrace_regs to pt_regs. If the architecture defines its own ftrace_regs, this copies partial registers to pt_regs and returns it. If not, ftrace_regs is the same as pt_regs and ftrace_partial_regs() will return

[PATCH v7 29/36] tracing: Add ftrace_fill_perf_regs() for perf event

2024-02-06 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Add ftrace_fill_perf_regs() which should be compatible with the perf_fetch_caller_regs(). In other words, the pt_regs returned from the ftrace_fill_perf_regs() must satisfy 'user_mode(regs) == false' and can be used for stack tracing. Signed-off-

[PATCH v7 30/36] tracing/fprobe: Enable fprobe events with CONFIG_DYNAMIC_FTRACE_WITH_ARGS

2024-02-06 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Allow fprobe events to be enabled with CONFIG_DYNAMIC_FTRACE_WITH_ARGS. With this change, fprobe events mostly use ftrace_regs instead of pt_regs. Note that if the arch doesn't enable HAVE_PT_REGS_COMPAT_FTRACE_REGS, fprobe events will not be able to be used

[PATCH v7 31/36] bpf: Enable kprobe_multi feature if CONFIG_FPROBE is enabled

2024-02-06 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Enable kprobe_multi feature if CONFIG_FPROBE is enabled. The pt_regs is converted from ftrace_regs by ftrace_partial_regs(), thus some registers may always returns 0. But it should be enough for function entry (access arguments) and exit (access return value

[PATCH v7 13/36] function_graph: Have the instances use their own ftrace_ops for filtering

2024-02-06 Thread Masami Hiramatsu (Google)
function_graph_enter_ops() instead of function_graph_enter() so that it avoid pushing on shadow stack multiple times on the same function. Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- Changes in v7: - Move FGRAPH_TYPE_BITMAP type implementation to earlier patch

[PATCH v7 32/36] fprobe: Rewrite fprobe on function-graph tracer

2024-02-06 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Rewrite fprobe implementation on function-graph tracer. Major API changes are: - 'nr_maxactive' field is deprecated. - This depends on CONFIG_DYNAMIC_FTRACE_WITH_ARGS or !CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS, and CONFIG_HAVE_FUNCTION_GRAPH

[PATCH v7 33/36] tracing/fprobe: Remove nr_maxactive from fprobe

2024-02-06 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Remove depercated fprobe::nr_maxactive. This involves fprobe events to rejects the maxactive number. Signed-off-by: Masami Hiramatsu (Google) --- Changes in v2: - Newly added. --- include/linux/fprobe.h |2 -- kernel/trace/trace_fprobe.c | 44

[PATCH v7 34/36] selftests: ftrace: Remove obsolate maxactive syntax check

2024-02-06 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Since the fprobe event does not support maxactive anymore, stop testing the maxactive syntax error checking. Signed-off-by: Masami Hiramatsu (Google) --- .../ftrace/test.d/dynevent/fprobe_syntax_errors.tc |4 +--- 1 file changed, 1 insertion(+), 3 deletions

[PATCH v7 36/36] Documentation: probes: Update fprobe on function-graph tracer

2024-02-06 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Update fprobe documentation for the new fprobe on function-graph tracer. This includes some bahvior changes and pt_regs to ftrace_regs interface change. Signed-off-by: Masami Hiramatsu (Google) --- Changes in v2: - Update @fregs parameter explanation

[PATCH v7 21/36] function_graph: Add selftest for passing local variables

2024-02-06 Thread Masami Hiramatsu (Google)
From: Steven Rostedt (VMware) Add boot up selftest that passes variables from a function entry to a function exit, and make sure that they do get passed around. Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- Changes in v2: - Add reserved size test

[PATCH v7 20/36] function_graph: Improve push operation for several interrupts

2024-02-06 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Improve push and data reserve operation on the shadow stack for several sequencial interrupts. To push a ret_stack or data entry on the shadow stack, we need to prepare an index (offset) entry before updating the stack pointer (curr_ret_stack) so that unwinder

[PATCH v7 35/36] selftests/ftrace: Add a test case for repeating register/unregister fprobe

2024-02-06 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) This test case repeats define and undefine the fprobe dynamic event to ensure that the fprobe does not cause any issue with such operations. Signed-off-by: Masami Hiramatsu (Google) --- .../test.d/dynevent/add_remove_fprobe_repeat.tc| 19

[PATCH RFC 0/5] tracing/probes: Support function parameter access from return probe

2024-02-14 Thread Masami Hiramatsu (Google)
e those fields are initialized at exit. TODO: - update README file - add/update ftracetest - update documents Thank you, --- Masami Hiramatsu (Google) (5): tracing/probes: Fix to search structure fields correctly tracing/fprobe-event: cleanup: Fix a wrong comment in fprobe e

[PATCH RFC 1/5] tracing/probes: Fix to search structure fields correctly

2024-02-14 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Fix to search a field from the structure which has anonymous union correctly. Since the reference `type` pointer was updated in the loop, the search loop suddenly aborted where it hits an anonymous union. Thus it can not find the field after the anonymous union

[PATCH RFC 2/5] tracing/fprobe-event: cleanup: Fix a wrong comment in fprobe event

2024-02-14 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Despite the fprobe event, "Kretprobe" was commented. So fix it. Signed-off-by: Masami Hiramatsu (Google) --- kernel/trace/trace_fprobe.c |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/trace/trace_fprobe.c b/ke

[PATCH RFC 3/5] tracing/probes: Cleanup probe argument parser

2024-02-14 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Cleanup traceprobe_parse_probe_arg_body() to split out the type parser and post-processing part of fetch_insn. This makes no functional change. Signed-off-by: Masami Hiramatsu (Google) --- kernel/trace/trace_probe.c | 230

[PATCH RFC 4/5] tracing/probes: cleanup: Set trace_probe::nr_args at trace_probe_init

2024-02-14 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Instead of incrementing the trace_probe::nr_args, init it at trace_probe_init(). This is a cleanup, so the behavior is not changed. Signed-off-by: Masami Hiramatsu (Google) --- kernel/trace/trace_eprobe.c |2 +- kernel/trace/trace_probe.c | 10

[PATCH RFC 5/5] tracing/probes: Support $argN in return probe (kprobe and fprobe)

2024-02-14 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Support accessing $argN in the return probe events. This will help users to record entry data in function return (exit) event for simplfing the function entry/exit information in one event, and record the result values (e.g. allocated object/initialized object) at

[PATCH v8 00/35] tracing: fprobe: function_graph: Multi-function graph and fprobe on fgraph

2024-02-25 Thread Masami Hiramatsu (Google)
before the return callback runs. Thus the address validation must be done before using it in the return callback. This series can be applied against the v6.8-rc4 kernel. This series can also be found below branch. https://git.kernel.org/pub/scm/linux/kernel/git/mhiramat/linux.git/log/?h=topi

[PATCH v8 01/35] tracing: Add a comment about ftrace_regs definition

2024-02-25 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) To clarify what will be expected on ftrace_regs, add a comment to the architecture independent definition of the ftrace_regs. Signed-off-by: Masami Hiramatsu (Google) Acked-by: Mark Rutland --- Changes in v8: - Update that the saved registers depends on the

[PATCH v8 02/35] tracing: Rename ftrace_regs_return_value to ftrace_regs_get_return_value

2024-02-25 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Rename ftrace_regs_return_value to ftrace_regs_get_return_value as same as other ftrace_regs_get/set_* APIs. Signed-off-by: Masami Hiramatsu (Google) Acked-by: Mark Rutland --- Changes in v6: - Moved to top of the series. Changes in v3: - Newly added

[PATCH v8 03/35] x86: tracing: Add ftrace_regs definition in the header

2024-02-25 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Add ftrace_regs definition for x86_64 in the ftrace header to clarify what register will be accessible from ftrace_regs. Signed-off-by: Masami Hiramatsu (Google) --- Changes in v3: - Add rip to be saved. Changes in v2: - Newly added. --- arch/x86/include

[PATCH v8 04/35] function_graph: Convert ret_stack to a series of longs

2024-02-25 Thread Masami Hiramatsu (Google)
the return side of the functions. Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- include/linux/sched.h |2 - kernel/trace/fgraph.c | 124 - 2 files changed, 71 insertions(+), 55 deletions(-) diff --git a

[PATCH v8 05/35] fgraph: Use BUILD_BUG_ON() to make sure we have structures divisible by long

2024-02-25 Thread Masami Hiramatsu (Google)
dt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- Changes in v7: - Use DIV_ROUND_UP() to calculate FGRAPH_RET_INDEX --- kernel/trace/fgraph.c |9 ++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c index 30

[PATCH v8 06/35] function_graph: Add an array structure that will allow multiple callbacks

2024-02-25 Thread Masami Hiramatsu (Google)
n the shadow stack. We need to only save the index, because this will allow the fgraph_ops to be freed before the function returns (which may happen if the function call schedule for a long time). Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- Changes in v2: - R

[PATCH v8 07/35] function_graph: Allow multiple users to attach to function graph

2024-02-25 Thread Masami Hiramatsu (Google)
s when both are called is not completely handled yet, but that shouldn't be too hard to manage. Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- Changes in v7: - Fix max limitation check in ftrace_graph_push_return(). - Rewrite the shadow stack impleme

[PATCH v8 08/35] function_graph: Remove logic around ftrace_graph_entry and return

2024-02-25 Thread Masami Hiramatsu (Google)
function_graph tracer. Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- Changes in v2: - Fix typo and make lines shorter than 76 chars in the description. - Remove unneeded return from return_run() function. --- kernel/trace/fgraph.c | 67

[PATCH v8 09/35] ftrace/function_graph: Pass fgraph_ops to function graph callbacks

2024-02-25 Thread Masami Hiramatsu (Google)
to the function graph tracer. Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- Changes in v2: - cleanup to set argument name on function prototype. --- include/linux/ftrace.h | 10 +++--- kernel/trace/fgraph.c| 16

[PATCH v8 10/35] ftrace: Allow function_graph tracer to be enabled in instances

2024-02-25 Thread Masami Hiramatsu (Google)
: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- Changes in v2: - Fix to remove set_graph_array() completely. --- include/linux/ftrace.h |1 + kernel/trace/ftrace.c|1 + kernel/trace/trace.h | 13 ++- kernel

[PATCH v8 11/35] ftrace: Allow ftrace startup flags exist without dynamic ftrace

2024-02-25 Thread Masami Hiramatsu (Google)
compile because dynamic ftrace is disabled. This change is needed to move some of the logic of what is passed to ftrace_startup() out of the parameters of ftrace_startup(). Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- include/linux/ftrace.h | 18

[PATCH v8 12/35] function_graph: Have the instances use their own ftrace_ops for filtering

2024-02-25 Thread Masami Hiramatsu (Google)
function_graph_enter_ops() instead of function_graph_enter() so that it avoid pushing on shadow stack multiple times on the same function. Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- Changes in v8: - Fix a compilation error in loongarch implementation

[PATCH v8 13/35] function_graph: Use a simple LRU for fgraph_array index number

2024-02-25 Thread Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) Since the fgraph_array index is used for the bitmap on the shadow stack, it may leave some entries after a function_graph instance is removed. Thus if another instance reuses the fgraph_array index soon after releasing it, the fgraph may confuse to call the newer

  1   2   3   4   5   >