diff options
-rw-r--r-- | kernel/trace/ftrace.c | 68 |
1 files changed, 21 insertions, 47 deletions
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 4771732037ee..157d4f68b0e0 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c | |||
@@ -62,8 +62,6 @@ int function_trace_stop; | |||
62 | static int ftrace_disabled __read_mostly; | 62 | static int ftrace_disabled __read_mostly; |
63 | 63 | ||
64 | static DEFINE_MUTEX(ftrace_lock); | 64 | static DEFINE_MUTEX(ftrace_lock); |
65 | static DEFINE_MUTEX(ftrace_sysctl_lock); | ||
66 | static DEFINE_MUTEX(ftrace_start_lock); | ||
67 | 65 | ||
68 | static struct ftrace_ops ftrace_list_end __read_mostly = | 66 | static struct ftrace_ops ftrace_list_end __read_mostly = |
69 | { | 67 | { |
@@ -134,8 +132,6 @@ static void ftrace_test_stop_func(unsigned long ip, unsigned long parent_ip) | |||
134 | 132 | ||
135 | static int __register_ftrace_function(struct ftrace_ops *ops) | 133 | static int __register_ftrace_function(struct ftrace_ops *ops) |
136 | { | 134 | { |
137 | mutex_lock(&ftrace_lock); | ||
138 | |||
139 | ops->next = ftrace_list; | 135 | ops->next = ftrace_list; |
140 | /* | 136 | /* |
141 | * We are entering ops into the ftrace_list but another | 137 | * We are entering ops into the ftrace_list but another |
@@ -171,17 +167,12 @@ static int __register_ftrace_function(struct ftrace_ops *ops) | |||
171 | #endif | 167 | #endif |
172 | } | 168 | } |
173 | 169 | ||
174 | mutex_unlock(&ftrace_lock); | ||
175 | |||
176 | return 0; | 170 | return 0; |
177 | } | 171 | } |
178 | 172 | ||
179 | static int __unregister_ftrace_function(struct ftrace_ops *ops) | 173 | static int __unregister_ftrace_function(struct ftrace_ops *ops) |
180 | { | 174 | { |
181 | struct ftrace_ops **p; | 175 | struct ftrace_ops **p; |
182 | int ret = 0; | ||
183 | |||
184 | mutex_lock(&ftrace_lock); | ||
185 | 176 | ||
186 | /* | 177 | /* |
187 | * If we are removing the last function, then simply point | 178 | * If we are removing the last function, then simply point |
@@ -190,17 +181,15 @@ static int __unregister_ftrace_function(struct ftrace_ops *ops) | |||
190 | if (ftrace_list == ops && ops->next == &ftrace_list_end) { | 181 | if (ftrace_list == ops && ops->next == &ftrace_list_end) { |
191 | ftrace_trace_function = ftrace_stub; | 182 | ftrace_trace_function = ftrace_stub; |
192 | ftrace_list = &ftrace_list_end; | 183 | ftrace_list = &ftrace_list_end; |
193 | goto out; | 184 | return 0; |
194 | } | 185 | } |
195 | 186 | ||
196 | for (p = &ftrace_list; *p != &ftrace_list_end; p = &(*p)->next) | 187 | for (p = &ftrace_list; *p != &ftrace_list_end; p = &(*p)->next) |
197 | if (*p == ops) | 188 | if (*p == ops) |
198 | break; | 189 | break; |
199 | 190 | ||
200 | if (*p != ops) { | 191 | if (*p != ops) |
201 | ret = -1; | 192 | return -1; |
202 | goto out; | ||
203 | } | ||
204 | 193 | ||
205 | *p = (*p)->next; | 194 | *p = (*p)->next; |
206 | 195 | ||
@@ -221,10 +210,7 @@ static int __unregister_ftrace_function(struct ftrace_ops *ops) | |||
221 | } | 210 | } |
222 | } | 211 | } |
223 | 212 | ||
224 | out: | 213 | return 0; |
225 | mutex_unlock(&ftrace_lock); | ||
226 | |||
227 | return ret; | ||
228 | } | 214 | } |
229 | 215 | ||
230 | static void ftrace_update_pid_func(void) | 216 | static void ftrace_update_pid_func(void) |
@@ -622,13 +608,10 @@ static void ftrace_startup(int command) | |||
622 | if (unlikely(ftrace_disabled)) | 608 | if (unlikely(ftrace_disabled)) |
623 | return; | 609 | return; |
624 | 610 | ||
625 | mutex_lock(&ftrace_start_lock); | ||
626 | ftrace_start_up++; | 611 | ftrace_start_up++; |
627 | command |= FTRACE_ENABLE_CALLS; | 612 | command |= FTRACE_ENABLE_CALLS; |
628 | 613 | ||
629 | ftrace_startup_enable(command); | 614 | ftrace_startup_enable(command); |
630 | |||
631 | mutex_unlock(&ftrace_start_lock); | ||
632 | } | 615 | } |
633 | 616 | ||
634 | static void ftrace_shutdown(int command) | 617 | static void ftrace_shutdown(int command) |
@@ -636,7 +619,6 @@ static void ftrace_shutdown(int command) | |||
636 | if (unlikely(ftrace_disabled)) | 619 | if (unlikely(ftrace_disabled)) |
637 | return; | 620 | return; |
638 | 621 | ||
639 | mutex_lock(&ftrace_start_lock); | ||
640 | ftrace_start_up--; | 622 | ftrace_start_up--; |
641 | if (!ftrace_start_up) | 623 | if (!ftrace_start_up) |
642 | command |= FTRACE_DISABLE_CALLS; | 624 | command |= FTRACE_DISABLE_CALLS; |
@@ -647,11 +629,9 @@ static void ftrace_shutdown(int command) | |||
647 | } | 629 | } |
648 | 630 | ||
649 | if (!command || !ftrace_enabled) | 631 | if (!command || !ftrace_enabled) |
650 | goto out; | 632 | return; |
651 | 633 | ||
652 | ftrace_run_update_code(command); | 634 | ftrace_run_update_code(command); |
653 | out: | ||
654 | mutex_unlock(&ftrace_start_lock); | ||
655 | } | 635 | } |
656 | 636 | ||
657 | static void ftrace_startup_sysctl(void) | 637 | static void ftrace_startup_sysctl(void) |
@@ -661,7 +641,6 @@ static void ftrace_startup_sysctl(void) | |||
661 | if (unlikely(ftrace_disabled)) | 641 | if (unlikely(ftrace_disabled)) |
662 | return; | 642 | return; |
663 | 643 | ||
664 | mutex_lock(&ftrace_start_lock); | ||
665 | /* Force update next time */ | 644 | /* Force update next time */ |
666 | saved_ftrace_func = NULL; | 645 | saved_ftrace_func = NULL; |
667 | /* ftrace_start_up is true if we want ftrace running */ | 646 | /* ftrace_start_up is true if we want ftrace running */ |
@@ -669,7 +648,6 @@ static void ftrace_startup_sysctl(void) | |||
669 | command |= FTRACE_ENABLE_CALLS; | 648 | command |= FTRACE_ENABLE_CALLS; |
670 | 649 | ||
671 | ftrace_run_update_code(command); | 650 | ftrace_run_update_code(command); |
672 | mutex_unlock(&ftrace_start_lock); | ||
673 | } | 651 | } |
674 | 652 | ||
675 | static void ftrace_shutdown_sysctl(void) | 653 | static void ftrace_shutdown_sysctl(void) |
@@ -679,13 +657,11 @@ static void ftrace_shutdown_sysctl(void) | |||
679 | if (unlikely(ftrace_disabled)) | 657 | if (unlikely(ftrace_disabled)) |
680 | return; | 658 | return; |
681 | 659 | ||
682 | mutex_lock(&ftrace_start_lock); | ||
683 | /* ftrace_start_up is true if ftrace is running */ | 660 | /* ftrace_start_up is true if ftrace is running */ |
684 | if (ftrace_start_up) | 661 | if (ftrace_start_up) |
685 | command |= FTRACE_DISABLE_CALLS; | 662 | command |= FTRACE_DISABLE_CALLS; |
686 | 663 | ||
687 | ftrace_run_update_code(command); | 664 | ftrace_run_update_code(command); |
688 | mutex_unlock(&ftrace_start_lock); | ||
689 | } | 665 | } |
690 | 666 | ||
691 | static cycle_t ftrace_update_time; | 667 | static cycle_t ftrace_update_time; |
@@ -1502,12 +1478,10 @@ ftrace_regex_release(struct inode *inode, struct file *file, int enable) | |||
1502 | ftrace_match_records(iter->buffer, iter->buffer_idx, enable); | 1478 | ftrace_match_records(iter->buffer, iter->buffer_idx, enable); |
1503 | } | 1479 | } |
1504 | 1480 | ||
1505 | mutex_lock(&ftrace_sysctl_lock); | 1481 | mutex_lock(&ftrace_lock); |
1506 | mutex_lock(&ftrace_start_lock); | ||
1507 | if (ftrace_start_up && ftrace_enabled) | 1482 | if (ftrace_start_up && ftrace_enabled) |
1508 | ftrace_run_update_code(FTRACE_ENABLE_CALLS); | 1483 | ftrace_run_update_code(FTRACE_ENABLE_CALLS); |
1509 | mutex_unlock(&ftrace_start_lock); | 1484 | mutex_unlock(&ftrace_lock); |
1510 | mutex_unlock(&ftrace_sysctl_lock); | ||
1511 | 1485 | ||
1512 | kfree(iter); | 1486 | kfree(iter); |
1513 | mutex_unlock(&ftrace_regex_lock); | 1487 | mutex_unlock(&ftrace_regex_lock); |
@@ -1824,7 +1798,7 @@ static int ftrace_convert_nops(struct module *mod, | |||
1824 | unsigned long addr; | 1798 | unsigned long addr; |
1825 | unsigned long flags; | 1799 | unsigned long flags; |
1826 | 1800 | ||
1827 | mutex_lock(&ftrace_start_lock); | 1801 | mutex_lock(&ftrace_lock); |
1828 | p = start; | 1802 | p = start; |
1829 | while (p < end) { | 1803 | while (p < end) { |
1830 | addr = ftrace_call_adjust(*p++); | 1804 | addr = ftrace_call_adjust(*p++); |
@@ -1843,7 +1817,7 @@ static int ftrace_convert_nops(struct module *mod, | |||
1843 | local_irq_save(flags); | 1817 | local_irq_save(flags); |
1844 | ftrace_update_code(mod); | 1818 | ftrace_update_code(mod); |
1845 | local_irq_restore(flags); | 1819 | local_irq_restore(flags); |
1846 | mutex_unlock(&ftrace_start_lock); | 1820 | mutex_unlock(&ftrace_lock); |
1847 | 1821 | ||
1848 | return 0; | 1822 | return 0; |
1849 | } | 1823 | } |
@@ -2016,7 +1990,7 @@ ftrace_pid_write(struct file *filp, const char __user *ubuf, | |||
2016 | if (ret < 0) | 1990 | if (ret < 0) |
2017 | return ret; | 1991 | return ret; |
2018 | 1992 | ||
2019 | mutex_lock(&ftrace_start_lock); | 1993 | mutex_lock(&ftrace_lock); |
2020 | if (val < 0) { | 1994 | if (val < 0) { |
2021 | /* disable pid tracing */ | 1995 | /* disable pid tracing */ |
2022 | if (!ftrace_pid_trace) | 1996 | if (!ftrace_pid_trace) |
@@ -2055,7 +2029,7 @@ ftrace_pid_write(struct file *filp, const char __user *ubuf, | |||
2055 | ftrace_startup_enable(0); | 2029 | ftrace_startup_enable(0); |
2056 | 2030 | ||
2057 | out: | 2031 | out: |
2058 | mutex_unlock(&ftrace_start_lock); | 2032 | mutex_unlock(&ftrace_lock); |
2059 | 2033 | ||
2060 | return cnt; | 2034 | return cnt; |
2061 | } | 2035 | } |
@@ -2118,12 +2092,12 @@ int register_ftrace_function(struct ftrace_ops *ops) | |||
2118 | if (unlikely(ftrace_disabled)) | 2092 | if (unlikely(ftrace_disabled)) |
2119 | return -1; | 2093 | return -1; |
2120 | 2094 | ||
2121 | mutex_lock(&ftrace_sysctl_lock); | 2095 | mutex_lock(&ftrace_lock); |
2122 | 2096 | ||
2123 | ret = __register_ftrace_function(ops); | 2097 | ret = __register_ftrace_function(ops); |
2124 | ftrace_startup(0); | 2098 | ftrace_startup(0); |
2125 | 2099 | ||
2126 | mutex_unlock(&ftrace_sysctl_lock); | 2100 | mutex_unlock(&ftrace_lock); |
2127 | return ret; | 2101 | return ret; |
2128 | } | 2102 | } |
2129 | 2103 | ||
@@ -2137,10 +2111,10 @@ int unregister_ftrace_function(struct ftrace_ops *ops) | |||
2137 | { | 2111 | { |
2138 | int ret; | 2112 | int ret; |
2139 | 2113 | ||
2140 | mutex_lock(&ftrace_sysctl_lock); | 2114 | mutex_lock(&ftrace_lock); |
2141 | ret = __unregister_ftrace_function(ops); | 2115 | ret = __unregister_ftrace_function(ops); |
2142 | ftrace_shutdown(0); | 2116 | ftrace_shutdown(0); |
2143 | mutex_unlock(&ftrace_sysctl_lock); | 2117 | mutex_unlock(&ftrace_lock); |
2144 | 2118 | ||
2145 | return ret; | 2119 | return ret; |
2146 | } | 2120 | } |
@@ -2155,7 +2129,7 @@ ftrace_enable_sysctl(struct ctl_table *table, int write, | |||
2155 | if (unlikely(ftrace_disabled)) | 2129 | if (unlikely(ftrace_disabled)) |
2156 | return -ENODEV; | 2130 | return -ENODEV; |
2157 | 2131 | ||
2158 | mutex_lock(&ftrace_sysctl_lock); | 2132 | mutex_lock(&ftrace_lock); |
2159 | 2133 | ||
2160 | ret = proc_dointvec(table, write, file, buffer, lenp, ppos); | 2134 | ret = proc_dointvec(table, write, file, buffer, lenp, ppos); |
2161 | 2135 | ||
@@ -2184,7 +2158,7 @@ ftrace_enable_sysctl(struct ctl_table *table, int write, | |||
2184 | } | 2158 | } |
2185 | 2159 | ||
2186 | out: | 2160 | out: |
2187 | mutex_unlock(&ftrace_sysctl_lock); | 2161 | mutex_unlock(&ftrace_lock); |
2188 | return ret; | 2162 | return ret; |
2189 | } | 2163 | } |
2190 | 2164 | ||
@@ -2296,7 +2270,7 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc, | |||
2296 | { | 2270 | { |
2297 | int ret = 0; | 2271 | int ret = 0; |
2298 | 2272 | ||
2299 | mutex_lock(&ftrace_sysctl_lock); | 2273 | mutex_lock(&ftrace_lock); |
2300 | 2274 | ||
2301 | ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call; | 2275 | ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call; |
2302 | register_pm_notifier(&ftrace_suspend_notifier); | 2276 | register_pm_notifier(&ftrace_suspend_notifier); |
@@ -2314,13 +2288,13 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc, | |||
2314 | ftrace_startup(FTRACE_START_FUNC_RET); | 2288 | ftrace_startup(FTRACE_START_FUNC_RET); |
2315 | 2289 | ||
2316 | out: | 2290 | out: |
2317 | mutex_unlock(&ftrace_sysctl_lock); | 2291 | mutex_unlock(&ftrace_lock); |
2318 | return ret; | 2292 | return ret; |
2319 | } | 2293 | } |
2320 | 2294 | ||
2321 | void unregister_ftrace_graph(void) | 2295 | void unregister_ftrace_graph(void) |
2322 | { | 2296 | { |
2323 | mutex_lock(&ftrace_sysctl_lock); | 2297 | mutex_lock(&ftrace_lock); |
2324 | 2298 | ||
2325 | atomic_dec(&ftrace_graph_active); | 2299 | atomic_dec(&ftrace_graph_active); |
2326 | ftrace_graph_return = (trace_func_graph_ret_t)ftrace_stub; | 2300 | ftrace_graph_return = (trace_func_graph_ret_t)ftrace_stub; |
@@ -2328,7 +2302,7 @@ void unregister_ftrace_graph(void) | |||
2328 | ftrace_shutdown(FTRACE_STOP_FUNC_RET); | 2302 | ftrace_shutdown(FTRACE_STOP_FUNC_RET); |
2329 | unregister_pm_notifier(&ftrace_suspend_notifier); | 2303 | unregister_pm_notifier(&ftrace_suspend_notifier); |
2330 | 2304 | ||
2331 | mutex_unlock(&ftrace_sysctl_lock); | 2305 | mutex_unlock(&ftrace_lock); |
2332 | } | 2306 | } |
2333 | 2307 | ||
2334 | /* Allocate a return stack for newly created task */ | 2308 | /* Allocate a return stack for newly created task */ |