All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Emil Tsalapatis" <emil@etsalapatis.com>
To: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
Cc: "bpf" <bpf@vger.kernel.org>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Eduard" <eddyz87@gmail.com>,
	"Martin KaFai Lau" <martin.lau@kernel.org>,
	"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
	"Song Liu" <song@kernel.org>,
	"Yonghong Song" <yonghong.song@linux.dev>,
	"Mykyta Yatsenko" <yatsenko@meta.com>
Subject: Re: [PATCH bpf-next v5 1/2] bpf: Only enforce 8 frame call stack limit for all-static stacks
Date: Mon, 16 Mar 2026 11:09:50 -0400	[thread overview]
Message-ID: <DH4AVUUSLYT5.1WWVVAWM0D5AX@etsalapatis.com> (raw)
In-Reply-To: <CAADnVQJ7c-biuSzin6+-Jt=xDEP0+PdJPwR6xDPCQDYjf_9qvg@mail.gmail.com>

On Fri Mar 13, 2026 at 10:40 PM EDT, Alexei Starovoitov wrote:
> On Wed, Mar 11, 2026 at 11:28 AM Emil Tsalapatis <emil@etsalapatis.com> wrote:
>>
>> The BPF verifier currently enforces a call stack depth of 8 frames,
>> regardless of the actual stack space consumption of those frames. The
>> limit is necessary for static call stacks, because the bookkeeping data
>> structures used by the verifier when stepping into static functions
>> during verification only support 8 stack frames. However, this
>> limitation only matters for static stack frames: Global subprogs are
>> verified by themselves and do not require limiting the call depth.
>>
>> Relax this limitation to only apply to static stack frames. Verification
>> now only fails when there is a sequence of 8 calls to non-global
>> subprogs. Calling into a global subprog resets the counter. This allows
>> deeper call stacks, provided all frames still fit in the stack.
>>
>> The change does not increase the maximum size of the call stack, only
>> the maximum number of frames we can place in it.
>>
>> Also change the progs/test_global_func3.c selftest to use static
>> functions, since with the new patch it would otherwise unexpectedly
>> pass verification.
>>
>> Acked-by: Mykyta Yatsenko <yatsenko@meta.com>
>> Acked-by: Eduard Zingerman <eddyz87@gmail.com>
>> Signed-off-by: Emil Tsalapatis <emil@etsalapatis.com>
>> ---
>>  include/linux/bpf_verifier.h                  |  9 +++
>>  kernel/bpf/verifier.c                         | 62 +++++++++++++------
>>  .../selftests/bpf/progs/test_global_func3.c   | 18 +++---
>>  3 files changed, 61 insertions(+), 28 deletions(-)
>>
>> diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
>> index 090aa26d1c98..f31194c2f0a8 100644
>> --- a/include/linux/bpf_verifier.h
>> +++ b/include/linux/bpf_verifier.h
>> @@ -742,6 +742,12 @@ struct bpf_scc_info {
>>
>>  struct bpf_liveness;
>>
>> +struct bpf_subprog_call_depth_info {
>> +       int ret_insn; /* caller instruction where we return to. */
>> +       int caller; /* caller subprogram idx */
>> +       int frame; /* # of consecutive static call stack frames on top of stack */
>> +};
>> +
>>  /* single container for all structs
>>   * one verifier_env per bpf_check() call
>>   */
>> @@ -851,6 +857,9 @@ struct bpf_verifier_env {
>>         u32 scc_cnt;
>>         struct bpf_iarray *succ;
>>         struct bpf_iarray *gotox_tmp_buf;
>> +
>> +       /* temporary state used for call frame depth calculation */
>> +       struct bpf_subprog_call_depth_info *dinfo;
>
> It doesn't have to be part of env, right?
> Could you just pass it as another argument to check_max_stack_depth_subprog() ?
>
> 'env' is for things that need to be around for most of the verifier's
> duration.
> This one was added to 'env' just to avoid an extra argument
> between check_max_stack_depth() and check_max_stack_depth_subprog().
> Why?
> Seems like a wrong tradeoff.
>
> and with that struct bpf_subprog_call_depth_info can be local
> in verifier.c?
>

Moving the struct out of env and into verifier.c is a strict improvement
over the current version, I will adjust the patch and respin.

> pw-bot: cr


  reply	other threads:[~2026-03-16 15:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-11 18:28 [PATCH bpf-next v5 0/2] bpf: Relax 8 frame limitation for global subprogs Emil Tsalapatis
2026-03-11 18:28 ` [PATCH bpf-next v5 1/2] bpf: Only enforce 8 frame call stack limit for all-static stacks Emil Tsalapatis
2026-03-11 19:16   ` bot+bpf-ci
2026-03-11 19:24     ` Emil Tsalapatis
2026-03-14  2:40   ` Alexei Starovoitov
2026-03-16 15:09     ` Emil Tsalapatis [this message]
2026-03-11 18:28 ` [PATCH bpf-next v5 2/2] selftests/bpf: Add deep call stack selftests Emil Tsalapatis

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=DH4AVUUSLYT5.1WWVVAWM0D5AX@etsalapatis.com \
    --to=emil@etsalapatis.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@kernel.org \
    --cc=memxor@gmail.com \
    --cc=song@kernel.org \
    --cc=yatsenko@meta.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 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.