···326327static int328__ftrace_replace_code(struct dyn_ftrace *rec,329- unsigned char *old, unsigned char *new, int enable)330{331 unsigned long ip, fl;0332333 ip = rec->ip;334335- if (ftrace_filtered && enable) {336- /*337- * If filtering is on:338- *339- * If this record is set to be filtered and340- * is enabled then do nothing.341- *342- * If this record is set to be filtered and343- * it is not enabled, enable it.344- *345- * If this record is not set to be filtered346- * and it is not enabled do nothing.347- *348- * If this record is set not to trace then349- * do nothing.350- *351- * If this record is set not to trace and352- * it is enabled then disable it.353- *354- * If this record is not set to be filtered and355- * it is enabled, disable it.356- */357-358- fl = rec->flags & (FTRACE_FL_FILTER | FTRACE_FL_NOTRACE |359- FTRACE_FL_ENABLED);360-361- if ((fl == (FTRACE_FL_FILTER | FTRACE_FL_ENABLED)) ||362- (fl == (FTRACE_FL_FILTER | FTRACE_FL_NOTRACE)) ||363- !fl || (fl == FTRACE_FL_NOTRACE))364 return 0;3650366 /*367- * If it is enabled disable it,368- * otherwise enable it!369 */370- if (fl & FTRACE_FL_ENABLED) {371- /* swap new and old */372- new = old;373- old = ftrace_call_replace(ip, FTRACE_ADDR);000000000374 rec->flags &= ~FTRACE_FL_ENABLED;375- } else {376- new = ftrace_call_replace(ip, FTRACE_ADDR);377 rec->flags |= FTRACE_FL_ENABLED;378- }379 } else {0380381 if (enable) {382- /*383- * If this record is set not to trace and is384- * not enabled, do nothing.385- */386- fl = rec->flags & (FTRACE_FL_NOTRACE | FTRACE_FL_ENABLED);387- if (fl == FTRACE_FL_NOTRACE)388- return 0;389-390- new = ftrace_call_replace(ip, FTRACE_ADDR);391- } else392- old = ftrace_call_replace(ip, FTRACE_ADDR);393-394- if (enable) {395 if (rec->flags & FTRACE_FL_ENABLED)396 return 0;0397 rec->flags |= FTRACE_FL_ENABLED;0398 } else {00399 if (!(rec->flags & FTRACE_FL_ENABLED))400 return 0;0401 rec->flags &= ~FTRACE_FL_ENABLED;402 }0000000000403 }404405 return ftrace_modify_code(ip, old, new);···404static void ftrace_replace_code(int enable)405{406 int i, failed;407- unsigned char *new = NULL, *old = NULL;408 struct dyn_ftrace *rec;409 struct ftrace_page *pg;410411- if (enable)412- old = ftrace_nop_replace();413- else414- new = ftrace_nop_replace();415416 for (pg = ftrace_pages_start; pg; pg = pg->next) {417 for (i = 0; i < pg->index; i++) {···426 unfreeze_record(rec);427 }428429- failed = __ftrace_replace_code(rec, old, new, enable);430 if (failed && (rec->flags & FTRACE_FL_CONVERTED)) {431 rec->flags |= FTRACE_FL_FAILED;432 if ((system_state == SYSTEM_BOOTING) ||···527528 mutex_lock(&ftrace_start_lock);529 ftrace_start++;530- if (ftrace_start == 1)531- command |= FTRACE_ENABLE_CALLS;532533 if (saved_ftrace_func != ftrace_trace_function) {534 saved_ftrace_func = ftrace_trace_function;···725726 ((iter->flags & FTRACE_ITER_FAILURES) &&727 !(rec->flags & FTRACE_FL_FAILED)) ||000728729 ((iter->flags & FTRACE_ITER_NOTRACE) &&730 !(rec->flags & FTRACE_FL_NOTRACE))) {···11811182 mutex_lock(&ftrace_sysctl_lock);1183 mutex_lock(&ftrace_start_lock);1184- if (iter->filtered && ftrace_start && ftrace_enabled)1185 ftrace_run_update_code(FTRACE_ENABLE_CALLS);1186 mutex_unlock(&ftrace_start_lock);1187 mutex_unlock(&ftrace_sysctl_lock);
···326327static int328__ftrace_replace_code(struct dyn_ftrace *rec,329+ unsigned char *nop, int enable)330{331 unsigned long ip, fl;332+ unsigned char *call, *old, *new;333334 ip = rec->ip;335336+ /*337+ * If this record is not to be traced and338+ * it is not enabled then do nothing.339+ *340+ * If this record is not to be traced and341+ * it is enabled then disabled it.342+ *343+ */344+ if (rec->flags & FTRACE_FL_NOTRACE) {345+ if (rec->flags & FTRACE_FL_ENABLED)346+ rec->flags &= ~FTRACE_FL_ENABLED;347+ else00000000000000000348 return 0;349350+ } else if (ftrace_filtered && enable) {351 /*352+ * Filtering is on:0353 */354+355+ fl = rec->flags & (FTRACE_FL_FILTER | FTRACE_FL_ENABLED);356+357+ /* Record is filtered and enabled, do nothing */358+ if (fl == (FTRACE_FL_FILTER | FTRACE_FL_ENABLED))359+ return 0;360+361+ /* Record is not filtered and is not enabled do nothing */362+ if (!fl)363+ return 0;364+365+ /* Record is not filtered but enabled, disable it */366+ if (fl == FTRACE_FL_ENABLED)367 rec->flags &= ~FTRACE_FL_ENABLED;368+ else369+ /* Otherwise record is filtered but not enabled, enable it */370 rec->flags |= FTRACE_FL_ENABLED;0371 } else {372+ /* Disable or not filtered */373374 if (enable) {375+ /* if record is enabled, do nothing */000000000000376 if (rec->flags & FTRACE_FL_ENABLED)377 return 0;378+379 rec->flags |= FTRACE_FL_ENABLED;380+381 } else {382+383+ /* if record is not enabled do nothing */384 if (!(rec->flags & FTRACE_FL_ENABLED))385 return 0;386+387 rec->flags &= ~FTRACE_FL_ENABLED;388 }389+ }390+391+ call = ftrace_call_replace(ip, FTRACE_ADDR);392+393+ if (rec->flags & FTRACE_FL_ENABLED) {394+ old = nop;395+ new = call;396+ } else {397+ old = call;398+ new = nop;399 }400401 return ftrace_modify_code(ip, old, new);···408static void ftrace_replace_code(int enable)409{410 int i, failed;411+ unsigned char *nop = NULL;412 struct dyn_ftrace *rec;413 struct ftrace_page *pg;414415+ nop = ftrace_nop_replace();000416417 for (pg = ftrace_pages_start; pg; pg = pg->next) {418 for (i = 0; i < pg->index; i++) {···433 unfreeze_record(rec);434 }435436+ failed = __ftrace_replace_code(rec, nop, enable);437 if (failed && (rec->flags & FTRACE_FL_CONVERTED)) {438 rec->flags |= FTRACE_FL_FAILED;439 if ((system_state == SYSTEM_BOOTING) ||···534535 mutex_lock(&ftrace_start_lock);536 ftrace_start++;537+ command |= FTRACE_ENABLE_CALLS;0538539 if (saved_ftrace_func != ftrace_trace_function) {540 saved_ftrace_func = ftrace_trace_function;···733734 ((iter->flags & FTRACE_ITER_FAILURES) &&735 !(rec->flags & FTRACE_FL_FAILED)) ||736+737+ ((iter->flags & FTRACE_ITER_FILTER) &&738+ !(rec->flags & FTRACE_FL_FILTER)) ||739740 ((iter->flags & FTRACE_ITER_NOTRACE) &&741 !(rec->flags & FTRACE_FL_NOTRACE))) {···11861187 mutex_lock(&ftrace_sysctl_lock);1188 mutex_lock(&ftrace_start_lock);1189+ if (ftrace_start && ftrace_enabled)1190 ftrace_run_update_code(FTRACE_ENABLE_CALLS);1191 mutex_unlock(&ftrace_start_lock);1192 mutex_unlock(&ftrace_sysctl_lock);