Skip to content

Commit e919a3f

Browse files
committed
Merge tag 'trace-v6.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace
Pull more tracing updates from Steven Rostedt: - Make buffer_percent read/write. The buffer_percent file is how users can state how long to block on the tracing buffer depending on how much is in the buffer. When it hits the "buffer_percent" it will wake the task waiting on the buffer. For some reason it was set to read-only. This was not noticed because testing was done as root without SELinux, but with SELinux it will prevent even root to write to it without having CAP_DAC_OVERRIDE. - The "touched_functions" was added this merge window, but one of the reasons for adding it was not implemented. That was to show what functions were not only touched, but had either a direct trampoline attached to it, or a kprobe or live kernel patching that can "hijack" the function to run a different function. The point is to know if there's functions in the kernel that may not be behaving as the kernel code shows. This can be used for debugging. TODO: Add this information to kernel oops too. * tag 'trace-v6.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: ftrace: Add MODIFIED flag to show if IPMODIFY or direct was attached tracing: Fix permissions for the buffer_percent file
2 parents b115d85 + 6ce2c04 commit e919a3f

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

Documentation/trace/ftrace.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,19 @@ of ftrace. Here is a list of some of the key files:
350350
an 'I' will be displayed on the same line as the function that
351351
can be overridden.
352352

353+
If a non ftrace trampoline is attached (BPF) a 'D' will be displayed.
354+
Note, normal ftrace trampolines can also be attached, but only one
355+
"direct" trampoline can be attached to a given function at a time.
356+
357+
Some architectures can not call direct trampolines, but instead have
358+
the ftrace ops function located above the function entry point. In
359+
such cases an 'O' will be displayed.
360+
361+
If a function had either the "ip modify" or a "direct" call attached to
362+
it in the past, a 'M' will be shown. This flag is never cleared. It is
363+
used to know if a function was every modified by the ftrace infrastructure,
364+
and can be used for debugging.
365+
353366
If the architecture supports it, it will also show what callback
354367
is being directly called by the function. If the count is greater
355368
than 1 it most likely will be ftrace_ops_list_func().
@@ -359,6 +372,18 @@ of ftrace. Here is a list of some of the key files:
359372
its address will be printed as well as the function that the
360373
trampoline calls.
361374

375+
touched_functions:
376+
377+
This file contains all the functions that ever had a function callback
378+
to it via the ftrace infrastructure. It has the same format as
379+
enabled_functions but shows all functions that have every been
380+
traced.
381+
382+
To see any function that has every been modified by "ip modify" or a
383+
direct trampoline, one can perform the following command:
384+
385+
grep ' M ' /sys/kernel/tracing/touched_functions
386+
362387
function_profile_enabled:
363388

364389
When set it will enable all functions with either the function

include/linux/ftrace.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ bool is_ftrace_trampoline(unsigned long addr);
549549
* CALL_OPS - the record can use callsite-specific ops
550550
* CALL_OPS_EN - the function is set up to use callsite-specific ops
551551
* TOUCHED - A callback was added since boot up
552+
* MODIFIED - The function had IPMODIFY or DIRECT attached to it
552553
*
553554
* When a new ftrace_ops is registered and wants a function to save
554555
* pt_regs, the rec->flags REGS is set. When the function has been
@@ -569,9 +570,10 @@ enum {
569570
FTRACE_FL_CALL_OPS = (1UL << 22),
570571
FTRACE_FL_CALL_OPS_EN = (1UL << 21),
571572
FTRACE_FL_TOUCHED = (1UL << 20),
573+
FTRACE_FL_MODIFIED = (1UL << 19),
572574
};
573575

574-
#define FTRACE_REF_MAX_SHIFT 20
576+
#define FTRACE_REF_MAX_SHIFT 19
575577
#define FTRACE_REF_MAX ((1UL << FTRACE_REF_MAX_SHIFT) - 1)
576578

577579
#define ftrace_rec_count(rec) ((rec)->flags & FTRACE_REF_MAX)

kernel/trace/ftrace.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
#include "trace_stat.h"
4747

4848
/* Flags that do not get reset */
49-
#define FTRACE_NOCLEAR_FLAGS (FTRACE_FL_DISABLED | FTRACE_FL_TOUCHED)
49+
#define FTRACE_NOCLEAR_FLAGS (FTRACE_FL_DISABLED | FTRACE_FL_TOUCHED | \
50+
FTRACE_FL_MODIFIED)
5051

5152
#define FTRACE_INVALID_FUNCTION "__ftrace_invalid_address__"
5253

@@ -2273,6 +2274,10 @@ static int ftrace_check_record(struct dyn_ftrace *rec, bool enable, bool update)
22732274
rec->flags &= ~FTRACE_FL_TRAMP_EN;
22742275
}
22752276

2277+
/* Keep track of anything that modifies the function */
2278+
if (rec->flags & (FTRACE_FL_DIRECT | FTRACE_FL_IPMODIFY))
2279+
rec->flags |= FTRACE_FL_MODIFIED;
2280+
22762281
if (flag & FTRACE_FL_DIRECT) {
22772282
/*
22782283
* If there's only one user (direct_ops helper)
@@ -3866,12 +3871,13 @@ static int t_show(struct seq_file *m, void *v)
38663871
if (iter->flags & (FTRACE_ITER_ENABLED | FTRACE_ITER_TOUCHED)) {
38673872
struct ftrace_ops *ops;
38683873

3869-
seq_printf(m, " (%ld)%s%s%s%s",
3874+
seq_printf(m, " (%ld)%s%s%s%s%s",
38703875
ftrace_rec_count(rec),
38713876
rec->flags & FTRACE_FL_REGS ? " R" : " ",
38723877
rec->flags & FTRACE_FL_IPMODIFY ? " I" : " ",
38733878
rec->flags & FTRACE_FL_DIRECT ? " D" : " ",
3874-
rec->flags & FTRACE_FL_CALL_OPS ? " O" : " ");
3879+
rec->flags & FTRACE_FL_CALL_OPS ? " O" : " ",
3880+
rec->flags & FTRACE_FL_MODIFIED ? " M " : " ");
38753881
if (rec->flags & FTRACE_FL_TRAMP_EN) {
38763882
ops = ftrace_find_tramp_ops_any(rec);
38773883
if (ops) {

kernel/trace/trace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9661,7 +9661,7 @@ init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer)
96619661

96629662
tr->buffer_percent = 50;
96639663

9664-
trace_create_file("buffer_percent", TRACE_MODE_READ, d_tracer,
9664+
trace_create_file("buffer_percent", TRACE_MODE_WRITE, d_tracer,
96659665
tr, &buffer_percent_fops);
96669666

96679667
create_trace_options_dir(tr);

0 commit comments

Comments
 (0)