All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Mike Rapoport <rppt@kernel.org>
Cc: Jiri Olsa <olsajiri@gmail.com>,
	Alexei Starovoitov <alexei.starovoitov@gmail.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>, bpf <bpf@vger.kernel.org>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>
Subject: Re: [PATCH bpf-next] bpf, x86: Use global buffer for trampoline size generation
Date: Wed, 9 Sep 2026 11:49:07 +0200	[thread overview]
Message-ID: <aqErk9S-bWpQCVRL@krava> (raw)
In-Reply-To: <aqAndUVLnR3sOOlk@kernel.org>

On Tue, Sep 08, 2026 at 06:19:17PM +0300, Mike Rapoport wrote:
> On Tue, Sep 08, 2026 at 02:25:24PM +0200, Jiri Olsa wrote:
> > On Mon, Sep 07, 2026 at 05:13:29PM -0700, Alexei Starovoitov wrote:
> >
> > > > > > +static void *trampoline_size_image;
> > > > > > +
> > > > > > +static int __init init_trampoline_size_image(void)
> > > > > > +{
> > > > > > +   trampoline_size_image = execmem_alloc(EXECMEM_MODULE_DATA, PAGE_SIZE);
> > > > >
> > > > > I think I asked it earlier... why does it have to be execmem ?
> > > > > Can it be normal page?
> > > >
> > > > ugh sorry I forgot.. the page/image needs to be in execmem range
> > > > for emitting call/jmp otherwise the delta won't fit in 4 bytes
> > > > and it fails on emit_patch is_simm32 check
> > > 
> > > ahh. I see. Please mention it in the comment and
> > > also use bpf_jit_alloc_exec(PAGE_SIZE).
> > > 
> > > execmem_alloc(EXECMEM_MODULE_DATA...) was working by accident.
> > > The VM ranges could have been different.
> 
> On x86 it's not an accident ;-)
> But would be a surprise if this is copied to another architecture.
>  
> > bpf_jit_alloc_exec returns read only page so I'd use bpf_jit_alloc_exec_rw,
> > but it was recently removed in:
> > 
> >   c7a2a3618290 x86/bpf: Make arch_bpf_trampoline_size allocate from EXECMEM_MODULE_DATA
> > 
> > so I ended up with:
> > 
> >   trampoline_size_image = execmem_alloc_rw(EXECMEM_BPF, PAGE_SIZE);
> 
> This will work, but it will permanently damage 2M mapping in the module
> address space.
> 
> execmem_alloc_rw() takes a page out of the ROX cache and resets that page
> permissions to RW. This splits the large mapping of the 2M cache page and
> since this is a permanent allocation, that chunk will be forever mapped
> with 4k pages.
> 
> execmem_alloc(EXECMEM_MODULE_DATA...) does not use ROX cache, so it won't
> take a page out of ROX cache and reset it's permissions.
> 
> Since this is anyway x86 code and on x86 the ranges for data and code are
> *always* the same, I'd keep execmem_alloc(EXECMEM_MODULE_DATA...) and add a
> comment.

sgtm, if there's no objection I'll add comment to init_trampoline_size_image
and send new version

thanks,
jirka

      reply	other threads:[~2026-09-09  9:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-07 16:05 [PATCH bpf-next] bpf, x86: Use global buffer for trampoline size generation Jiri Olsa
2026-09-07 16:20 ` sashiko-bot
2026-09-07 19:56 ` Alexei Starovoitov
2026-09-07 20:26   ` Jiri Olsa
2026-09-08  0:13     ` Alexei Starovoitov
2026-09-08 12:25       ` Jiri Olsa
2026-09-08 15:19         ` Mike Rapoport
2026-09-09  9:49           ` Jiri Olsa [this message]

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=aqErk9S-bWpQCVRL@krava \
    --to=olsajiri@gmail.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=martin.lau@linux.dev \
    --cc=rppt@kernel.org \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /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.