Re: [PATCH -v5 05/17] x86/ftrace: Use text_poke()

From: Peter Zijlstra
Date: Wed Nov 13 2019 - 03:54:17 EST


On Tue, Nov 12, 2019 at 11:24:13PM +0100, Peter Zijlstra wrote:
> On Tue, Nov 12, 2019 at 01:25:36PM -0500, Steven Rostedt wrote:
> > On Mon, 11 Nov 2019 14:12:57 +0100
> > Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
>
> > > int ftrace_arch_code_modify_post_process(void)
> > > __releases(&text_mutex)
> > > {
> > > - set_all_modules_text_ro();
> > > - set_kernel_text_ro();
> > > + text_poke_finish();
> >
> > Why is the text_poke_finish() needed here? Can we add a comment about
> > why?
>
> I think this is because of the text_poke_queue() in
> ftrace_modify_code_direct(). I seem to have forgotten the code-flow
> between the core and arch parts of ftrace again.
>
> But sure, I can try and dig that out again and write a comment.

These are the two callgraphs:

ftrace_module_enable()
ftrace_arch_code_modify_prepare()
do_for_each_ftrace_rec()
__ftrace_replace_code()
ftrace_make_{call,nop}()
ftrace_modify_code_direct()
text_poke_queue()

ftrace_arch_code_modify_post_process()
text_poke_finish();


ftrace_run_update_code()
ftrace_arch_code_modify_prepare()
arch_ftrace_update_code()
ftrace_modify_all_code()
ftrace_replace_code()
for_ftrace_rec_iter()
text_poke_queue()
text_poke_finish()
ftrace_arch_code_modify_post_process()
text_poke_finish()


So while it is superfluous for ftrace_run_update_code() it is required
for ftrace_module_enable(), and, as I said, pairs with the
text_poke_queue() in ftrace_modify_code_direct().

I'll stick in a comment.