mbox series

[v2,bpf-next,0/5] ftrace: host klp and bpf trampoline together

Message ID 20220602193706.2607681-1-song@kernel.org (mailing list archive)
Headers show
Series ftrace: host klp and bpf trampoline together | expand

Message

Song Liu June 2, 2022, 7:37 p.m. UTC
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 non-DIRECT IPMODIFY ftrace_ops and one non-IPMODIFY DIRECT ftrace_ops
on the same kernel function at the same time. Please see 3/5 for more
details on this.

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.

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

Song Liu (4):
  ftrace: allow customized flags for ftrace_direct_multi ftrace_ops
  ftrace: add modify_ftrace_direct_multi_nolock
  ftrace: introduce FTRACE_OPS_FL_SHARE_IPMODIFY
  bpf: trampoline: support FTRACE_OPS_FL_SHARE_IPMODIFY

 arch/x86/net/bpf_jit_comp.c |  13 +-
 include/linux/bpf.h         |   8 ++
 include/linux/ftrace.h      |  79 +++++++++++
 kernel/bpf/trampoline.c     | 109 +++++++++++++--
 kernel/trace/ftrace.c       | 269 +++++++++++++++++++++++++++++++-----
 5 files changed, 424 insertions(+), 54 deletions(-)

--
2.30.2

Comments

Song Liu June 6, 2022, 10:57 p.m. UTC | #1
Hi Steven, 

> On Jun 2, 2022, at 12:37 PM, Song Liu <song@kernel.org> wrote:
> 
> 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 non-DIRECT IPMODIFY ftrace_ops and one non-IPMODIFY DIRECT ftrace_ops
> on the same kernel function at the same time. Please see 3/5 for more
> details on this.
> 
> 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.

Could you please share your comments on this set? 

Thanks!
Song

> 
> Jiri Olsa (1):
>  bpf, x64: Allow to use caller address from stack
> 
> Song Liu (4):
>  ftrace: allow customized flags for ftrace_direct_multi ftrace_ops
>  ftrace: add modify_ftrace_direct_multi_nolock
>  ftrace: introduce FTRACE_OPS_FL_SHARE_IPMODIFY
>  bpf: trampoline: support FTRACE_OPS_FL_SHARE_IPMODIFY
> 
> arch/x86/net/bpf_jit_comp.c |  13 +-
> include/linux/bpf.h         |   8 ++
> include/linux/ftrace.h      |  79 +++++++++++
> kernel/bpf/trampoline.c     | 109 +++++++++++++--
> kernel/trace/ftrace.c       | 269 +++++++++++++++++++++++++++++++-----
> 5 files changed, 424 insertions(+), 54 deletions(-)
> 
> --
> 2.30.2
Steven Rostedt July 11, 2022, 11:55 p.m. UTC | #2
I just realized that none of the live kernel patching folks are Cc'd on
this thread. I think they will care much more about this than I do.

-- Steve


On Thu, 2 Jun 2022 12:37:01 -0700
Song Liu <song@kernel.org> wrote:

> 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 non-DIRECT IPMODIFY ftrace_ops and one non-IPMODIFY DIRECT ftrace_ops
> on the same kernel function at the same time. Please see 3/5 for more
> details on this.
> 
> 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.
> 
> Jiri Olsa (1):
>   bpf, x64: Allow to use caller address from stack
> 
> Song Liu (4):
>   ftrace: allow customized flags for ftrace_direct_multi ftrace_ops
>   ftrace: add modify_ftrace_direct_multi_nolock
>   ftrace: introduce FTRACE_OPS_FL_SHARE_IPMODIFY
>   bpf: trampoline: support FTRACE_OPS_FL_SHARE_IPMODIFY
> 
>  arch/x86/net/bpf_jit_comp.c |  13 +-
>  include/linux/bpf.h         |   8 ++
>  include/linux/ftrace.h      |  79 +++++++++++
>  kernel/bpf/trampoline.c     | 109 +++++++++++++--
>  kernel/trace/ftrace.c       | 269 +++++++++++++++++++++++++++++++-----
>  5 files changed, 424 insertions(+), 54 deletions(-)
> 
> --
> 2.30.2
Song Liu July 12, 2022, 5:15 a.m. UTC | #3
> On Jul 11, 2022, at 4:55 PM, Steven Rostedt <rostedt@goodmis.org> wrote:
> 
> I just realized that none of the live kernel patching folks are Cc'd on
> this thread. I think they will care much more about this than I do.

vger.kernel.org often drops my email when the CC list is too long. So I
try to keep the list short. In this case, since we are not changing live
patch code, and there isn't any negative impact for live patch side, I 
didn't CC live patch folks. 

I will at least CC live-patching@ in the next version. 

Thanks,
Song

PS: I am the live patch guy at Meta. :)


> 
> -- Steve
> 
> 
> On Thu, 2 Jun 2022 12:37:01 -0700
> Song Liu <song@kernel.org> wrote:
> 
>> 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 non-DIRECT IPMODIFY ftrace_ops and one non-IPMODIFY DIRECT ftrace_ops
>> on the same kernel function at the same time. Please see 3/5 for more
>> details on this.
>> 
>> 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.
>> 
>> Jiri Olsa (1):
>>  bpf, x64: Allow to use caller address from stack
>> 
>> Song Liu (4):
>>  ftrace: allow customized flags for ftrace_direct_multi ftrace_ops
>>  ftrace: add modify_ftrace_direct_multi_nolock
>>  ftrace: introduce FTRACE_OPS_FL_SHARE_IPMODIFY
>>  bpf: trampoline: support FTRACE_OPS_FL_SHARE_IPMODIFY
>> 
>> arch/x86/net/bpf_jit_comp.c |  13 +-
>> include/linux/bpf.h         |   8 ++
>> include/linux/ftrace.h      |  79 +++++++++++
>> kernel/bpf/trampoline.c     | 109 +++++++++++++--
>> kernel/trace/ftrace.c       | 269 +++++++++++++++++++++++++++++++-----
>> 5 files changed, 424 insertions(+), 54 deletions(-)
>> 
>> --
>> 2.30.2
>
Steven Rostedt July 12, 2022, 1:36 p.m. UTC | #4
On Tue, 12 Jul 2022 05:15:26 +0000
Song Liu <songliubraving@fb.com> wrote:

> > On Jul 11, 2022, at 4:55 PM, Steven Rostedt <rostedt@goodmis.org> wrote:
> > 
> > I just realized that none of the live kernel patching folks are Cc'd on
> > this thread. I think they will care much more about this than I do.  
> 
> vger.kernel.org often drops my email when the CC list is too long. So I

Oh, they fixed that. I've had over 20 Cc's and it still works. ;-)

> try to keep the list short. In this case, since we are not changing live
> patch code, and there isn't any negative impact for live patch side, I 
> didn't CC live patch folks. 

It affects them indirectly, and they should be aware of what is happening
underneath.

> 
> I will at least CC live-patching@ in the next version. 

Thanks.

-- Steve