Skip to content

Commit 982c350

Browse files
Steven RostedtIngo Molnar
authored andcommitted
ftrace: fix dyn ftrace filter
Impact: correct implementation of dyn ftrace filter The old decisions made by the filter algorithm was complex and incorrect. This lead to inconsistent enabling or disabling of functions when the filter was used. This patch simplifies that code and in doing so, corrects the usage of the filters. Signed-off-by: Steven Rostedt <srostedt@redhat.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent 20e5227 commit 982c350

1 file changed

Lines changed: 36 additions & 47 deletions

File tree

‎kernel/trace/ftrace.c‎

Lines changed: 36 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -394,72 +394,62 @@ __ftrace_replace_code(struct dyn_ftrace *rec, int enable)
394394

395395
ip = rec->ip;
396396

397-
if (ftrace_filtered && enable) {
397+
/*
398+
* If this record is not to be traced and
399+
* it is not enabled then do nothing.
400+
*
401+
* If this record is not to be traced and
402+
* it is enabled then disabled it.
403+
*
404+
*/
405+
if (rec->flags & FTRACE_FL_NOTRACE) {
406+
if (rec->flags & FTRACE_FL_ENABLED)
407+
rec->flags &= ~FTRACE_FL_ENABLED;
408+
else
409+
return 0;
410+
411+
} else if (ftrace_filtered && enable) {
398412
/*
399-
* If filtering is on:
400-
*
401-
* If this record is set to be filtered and
402-
* is enabled then do nothing.
403-
*
404-
* If this record is set to be filtered and
405-
* it is not enabled, enable it.
406-
*
407-
* If this record is not set to be filtered
408-
* and it is not enabled do nothing.
409-
*
410-
* If this record is set not to trace then
411-
* do nothing.
412-
*
413-
* If this record is set not to trace and
414-
* it is enabled then disable it.
415-
*
416-
* If this record is not set to be filtered and
417-
* it is enabled, disable it.
413+
* Filtering is on:
418414
*/
419415

420-
fl = rec->flags & (FTRACE_FL_FILTER | FTRACE_FL_NOTRACE |
421-
FTRACE_FL_ENABLED);
416+
fl = rec->flags & (FTRACE_FL_FILTER | FTRACE_FL_ENABLED);
422417

423-
if ((fl == (FTRACE_FL_FILTER | FTRACE_FL_ENABLED)) ||
424-
(fl == (FTRACE_FL_FILTER | FTRACE_FL_NOTRACE)) ||
425-
!fl || (fl == FTRACE_FL_NOTRACE))
418+
/* Record is filtered and enabled, do nothing */
419+
if (fl == (FTRACE_FL_FILTER | FTRACE_FL_ENABLED))
426420
return 0;
427421

428-
/*
429-
* If it is enabled disable it,
430-
* otherwise enable it!
431-
*/
432-
if (fl & FTRACE_FL_ENABLED) {
433-
enable = 0;
422+
/* Record is not filtered and is not enabled do nothing */
423+
if (!fl)
424+
return 0;
425+
426+
/* Record is not filtered but enabled, disable it */
427+
if (fl == FTRACE_FL_ENABLED)
434428
rec->flags &= ~FTRACE_FL_ENABLED;
435-
} else {
436-
enable = 1;
429+
else
430+
/* Otherwise record is filtered but not enabled, enable it */
437431
rec->flags |= FTRACE_FL_ENABLED;
438-
}
439432
} else {
433+
/* Disable or not filtered */
440434

441435
if (enable) {
442-
/*
443-
* If this record is set not to trace and is
444-
* not enabled, do nothing.
445-
*/
446-
fl = rec->flags & (FTRACE_FL_NOTRACE | FTRACE_FL_ENABLED);
447-
if (fl == FTRACE_FL_NOTRACE)
448-
return 0;
449-
}
450-
451-
if (enable) {
436+
/* if record is enabled, do nothing */
452437
if (rec->flags & FTRACE_FL_ENABLED)
453438
return 0;
439+
454440
rec->flags |= FTRACE_FL_ENABLED;
441+
455442
} else {
443+
444+
/* if record is not enabled do nothing */
456445
if (!(rec->flags & FTRACE_FL_ENABLED))
457446
return 0;
447+
458448
rec->flags &= ~FTRACE_FL_ENABLED;
459449
}
460450
}
461451

462-
if (enable)
452+
if (rec->flags & FTRACE_FL_ENABLED)
463453
return ftrace_make_call(rec, FTRACE_ADDR);
464454
else
465455
return ftrace_make_nop(NULL, rec, FTRACE_ADDR);
@@ -554,8 +544,7 @@ static void ftrace_startup(void)
554544

555545
mutex_lock(&ftrace_start_lock);
556546
ftrace_start_up++;
557-
if (ftrace_start_up == 1)
558-
command |= FTRACE_ENABLE_CALLS;
547+
command |= FTRACE_ENABLE_CALLS;
559548

560549
if (saved_ftrace_func != ftrace_trace_function) {
561550
saved_ftrace_func = ftrace_trace_function;

0 commit comments

Comments
 (0)