From: Jiri Olsa <olsajiri@gmail.com>
To: Yonghong Song <yonghong.song@linux.dev>
Cc: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
kernel-team@fb.com, Martin KaFai Lau <martin.lau@kernel.org>,
Arnd Bergmann <arnd@kernel.org>
Subject: Re: [PATCH bpf-next 2/2] bpf: Avoid putting struct bpf_scc_callchain variables on the stack
Date: Wed, 2 Jul 2025 10:49:45 +0200 [thread overview]
Message-ID: <aGTyqbsSOTceHJDi@krava> (raw)
In-Reply-To: <20250702053337.1991752-1-yonghong.song@linux.dev>
On Tue, Jul 01, 2025 at 10:33:37PM -0700, Yonghong Song wrote:
> Add a 'struct bpf_scc_callchain callchain' field in bpf_verifier_env.
> This way, the previous bpf_scc_callchain local variables can be
> replaced by taking address of env->callchain. This can reduce stack
> usage and fix the following error:
> kernel/bpf/verifier.c:19921:12: error: stack frame size (1368) exceeds limit (1280) in 'do_check'
> [-Werror,-Wframe-larger-than]
>
> Reported-by: Arnd Bergmann <arnd@kernel.org>
> Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
Acked-by: Jiri Olsa <jolsa@kernel.org>
jirka
> ---
> include/linux/bpf_verifier.h | 1 +
> kernel/bpf/verifier.c | 36 ++++++++++++++++++------------------
> 2 files changed, 19 insertions(+), 18 deletions(-)
>
> diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
> index 7e459e839f8b..e2c175d608bb 100644
> --- a/include/linux/bpf_verifier.h
> +++ b/include/linux/bpf_verifier.h
> @@ -841,6 +841,7 @@ struct bpf_verifier_env {
> char tmp_str_buf[TMP_STR_BUF_LEN];
> struct bpf_insn insn_buf[INSN_BUF_SIZE];
> struct bpf_insn epilogue_buf[INSN_BUF_SIZE];
> + struct bpf_scc_callchain callchain;
> /* array of pointers to bpf_scc_info indexed by SCC id */
> struct bpf_scc_info **scc_info;
> u32 scc_cnt;
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 29faef51065d..b334e6434eb4 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -1913,19 +1913,19 @@ static char *format_callchain(struct bpf_verifier_env *env, struct bpf_scc_callc
> */
> static int maybe_enter_scc(struct bpf_verifier_env *env, struct bpf_verifier_state *st)
> {
> - struct bpf_scc_callchain callchain;
> + struct bpf_scc_callchain *callchain = &env->callchain;
> struct bpf_scc_visit *visit;
>
> - if (!compute_scc_callchain(env, st, &callchain))
> + if (!compute_scc_callchain(env, st, callchain))
> return 0;
> - visit = scc_visit_lookup(env, &callchain);
> - visit = visit ?: scc_visit_alloc(env, &callchain);
> + visit = scc_visit_lookup(env, callchain);
> + visit = visit ?: scc_visit_alloc(env, callchain);
> if (!visit)
> return -ENOMEM;
> if (!visit->entry_state) {
> visit->entry_state = st;
> if (env->log.level & BPF_LOG_LEVEL2)
> - verbose(env, "SCC enter %s\n", format_callchain(env, &callchain));
> + verbose(env, "SCC enter %s\n", format_callchain(env, callchain));
> }
> return 0;
> }
> @@ -1938,21 +1938,21 @@ static int propagate_backedges(struct bpf_verifier_env *env, struct bpf_scc_visi
> */
> static int maybe_exit_scc(struct bpf_verifier_env *env, struct bpf_verifier_state *st)
> {
> - struct bpf_scc_callchain callchain;
> + struct bpf_scc_callchain *callchain = &env->callchain;
> struct bpf_scc_visit *visit;
>
> - if (!compute_scc_callchain(env, st, &callchain))
> + if (!compute_scc_callchain(env, st, callchain))
> return 0;
> - visit = scc_visit_lookup(env, &callchain);
> + visit = scc_visit_lookup(env, callchain);
> if (!visit) {
> verifier_bug(env, "scc exit: no visit info for call chain %s",
> - format_callchain(env, &callchain));
> + format_callchain(env, callchain));
> return -EFAULT;
> }
> if (visit->entry_state != st)
> return 0;
> if (env->log.level & BPF_LOG_LEVEL2)
> - verbose(env, "SCC exit %s\n", format_callchain(env, &callchain));
> + verbose(env, "SCC exit %s\n", format_callchain(env, callchain));
> visit->entry_state = NULL;
> env->num_backedges -= visit->num_backedges;
> visit->num_backedges = 0;
> @@ -1967,22 +1967,22 @@ static int add_scc_backedge(struct bpf_verifier_env *env,
> struct bpf_verifier_state *st,
> struct bpf_scc_backedge *backedge)
> {
> - struct bpf_scc_callchain callchain;
> + struct bpf_scc_callchain *callchain = &env->callchain;
> struct bpf_scc_visit *visit;
>
> - if (!compute_scc_callchain(env, st, &callchain)) {
> + if (!compute_scc_callchain(env, st, callchain)) {
> verifier_bug(env, "add backedge: no SCC in verification path, insn_idx %d",
> st->insn_idx);
> return -EFAULT;
> }
> - visit = scc_visit_lookup(env, &callchain);
> + visit = scc_visit_lookup(env, callchain);
> if (!visit) {
> verifier_bug(env, "add backedge: no visit info for call chain %s",
> - format_callchain(env, &callchain));
> + format_callchain(env, callchain));
> return -EFAULT;
> }
> if (env->log.level & BPF_LOG_LEVEL2)
> - verbose(env, "SCC backedge %s\n", format_callchain(env, &callchain));
> + verbose(env, "SCC backedge %s\n", format_callchain(env, callchain));
> backedge->next = visit->backedges;
> visit->backedges = backedge;
> visit->num_backedges++;
> @@ -1998,12 +1998,12 @@ static int add_scc_backedge(struct bpf_verifier_env *env,
> static bool incomplete_read_marks(struct bpf_verifier_env *env,
> struct bpf_verifier_state *st)
> {
> - struct bpf_scc_callchain callchain;
> + struct bpf_scc_callchain *callchain = &env->callchain;
> struct bpf_scc_visit *visit;
>
> - if (!compute_scc_callchain(env, st, &callchain))
> + if (!compute_scc_callchain(env, st, callchain))
> return false;
> - visit = scc_visit_lookup(env, &callchain);
> + visit = scc_visit_lookup(env, callchain);
> if (!visit)
> return false;
> return !!visit->backedges;
> --
> 2.47.1
>
>
next prev parent reply other threads:[~2025-07-02 8:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-02 5:33 [PATCH bpf-next 1/2] bpf: Reduce stack frame size by using env->insn_buf for bpf insns Yonghong Song
2025-07-02 5:33 ` [PATCH bpf-next 2/2] bpf: Avoid putting struct bpf_scc_callchain variables on the stack Yonghong Song
2025-07-02 8:49 ` Jiri Olsa [this message]
2025-07-02 8:54 ` [PATCH bpf-next 1/2] bpf: Reduce stack frame size by using env->insn_buf for bpf insns Jiri Olsa
2025-07-02 9:28 ` Arnd Bergmann
2025-07-02 15:09 ` Alexei Starovoitov
2025-07-02 15:29 ` Yonghong Song
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=aGTyqbsSOTceHJDi@krava \
--to=olsajiri@gmail.com \
--cc=andrii@kernel.org \
--cc=arnd@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=martin.lau@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.