Skip to content

Commit 5f3719f

Browse files
committed
tracing: Update modules to persistent instances when loaded
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 <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Andrew Morton <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 1bd25a6 commit 5f3719f

File tree

3 files changed

+57
-12
lines changed

3 files changed

+57
-12
lines changed

kernel/trace/trace.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10087,6 +10087,32 @@ static void trace_module_remove_evals(struct module *mod)
1008710087
static inline void trace_module_remove_evals(struct module *mod) { }
1008810088
#endif /* CONFIG_TRACE_EVAL_MAP_FILE */
1008910089

10090+
static bool trace_array_active(struct trace_array *tr)
10091+
{
10092+
if (tr->current_trace != &nop_trace)
10093+
return true;
10094+
10095+
/* 0 is no events, 1 is all disabled */
10096+
return trace_events_enabled(tr, NULL) > 1;
10097+
}
10098+
10099+
static void trace_module_record(struct module *mod)
10100+
{
10101+
struct trace_array *tr;
10102+
10103+
list_for_each_entry(tr, &ftrace_trace_arrays, list) {
10104+
/* Update any persistent trace array that has already been started */
10105+
if ((tr->flags & (TRACE_ARRAY_FL_BOOT | TRACE_ARRAY_FL_LAST_BOOT)) ==
10106+
TRACE_ARRAY_FL_BOOT) {
10107+
/* Only update if the trace array is active */
10108+
if (trace_array_active(tr)) {
10109+
guard(mutex)(&scratch_mutex);
10110+
save_mod(mod, tr);
10111+
}
10112+
}
10113+
}
10114+
}
10115+
1009010116
static int trace_module_notify(struct notifier_block *self,
1009110117
unsigned long val, void *data)
1009210118
{
@@ -10095,6 +10121,7 @@ static int trace_module_notify(struct notifier_block *self,
1009510121
switch (val) {
1009610122
case MODULE_STATE_COMING:
1009710123
trace_module_add_evals(mod);
10124+
trace_module_record(mod);
1009810125
break;
1009910126
case MODULE_STATE_GOING:
1010010127
trace_module_remove_evals(mod);

kernel/trace/trace.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,8 @@ extern void trace_find_cmdline(int pid, char comm[]);
786786
extern int trace_find_tgid(int pid);
787787
extern void trace_event_follow_fork(struct trace_array *tr, bool enable);
788788

789+
extern int trace_events_enabled(struct trace_array *tr, const char *system);
790+
789791
#ifdef CONFIG_DYNAMIC_FTRACE
790792
extern unsigned long ftrace_update_tot_cnt;
791793
extern unsigned long ftrace_number_of_pages;

kernel/trace/trace_events.c

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,28 +1818,28 @@ event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
18181818
return cnt;
18191819
}
18201820

1821-
static ssize_t
1822-
system_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
1823-
loff_t *ppos)
1821+
/*
1822+
* Returns:
1823+
* 0 : no events exist?
1824+
* 1 : all events are disabled
1825+
* 2 : all events are enabled
1826+
* 3 : some events are enabled and some are enabled
1827+
*/
1828+
int trace_events_enabled(struct trace_array *tr, const char *system)
18241829
{
1825-
const char set_to_char[4] = { '?', '0', '1', 'X' };
1826-
struct trace_subsystem_dir *dir = filp->private_data;
1827-
struct event_subsystem *system = dir->subsystem;
18281830
struct trace_event_call *call;
18291831
struct trace_event_file *file;
1830-
struct trace_array *tr = dir->tr;
1831-
char buf[2];
18321832
int set = 0;
1833-
int ret;
18341833

1835-
mutex_lock(&event_mutex);
1834+
guard(mutex)(&event_mutex);
1835+
18361836
list_for_each_entry(file, &tr->events, list) {
18371837
call = file->event_call;
18381838
if ((call->flags & TRACE_EVENT_FL_IGNORE_ENABLE) ||
18391839
!trace_event_name(call) || !call->class || !call->class->reg)
18401840
continue;
18411841

1842-
if (system && strcmp(call->class->system, system->name) != 0)
1842+
if (system && strcmp(call->class->system, system) != 0)
18431843
continue;
18441844

18451845
/*
@@ -1855,7 +1855,23 @@ system_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
18551855
if (set == 3)
18561856
break;
18571857
}
1858-
mutex_unlock(&event_mutex);
1858+
1859+
return set;
1860+
}
1861+
1862+
static ssize_t
1863+
system_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
1864+
loff_t *ppos)
1865+
{
1866+
const char set_to_char[4] = { '?', '0', '1', 'X' };
1867+
struct trace_subsystem_dir *dir = filp->private_data;
1868+
struct event_subsystem *system = dir->subsystem;
1869+
struct trace_array *tr = dir->tr;
1870+
char buf[2];
1871+
int set;
1872+
int ret;
1873+
1874+
set = trace_events_enabled(tr, system ? system->name : NULL);
18591875

18601876
buf[0] = set_to_char[set];
18611877
buf[1] = '\n';

0 commit comments

Comments
 (0)