tracing: Remove unnecessary copying of tr->current_trace
[platform/kernel/linux-starfive.git] / kernel / trace / trace.c
index 5d2c567..5e665c3 100644 (file)
@@ -199,7 +199,7 @@ static int boot_snapshot_index;
 
 static int __init set_cmdline_ftrace(char *str)
 {
-       strlcpy(bootup_tracer_buf, str, MAX_TRACER_SIZE);
+       strscpy(bootup_tracer_buf, str, MAX_TRACER_SIZE);
        default_bootup_tracer = bootup_tracer_buf;
        /* We are using ftrace early, expand it */
        ring_buffer_expanded = true;
@@ -284,7 +284,7 @@ static char trace_boot_options_buf[MAX_TRACER_SIZE] __initdata;
 
 static int __init set_trace_boot_options(char *str)
 {
-       strlcpy(trace_boot_options_buf, str, MAX_TRACER_SIZE);
+       strscpy(trace_boot_options_buf, str, MAX_TRACER_SIZE);
        return 1;
 }
 __setup("trace_options=", set_trace_boot_options);
@@ -294,7 +294,7 @@ static char *trace_boot_clock __initdata;
 
 static int __init set_trace_boot_clock(char *str)
 {
-       strlcpy(trace_boot_clock_buf, str, MAX_TRACER_SIZE);
+       strscpy(trace_boot_clock_buf, str, MAX_TRACER_SIZE);
        trace_boot_clock = trace_boot_clock_buf;
        return 1;
 }
@@ -1928,9 +1928,10 @@ update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu)
                 * place on this CPU. We fail to record, but we reset
                 * the max trace buffer (no one writes directly to it)
                 * and flag that it failed.
+                * Another reason is resize is in progress.
                 */
                trace_array_printk_buf(tr->max_buffer.buffer, _THIS_IP_,
-                       "Failed to swap buffers due to commit in progress\n");
+                       "Failed to swap buffers due to commit or resize in progress\n");
        }
 
        WARN_ON_ONCE(ret && ret != -EAGAIN && ret != -EBUSY);
@@ -2546,7 +2547,7 @@ static void __trace_find_cmdline(int pid, char comm[])
        if (map != NO_CMDLINE_MAP) {
                tpid = savedcmd->map_cmdline_to_pid[map];
                if (tpid == pid) {
-                       strlcpy(comm, get_saved_cmdlines(map), TASK_COMM_LEN);
+                       strscpy(comm, get_saved_cmdlines(map), TASK_COMM_LEN);
                        return;
                }
        }
@@ -3155,16 +3156,16 @@ static void __ftrace_trace_stack(struct trace_buffer *buffer,
                nr_entries = stack_trace_save(fstack->calls, size, skip);
        }
 
-       size = nr_entries * sizeof(unsigned long);
        event = __trace_buffer_lock_reserve(buffer, TRACE_STACK,
-                                   (sizeof(*entry) - sizeof(entry->caller)) + size,
+                                   struct_size(entry, caller, nr_entries),
                                    trace_ctx);
        if (!event)
                goto out;
        entry = ring_buffer_event_data(event);
 
-       memcpy(&entry->caller, fstack->calls, size);
        entry->size = nr_entries;
+       memcpy(&entry->caller, fstack->calls,
+              flex_array_size(entry, caller, nr_entries));
 
        if (!call_filter_check_discard(call, entry, buffer, event))
                __buffer_unlock_commit(buffer, event);
@@ -4188,15 +4189,9 @@ static void *s_start(struct seq_file *m, loff_t *pos)
        loff_t l = 0;
        int cpu;
 
-       /*
-        * copy the tracer to avoid using a global lock all around.
-        * iter->trace is a copy of current_trace, the pointer to the
-        * name may be used instead of a strcmp(), as iter->trace->name
-        * will point to the same string as current_trace->name.
-        */
        mutex_lock(&trace_types_lock);
-       if (unlikely(tr->current_trace && iter->trace->name != tr->current_trace->name))
-               *iter->trace = *tr->current_trace;
+       if (unlikely(tr->current_trace != iter->trace))
+               iter->trace = tr->current_trace;
        mutex_unlock(&trace_types_lock);
 
 #ifdef CONFIG_TRACER_MAX_TRACE
@@ -4845,16 +4840,8 @@ __tracing_open(struct inode *inode, struct file *file, bool snapshot)
        iter->fmt = NULL;
        iter->fmt_size = 0;
 
-       /*
-        * We make a copy of the current tracer to avoid concurrent
-        * changes on it while we are reading.
-        */
        mutex_lock(&trace_types_lock);
-       iter->trace = kzalloc(sizeof(*iter->trace), GFP_KERNEL);
-       if (!iter->trace)
-               goto fail;
-
-       *iter->trace = *tr->current_trace;
+       iter->trace = tr->current_trace;
 
        if (!zalloc_cpumask_var(&iter->started, GFP_KERNEL))
                goto fail;
@@ -4919,7 +4906,6 @@ __tracing_open(struct inode *inode, struct file *file, bool snapshot)
 
  fail:
        mutex_unlock(&trace_types_lock);
-       kfree(iter->trace);
        kfree(iter->temp);
        kfree(iter->buffer_iter);
 release:
@@ -5004,7 +4990,6 @@ static int tracing_release(struct inode *inode, struct file *file)
        free_cpumask_var(iter->started);
        kfree(iter->fmt);
        kfree(iter->temp);
-       kfree(iter->trace);
        kfree(iter->buffer_iter);
        seq_release_private(inode, file);
 
@@ -5672,10 +5657,17 @@ static const char readme_msg[] =
        "  uprobe_events\t\t- Create/append/remove/show the userspace dynamic events\n"
        "\t\t\t  Write into this file to define/undefine new trace events.\n"
 #endif
-#if defined(CONFIG_KPROBE_EVENTS) || defined(CONFIG_UPROBE_EVENTS)
+#if defined(CONFIG_KPROBE_EVENTS) || defined(CONFIG_UPROBE_EVENTS) || \
+    defined(CONFIG_FPROBE_EVENTS)
        "\t  accepts: event-definitions (one definition per line)\n"
+#if defined(CONFIG_KPROBE_EVENTS) || defined(CONFIG_UPROBE_EVENTS)
        "\t   Format: p[:[<group>/][<event>]] <place> [<args>]\n"
        "\t           r[maxactive][:[<group>/][<event>]] <place> [<args>]\n"
+#endif
+#ifdef CONFIG_FPROBE_EVENTS
+       "\t           f[:[<group>/][<event>]] <func-name>[%return] [<args>]\n"
+       "\t           t[:[<group>/][<event>]] <tracepoint> [<args>]\n"
+#endif
 #ifdef CONFIG_HIST_TRIGGERS
        "\t           s:[synthetic/]<event> <field> [<field>]\n"
 #endif
@@ -5691,7 +5683,11 @@ static const char readme_msg[] =
        "\t     args: <name>=fetcharg[:type]\n"
        "\t fetcharg: (%<register>|$<efield>), @<address>, @<symbol>[+|-<offset>],\n"
 #ifdef CONFIG_HAVE_FUNCTION_ARG_ACCESS_API
+#ifdef CONFIG_PROBE_EVENTS_BTF_ARGS
+       "\t           $stack<index>, $stack, $retval, $comm, $arg<N>, <argname>\n"
+#else
        "\t           $stack<index>, $stack, $retval, $comm, $arg<N>,\n"
+#endif
 #else
        "\t           $stack<index>, $stack, $retval, $comm,\n"
 #endif
@@ -6753,6 +6749,7 @@ static int tracing_release_pipe(struct inode *inode, struct file *file)
 
        free_cpumask_var(iter->started);
        kfree(iter->fmt);
+       kfree(iter->temp);
        mutex_destroy(&iter->mutex);
        kfree(iter);
 
@@ -8135,7 +8132,7 @@ static const struct file_operations tracing_err_log_fops = {
        .open           = tracing_err_log_open,
        .write          = tracing_err_log_write,
        .read           = seq_read,
-       .llseek         = seq_lseek,
+       .llseek         = tracing_lseek,
        .release        = tracing_err_log_release,
 };