public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tracing: Track event ref in tracefs enable/disable
@ 2022-10-12 21:57 Beau Belgrave
  2022-10-12 22:26 ` Steven Rostedt
  0 siblings, 1 reply; 5+ messages in thread
From: Beau Belgrave @ 2022-10-12 21:57 UTC (permalink / raw)
  To: rostedt, mhiramat; +Cc: linux-trace-devel, linux-kernel

When events are enabled via the "enable" file within tracefs there is no
get or put ref. Add these to ensure modules and dynamic events do not
unload while the event is enabled via tracefs.

Signed-off-by: Beau Belgrave <beaub@linux.microsoft.com>
---
 kernel/trace/trace_events.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 0356cae0cf74..f0b17adba1bc 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -634,6 +634,8 @@ static int __ftrace_event_enable_disable(struct trace_event_file *file,
 			}
 
 			call->class->reg(call, TRACE_REG_UNREGISTER, file);
+
+			trace_event_put_ref(call);
 		}
 		/* If in SOFT_MODE, just set the SOFT_DISABLE_BIT, else clear it */
 		if (file->flags & EVENT_FILE_FL_SOFT_MODE)
@@ -659,7 +661,7 @@ static int __ftrace_event_enable_disable(struct trace_event_file *file,
 		}
 
 		if (!(file->flags & EVENT_FILE_FL_ENABLED)) {
-			bool cmd = false, tgid = false;
+			bool cmd = false, tgid = false, put = false;
 
 			/* Keep the event disabled, when going to SOFT_MODE. */
 			if (soft_disable)
@@ -677,14 +679,22 @@ static int __ftrace_event_enable_disable(struct trace_event_file *file,
 				set_bit(EVENT_FILE_FL_RECORDED_TGID_BIT, &file->flags);
 			}
 
+			if (!trace_event_try_get_ref(call))
+				goto error_enabling;
+
+			put = true;
+
 			ret = call->class->reg(call, TRACE_REG_REGISTER, file);
 			if (ret) {
+error_enabling:
+				pr_info("event trace: Could not enable event "
+					"%s\n", trace_event_name(call));
 				if (cmd)
 					tracing_stop_cmdline_record();
 				if (tgid)
 					tracing_stop_tgid_record();
-				pr_info("event trace: Could not enable event "
-					"%s\n", trace_event_name(call));
+				if (put)
+					trace_event_put_ref(call);
 				break;
 			}
 			set_bit(EVENT_FILE_FL_ENABLED_BIT, &file->flags);

base-commit: 6c0f39e87b6ab1a3009e3a49d3e6f6db8dc756a8
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-10-13 16:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-12 21:57 [PATCH] tracing: Track event ref in tracefs enable/disable Beau Belgrave
2022-10-12 22:26 ` Steven Rostedt
2022-10-13  0:19   ` Beau Belgrave
2022-10-13  7:58     ` Steven Rostedt
2022-10-13 16:39       ` Beau Belgrave

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox