• Steven Rostedt (Red Hat)'s avatar
    ftrace: Add infrastructure for delayed enabling of module functions · b7ffffbb
    Steven Rostedt (Red Hat) authored
    Qiu Peiyang pointed out that there's a race when enabling function tracing
    and loading a module. In order to make the modifications of converting nops
    in the prologue of functions into callbacks, the text needs to be converted
    from read-only to read-write. When enabling function tracing, the text
    permission is updated, the functions are modified, and then they are put
    back.
    
    When loading a module, the updates to convert function calls to mcount is
    done before the module text is set to read-only. But after it is done, the
    module text is visible by the function tracer. Thus we have the following
    race:
    
    	CPU 0			CPU 1
    	-----			-----
       start function tracing
       set text to read-write
    			     load_module
    			     add functions to ftrace
    			     set module text read-only
    
       update all functions to callbacks
       modify module functions too
       < Can't it's read-only >
    
    When this happens, ftrace detects the issue and disables itself till the
    next reboot.
    
    To fix this, a new DISABLED flag is added for ftrace records, which all
    module functions get when they are added. Then later, after the module code
    is all set, the records will have the DISABLED flag cleared, and they will
    be enabled if any callback wants all functions to be traced.
    
    Note, this doesn't add the delay to later. It simply changes the
    ftrace_module_init() to do both the setting of DISABLED records, and then
    immediately calls the enable code. This helps with testing this new code as
    it has the same behavior as previously. Another change will come after this
    to have the ftrace_module_enable() called after the text is set to
    read-only.
    
    Cc: Qiu Peiyang <peiyangx.qiu@intel.com>
    Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
    b7ffffbb
ftrace.c 139 KB