]> Gentwo Git Trees - linux/.git/commitdiff
tracing: uprobe: eprobes: Allocate traceprobe_parse_context per probe
authorMasami Hiramatsu (Google) <mhiramat@kernel.org>
Thu, 25 Sep 2025 00:56:48 +0000 (09:56 +0900)
committerMasami Hiramatsu (Google) <mhiramat@kernel.org>
Fri, 31 Oct 2025 16:10:29 +0000 (01:10 +0900)
Since traceprobe_parse_context is reusable among a probe arguments,
it is more efficient to allocate it outside of the loop for parsing
probe argument as kprobe and fprobe events do.

Link: https://lore.kernel.org/all/175509541393.193596.16330324746701582114.stgit@devnote2/
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
kernel/trace/trace_eprobe.c
kernel/trace/trace_uprobe.c

index f7a1ff509d7e699ae7ca72893a06b50f69291a74..d58d8702a3275c1157debdb6c43396f33eeaffe4 100644 (file)
@@ -801,25 +801,6 @@ find_and_get_event(const char *system, const char *event_name)
        return NULL;
 }
 
-static int trace_eprobe_tp_update_arg(struct trace_eprobe *ep, const char *argv[], int i)
-{
-       struct traceprobe_parse_context *ctx __free(traceprobe_parse_context) = NULL;
-       int ret;
-
-       ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
-       if (!ctx)
-               return -ENOMEM;
-       ctx->event = ep->event;
-       ctx->flags = TPARG_FL_KERNEL | TPARG_FL_TEVENT;
-
-       ret = traceprobe_parse_probe_arg(&ep->tp, i, argv[i], ctx);
-       /* Handle symbols "@" */
-       if (!ret)
-               ret = traceprobe_update_arg(&ep->tp.args[i]);
-
-       return ret;
-}
-
 static int trace_eprobe_parse_filter(struct trace_eprobe *ep, int argc, const char *argv[])
 {
        struct event_filter *dummy = NULL;
@@ -871,6 +852,7 @@ static int __trace_eprobe_create(int argc, const char *argv[])
         * Fetch args (no space):
         *  <name>=$<field>[:TYPE]
         */
+       struct traceprobe_parse_context *ctx __free(traceprobe_parse_context) = NULL;
        struct trace_eprobe *ep __free(trace_event_probe_cleanup) = NULL;
        const char *trlog __free(trace_probe_log_clear) = NULL;
        const char *event = NULL, *group = EPROBE_EVENT_SYSTEM;
@@ -956,11 +938,21 @@ static int __trace_eprobe_create(int argc, const char *argv[])
        } else
                ep->filter_str = NULL;
 
+       ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
+       if (!ctx)
+               return -ENOMEM;
+       ctx->event = ep->event;
+       ctx->flags = TPARG_FL_KERNEL | TPARG_FL_TEVENT;
+
        argc -= 2; argv += 2;
        /* parse arguments */
        for (i = 0; i < argc; i++) {
                trace_probe_log_set_index(i + 2);
-               ret = trace_eprobe_tp_update_arg(ep, argv, i);
+
+               ret = traceprobe_parse_probe_arg(&ep->tp, i, argv[i], ctx);
+               /* Handle symbols "@" */
+               if (!ret)
+                       ret = traceprobe_update_arg(&ep->tp.args[i]);
                if (ret)
                        return ret;
        }
index d1d9abbe624833c241dbc623d1662ae1b808d960..1b4f32e2b9bd971f8270c1aa3a3a4ed561cba56b 100644 (file)
@@ -541,6 +541,7 @@ DEFINE_FREE(free_trace_uprobe, struct trace_uprobe *, if (_T) free_trace_uprobe(
  */
 static int __trace_uprobe_create(int argc, const char **argv)
 {
+       struct traceprobe_parse_context *ctx __free(traceprobe_parse_context) = NULL;
        struct trace_uprobe *tu __free(free_trace_uprobe) = NULL;
        const char *trlog __free(trace_probe_log_clear) = NULL;
        const char *event = NULL, *group = UPROBE_EVENT_SYSTEM;
@@ -698,14 +699,13 @@ static int __trace_uprobe_create(int argc, const char **argv)
        memset(&path, 0, sizeof(path));
        tu->filename = no_free_ptr(filename);
 
+       ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
+       if (!ctx)
+               return -ENOMEM;
+       ctx->flags = (is_return ? TPARG_FL_RETURN : 0) | TPARG_FL_USER;
+
        /* parse arguments */
        for (i = 0; i < argc; i++) {
-               struct traceprobe_parse_context *ctx __free(traceprobe_parse_context)
-                       = kzalloc(sizeof(*ctx), GFP_KERNEL);
-
-               if (!ctx)
-                       return -ENOMEM;
-               ctx->flags = (is_return ? TPARG_FL_RETURN : 0) | TPARG_FL_USER;
                trace_probe_log_set_index(i + 2);
                ret = traceprobe_parse_probe_arg(&tu->tp, i, argv[i], ctx);
                if (ret)