From: Steven Rostedt <rostedt@goodmis.org>
To: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH 2/5] tracing: fprobe-event: Allocate string buffers from heap
Date: Fri, 18 Jul 2025 13:39:07 -0400 [thread overview]
Message-ID: <20250718133907.6e56a3fa@batman.local.home> (raw)
In-Reply-To: <175283845881.343578.10010946807218897188.stgit@devnote2>
On Fri, 18 Jul 2025 20:34:19 +0900
"Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:
> From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
>
> Allocate temporary string buffers for fprobe-event from heap
> instead of stack. This fixes the stack frame exceed limit error.
>
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202506240416.nZIhDXoO-lkp@intel.com/
> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> ---
> kernel/trace/trace_fprobe.c | 39 ++++++++++++++++++++++++++-------------
> 1 file changed, 26 insertions(+), 13 deletions(-)
>
> diff --git a/kernel/trace/trace_fprobe.c b/kernel/trace/trace_fprobe.c
> index 264cf7fc9a1d..fd1036e27309 100644
> --- a/kernel/trace/trace_fprobe.c
> +++ b/kernel/trace/trace_fprobe.c
> @@ -1234,18 +1234,18 @@ static int trace_fprobe_create_internal(int argc, const char *argv[],
> * FETCHARG:TYPE : use TYPE instead of unsigned long.
> */
> struct trace_fprobe *tf __free(free_trace_fprobe) = NULL;
> - struct module *mod __free(module_put) = NULL;
> - int i, new_argc = 0, ret = 0;
> - bool is_return = false;
> - char *symbol __free(kfree) = NULL;
> const char *event = NULL, *group = FPROBE_EVENT_SYSTEM;
> + struct module *mod __free(module_put) = NULL;
> const char **new_argv __free(kfree) = NULL;
> - char buf[MAX_EVENT_NAME_LEN];
> - char gbuf[MAX_EVENT_NAME_LEN];
> - char sbuf[KSYM_NAME_LEN];
> - char abuf[MAX_BTF_ARGS_LEN];
> + char *symbol __free(kfree) = NULL;
> + char *ebuf __free(kfree) = NULL;
> + char *gbuf __free(kfree) = NULL;
> + char *sbuf __free(kfree) = NULL;
> + char *abuf __free(kfree) = NULL;
> char *dbuf __free(kfree) = NULL;
> + int i, new_argc = 0, ret = 0;
> bool is_tracepoint = false;
> + bool is_return = false;
>
> if ((argv[0][0] != 'f' && argv[0][0] != 't') || argc < 2)
> return -ECANCELED;
> @@ -1273,6 +1273,9 @@ static int trace_fprobe_create_internal(int argc, const char *argv[],
>
> trace_probe_log_set_index(0);
> if (event) {
> + gbuf = kmalloc(MAX_EVENT_NAME_LEN, GFP_KERNEL);
> + if (!gbuf)
> + return -ENOMEM;
> ret = traceprobe_parse_event_name(&event, &group, gbuf,
> event - argv[0]);
> if (ret)
> @@ -1280,15 +1283,18 @@ static int trace_fprobe_create_internal(int argc, const char *argv[],
> }
>
> if (!event) {
> + ebuf = kmalloc(MAX_EVENT_NAME_LEN, GFP_KERNEL);
ebuf and gbuf are used with the same length. Why not just keep them
using the same buffer? It worked before this patch, it should work
after too.
buf = kmalloc(MAX_EVENT_NAME_LEN, GFP_KERNEL);
if (!buf)
return -ENOMEM;
if (event) {
[..]
}
if (!event) {
[..]
}
And not require two different variables that will add two exit codes
when one would do.
-- Steve
> + if (!ebuf)
> + return -ENOMEM;
> /* Make a new event name */
> if (is_tracepoint)
> - snprintf(buf, MAX_EVENT_NAME_LEN, "%s%s",
> + snprintf(ebuf, MAX_EVENT_NAME_LEN, "%s%s",
> isdigit(*symbol) ? "_" : "", symbol);
> else
> - snprintf(buf, MAX_EVENT_NAME_LEN, "%s__%s", symbol,
> + snprintf(ebuf, MAX_EVENT_NAME_LEN, "%s__%s", symbol,
> is_return ? "exit" : "entry");
> - sanitize_event_name(buf);
> - event = buf;
> + sanitize_event_name(ebuf);
> + event = ebuf;
> }
>
> if (is_return)
> @@ -1304,13 +1310,20 @@ static int trace_fprobe_create_internal(int argc, const char *argv[],
> ctx->flags |= TPARG_FL_TPOINT;
> mod = NULL;
> tpoint = find_tracepoint(symbol, &mod);
> - if (tpoint)
> + if (tpoint) {
> + sbuf = kmalloc(KSYM_NAME_LEN, GFP_KERNEL);
> + if (!sbuf)
> + return -ENOMEM;
> ctx->funcname = kallsyms_lookup((unsigned long)tpoint->probestub,
> NULL, NULL, NULL, sbuf);
> + }
> }
> if (!ctx->funcname)
> ctx->funcname = symbol;
>
> + abuf = kmalloc(MAX_BTF_ARGS_LEN, GFP_KERNEL);
> + if (!abuf)
> + return -ENOMEM;
> argc -= 2; argv += 2;
> new_argv = traceprobe_expand_meta_args(argc, argv, &new_argc,
> abuf, MAX_BTF_ARGS_LEN, ctx);
next prev parent reply other threads:[~2025-07-18 17:39 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-18 11:33 [PATCH 0/5] tracing: probes: Use heap instead of stack for temporary buffers Masami Hiramatsu (Google)
2025-07-18 11:34 ` [PATCH 1/5] tracing: probe: Allocate traceprobe_parse_context from heap Masami Hiramatsu (Google)
2025-07-18 16:58 ` Steven Rostedt
2025-07-19 0:33 ` Masami Hiramatsu
2025-07-18 11:34 ` [PATCH 2/5] tracing: fprobe-event: Allocate string buffers " Masami Hiramatsu (Google)
2025-07-18 17:39 ` Steven Rostedt [this message]
2025-07-19 0:57 ` Masami Hiramatsu
2025-07-19 4:35 ` Masami Hiramatsu
2025-07-18 11:34 ` [PATCH 3/5] tracing: kprobe-event: " Masami Hiramatsu (Google)
2025-07-18 17:46 ` Steven Rostedt
2025-07-19 1:17 ` Masami Hiramatsu
2025-07-18 11:34 ` [PATCH 4/5] tracing: eprobe-event: " Masami Hiramatsu (Google)
2025-07-18 17:55 ` Steven Rostedt
2025-07-19 1:11 ` Masami Hiramatsu
2025-07-18 11:34 ` [PATCH 5/5] tracing: uprobe-event: " Masami Hiramatsu (Google)
2025-07-18 17:58 ` Steven Rostedt
2025-07-19 1:13 ` Masami Hiramatsu
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=20250718133907.6e56a3fa@batman.local.home \
--to=rostedt@goodmis.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.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®