@@ -1200,19 +1200,14 @@ void fgraph_update_pid_func(void)
12001200static int start_graph_tracing (void )
12011201{
12021202 unsigned long * * ret_stack_list ;
1203- int ret , cpu ;
1203+ int ret ;
12041204
1205- ret_stack_list = kmalloc (SHADOW_STACK_SIZE , GFP_KERNEL );
1205+ ret_stack_list = kcalloc (FTRACE_RETSTACK_ALLOC_SIZE ,
1206+ sizeof (* ret_stack_list ), GFP_KERNEL );
12061207
12071208 if (!ret_stack_list )
12081209 return - ENOMEM ;
12091210
1210- /* The cpu_boot init_task->ret_stack will never be freed */
1211- for_each_online_cpu (cpu ) {
1212- if (!idle_task (cpu )-> ret_stack )
1213- ftrace_graph_init_idle_task (idle_task (cpu ), cpu );
1214- }
1215-
12161211 do {
12171212 ret = alloc_retstack_tasklist (ret_stack_list );
12181213 } while (ret == - EAGAIN );
@@ -1282,13 +1277,33 @@ static void ftrace_graph_disable_direct(bool disable_branch)
12821277 fgraph_direct_gops = & fgraph_stub ;
12831278}
12841279
1280+ /* The cpu_boot init_task->ret_stack will never be freed */
1281+ static int fgraph_cpu_init (unsigned int cpu )
1282+ {
1283+ if (!idle_task (cpu )-> ret_stack )
1284+ ftrace_graph_init_idle_task (idle_task (cpu ), cpu );
1285+ return 0 ;
1286+ }
1287+
12851288int register_ftrace_graph (struct fgraph_ops * gops )
12861289{
1290+ static bool fgraph_initialized ;
12871291 int command = 0 ;
12881292 int ret = 0 ;
12891293 int i = -1 ;
12901294
1291- mutex_lock (& ftrace_lock );
1295+ guard (mutex )(& ftrace_lock );
1296+
1297+ if (!fgraph_initialized ) {
1298+ ret = cpuhp_setup_state (CPUHP_AP_ONLINE_DYN , "fgraph:online" ,
1299+ fgraph_cpu_init , NULL );
1300+ if (ret < 0 ) {
1301+ pr_warn ("fgraph: Error to init cpu hotplug support\n" );
1302+ return ret ;
1303+ }
1304+ fgraph_initialized = true;
1305+ ret = 0 ;
1306+ }
12921307
12931308 if (!fgraph_array [0 ]) {
12941309 /* The array must always have real data on it */
@@ -1298,10 +1313,8 @@ int register_ftrace_graph(struct fgraph_ops *gops)
12981313 }
12991314
13001315 i = fgraph_lru_alloc_index ();
1301- if (i < 0 || WARN_ON_ONCE (fgraph_array [i ] != & fgraph_stub )) {
1302- ret = - ENOSPC ;
1303- goto out ;
1304- }
1316+ if (i < 0 || WARN_ON_ONCE (fgraph_array [i ] != & fgraph_stub ))
1317+ return - ENOSPC ;
13051318 gops -> idx = i ;
13061319
13071320 ftrace_graph_active ++ ;
@@ -1338,8 +1351,6 @@ int register_ftrace_graph(struct fgraph_ops *gops)
13381351 gops -> saved_func = NULL ;
13391352 fgraph_lru_release_index (i );
13401353 }
1341- out :
1342- mutex_unlock (& ftrace_lock );
13431354 return ret ;
13441355}
13451356
0 commit comments