When inserting a module, we find all ftrace_ops referencing it on the ftrace_ops_list. But FTRACE_OPS_FL_DIRECT and FTRACE_OPS_FL_IPMODIFY flags are special, and should not be set automatically. So warn and skip ftrace_ops that have these two flags set and adding new code. Also check if only one ftrace_ops references the module, in which case we can use a trampoline as an optimization. Link: https://lkml.kernel.org/r/20200728180554.65203-2-zhouchengming@bytedance.com
Unified · Split
| @@ -6199,9 +6199,17 @@ static int referenced_filters(struct dyn_ftrace *rec) · 6198 unmodified lines | |||
| 6199 | 6199 | ||
| 6200 | for (ops = ftrace_ops_list; ops != &ftrace_list_end; ops = ops->next) { | 6200 | for (ops = ftrace_ops_list; ops != &ftrace_list_end; ops = ops->next) { |
| 6201 | if (ops_references_rec(ops, rec)) { | 6201 | if (ops_references_rec(ops, rec)) { |
| 6202 | if (WARN_ON_ONCE(ops->flags & FTRACE_OPS_FL_DIRECT)) | ||
| 6203 | continue; | ||
| 6204 | if (WARN_ON_ONCE(ops->flags & FTRACE_OPS_FL_IPMODIFY)) | ||
| 6205 | continue; | ||
| 6202 | cnt++; | 6206 | cnt++; |
| 6203 | if (ops->flags & FTRACE_OPS_FL_SAVE_REGS) | 6207 | if (ops->flags & FTRACE_OPS_FL_SAVE_REGS) |
| 6204 | rec->flags |= FTRACE_FL_REGS; | 6208 | rec->flags |= FTRACE_FL_REGS; |
| 6209 | if (cnt == 1 && ops->trampoline) | ||
| 6210 | rec->flags |= FTRACE_FL_TRAMP; | ||
| 6211 | else | ||
| 6212 | rec->flags &= ~FTRACE_FL_TRAMP; | ||
| 6205 | } | 6213 | } |
| 6206 | } | 6214 | } |
| 6207 | 6215 | ||