History

ftrace: Add MODIFIED flag to show if IPMODIFY or direct was attached

If a function had ever had IPMODIFY or DIRECT attached to it, where this is how live kernel patching and BPF overrides work, mark them and display an "M" in the enabled_functions and touched_functions files. This can be used for debugging. If a function had been modified and later there's a bug in the code related to that function, this can be used to know if the cause is possibly from a live kernel patch or a BPF program that changed the behavior of the code. Also update the documentation on the enabled_functions and touched_functions output, as it was missing direct callers and CALL_OPS. And include this new modify attribute. Link: https://lore.kernel.org/linux-trace-kernel/20230502213233.004e3ae4@gandalf.local.home

Steven Rostedt (Google) committed 3 years ago

Commit 6ce2c041 parent 4f945593 files · +37 −4Browse files

Showing the changes to kernel (1 of 3 files). Show all

Unified · Split

kernel/trace/ftrace.c+9−3
@@ -46,7 +46,8 @@ · 45 unmodified lines
46#include "trace_stat.h"46#include "trace_stat.h"
47 47
48/* Flags that do not get reset */48/* 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)
50 51
51#define FTRACE_INVALID_FUNCTION "__ftrace_invalid_address__"52#define FTRACE_INVALID_FUNCTION "__ftrace_invalid_address__"
52 53
@@ -2273,6 +2274,10 @@ static int ftrace_check_record(struct dyn_ftrace *rec, bool enable, bool update) · 2220 unmodified lines
2273 rec->flags &= ~FTRACE_FL_TRAMP_EN;2274 rec->flags &= ~FTRACE_FL_TRAMP_EN;
2274 }2275 }
2275 2276
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
2276 if (flag & FTRACE_FL_DIRECT) {2281 if (flag & FTRACE_FL_DIRECT) {
2277 /*2282 /*
2278 * If there's only one user (direct_ops helper)2283 * If there's only one user (direct_ops helper)
@@ -3866,12 +3871,13 @@ static int t_show(struct seq_file *m, void *v) · 1587 unmodified lines
3866 if (iter->flags & (FTRACE_ITER_ENABLED | FTRACE_ITER_TOUCHED)) {3871 if (iter->flags & (FTRACE_ITER_ENABLED | FTRACE_ITER_TOUCHED)) {
3867 struct ftrace_ops *ops;3872 struct ftrace_ops *ops;
3868 3873
3869 seq_printf(m, " (%ld)%s%s%s%s",3874 seq_printf(m, " (%ld)%s%s%s%s%s",
3870 ftrace_rec_count(rec),3875 ftrace_rec_count(rec),
3871 rec->flags & FTRACE_FL_REGS ? " R" : " ",3876 rec->flags & FTRACE_FL_REGS ? " R" : " ",
3872 rec->flags & FTRACE_FL_IPMODIFY ? " I" : " ",3877 rec->flags & FTRACE_FL_IPMODIFY ? " I" : " ",
3873 rec->flags & FTRACE_FL_DIRECT ? " D" : " ",3878 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 " : " ");
3875 if (rec->flags & FTRACE_FL_TRAMP_EN) {3881 if (rec->flags & FTRACE_FL_TRAMP_EN) {
3876 ops = ftrace_find_tramp_ops_any(rec);3882 ops = ftrace_find_tramp_ops_any(rec);
3877 if (ops) {3883 if (ops) {