Commit bdd1a65b62995eb29f93b2b0d54ef1f9b9a8ece3

Authored by Steven Rostedt (Red Hat)
Committed by Greg Kroah-Hartman
1 parent 866da94194

tracing: Try again for saved cmdline if failed due to locking

commit 379cfdac37923653c9d4242d10052378b7563005 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: 7ffbd48d5cab "tracing: Cache comms only after an event occurred"
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Showing 1 changed file with 7 additions and 6 deletions Side-by-side Diff

kernel/trace/trace.c
... ... @@ -1461,12 +1461,12 @@
1461 1461  
1462 1462 void trace_stop_cmdline_recording(void);
1463 1463  
1464   -static void trace_save_cmdline(struct task_struct *tsk)
  1464 +static int trace_save_cmdline(struct task_struct *tsk)
1465 1465 {
1466 1466 unsigned pid, idx;
1467 1467  
1468 1468 if (!tsk->pid || unlikely(tsk->pid > PID_MAX_DEFAULT))
1469   - return;
  1469 + return 0;
1470 1470  
1471 1471 /*
1472 1472 * It's not the end of the world if we don't get
... ... @@ -1475,7 +1475,7 @@
1475 1475 * so if we miss here, then better luck next time.
1476 1476 */
1477 1477 if (!arch_spin_trylock(&trace_cmdline_lock))
1478   - return;
  1478 + return 0;
1479 1479  
1480 1480 idx = map_pid_to_cmdline[tsk->pid];
1481 1481 if (idx == NO_CMDLINE_MAP) {
... ... @@ -1500,6 +1500,8 @@
1500 1500 memcpy(&saved_cmdlines[idx], tsk->comm, TASK_COMM_LEN);
1501 1501  
1502 1502 arch_spin_unlock(&trace_cmdline_lock);
  1503 +
  1504 + return 1;
1503 1505 }
1504 1506  
1505 1507 void trace_find_cmdline(int pid, char comm[])
... ... @@ -1541,9 +1543,8 @@
1541 1543 if (!__this_cpu_read(trace_cmdline_save))
1542 1544 return;
1543 1545  
1544   - __this_cpu_write(trace_cmdline_save, false);
1545   -
1546   - trace_save_cmdline(tsk);
  1546 + if (trace_save_cmdline(tsk))
  1547 + __this_cpu_write(trace_cmdline_save, false);
1547 1548 }
1548 1549  
1549 1550 void