All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: "Alexei Starovoitov" <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	bpf@vger.kernel.org, "Martin KaFai Lau" <kafai@fb.com>,
	"Song Liu" <songliubraving@fb.com>, "Yonghong Song" <yhs@fb.com>,
	"John Fastabend" <john.fastabend@gmail.com>,
	"KP Singh" <kpsingh@chromium.org>,
	"Stanislav Fomichev" <sdf@google.com>,
	"Hao Luo" <haoluo@google.com>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Björn Töpel" <bjorn@kernel.org>
Subject: Re: [PATCH bpf-next 2/2] bpf: Move bpf_dispatcher function out of ftrace locations
Date: Tue, 30 Aug 2022 15:29:19 +0200	[thread overview]
Message-ID: <Yw4Qr65TnpXBX8vl@krava> (raw)
In-Reply-To: <Yw3p/WBKlOaN+W9h@hirez.programming.kicks-ass.net>

On Tue, Aug 30, 2022 at 12:44:13PM +0200, Peter Zijlstra wrote:
> On Fri, Aug 26, 2022 at 08:46:08PM +0200, Jiri Olsa wrote:
> > The dispatcher function is attached/detached to trampoline by
> > dispatcher update function. At the same time it's available as
> > ftrace attachable function.
> > 
> > After discussion [1] the proposed solution is to use compiler
> > attributes to alter bpf_dispatcher_##name##_func function:
> > 
> >   - remove it from being instrumented with __no_instrument_function__
> >     attribute, so ftrace has no track of it
> 
> This is typically spelled like: 'notrace' in the kernel.
> 
> >   - but still generate 5 nop instructions with patchable_function_entry(5)
> >     attribute, which are expected by bpf_arch_text_poke used by
> >     dispatcher update function
> > 
> > Enabling HAVE_DYNAMIC_FTRACE_NO_PATCHABLE option for x86, so
> > __patchable_function_entries functions are not part of ftrace/mcount
> > locations.
> > 
> > The dispatcher code is generated and attached only for x86 so it's safe
> > to keep bpf_dispatcher func in patchable_function_entry locations for
> > other archs.
> > 
> > [1] https://lore.kernel.org/bpf/20220722110811.124515-1-jolsa@kernel.org/
> > Suggested-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> >  arch/x86/Kconfig    | 1 +
> >  include/linux/bpf.h | 2 ++
> >  2 files changed, 3 insertions(+)
> > 
> > diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
> > index f9920f1341c8..089c20cefd2b 100644
> > --- a/arch/x86/Kconfig
> > +++ b/arch/x86/Kconfig
> > @@ -284,6 +284,7 @@ config X86
> >  	select PROC_PID_ARCH_STATUS		if PROC_FS
> >  	select HAVE_ARCH_NODE_DEV_GROUP		if X86_SGX
> >  	imply IMA_SECURE_AND_OR_TRUSTED_BOOT    if EFI
> > +	select HAVE_DYNAMIC_FTRACE_NO_PATCHABLE
> >  
> >  config INSTRUCTION_DECODER
> >  	def_bool y
> > diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> > index 9c1674973e03..945d5414bb62 100644
> > --- a/include/linux/bpf.h
> > +++ b/include/linux/bpf.h
> > @@ -925,6 +925,8 @@ int arch_prepare_bpf_dispatcher(void *image, s64 *funcs, int num_funcs);
> >  }
> >  
> >  #define DEFINE_BPF_DISPATCHER(name)					\
> > +	__attribute__((__no_instrument_function__))			\
> > +	__attribute__((patchable_function_entry(5)))			\
> >  	noinline __nocfi unsigned int bpf_dispatcher_##name##_func(	\
> >  		const void *ctx,					\
> >  		const struct bpf_insn *insnsi,				\
> 
> What makes that whole dispatcher thing x86 only? AFAICT it is only under
> BPF_JIT here and could be used by anyone.

it is just optimalization on x86, that transform default indirect calls to
direct call,  described in changelog in here:

  75ccbef6369e bpf: Introduce BPF dispatcher

other archs just make the call to bpf_func

jirka

> 
> ARM64 for instance has BPG_JIT and builds net/core/filter.c. And ARM64
> very much does use patchable_function_entry() for its ftrace
> implementation.

  reply	other threads:[~2022-08-30 13:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-26 18:46 [PATCH bpf-next 0/2] bpf,ftrace: bpf dispatcher function fix Jiri Olsa
2022-08-26 18:46 ` [PATCH bpf-next 1/2] ftrace: Add HAVE_DYNAMIC_FTRACE_NO_PATCHABLE Jiri Olsa
2022-08-26 18:46 ` [PATCH bpf-next 2/2] bpf: Move bpf_dispatcher function out of ftrace locations Jiri Olsa
2022-08-28 23:01   ` KP Singh
2022-08-30 10:44   ` Peter Zijlstra
2022-08-30 13:29     ` Jiri Olsa [this message]
2022-08-29 22:25 ` [PATCH bpf-next 0/2] bpf,ftrace: bpf dispatcher function fix Daniel Borkmann
2022-08-30 13:48   ` Jiri Olsa
2022-08-30 16:46     ` Ilya Leoshkevich
2022-08-30 23:46       ` Ilya Leoshkevich
2022-08-31 10:00         ` Jiri Olsa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Yw4Qr65TnpXBX8vl@krava \
    --to=olsajiri@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bjorn@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@chromium.org \
    --cc=peterz@infradead.org \
    --cc=sdf@google.com \
    --cc=songliubraving@fb.com \
    --cc=tglx@linutronix.de \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.