mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Song Shuai <suagrfillet@gmail.com>
To: rostedt@goodmis.org, mingo@redhat.com
Cc: linux-kernel@vger.kernel.org, Song Shuai <suagrfillet@gmail.com>
Subject: [PATCH] ftrace: avoid replacing the list func with itself
Date: Wed, 26 Oct 2022 21:20:39 +0800	[thread overview]
Message-ID: <20221026132039.2236233-1-suagrfillet@gmail.com> (raw)

The list func (ftrace_ops_list_func) will be patched first
before the transition between old and new calls are set,
which fixed the race described in this commit `59338f75`.

While ftrace_trace_function changes from the list func to a
ftrace_ops func, like unregistering the klp_ops to leave the only
global_ops in ftrace_ops_list, the ftrace_[regs]_call will be
replaced with the list func although it already exists. So there
should be a condition to avoid this.

This patch backups saved_ftrace_func by saved_ftrace_func_old
which will be compared with the list func before trying to patch it.

Signed-off-by: Song Shuai <suagrfillet@gmail.com>
---
 kernel/trace/ftrace.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index bc921a3f7ea8..56b1a42e1937 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -2755,6 +2755,8 @@ void __weak ftrace_arch_code_modify_post_process(void)
 {
 }
 
+static ftrace_func_t saved_ftrace_func_old;
+
 void ftrace_modify_all_code(int command)
 {
 	int update = command & FTRACE_UPDATE_TRACE_FUNC;
@@ -2774,7 +2776,7 @@ void ftrace_modify_all_code(int command)
 	 * to make sure the ops are having the right functions
 	 * traced.
 	 */
-	if (update) {
+	if (update && saved_ftrace_func_old != ftrace_ops_list_func) {
 		err = ftrace_update_ftrace_func(ftrace_ops_list_func);
 		if (FTRACE_WARN_ON(err))
 			return;
@@ -2918,6 +2920,7 @@ static void ftrace_trampoline_free(struct ftrace_ops *ops)
 static void ftrace_startup_enable(int command)
 {
 	if (saved_ftrace_func != ftrace_trace_function) {
+		saved_ftrace_func_old = saved_ftrace_func;
 		saved_ftrace_func = ftrace_trace_function;
 		command |= FTRACE_UPDATE_TRACE_FUNC;
 	}
@@ -3007,6 +3010,7 @@ int ftrace_shutdown(struct ftrace_ops *ops, int command)
 	ops->flags &= ~FTRACE_OPS_FL_ENABLED;
 
 	if (saved_ftrace_func != ftrace_trace_function) {
+		saved_ftrace_func_old = saved_ftrace_func;
 		saved_ftrace_func = ftrace_trace_function;
 		command |= FTRACE_UPDATE_TRACE_FUNC;
 	}
@@ -8321,6 +8325,7 @@ static void ftrace_startup_sysctl(void)
 
 	/* Force update next time */
 	saved_ftrace_func = NULL;
+	saved_ftrace_func_old = NULL;
 	/* ftrace_start_up is true if we want ftrace running */
 	if (ftrace_start_up) {
 		command = FTRACE_UPDATE_CALLS;
-- 
2.20.1


             reply	other threads:[~2022-10-26 13:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-26 13:20 Song Shuai [this message]
2022-11-22  2:28 ` Song Shuai
2022-11-22  2:34   ` Steven Rostedt
2022-11-22  2:37     ` Song Shuai
2022-11-22 21:32   ` Steven Rostedt
2022-11-23  1:58     ` Song Shuai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221026132039.2236233-1-suagrfillet@gmail.com \
    --to=suagrfillet@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®