Re: [PATCH] ftrace: fix recursive locking direct_mutex in ftrace_modify_direct_caller
From: Steven Rostedt
Date: Sat Sep 24 2022 - 11:01:24 EST
On Mon, 19 Sep 2022 10:29:55 -0700
Song Liu <song@xxxxxxxxxx> wrote:
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index 439e2ab6905e..d308d0674805 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -5461,7 +5461,7 @@ int __weak ftrace_modify_direct_caller(struct ftrace_func_entry *entry,
> if (ret)
> goto out_lock;
>
> - ret = register_ftrace_function(&stub_ops);
> + ret = register_ftrace_function_nolock(&stub_ops);
> if (ret) {
> ftrace_set_filter_ip(&stub_ops, ip, 1, 0);
> goto out_lock;
> --
We need to update the comments to this function, as well add an:
#define lock_direct_assert_held() lockdep_assert_held(&direct_mutex);
And call that in this function. Otherwise, we can be calling this code
without it held and cause races.
-- Steve