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
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) · 2220 unmodified lines
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) · 1587 unmodified lines
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) {