All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Eduard Zingerman" <eddyz87@gmail.com>, <bpf@vger.kernel.org>
Cc: <daniel@iogearbox.net>, <andrii@kernel.org>, <memxor@gmail.com>
Subject: Re: [PATCH v2 bpf-next 0/5] bpf: Unwinding with unwind_goto and unwind_exit
Date: Tue, 20 Oct 2026 00:35:05 +0000	[thread overview]
Message-ID: <DM98SV0GW8PZ.30OUT4OGNRX17@gmail.com> (raw)
In-Reply-To: <a54f8bb126343e4606dbc46f0dfc7c48f6a08c0e.camel@gmail.com>

On Mon, Oct 19, 2026 at 01:32 PM Eduard Zingerman <eddyz87@gmail.com> wrote:
> As far as I understand, the main difference from what was discussed in [1]
> is that for nested calls of functions that can unwind, each function
> in a chain must be called as call/unwind_goto pair, right?

Right. Otherwise prepare_func_exit() rejects unwind_exit of the callee.

> LLVM IR does not have such limitation: `call` and `invoke` calls can
> be mixed in a chain. What the limitation buys is an ability to skip
> the loop like [2] in the verifier.

It buys more than that. Every frame returns through its own epilogue,
so r6-r9 are restored by the frame that saved them, and there is no
stack walk at run time.

> Is it planned to add an LLVM pass that converts all `call`s to
> `invoke`s for unwinding functions?

No need for a new pass. The llvm PR does it already: a plain call that
can unwind gets unwind_goto to a pad with 'r0 = 0; unwind_exit'.
does_not_catch() in patch 5 is such a case.

> If I read the series correctly before the replacement runtime control
> flow would follow `unwind_goto pad`, but after the replacement it
> would follow the normal continuation flow.
> Is it intentional? Seem to be a surprising behavior.

Yes, you read it right. An extension is a main prog of its own and
unwind_exit of the main prog is exit: it's frame 0 in the verifier and
bpf_is_subprog() is false in JITs. So the exception stops at the
extension, and the caller continues as if foo returned r0.

> Commit message says:
>
>   > So is freplace: an extension leaves with exit and
>   > the callers are ready for that.
>
> But I'm not sure I understand that.

foo can unwind, so check_func_call() made the verifier explore both
ways out of the call. The normal continuation is checked with an
unknown r0, so it's safe whatever the extension does.
Works out of the box, but maybe it's easier to disable freplace for now.

      reply	other threads:[~2026-10-20  0:35 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-19  5:18 [PATCH v2 bpf-next 0/5] bpf: Unwinding with unwind_goto and unwind_exit Alexei Starovoitov
2026-10-19  5:18 ` [PATCH v2 bpf-next 1/5] bpf: Add unwind_goto and unwind_exit insns Alexei Starovoitov
2026-10-19  5:45   ` sashiko-bot
2026-10-19  6:59   ` bot+bpf-ci
2026-10-19  5:18 ` [PATCH v2 bpf-next 2/5] bpf, x86: Support unwind_goto and unwind_exit Alexei Starovoitov
2026-10-19  5:18 ` [PATCH v2 bpf-next 3/5] bpf, arm64: " Alexei Starovoitov
2026-10-19  5:18 ` [PATCH v2 bpf-next 4/5] selftests/bpf: Add tests for " Alexei Starovoitov
2026-10-19  6:00   ` bot+bpf-ci
2026-10-19  5:18 ` [PATCH v2 bpf-next 5/5] selftests/bpf: Add a C++ prog with exceptions Alexei Starovoitov
2026-10-19 20:32 ` [PATCH v2 bpf-next 0/5] bpf: Unwinding with unwind_goto and unwind_exit Eduard Zingerman
2026-10-20  0:35   ` Alexei Starovoitov [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=DM98SV0GW8PZ.30OUT4OGNRX17@gmail.com \
    --to=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=memxor@gmail.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.