• Steven Rostedt (Red Hat)'s avatar
    ftrace/module: Hardcode ftrace_module_init() call into load_module() · 8f4c0e8b
    Steven Rostedt (Red Hat) authored
    commit a949ae56 upstream.
    
    A race exists between module loading and enabling of function tracer.
    
    	CPU 1				CPU 2
    	-----				-----
      load_module()
       module->state = MODULE_STATE_COMING
    
    				register_ftrace_function()
    				 mutex_lock(&ftrace_lock);
    				 ftrace_startup()
    				  update_ftrace_function();
    				   ftrace_arch_code_modify_prepare()
    				    set_all_module_text_rw();
    				   <enables-ftrace>
    				    ftrace_arch_code_modify_post_process()
    				     set_all_module_text_ro();
    
    				[ here all module text is set to RO,
    				  including the module that is
    				  loading!! ]
    
       blocking_notifier_call_chain(MODULE_STATE_COMING);
        ftrace_init_module()
    
         [ tries to modify code, but it's RO, and fails!
           ftrace_bug() is called]
    
    When this race happens, ftrace_bug() will produces a nasty warning and
    all of the function tracing features will be disabled until reboot.
    
    The simple solution is to treate mo...
    8f4c0e8b
module.c 90 KB