All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Florent Revest" <florent.revest@linux.dev>
To: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
Cc: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
	"bpf" <bpf@vger.kernel.org>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Andrii Nakryiko" <andrii@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>,
	"Jiri Olsa" <jolsa@kernel.org>, "KP Singh" <kpsingh@kernel.org>,
	"Emil Tsalapatis" <emil@etsalapatis.com>,
	"John Fastabend" <john.fastabend@gmail.com>,
	"Paul E. McKenney" <paulmck@kernel.org>,
	"Jose Fernandez" <jose.fernandez@linux.dev>,
	"LKML" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH bpf] bpf: Keep progs alive until the trampoline image calling them is freed
Date: Wed, 02 Sep 2026 23:25:35 +0000	[thread overview]
Message-ID: <DL57W17T3VEC.1EJMWXYOB7JFU@linux.dev> (raw)
In-Reply-To: <CAADnVQJ+OJKmgaDM9B58g30M_-pkZgGmbDuvEWmrg8U_ZkxbSg@mail.gmail.com>

On Wed Sep 2, 2026 at 10:06 PM UTC, Alexei Starovoitov wrote:
> On Wed, Sep 2, 2026 at 3:15 AM Florent Revest <florent.revest@linux.dev> wrote:
> >
> > On Wed Sep 2, 2026 at 5:57 AM UTC, Alexei Starovoitov wrote:
> > > On Mon, Aug 31, 2026 at 1:58 PM Florent Revest <florent.revest@linux.dev> wrote:
> > > >
> > > > How about having old trampolines skip freed programs instead of keeping
> > > > them alive ?
> > >
> > > Isn't it doing it now?
> > > That was the whole point of patching nop to jmp in a trampoline.
> >
> > Just to be sure we're talking about the same thing, you're referring to the
> > "ip_after_call" patching done in bpf_tramp_image_put, right ?
> >
> > My understanding is that this only helps in the case where a task is in the
> > traced function while a prog is detached. It'd make it skip all fexit progs.
>
> Right. That's the one I meant.
>
> > But if a task is sleeping in a fexit.s prog for example, it is already past
> > ip_after_call, so this patching would not prevent it from calling a second,
> > freed, fexit prog lined up after it in the trampoline, no ? The same situation
> > should happen with a sleeping fentry.s prog followed by a fentry prog.
>
> Hmm. You mean like fexit prog A called a sleepable kfunc and
> another prog B is attached to the same trampoline.
>
> Then the trampoline needs to be freed. ip_after_call patches jmp in,
> and trampoline proceeds to free progs A and B.
> B is freed right away.
> Eventually A's kfunc returns from sleep
> and jmps back into a trampoline
> which is not freed yet, since percpu_ref keeps it,
> but prog B is gone, so it attempts to execute a freed prog B ?

Yep, exactly!

> > I have a reproducer for those scenarios that crashes bpf-next. I will make it a
> > selftest in v2 like Jiri suggested.
>
> Please narrow down the reproducer (sounds like it's a random stress test
> at this point) to specific steps.
>
> If my guess above is correct the reproducer will be short
> and deterministic.

Indeed. When I originally sent this patch my repro was a stress test but when I
found out about the above scenario I could make a short and deterministic repro

My only question then is, what kind of fix would you prefer in v2: keeping refs
to progs while the trampoline is alive ? (like in this v1, but I think you
nacked this approach already ?) or some other creative solution like having
__bpf_prog_enter*() skip each freed prog individually ? Or maybe something
else ?

  reply	other threads:[~2026-09-02 23:25 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-19 12:22 [PATCH bpf] bpf: Keep progs alive until the trampoline image calling them is freed Florent Revest (Anthropic)
2026-08-20 15:26 ` Junseo Lim
     [not found]   ` <bc0edb11e07e0f6147e9c552805d0029c7aec7fc@linux.dev>
2026-08-21  7:58     ` Junseo Lim
2026-08-31 21:07       ` Florent Revest
2026-08-20 16:19 ` Leon Hwang
2026-08-30 10:40 ` Kumar Kartikeya Dwivedi
2026-08-30 13:21   ` Alexei Starovoitov
2026-08-31  2:43     ` Kumar Kartikeya Dwivedi
2026-08-31 20:58       ` Florent Revest
2026-09-02  5:57         ` Alexei Starovoitov
2026-09-02 10:15           ` Florent Revest
2026-09-02 22:06             ` Alexei Starovoitov
2026-09-02 23:25               ` Florent Revest [this message]
2026-09-03  0:48                 ` Alexei Starovoitov
2026-09-12  0:20                   ` Alexei Starovoitov
2026-09-12 10:00                     ` Florent Revest
2026-08-31 16:40 ` Jiri Olsa
2026-08-31 20:43   ` Florent Revest

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=DL57W17T3VEC.1EJMWXYOB7JFU@linux.dev \
    --to=florent.revest@linux.dev \
    --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=emil@etsalapatis.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=jose.fernandez@linux.dev \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=paulmck@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.