Re: [PATCH] fprobe: Ensure running fprobe_exit_handler() finished before calling rethook_free()

From: Google
Date: Thu Jul 06 2023 - 20:17:26 EST


On Thu, 6 Jul 2023 09:56:24 -0400
Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:

> On Thu, 6 Jul 2023 14:10:12 +0900
> Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx> wrote:
>
> > With only Jiri's patch, following flow can happen;
> >
> > ------
> > CPU1 CPU2
> > call unregister_fprobe()
> > ...
> > __fprobe_handler()
> > rethook_hook() on probed function
> > unregister_ftrace_function()
> > return from probed function
> > rethook hooks
> > find rh->handler == fprobe_exit_handler
> > call fprobe_exit_handler()
> > rethook_free():
> > set rh->handler = NULL;
> > return from unreigster_fprobe;
> > call fp->exit_handler() <- (*)
> >
> > (*) In this point, the exit handler is called after returning from
> > unregister_fprobe().
> > ------
> >
> > So, this patch changes it as following;
> > ------
> > CPU1 CPU2
> > call unregister_fprobe()
> > ...
> > rethook_stop():
> > set rh->handler = NULL;
> > __fprobe_handler()
> > rethook_hook() on probed function
> > unregister_ftrace_function()
> > return from probed function
> > rethook hooks
> > find rh->handler == NULL
> > return from rethook
> > rethook_free()
> > return from unreigster_fprobe;
> > ------
> >
> > I can also just put a synchronize_sched_rcu() right after rethook_free()
> > to wait for all running fprobe_exit_handler() too.
> >
>
> This makes more sense. Can you please add the above to the change log.

OK, let me update it.

Thanks!

>
> Thanks,
>
> -- Steve


--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>