BPF List
 help / color / mirror / Atom feed
From: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>
To: "Andrii Nakryiko" <andrii.nakryiko@gmail.com>,
	"Eduard Zingerman" <eddyz87@gmail.com>
Cc: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>,
	"Yonghong Song" <yonghong.song@linux.dev>, <bpf@vger.kernel.org>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>, <kernel-team@fb.com>
Subject: Re: [PATCH bpf-next v4 00/20] bpf: Run exception cleanup landing pads when bpf_throw() unwinds
Date: Wed, 23 Sep 2026 21:34:18 +0200	[thread overview]
Message-ID: <DLMY4E5MYGQI.29MKOKECHM134@gmail.com> (raw)
In-Reply-To: <CAEf4BzaStrSG-hGERB8J=mt3agEq7d9L8+L9rsr4Z+=68gtA-w@mail.gmail.com>

On Wed Sep 23, 2026 at 9:24 PM CEST, Andrii Nakryiko wrote:
> On Wed, Sep 23, 2026 at 12:04 PM Eduard Zingerman <eddyz87@gmail.com> wrote:
>>
>> On Tue, 2026-09-22 at 17:04 -0700, Eduard Zingerman wrote:
>> > On Tue, 2026-09-22 at 23:37 +0000, Alexei Starovoitov wrote:
>> > > On Tue Sep 22, 2026 at 11:08 PM UTC, Eduard Zingerman wrote:
>> > > > On Tue, 2026-09-22 at 21:47 +0000, Alexei Starovoitov wrote:
>> > > > > On Tue Sep 22, 2026 at 4:27 AM UTC, Eduard Zingerman wrote:
>> > > > > >
>> > > > > > Total size of executable sections for all Meta BPF object files used
>> > > > > > for CI veristat testing is 10Mb. Of these there are 30K non-helper
>> > > > > > call instructions in total.
>> > > > > > So we are talking about increase by 8 * 30K = 240K ~ 2.4% worst case.
>> > > > > > Note that the instruction encoding optimized for size already hearts
>> > > > > > us in src/dst registers department: we have no room for virtual
>> > > > > > registers, which would have simplified e.g. register allocation task
>> > > > > > for ARM64. Point being that optimizing intermediate IR for size is not
>> > > > > > always a right target.
>> > > > >
>> > > > > I wasn't talking about increase in bpf ELF size,
>> > > > > but the amount of the verifier work necessary to double the number
>> > > > > of call insns.
>> > > >
>> > > > I don't understand what you mean by the amount of the verifier work.
>> > > > Traced program paths would remain the same, only the encoding of the
>> > > > information about exceptions changes.
>> > >
>> > > Any new insn requires plumbing through out.
>> > > imo ld_imm64 encoding FD inline was a mistake.
>> > > We should have went with relocations through out.
>> > > Much cleaner to extend.
>> > > Same philosophy here. Landing pad is a metadata.
>> > > It's not a good idea to encode metadata into assembly instruction.
>> > > bpf ISA is not a high level IR.
>> >
>> > Here [1] is Yonghong's series repackaged by codex with the following
>> > encoding:
>> >
>> >   call <subprog-or-kfunc> // regular encoding
>> >   unwind <label>          // a new instruction that must follow the call instruction
>> >
>> > The amount of the verifier/libbpf code dropped from ~2K to 1K lines.
>> >
>> > [1] https://github.com/eddyz87/bpf/tree/unwind-postfix
>>
>> I want to highlight this once more, before it gets buried.
>>
>> Whether landing pad is metadata or not is a matter of opinion,
>> seeing the program CFG from it's source w/o a need to consult
>> additional tables is definitely a plus.
>> Same with ld_imm64, and yes it adds a few checks in the verifier,
>> but those checks are trivial.
>>
>> I looked a bit at what other VMs/IRs do and it's a mix:
>> - JVM has exception tables similar to ours (begin, end, landing-pad).
>> - GCC (gimple and rtl) have landing pad address attached to an
>>   instruction / control flow graph node.
>> - LLVM has invoke instruction that takes three parameters:
>>   what to call, where to jump on success, where to jump to unwind.
>>
>> With that in mind, I think that the rational thing to do is to choose
>> based on the implementation complexity. Compared to v5 [2] of this
>> series the branch [1] allows to forgo:
>> - UAPI to copy the cleanup table from user space (patch #2)

We will still have UAPI, in form of new instruction, so this is less salient.

>> - insn_aux_data changes for cleanup_pad address (patch #4)
>> - simplifies check_cfg() handling (patch #5)
>> - simplifies main verification pass (patch #9):
>>   - throw raises unwinding flag
>>   - varifier interprets `unwind` as any other instruction,
>>         jump if unwinding, fallthrough during normal operation.
>> - dramatically simplifies libbpf part, dropping patches #16,17,18:
>>   - no need to collect cleanup tables from elf
>>   - no need to relocate these tables
>>   - no need to pass them to the syscall
>>

All of these do make sense.

>
> All of the above sounds like a pretty compelling reason to do the
> invoke instruction. 16-byte instructions is a fact of life due to
> ldimm64 anyways, might as well utilize those extended instructions to
> simplify a bunch of other stuff. Not having a bunch of arbitrary
> ELF-side conventions is a big plus, IMO.
>

IIUC we just need extra unwind following the call, since it already has two
control flow edges (target and fallthrough for what it would return to), so
it might be simpler than full blown new invoke.

But yeah, we didn't shy away from adding bespoke instructions when it suited us
(may_goto, etc.) in the past.

> Unless there are some technical reasons why metadata table on the side
> is objectively better, but seeing that we have precedents with LLVM
> using same approach, seems like it's workable and shouldn't paint us
> into the corner design-wise, no?
>
> Given a rather lively interest and discussion, perhaps we should do
> one of those long forgotten BPF office hours and go over this in a
> more face-to-face-ish way?
>
>> > bpf ISA is not a high level IR.
>> [...]

  reply	other threads:[~2026-09-23 19:34 UTC|newest]

Thread overview: 80+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-21 21:00 [PATCH bpf-next v4 00/20] bpf: Run exception cleanup landing pads when bpf_throw() unwinds Yonghong Song
2026-09-21 21:00 ` [PATCH bpf-next v4 01/20] bpf: Accept the compiler's exception cleanup table at program load Yonghong Song
2026-09-21 21:56   ` bot+bpf-ci
2026-09-22  3:27     ` Yonghong Song
2026-09-21 21:00 ` [PATCH bpf-next v4 02/20] bpf: Add the bpf_unwind_resume() kfunc Yonghong Song
2026-09-21 21:56   ` bot+bpf-ci
2026-09-22  3:31     ` Yonghong Song
2026-09-21 21:00 ` [PATCH bpf-next v4 03/20] bpf: Add lookups for exception cleanup resumes and landing pads Yonghong Song
2026-09-22  4:04   ` Alexei Starovoitov
2026-09-22  5:28     ` Yonghong Song
2026-09-21 21:00 ` [PATCH bpf-next v4 04/20] bpf: Prepare for an exception cleanup table before the CFG walk Yonghong Song
2026-09-22 18:27   ` Eduard Zingerman
2026-09-23  3:07     ` Yonghong Song
2026-09-23  3:54       ` Eduard Zingerman
2026-09-23  4:05         ` Yonghong Song
2026-09-21 21:00 ` [PATCH bpf-next v4 05/20] bpf: Make exception landing pads reachable in the CFG Yonghong Song
2026-09-21 21:01 ` [PATCH bpf-next v4 06/20] bpf: Explore the landing pads no call site reaches Yonghong Song
2026-09-21 23:58   ` Eduard Zingerman
2026-09-22  3:32     ` Yonghong Song
2026-09-22  4:10       ` Eduard Zingerman
2026-09-21 21:01 ` [PATCH bpf-next v4 07/20] bpf: Refuse exception cleanup shapes bpf_throw() cannot dispatch Yonghong Song
2026-09-21 21:20   ` sashiko-bot
2026-09-22  3:39     ` Yonghong Song
2026-09-21 21:56   ` bot+bpf-ci
2026-09-22  3:44     ` Yonghong Song
2026-09-22  0:30   ` Eduard Zingerman
2026-09-22  3:45     ` Yonghong Song
2026-09-22 21:43       ` Eduard Zingerman
2026-09-23  3:11         ` Yonghong Song
2026-09-21 21:01 ` [PATCH bpf-next v4 08/20] bpf: Walk the exception unwind in the verifier Yonghong Song
2026-09-21 21:40   ` sashiko-bot
2026-09-22  4:17     ` Yonghong Song
2026-09-21 21:56   ` bot+bpf-ci
2026-09-22  5:21     ` Yonghong Song
2026-09-22  4:08   ` Alexei Starovoitov
2026-09-22  5:25     ` Yonghong Song
2026-09-22 21:53       ` Eduard Zingerman
2026-09-23  3:18         ` Yonghong Song
2026-09-22 23:43   ` Eduard Zingerman
2026-09-23  3:21     ` Yonghong Song
2026-09-21 21:01 ` [PATCH bpf-next v4 09/20] bpf: Refuse a private stack for a program with an exception cleanup table Yonghong Song
2026-09-21 21:01 ` [PATCH bpf-next v4 10/20] bpf: Dispatch exception cleanup pads from bpf_throw() Yonghong Song
2026-09-22 21:38   ` Eduard Zingerman
2026-09-23  3:22     ` Yonghong Song
2026-09-21 21:01 ` [PATCH bpf-next v4 11/20] bpf, x86: Dispatch exception cleanup pads at run time Yonghong Song
2026-09-21 21:01 ` [PATCH bpf-next v4 12/20] bpf, arm64: " Yonghong Song
2026-09-21 21:01 ` [PATCH bpf-next v4 13/20] libbpf: Resolve the compiler's _Unwind_Resume to the kernel's kfunc Yonghong Song
2026-09-21 21:13   ` sashiko-bot
2026-09-21 21:01 ` [PATCH bpf-next v4 14/20] libbpf: Add cleanup_info to bpf_prog_load_opts Yonghong Song
2026-09-21 21:01 ` [PATCH bpf-next v4 15/20] libbpf: Collect .bpf_cleanup records and pass them to the kernel Yonghong Song
2026-09-21 21:20   ` sashiko-bot
2026-09-21 21:01 ` [PATCH bpf-next v4 16/20] libbpf: Carry the exception cleanup table through the light skeleton Yonghong Song
2026-09-21 21:02 ` [PATCH bpf-next v4 17/20] libbpf: Let the static linker carry .bpf_cleanup relocations Yonghong Song
2026-09-21 21:02 ` [PATCH bpf-next v4 18/20] selftests/bpf: Add an end-to-end .bpf_cleanup exception test Yonghong Song
2026-09-21 21:22   ` sashiko-bot
2026-09-22  5:26     ` Yonghong Song
2026-09-21 21:56   ` bot+bpf-ci
2026-09-21 21:02 ` [PATCH bpf-next v4 19/20] selftests/bpf: Cover the exception cleanup shapes the chain does not reach Yonghong Song
2026-09-21 21:19   ` sashiko-bot
2026-09-21 21:02 ` [PATCH bpf-next v4 20/20] selftests/bpf: Load an exception cleanup program from a light skeleton Yonghong Song
2026-09-22  1:08 ` [PATCH bpf-next v4 00/20] bpf: Run exception cleanup landing pads when bpf_throw() unwinds Eduard Zingerman
2026-09-22  2:16   ` Alexei Starovoitov
2026-09-22  2:31     ` Kumar Kartikeya Dwivedi
2026-09-22 21:44       ` Alexei Starovoitov
2026-09-23  4:36         ` Kumar Kartikeya Dwivedi
2026-09-23  4:54           ` Alexei Starovoitov
2026-09-23  5:20             ` Kumar Kartikeya Dwivedi
2026-09-23  6:16             ` Eduard Zingerman
2026-09-23  6:44               ` Kumar Kartikeya Dwivedi
2026-09-22  4:27     ` Eduard Zingerman
2026-09-22 21:47       ` Alexei Starovoitov
2026-09-22 23:08         ` Eduard Zingerman
2026-09-22 23:37           ` Alexei Starovoitov
2026-09-23  0:04             ` Eduard Zingerman
2026-09-23 19:04               ` Eduard Zingerman
2026-09-23 19:24                 ` Andrii Nakryiko
2026-09-23 19:34                   ` Kumar Kartikeya Dwivedi [this message]
2026-09-23 21:34                     ` Alexei Starovoitov
2026-09-23 22:00                       ` Eduard Zingerman
2026-09-23 23:22                         ` Alexei Starovoitov

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=DLMY4E5MYGQI.29MKOKECHM134@gmail.com \
    --to=memxor@gmail.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=kernel-team@fb.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox