All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: George Guo <dongtai.guo@linux.dev>
To: gregkh@linuxfoundation.org, rostedt@goodmis.org,
	mhiramat@kernel.org, tom.zanussi@linux.intel.com
Cc: stable@vger.kernel.org, George Guo <guodongtai@kylinos.cn>
Subject: [PATCH 4.19.y 01/13] tracing: Simplify creation and deletion of synthetic events
Date: Thu,  9 May 2024 10:29:19 +0800	[thread overview]
Message-ID: <20240509022931.3513365-2-dongtai.guo@linux.dev> (raw)
In-Reply-To: <20240509022931.3513365-1-dongtai.guo@linux.dev>

From: Masami Hiramatsu <mhiramat@kernel.org>

commit faacb361f271be4baf2d807e2eeaba87e059225f upstream.

Since the event_mutex and synth_event_mutex ordering issue
is gone, we can skip existing event check when adding or
deleting events, and some redundant code in error path.

This changes release_all_synth_events() to abort the process
when it hits any error and returns the error code. It succeeds
only if it has no error.

Link: http://lkml.kernel.org/r/154140847194.17322.17960275728005067803.stgit@devbox

Reviewed-by: Tom Zanussi <tom.zanussi@linux.intel.com>
Tested-by: Tom Zanussi <tom.zanussi@linux.intel.com>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: George Guo <guodongtai@kylinos.cn>
---
 kernel/trace/trace_events_hist.c | 53 +++++++++++---------------------
 1 file changed, 18 insertions(+), 35 deletions(-)

diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index ede370225245..efba381dbc60 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -1028,18 +1028,6 @@ struct hist_var_data {
 	struct hist_trigger_data *hist_data;
 };
 
-static void add_or_delete_synth_event(struct synth_event *event, int delete)
-{
-	if (delete)
-		free_synth_event(event);
-	else {
-		if (!find_synth_event(event->name))
-			list_add(&event->list, &synth_event_list);
-		else
-			free_synth_event(event);
-	}
-}
-
 static int create_synth_event(int argc, char **argv)
 {
 	struct synth_field *field, *fields[SYNTH_FIELDS_MAX];
@@ -1072,15 +1060,16 @@ static int create_synth_event(int argc, char **argv)
 	if (event) {
 		if (delete_event) {
 			if (event->ref) {
-				event = NULL;
 				ret = -EBUSY;
 				goto out;
 			}
-			list_del(&event->list);
-			goto out;
-		}
-		event = NULL;
-		ret = -EEXIST;
+			ret = unregister_synth_event(event);
+			if (!ret) {
+				list_del(&event->list);
+				free_synth_event(event);
+			}
+		} else
+			ret = -EEXIST;
 		goto out;
 	} else if (delete_event) {
 		ret = -ENOENT;
@@ -1120,29 +1109,21 @@ static int create_synth_event(int argc, char **argv)
 		event = NULL;
 		goto err;
 	}
+	ret = register_synth_event(event);
+	if (!ret)
+		list_add(&event->list, &synth_event_list);
+	else
+		free_synth_event(event);
  out:
-	if (event) {
-		if (delete_event) {
-			ret = unregister_synth_event(event);
-			add_or_delete_synth_event(event, !ret);
-		} else {
-			ret = register_synth_event(event);
-			add_or_delete_synth_event(event, ret);
-		}
-	}
 	mutex_unlock(&synth_event_mutex);
 	mutex_unlock(&event_mutex);
 
 	return ret;
  err:
-	mutex_unlock(&synth_event_mutex);
-	mutex_unlock(&event_mutex);
-
 	for (i = 0; i < n_fields; i++)
 		free_synth_field(fields[i]);
-	free_synth_event(event);
 
-	return ret;
+	goto out;
 }
 
 static int release_all_synth_events(void)
@@ -1161,10 +1142,12 @@ static int release_all_synth_events(void)
 	}
 
 	list_for_each_entry_safe(event, e, &synth_event_list, list) {
-		list_del(&event->list);
-
 		ret = unregister_synth_event(event);
-		add_or_delete_synth_event(event, !ret);
+		if (!ret) {
+			list_del(&event->list);
+			free_synth_event(event);
+		} else
+			break;
 	}
 	mutex_unlock(&synth_event_mutex);
 	mutex_unlock(&event_mutex);
-- 
2.34.1


  reply	other threads:[~2024-05-09  2:30 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-09  2:29 [PATCH 4.19.y 00/13] fix double-free bug causing by destroy_hist_field(data->onmax.var, 0) George Guo
2024-05-09  2:29 ` George Guo [this message]
2024-05-09  2:29 ` [PATCH 4.19.y 02/13] tracing: Add unified dynamic event framework George Guo
2024-05-09  2:29 ` [PATCH 4.19.y 03/13] tracing: Use dyn_event framework for synthetic events George Guo
2024-05-09  2:29 ` [PATCH 4.19.y 04/13] tracing: Remove unneeded synth_event_mutex George Guo
2024-05-09  2:29 ` [PATCH 4.19.y 05/13] tracing: Consolidate trace_add/remove_event_call back to the nolock functions George Guo
2024-05-09  2:29 ` [PATCH 4.19.y 06/13] string.h: Add str_has_prefix() helper function George Guo
2024-05-09  2:29 ` [PATCH 4.19.y 07/13] tracing: Use str_has_prefix() helper for histogram code George Guo
2024-05-09  2:29 ` [PATCH 4.19.y 08/13] tracing: Use str_has_prefix() instead of using fixed sizes George Guo
2024-05-09  2:29 ` [PATCH 4.19.y 09/13] tracing: Have the historgram use the result of str_has_prefix() for len of prefix George Guo
2024-05-09  2:29 ` [PATCH 4.19.y 10/13] tracing: Refactor hist trigger action code George Guo
2024-05-09  2:29 ` [PATCH 4.19.y 11/13] tracing: Split up onmatch action data George Guo
2024-05-09  2:29 ` [PATCH 4.19.y 12/13] tracing: Generalize hist trigger onmax and save action George Guo
2024-05-09  2:29 ` [PATCH 4.19.y 13/13] tracing: Remove unnecessary var_ref destroy in track_data_destroy() George Guo
2024-05-23 12:09 ` [PATCH 4.19.y 00/13] fix double-free bug causing by destroy_hist_field(data->onmax.var, 0) Greg KH

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=20240509022931.3513365-2-dongtai.guo@linux.dev \
    --to=dongtai.guo@linux.dev \
    --cc=gregkh@linuxfoundation.org \
    --cc=guodongtai@kylinos.cn \
    --cc=mhiramat@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=stable@vger.kernel.org \
    --cc=tom.zanussi@linux.intel.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.