]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
tracing: Update modules to persistent instances when loaded
authorSteven Rostedt <rostedt@goodmis.org>
Wed, 5 Mar 2025 16:45:47 +0000 (11:45 -0500)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Fri, 28 Mar 2025 12:39:27 +0000 (08:39 -0400)
When a module is loaded and a persistent buffer is actively tracing, add
it to the list of modules in the persistent memory.

Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Link: https://lore.kernel.org/20250305164609.469844721@goodmis.org
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
kernel/trace/trace.c
kernel/trace/trace.h
kernel/trace/trace_events.c

index d22f8d34b18d38ea8f7f0eae81172c8cf7e704f8..66c1683fa1dda2a209b10562dd322774802df2d8 100644 (file)
@@ -10087,6 +10087,32 @@ static void trace_module_remove_evals(struct module *mod)
 static inline void trace_module_remove_evals(struct module *mod) { }
 #endif /* CONFIG_TRACE_EVAL_MAP_FILE */
 
+static bool trace_array_active(struct trace_array *tr)
+{
+       if (tr->current_trace != &nop_trace)
+               return true;
+
+       /* 0 is no events, 1 is all disabled */
+       return trace_events_enabled(tr, NULL) > 1;
+}
+
+static void trace_module_record(struct module *mod)
+{
+       struct trace_array *tr;
+
+       list_for_each_entry(tr, &ftrace_trace_arrays, list) {
+               /* Update any persistent trace array that has already been started */
+               if ((tr->flags & (TRACE_ARRAY_FL_BOOT | TRACE_ARRAY_FL_LAST_BOOT)) ==
+                   TRACE_ARRAY_FL_BOOT) {
+                       /* Only update if the trace array is active */
+                       if (trace_array_active(tr)) {
+                               guard(mutex)(&scratch_mutex);
+                               save_mod(mod, tr);
+                       }
+               }
+       }
+}
+
 static int trace_module_notify(struct notifier_block *self,
                               unsigned long val, void *data)
 {
@@ -10095,6 +10121,7 @@ static int trace_module_notify(struct notifier_block *self,
        switch (val) {
        case MODULE_STATE_COMING:
                trace_module_add_evals(mod);
+               trace_module_record(mod);
                break;
        case MODULE_STATE_GOING:
                trace_module_remove_evals(mod);
index 3a020fb82a348312a17337bdc79a25da880c7a88..90493220c3624f4893ebbccbc77d1740c1a0106f 100644 (file)
@@ -786,6 +786,8 @@ extern void trace_find_cmdline(int pid, char comm[]);
 extern int trace_find_tgid(int pid);
 extern void trace_event_follow_fork(struct trace_array *tr, bool enable);
 
+extern int trace_events_enabled(struct trace_array *tr, const char *system);
+
 #ifdef CONFIG_DYNAMIC_FTRACE
 extern unsigned long ftrace_update_tot_cnt;
 extern unsigned long ftrace_number_of_pages;
index 513de9ceb80ef0ada33f494e5b1c94d9ab383e33..7b3ef1d2616731870186cb502c28d79262b43851 100644 (file)
@@ -1818,28 +1818,28 @@ event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
        return cnt;
 }
 
-static ssize_t
-system_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
-                  loff_t *ppos)
+/*
+ * Returns:
+ *   0 : no events exist?
+ *   1 : all events are disabled
+ *   2 : all events are enabled
+ *   3 : some events are enabled and some are enabled
+ */
+int trace_events_enabled(struct trace_array *tr, const char *system)
 {
-       const char set_to_char[4] = { '?', '0', '1', 'X' };
-       struct trace_subsystem_dir *dir = filp->private_data;
-       struct event_subsystem *system = dir->subsystem;
        struct trace_event_call *call;
        struct trace_event_file *file;
-       struct trace_array *tr = dir->tr;
-       char buf[2];
        int set = 0;
-       int ret;
 
-       mutex_lock(&event_mutex);
+       guard(mutex)(&event_mutex);
+
        list_for_each_entry(file, &tr->events, list) {
                call = file->event_call;
                if ((call->flags & TRACE_EVENT_FL_IGNORE_ENABLE) ||
                    !trace_event_name(call) || !call->class || !call->class->reg)
                        continue;
 
-               if (system && strcmp(call->class->system, system->name) != 0)
+               if (system && strcmp(call->class->system, system) != 0)
                        continue;
 
                /*
@@ -1855,7 +1855,23 @@ system_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
                if (set == 3)
                        break;
        }
-       mutex_unlock(&event_mutex);
+
+       return set;
+}
+
+static ssize_t
+system_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
+                  loff_t *ppos)
+{
+       const char set_to_char[4] = { '?', '0', '1', 'X' };
+       struct trace_subsystem_dir *dir = filp->private_data;
+       struct event_subsystem *system = dir->subsystem;
+       struct trace_array *tr = dir->tr;
+       char buf[2];
+       int set;
+       int ret;
+
+       set = trace_events_enabled(tr, system ? system->name : NULL);
 
        buf[0] = set_to_char[set];
        buf[1] = '\n';