From: sashiko-bot@kernel.org
To: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 7/7] selftests/bpf: Test may_goto state across calls and clobbers of %r11
Date: Sat, 05 Dec 2026 04:51:11 +0000 [thread overview]
Message-ID: <sashiko-outbox-251104@kernel.org> (raw)
In-Reply-To: <20261205033801.1046411-8-alexei.starovoitov@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] selftests/bpf: fetch_fault_in_loop() fails on arm64 CPUs
without LSE atomics
- [Low] selftests/bpf: nests() 2s bailout lacks iteration guard for
131071 trips
--
commit 5645b13a4a71b76c527f8d3a4d37bbf30c734be9
Author: Alexei Starovoitov <ast@kernel.org>
selftests/bpf: Test may_goto state across calls and clobbers of %r11
This commit adds BPF selftests verifying that timed may_goto loops still
cancel across callback helpers, traced functions, instructions that clobber
%r11, and nested program invocations, and checks that freplace on such
programs is refused.
> diff --git a/tools/testing/selftests/bpf/progs/timed_may_goto.c b/tools/testing/selftests/bpf/progs/timed_may_goto.c
> index 250ea6ca4d9ed..037ddb81d38f5 100644
> --- a/tools/testing/selftests/bpf/progs/timed_may_goto.c
> +++ b/tools/testing/selftests/bpf/progs/timed_may_goto.c
> @@ -256,6 +256,88 @@ int loop_not_inlined(void *ctx)
[ ... ]
> +/* The arena has no pages. The access is skipped and fetches 0. */
> +static bool less_faults(struct bpf_rb_node *a, const struct bpf_rb_node *b)
> +{
> + __u64 *p = (void *)__PAGE_SIZE, n = zero;
> +
> + asm volatile ("r0 = %[arena] ll" :: __imm_addr(arena) : "r0");
> + bpf_addr_space_cast(p, 0, 1);
> + while (n < 1 << 24 && can_loop)
> + n += 1 + __sync_fetch_and_or(p, 1);
> + stuck_ret = n > 100 && n < 1 << 24;
> + return false;
> +}
> +
> +SEC("tc")
> +__description("timed may_goto: fault of a fetching atomic in a loop")
> +__success __retval(1)
> +int fetch_fault_in_loop(void *ctx)
> +{
> + return run_stuck(less_faults) ?: stuck_ret;
> +}
[Severity: Medium]
Will fetch_fault_in_loop() fail to load on arm64 CPUs without LSE atomics?
timed_may_goto.c builds for both x86 and arm64, and fetch_fault_in_loop()
expects unconditional load success. On arm64 without ARM64_HAS_LSE_ATOMICS,
bpf_jit_supports_insn() rejects fetching arena atomics (LL/SC does not
support BPF_PROBE_ATOMIC), so atomic_ptr_type_ok() returns -EACCES.
Restricting fetch_fault_in_loop() with __arch_x86_64 (matching
arena_atomics.c) or skipping when LSE is unavailable would avoid failing the
suite on non-LSE arm64 hosts.
[ ... ]
> diff --git a/tools/testing/selftests/bpf/progs/timed_may_goto_user.c b/tools/testing/selftests/bpf/progs/timed_may_goto_user.c
> index a1a13c9b8236e..709c3a12ea402 100644
> --- a/tools/testing/selftests/bpf/progs/timed_may_goto_user.c
> +++ b/tools/testing/selftests/bpf/progs/timed_may_goto_user.c
> @@ -242,25 +242,29 @@ int spin_under_timer(void *ctx)
[ ... ]
> +/* The prog runs on top of itself on each trip. That doesn't give it more time. */
> +SEC("tcx/egress")
> +int nests(struct __sk_buff *skb)
> {
> - int i, n = 10;
> + __u64 t0 = bpf_ktime_get_ns();
>
> - for (i = 0; i < TRIES; i++)
> - n += replaced_global(zero);
> - return n;
> + if (nested) {
> + nested_cnt = counts_to_1000();
> + return 2;
> + }
> + nested = 1;
> + while (can_loop) {
> + bpf_clone_redirect(skb, 1, 0);
> + /* give up, so that the test fails and doesn't lock up */
> + if (bpf_ktime_get_ns() - t0 > 2000 * 1000 * 1000)
> + break;
> + }
> + return 10;
> }
[Severity: Low]
Can the 2-second bailout in nests() fire before may_goto has a chance to
unwind?
Because the first bpf_may_goto_slowpath() call at trip 65,535 only
initializes the start time and reloads 65,534 trips, nests() cannot unwind
until trip 131,071.
Each outer trip runs bpf_clone_redirect() (skb_clone(), pskb_expand_head(),
and tcx egress dispatch) plus counts_to_1000() and two bpf_ktime_get_ns()
calls. On debug kernels or slow virtualized guests, the 2-second timeout can
expire first and return 10, spuriously failing test_nested().
Guarding the timeout check with an outer iteration count of at least two
slowpath rounds (as loop_calls_subprog_with_65534_iterations() in
timed_may_goto.c does) would prevent false failures.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205033801.1046411-1-alexei.starovoitov@gmail.com?part=7
prev parent reply other threads:[~2026-12-05 4:51 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 3:37 [PATCH bpf-next 0/7] bpf: Keep the state of may_goto in a register Alexei Starovoitov
2026-12-05 3:37 ` [PATCH bpf-next 1/7] selftests/bpf: Don't depend on the expansion of may_goto Alexei Starovoitov
2026-12-05 3:37 ` [PATCH bpf-next 2/7] selftests/bpf: Wait longer in parallel tests of libarena Alexei Starovoitov
2026-12-05 3:37 ` [PATCH bpf-next 3/7] bpf: Keep the state of may_goto per invocation Alexei Starovoitov
2026-12-05 3:37 ` [PATCH bpf-next 4/7] bpf, x86: Keep the state of may_goto in %r11 Alexei Starovoitov
2026-12-05 4:29 ` bot+bpf-ci
2026-12-05 3:37 ` [PATCH bpf-next 5/7] bpf, arm64: Keep the state of may_goto in x24 Alexei Starovoitov
2026-12-05 4:18 ` bot+bpf-ci
2026-12-05 3:38 ` [PATCH bpf-next 6/7] bpf: Keep the state of may_goto in the task on other archs Alexei Starovoitov
2026-12-05 4:18 ` bot+bpf-ci
2026-12-05 3:38 ` [PATCH bpf-next 7/7] selftests/bpf: Test may_goto state across calls and clobbers of %r11 Alexei Starovoitov
2026-12-05 4:51 ` sashiko-bot [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=sashiko-outbox-251104@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=alexei.starovoitov@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=sashiko-reviews@lists.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