[PATCH 2/2] ftrace: skip special ftrace_ops when enable module

From: Chengming Zhou
Date: Tue Jul 28 2020 - 14:08:32 EST


When enable module, we find all ftrace_ops referenced it on the
ftrace_ops_list. But FTRACE_OPS_FL_DIRECT and FTRACE_OPS_FL_IPMODIFY
flag are special, and should not be set automatically. So warn and
skip ftrace_ops that have these two flags.
Also check if only one ftrace_ops references the module, in which case
we can use trampoline as an optimization.

Signed-off-by: Chengming Zhou <zhouchengming@xxxxxxxxxxxxx>
Signed-off-by: Muchun Song <songmuchun@xxxxxxxxxxxxx>
---
kernel/trace/ftrace.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index a3d141f53c9e..8c1d9e3daa67 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -6191,9 +6191,17 @@ static int referenced_filters(struct dyn_ftrace *rec)

for (ops = ftrace_ops_list; ops != &ftrace_list_end; ops = ops->next) {
if (ops_references_rec(ops, rec)) {
+ if (WARN_ON_ONCE(ops->flags & FTRACE_OPS_FL_DIRECT))
+ continue;
+ if (WARN_ON_ONCE(ops->flags & FTRACE_OPS_FL_IPMODIFY))
+ continue;
cnt++;
if (ops->flags & FTRACE_OPS_FL_SAVE_REGS)
rec->flags |= FTRACE_FL_REGS;
+ if (cnt == 1 && ops->trampoline)
+ rec->flags |= FTRACE_FL_TRAMP;
+ else
+ rec->flags &= ~FTRACE_FL_TRAMP;
}
}

--
2.20.1