From: Beau Belgrave <beaub@linux.microsoft.com>
To: rostedt@goodmis.org, mhiramat@kernel.org
Cc: linux-trace-devel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] tracing: Track event ref in tracefs enable/disable
Date: Wed, 12 Oct 2022 14:57:17 -0700 [thread overview]
Message-ID: <20221012215717.10492-1-beaub@linux.microsoft.com> (raw)
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
next reply other threads:[~2022-10-12 21:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-12 21:57 Beau Belgrave [this message]
2022-10-12 22:26 ` [PATCH] tracing: Track event ref in tracefs enable/disable Steven Rostedt
2022-10-13 0:19 ` Beau Belgrave
2022-10-13 7:58 ` Steven Rostedt
2022-10-13 16:39 ` Beau Belgrave
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=20221012215717.10492-1-beaub@linux.microsoft.com \
--to=beaub@linux.microsoft.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-devel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--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