-
Notifications
You must be signed in to change notification settings - Fork 5
bpf trampoline support "jmp" mode #6388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpf trampoline support "jmp" mode #6388
Conversation
|
Upstream branch: 7dc211c |
c8a7e22 to
c919396
Compare
|
Upstream branch: ec12ab2 |
b42d4ea to
d0fb01e
Compare
c919396 to
73c6b0b
Compare
|
Upstream branch: d6ec090 |
d0fb01e to
bd04851
Compare
73c6b0b to
0bdd2b9
Compare
|
Upstream branch: d6ec090 |
bd04851 to
4324a81
Compare
0bdd2b9 to
729c7ba
Compare
|
Upstream branch: d088da9 |
4324a81 to
cf9f5e8
Compare
729c7ba to
623bab9
Compare
|
Upstream branch: e0940c6 |
cf9f5e8 to
141ed8f
Compare
623bab9 to
fe03c14
Compare
|
Upstream branch: 792f258 |
141ed8f to
4f27b02
Compare
fe03c14 to
65bfb85
Compare
|
Upstream branch: 878ee3c |
4f27b02 to
419f5c6
Compare
65bfb85 to
b1f8b58
Compare
|
Upstream branch: ae24fc8 |
419f5c6 to
0a89f55
Compare
b1f8b58 to
8f7081b
Compare
|
Upstream branch: b7f7d76 |
0a89f55 to
e9e581f
Compare
8f7081b to
c347688
Compare
|
Upstream branch: 4dd3a48 |
e9e581f to
dedc181
Compare
c347688 to
fb42a92
Compare
|
Upstream branch: 8f7cf30 |
dedc181 to
7eb9da8
Compare
fb42a92 to
3282beb
Compare
|
Upstream branch: c427320 |
7eb9da8 to
dbce641
Compare
|
Upstream branch: c427320 |
dbce641 to
31a664c
Compare
3282beb to
067f842
Compare
|
Upstream branch: fad8040 |
For now, the "nop" will be replaced with a "call" instruction when a function is hooked by the ftrace. However, sometimes the "call" can break the RSB and introduce extra overhead. Therefore, introduce the flag FTRACE_OPS_FL_JMP, which indicate that the ftrace_ops should be called with a "jmp" instead of "call". For now, it is only used by the direct call case. When a direct ftrace_ops is marked with FTRACE_OPS_FL_JMP, the last bit of the ops->direct_call will be set to 1. Therefore, we can tell if we should use "jmp" for the callback in ftrace_call_replace(). Signed-off-by: Menglong Dong <[email protected]>
Implement the DYNAMIC_FTRACE_WITH_JMP for x86_64. In ftrace_call_replace,
we will use JMP32_INSN_OPCODE instead of CALL_INSN_OPCODE if the address
should use "jmp".
Meanwhile, adjust the direct call in the ftrace_regs_caller. The RSB is
balanced in the "jmp" mode. Take the function "foo" for example:
original_caller:
call foo -> foo:
call fentry -> fentry:
[do ftrace callbacks ]
move tramp_addr to stack
RET -> tramp_addr
tramp_addr:
[..]
call foo_body -> foo_body:
[..]
RET -> back to tramp_addr
[..]
RET -> back to original_caller
Signed-off-by: Menglong Dong <[email protected]>
Some places calculate the origin_call by checking if BPF_TRAMP_F_SKIP_FRAME is set. However, it should use BPF_TRAMP_F_ORIG_STACK for this propose. Just fix them. Signed-off-by: Menglong Dong <[email protected]> Acked-by: Alexei Starovoitov <[email protected]>
In the origin call case, if BPF_TRAMP_F_SKIP_FRAME is not set, it means that the trampoline is not called, but "jmp". Introduce the function bpf_trampoline_use_jmp() to check if the trampoline is in "jmp" mode. Do some adjustment on the "jmp" mode for the x86_64. The main adjustment that we make is for the stack parameter passing case, as the stack alignment logic changes in the "jmp" mode without the "rip". What's more, the location of the parameters on the stack also changes. Signed-off-by: Menglong Dong <[email protected]>
In the origin logic, the bpf_arch_text_poke() assume that the old and new instructions have the same opcode. However, they can have different opcode if we want to replace a "call" insn with a "jmp" insn. Therefore, add the new function parameter "old_t" along with the "new_t", which are used to indicate the old and new poke type. Meanwhile, adjust the implement of bpf_arch_text_poke() for all the archs. "BPF_MOD_NOP" is added to make the code more readable. In bpf_arch_text_poke(), we still check if the new and old address is NULL to determine if nop insn should be used, which I think is more safe. Signed-off-by: Menglong Dong <[email protected]>
Implement the "jmp" mode for the bpf trampoline. For the ftrace_managed case, we need only to set the FTRACE_OPS_FL_JMP on the tr->fops if "jmp" is needed. For the bpf poke case, we will check the origin poke type with the "origin_flags", and current poke type with "tr->flags". The function bpf_trampoline_update_fentry() is introduced to do the job. The "jmp" mode will only be enabled with CONFIG_DYNAMIC_FTRACE_WITH_JMP enabled and BPF_TRAMP_F_SHARE_IPMODIFY is not set. With BPF_TRAMP_F_SHARE_IPMODIFY, we need to get the origin call ip from the stack, so we can't use the "jmp" mode. Signed-off-by: Menglong Dong <[email protected]> Acked-by: Steven Rostedt (Google) <[email protected]>
31a664c to
47b0b74
Compare
067f842 to
3bd2c43
Compare
|
At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=1024844 irrelevant now. Closing PR. |
Pull request for series with
subject: bpf trampoline support "jmp" mode
version: 3
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1024844