From nobody Sat Feb 7 08:28:37 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72D9369D3C; Fri, 9 Feb 2024 10:22:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707474140; cv=none; b=anvjGL+qW7YNgJkXFIchYY5cDIyCMxUejtRqiGgAu5UbIZP3Pn3b6LqT9S7Rb08Lk7YoEZp07Etke8andrpNhaTQe7VFwjjvMEuN44WFZgtFmGokFcAWg2TGpCS5qVntTq1gz5fVRphVW2J+Bo4PgD4oUOzOnKiAk28L+0s4zr0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707474140; c=relaxed/simple; bh=gcrpK3JCHbvy8Q1untTYfCckW8ZGxPgkiJAX+Ww1Dl4=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=oGtE8IT3Xe+eI3SGiicL7N+vMD/myAvOgNGz8w2D8yyR4DYZjGY1eWxbripRV/swrZ0EDdvvfvvxO+XE/7UtmYJqDQBgTnw/caV1YSezxzp2MasXFrUDZC1Rh5ONWPFTgxAzimF2YADZA6xvkm37RA5PkS32GUazy+WYtJ16W8s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 17CB0C433A6; Fri, 9 Feb 2024 10:22:20 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rYO23-00000006pwX-1qXh; Fri, 09 Feb 2024 05:22:55 -0500 Message-ID: <20240209102255.301135077@goodmis.org> User-Agent: quilt/0.67 Date: Fri, 09 Feb 2024 05:22:21 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , stable@vger.kernel.org, Florent Revest , Jiri Olsa Subject: [for-linus][PATCH 1/2] ftrace: Fix DIRECT_CALLS to use SAVE_REGS by default References: <20240209102220.255052617@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Masami Hiramatsu (Google)" The commit 60c8971899f3 ("ftrace: Make DIRECT_CALLS work WITH_ARGS and !WITH_REGS") changed DIRECT_CALLS to use SAVE_ARGS when there are multiple ftrace_ops at the same function, but since the x86 only support to jump to direct_call from ftrace_regs_caller, when we set the function tracer on the same target function on x86, ftrace-direct does not work as below (this actually works on arm64.) At first, insmod ftrace-direct.ko to put a direct_call on 'wake_up_process()'. # insmod kernel/samples/ftrace/ftrace-direct.ko # less trace ... -0 [006] ..s1. 564.686958: my_direct_func: waking u= p rcu_preempt-17 -0 [007] ..s1. 564.687836: my_direct_func: waking u= p kcompactd0-63 -0 [006] ..s1. 564.690926: my_direct_func: waking u= p rcu_preempt-17 -0 [006] ..s1. 564.696872: my_direct_func: waking u= p rcu_preempt-17 -0 [007] ..s1. 565.191982: my_direct_func: waking u= p kcompactd0-63 Setup a function filter to the 'wake_up_process' too, and enable it. # cd /sys/kernel/tracing/ # echo wake_up_process > set_ftrace_filter # echo function > current_tracer # less trace ... -0 [006] ..s3. 686.180972: wake_up_process <-call_t= imer_fn -0 [006] ..s3. 686.186919: wake_up_process <-call_t= imer_fn -0 [002] ..s3. 686.264049: wake_up_process <-call_t= imer_fn -0 [002] d.h6. 686.515216: wake_up_process <-kick_p= ool -0 [002] d.h6. 686.691386: wake_up_process <-kick_p= ool Then, only function tracer is shown on x86. But if you enable 'kprobe on ftrace' event (which uses SAVE_REGS flag) on the same function, it is shown again. # echo 'p wake_up_process' >> dynamic_events # echo 1 > events/kprobes/p_wake_up_process_0/enable # echo > trace # less trace ... -0 [006] ..s2. 2710.345919: p_wake_up_process_0: (wa= ke_up_process+0x4/0x20) -0 [006] ..s3. 2710.345923: wake_up_process <-call_t= imer_fn -0 [006] ..s1. 2710.345928: my_direct_func: waking u= p rcu_preempt-17 -0 [006] ..s2. 2710.349931: p_wake_up_process_0: (wa= ke_up_process+0x4/0x20) -0 [006] ..s3. 2710.349934: wake_up_process <-call_t= imer_fn -0 [006] ..s1. 2710.349937: my_direct_func: waking u= p rcu_preempt-17 To fix this issue, use SAVE_REGS flag for multiple ftrace_ops flag of direct_call by default. Link: https://lore.kernel.org/linux-trace-kernel/170484558617.178953.159051= 6949390270842.stgit@devnote2 Fixes: 60c8971899f3 ("ftrace: Make DIRECT_CALLS work WITH_ARGS and !WITH_RE= GS") Cc: stable@vger.kernel.org Cc: Florent Revest Signed-off-by: Masami Hiramatsu (Google) Reviewed-by: Mark Rutland Tested-by: Mark Rutland [arm64] Acked-by: Jiri Olsa Signed-off-by: Steven Rostedt (Google) --- kernel/trace/ftrace.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index b01ae7d36021..c060d5b47910 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -5325,7 +5325,17 @@ static LIST_HEAD(ftrace_direct_funcs); =20 static int register_ftrace_function_nolock(struct ftrace_ops *ops); =20 +/* + * If there are multiple ftrace_ops, use SAVE_REGS by default, so that dir= ect + * call will be jumped from ftrace_regs_caller. Only if the architecture d= oes + * not support ftrace_regs_caller but direct_call, use SAVE_ARGS so that it + * jumps from ftrace_caller for multiple ftrace_ops. + */ +#ifndef HAVE_DYNAMIC_FTRACE_WITH_REGS #define MULTI_FLAGS (FTRACE_OPS_FL_DIRECT | FTRACE_OPS_FL_SAVE_ARGS) +#else +#define MULTI_FLAGS (FTRACE_OPS_FL_DIRECT | FTRACE_OPS_FL_SAVE_REGS) +#endif =20 static int check_direct_multi(struct ftrace_ops *ops) { --=20 2.43.0