Re: [PATCH] ftrace: enable trampoline when rec count decrement to one

From: Steven Rostedt
Date: Wed May 08 2019 - 12:54:44 EST


On Wed, 8 May 2019 23:02:33 +0800
"chengjian (D)" <cj.chengjian@xxxxxxxxxx> wrote:

> function tracer uses ftrace_caller() and livepatch uses
> ftrace_regs_caller().
>
> I can modify my testcase to trigger this race condition.
>
>
> #enable livepatch
> insmod klp_unshare_files.ko
> cat /sys/kernel/debug/tracing/enabled_functions
> unshare_files (1) R I tramp: 0xffffffffc0008000 (klp_ftrace_handler+0x0/0xa0) ->ftrace_ops_assist_func+0x0/0xf0
> [NOW, the rec caller is ftracer_regs_caller TRAMPOLINE]
>
> #function tracer
> echo unshare_files > /sys/kernel/debug/tracing/set_ftrace_filter
> echo function > /sys/kernel/debug/tracing/current_tracer
> cat /sys/kernel/debug/tracing/enabled_functions
> unshare_files (2) R I ->ftrace_ops_list_func+0x0/0x170
> [NOW, the rec caller is ftracer_regs_caller]
>
>
> # disable livepatch
> echo 0 > /sys/kernel/livepatch/klp_unshare_files/enabled
> rmmod klp_unshare_files
>
>
> cat /sys/kernel/debug/tracing/enabled_functions
> unshare_files (1) tramp: 0xffffffffc0005000 (function_trace_call+0x0/0x120) ->function_trace_call+0x0/0x120
> [NOW, the rec caller is ftrace_caller TRAMPOLINE]
>
> So, the caller switch from regs caller back to non regs caller
> when disable the livepatch. Could this testcase cause the race
> condition ? BUT, Nothing happened here.
>
> What will happen when the race triggers ? What can I do.
>

I still can't think of it. But since the merge window already opened,
I'd like to have this patch sit in linux-next for a bit. That is, I
would wait to pull it in for the next merge window, and not this one.

-- Steve