Skip to content

Commit 0ecae6c

Browse files
rostedtJiri Slaby
authored andcommitted
tracing: Try again for saved cmdline if failed due to locking
commit 379cfda upstream. In order to prevent the saved cmdline cache from being filled when tracing is not active, the comms are only recorded after a trace event is recorded. The problem is, a comm can fail to be recorded if the trace_cmdline_lock is held. That lock is taken via a trylock to allow it to happen from any context (including NMI). If the lock fails to be taken, the comm is skipped. No big deal, as we will try again later. But! Because of the code that was added to only record after an event, we may not try again later as the recording is made as a oneshot per event per CPU. Only disable the recording of the comm if the comm is actually recorded. Fixes: 7ffbd48 "tracing: Cache comms only after an event occurred" Signed-off-by: Steven Rostedt <rostedt@goodmis.org> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
1 parent 0b052a0 commit 0ecae6c

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

‎kernel/trace/trace.c‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,12 +1417,12 @@ static void tracing_stop_tr(struct trace_array *tr)
14171417

14181418
void trace_stop_cmdline_recording(void);
14191419

1420-
static void trace_save_cmdline(struct task_struct *tsk)
1420+
static int trace_save_cmdline(struct task_struct *tsk)
14211421
{
14221422
unsigned pid, idx;
14231423

14241424
if (!tsk->pid || unlikely(tsk->pid > PID_MAX_DEFAULT))
1425-
return;
1425+
return 0;
14261426

14271427
/*
14281428
* It's not the end of the world if we don't get
@@ -1431,7 +1431,7 @@ static void trace_save_cmdline(struct task_struct *tsk)
14311431
* so if we miss here, then better luck next time.
14321432
*/
14331433
if (!arch_spin_trylock(&trace_cmdline_lock))
1434-
return;
1434+
return 0;
14351435

14361436
idx = map_pid_to_cmdline[tsk->pid];
14371437
if (idx == NO_CMDLINE_MAP) {
@@ -1456,6 +1456,8 @@ static void trace_save_cmdline(struct task_struct *tsk)
14561456
memcpy(&saved_cmdlines[idx], tsk->comm, TASK_COMM_LEN);
14571457

14581458
arch_spin_unlock(&trace_cmdline_lock);
1459+
1460+
return 1;
14591461
}
14601462

14611463
void trace_find_cmdline(int pid, char comm[])
@@ -1497,9 +1499,8 @@ void tracing_record_cmdline(struct task_struct *tsk)
14971499
if (!__this_cpu_read(trace_cmdline_save))
14981500
return;
14991501

1500-
__this_cpu_write(trace_cmdline_save, false);
1501-
1502-
trace_save_cmdline(tsk);
1502+
if (trace_save_cmdline(tsk))
1503+
__this_cpu_write(trace_cmdline_save, false);
15031504
}
15041505

15051506
void

0 commit comments

Comments
 (0)