[PATCH v5 bpf-next 0/4] ftrace: host klp and bpf trampoline together

Song Liu posted 4 patches 3 years, 9 months ago
arch/x86/net/bpf_jit_comp.c |  13 +-
include/linux/bpf.h         |  13 ++
include/linux/ftrace.h      |  43 +++++
kernel/bpf/trampoline.c     | 158 +++++++++++++++--
kernel/trace/ftrace.c       | 328 ++++++++++++++++++++++++++++++------
5 files changed, 484 insertions(+), 71 deletions(-)
[PATCH v5 bpf-next 0/4] ftrace: host klp and bpf trampoline together
Posted by Song Liu 3 years, 9 months ago
Changes v4 => v5:
1. Cleanup direct_mutex handling in register_ftrace_function.
   (Steven Rostedt, Petr Mladek).
2. Various smallish fixes. (Steven Rostedt, Petr Mladek).

Changes v3 => v4:
1. Fix build errors for different config. (kernel test robot)

Changes v2 => v3:
1. Major rewrite after discussions with Steven Rostedt. [1]
2. Remove SHARE_IPMODIFY flag from ftrace code. Instead use the callback
   function to communicate this information. (Steven)
3. Add cleanup_direct_functions_after_ipmodify() to clear SHARE_IPMODIFY
   on the DIRECT ops when the IPMODIFY ops is removed.

Changes v1 => v2:
1. Fix build errors for different config. (kernel test robot)

Kernel Live Patch (livepatch, or klp) and bpf trampoline are important
features for modern systems. This set allows the two to work on the same
kernel function as the same time.

live patch uses ftrace with IPMODIFY, while bpf trampoline use direct
ftrace. Existing policy does not allow the two to attach to the same kernel
function. This is changed by fine tuning ftrace IPMODIFY policy, and allows
one IPMODIFY ftrace_ops and one DIRECT ftrace_ops on the same kernel
function at the same time. Please see patch 2 and 4 for more details.

Note that, one of the constraint here is to let bpf trampoline use direct
call when it is not working on the same function as live patch. This is
achieved by allowing ftrace code to ask bpf trampoline to make changes.

[1] https://lore.kernel.org/all/20220602193706.2607681-2-song@kernel.org/

Jiri Olsa (1):
  bpf, x64: Allow to use caller address from stack

Song Liu (3):
  ftrace: Add modify_ftrace_direct_multi_nolock
  ftrace: Allow IPMODIFY and DIRECT ops on the same function
  bpf: Support bpf_trampoline on functions with IPMODIFY (e.g.
    livepatch)

 arch/x86/net/bpf_jit_comp.c |  13 +-
 include/linux/bpf.h         |  13 ++
 include/linux/ftrace.h      |  43 +++++
 kernel/bpf/trampoline.c     | 158 +++++++++++++++--
 kernel/trace/ftrace.c       | 328 ++++++++++++++++++++++++++++++------
 5 files changed, 484 insertions(+), 71 deletions(-)

--
2.30.2
Re: [PATCH v5 bpf-next 0/4] ftrace: host klp and bpf trampoline together
Posted by patchwork-bot+netdevbpf@kernel.org 3 years, 8 months ago
Hello:

This series was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:

On Tue, 19 Jul 2022 17:21:22 -0700 you wrote:
> Changes v4 => v5:
> 1. Cleanup direct_mutex handling in register_ftrace_function.
>    (Steven Rostedt, Petr Mladek).
> 2. Various smallish fixes. (Steven Rostedt, Petr Mladek).
> 
> Changes v3 => v4:
> 1. Fix build errors for different config. (kernel test robot)
> 
> [...]

Here is the summary with links:
  - [v5,bpf-next,1/4] ftrace: Add modify_ftrace_direct_multi_nolock
    https://git.kernel.org/bpf/bpf-next/c/f96f644ab97a
  - [v5,bpf-next,2/4] ftrace: Allow IPMODIFY and DIRECT ops on the same function
    https://git.kernel.org/bpf/bpf-next/c/53cd885bc5c3
  - [v5,bpf-next,3/4] bpf, x64: Allow to use caller address from stack
    https://git.kernel.org/bpf/bpf-next/c/316cba62dfb7
  - [v5,bpf-next,4/4] bpf: Support bpf_trampoline on functions with IPMODIFY (e.g. livepatch)
    https://git.kernel.org/bpf/bpf-next/c/00963a2e75a8

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Re: [PATCH v5 bpf-next 0/4] ftrace: host klp and bpf trampoline together
Posted by Song Liu 3 years, 9 months ago
Hi Steven, 

> On Jul 19, 2022, at 5:21 PM, Song Liu <song@kernel.org> wrote:
> 
> Changes v4 => v5:
> 1. Cleanup direct_mutex handling in register_ftrace_function.
>   (Steven Rostedt, Petr Mladek).
> 2. Various smallish fixes. (Steven Rostedt, Petr Mladek).
> 
> Changes v3 => v4:
> 1. Fix build errors for different config. (kernel test robot)
> 
> Changes v2 => v3:
> 1. Major rewrite after discussions with Steven Rostedt. [1]
> 2. Remove SHARE_IPMODIFY flag from ftrace code. Instead use the callback
>   function to communicate this information. (Steven)
> 3. Add cleanup_direct_functions_after_ipmodify() to clear SHARE_IPMODIFY
>   on the DIRECT ops when the IPMODIFY ops is removed.
> 
> Changes v1 => v2:
> 1. Fix build errors for different config. (kernel test robot)
> 
> Kernel Live Patch (livepatch, or klp) and bpf trampoline are important
> features for modern systems. This set allows the two to work on the same
> kernel function as the same time.
> 
> live patch uses ftrace with IPMODIFY, while bpf trampoline use direct
> ftrace. Existing policy does not allow the two to attach to the same kernel
> function. This is changed by fine tuning ftrace IPMODIFY policy, and allows
> one IPMODIFY ftrace_ops and one DIRECT ftrace_ops on the same kernel
> function at the same time. Please see patch 2 and 4 for more details.
> 
> Note that, one of the constraint here is to let bpf trampoline use direct
> call when it is not working on the same function as live patch. This is
> achieved by allowing ftrace code to ask bpf trampoline to make changes.
> 
> [1] https://lore.kernel.org/all/20220602193706.2607681-2-song@kernel.org/

How does this version look to you? 

Thanks,
Song
Re: [PATCH v5 bpf-next 0/4] ftrace: host klp and bpf trampoline together
Posted by Steven Rostedt 3 years, 8 months ago
On Thu, 21 Jul 2022 22:59:30 +0000
Song Liu <songliubraving@fb.com> wrote:

> How does this version look to you? 

Looks good. Thanks Song!

For the first two patches:

Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>

-- Steve
Re: [PATCH v5 bpf-next 0/4] ftrace: host klp and bpf trampoline together
Posted by Song Liu 3 years, 8 months ago

> On Jul 22, 2022, at 9:56 AM, Steven Rostedt <rostedt@goodmis.org> wrote:
> 
> On Thu, 21 Jul 2022 22:59:30 +0000
> Song Liu <songliubraving@fb.com> wrote:
> 
>> How does this version look to you? 
> 
> Looks good. Thanks Song!
> 
> For the first two patches:
> 
> Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>

Thanks! 

Song