From: Kees Cook <kees@kernel.org>
To: Shung-Hsi Yu <shung-hsi.yu@suse.com>,
bpf@vger.kernel.org, linux-mm@kvack.org,
Andrii Nakryiko <andrii@kernel.org>,
Ihor Solodrai <ihor.solodrai@linux.dev>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Michal Hocko <mhocko@suse.com>, Vlastimil Babka <vbabka@suse.cz>,
Uladzislau Rezki <urezki@gmail.com>,
linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org,
regressions@lists.linux.dev,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Pawan Gupta <pawan.kumar.gupta@linux.intel.com>,
Eduard Zingerman <eddyz87@gmail.com>
Subject: Re: [REGRESSION] bpf verifier slowdown due to vrealloc() change since 6.15-rc6
Date: Thu, 15 May 2025 07:51:26 -0700 [thread overview]
Message-ID: <C66C764E-C898-457D-93F0-A680983707F0@kernel.org> (raw)
In-Reply-To: <20250515-bpf-verifier-slowdown-vwo2meju4cgp2su5ckj@6gi6ssxbnfqg>
On May 15, 2025 6:12:25 AM PDT, Shung-Hsi Yu <shung-hsi.yu@suse.com> wrote:
>Hi,
>
>There is an observable slowdown when running BPF selftests on 6.15-rc6
>kernel[1] built with tools/testing/selftests/bpf/{config,config.x86_64}.
>Overall the BPF selftests now takes 2x time to run (from ~25m to ~50m),
>and for the verif_scale_loop3_fail it went from single digit seconds to
>6 minutes.
>
>Bisect was done by Pawan and got to commit a0309faf1cb0 "mm: vmalloc:
>support more granular vrealloc() sizing"[2]. To further zoom in the
>issue, I tried removing the only kvrealloc() call in kernel/bpf/ by
>reverting commit 96a30e469ca1 "bpf: use common instruction history
>across all states", so _krealloc()_ was used instead of kvrealloc(), and
>observe that there is _no_ slowdown[3]. While the bisect and the revert
>is done on 6.14.7-rc2, I think it should stll be pretty representitive.
>
>In short, the follow were tested:
>- 6.15-rc6 (has a0309faf1cb0) -> slowdown
>- 6.14.7-rc2 (has a0309faf1cb0) -> slowdown
>- 6.14.7-rc2 (has a0309faf1cb0, call to kvrealloc in
> kernel/bpf/verifier.c replaced with krealloc) -> _no_ slowdown
>
>And the vrealloc() change is causing slowdown in kvrealloc() call within
>push_insn_history().
This is very strange! The vrealloc change should make things faster -- it removes potentially unneeded vmalloc and full object copies when it isn't needed.
Where can I find the .config for the slow runs?
And how do I run the test myself directly?
-Kees
>
> /* for any branch, call, exit record the history of jmps in the given state */
> static int push_insn_history(struct bpf_verifier_env *env, struct bpf_verifier_state *cur,
> int insn_flags, u64 linked_regs)
> {
> struct bpf_insn_hist_entry *p;
> size_t alloc_size;
> ...
> if (cur->insn_hist_end + 1 > env->insn_hist_cap) {
> alloc_size = size_mul(cur->insn_hist_end + 1, sizeof(*p));
> p = kvrealloc(env->insn_hist, alloc_size, GFP_USER);
> if (!p)
> return -ENOMEM;
> env->insn_hist = p;
> env->insn_hist_cap = alloc_size / sizeof(*p);
> }
>
> p = &env->insn_hist[cur->insn_hist_end];
> p->idx = env->insn_idx;
> p->prev_idx = env->prev_insn_idx;
> p->flags = insn_flags;
> p->linked_regs = linked_regs;
>
> cur->insn_hist_end++;
> env->cur_hist_ent = p;
>
> return 0;
> }
>
>BPF CI probably hasn't hit this yet because bpf-next have only got to
>6.15-rc4.
>
>Shung-Hsi
>
>#regzbot introduced: a0309faf1cb0622cac7c820150b7abf2024acff5
>
>1: https://github.com/shunghsiyu/libbpf/actions/runs/15038992168/job/42266125686
>2: https://lore.kernel.org/stable/20250515041659.smhllyarxdwp7cav@desk/
>3: https://github.com/shunghsiyu/libbpf/actions/runs/15043433548/job/42280277024
--
Kees Cook
next prev parent reply other threads:[~2025-05-15 14:51 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-15 13:12 Shung-Hsi Yu
2025-05-15 14:51 ` Kees Cook [this message]
2025-05-15 16:51 ` Kees Cook
2025-05-15 17:18 ` Pawan Gupta
2025-05-15 17:41 ` Kees Cook
2025-05-15 17:52 ` Pawan Gupta
2025-05-15 20:26 ` Pawan Gupta
2025-05-15 17:53 ` Andrii Nakryiko
2025-05-15 18:24 ` Kees Cook
2025-05-15 18:50 ` Eduard Zingerman
2025-05-15 15:47 ` Kees Cook
2025-05-15 15:53 ` Kees Cook
2025-05-15 15:55 ` Andrii Nakryiko
2025-05-15 16:01 ` Kees Cook
2025-05-15 18:31 ` Eduard Zingerman
2025-05-15 21:36 ` Kees Cook
2025-05-15 21:39 ` Eduard Zingerman
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=C66C764E-C898-457D-93F0-A680983707F0@kernel.org \
--to=kees@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=ihor.solodrai@linux.dev \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=pawan.kumar.gupta@linux.intel.com \
--cc=regressions@lists.linux.dev \
--cc=shung-hsi.yu@suse.com \
--cc=urezki@gmail.com \
--cc=vbabka@suse.cz \
/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