From: sashiko-bot@kernel.org
To: "Ankur Arora" <ankur.a.arora@oracle.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v14 15/15] barrier: add clock tests for smp_cond_load_relaxed_timeout()
Date: Tue, 14 Jul 2026 08:03:01 +0000 [thread overview]
Message-ID: <20260714080301.DB9651F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260714073041.40250-16-ankur.a.arora@oracle.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] smp_cond_load_relaxed_timeout() effectively doubles the intended timeout on architectures with a waiting cpu_poll_relax() (e.g., ARM64).
- [High] Passing U64_MAX or S64_MAX to smp_cond_load_relaxed_timeout() causes an immediate timeout instead of an infinite wait.
--
--- Patch [15]: [PATCH v14 15/15] barrier: add clock tests for smp_cond_load_relaxed_timeout() ---
commit 9919abc9f7cd30b282ef4aefe31726e940d7bd0d
Author: Ankur Arora <ankur.a.arora@oracle.com>
barrier: add clock tests for smp_cond_load_relaxed_timeout()
Add a few clock tests for smp_cond_load_relaxed_timeout(). These ensure that
the implementation doesn't do anything funny stuff with the clock (like
multiple accesses per iteration).
> Also ensure that we handle edge cases sanely. Note that two edge cases
> fail: S64_MAX and U64_MAX. However, both of those are quite far out
> and if needed, can be addressed in the implementation of the interface.
[Severity: High]
This isn't a bug introduced by this patch, but passing U64_MAX or S64_MAX to
smp_cond_load_relaxed_timeout() causes an immediate timeout instead of an
infinite wait.
A caller passing ~0ULL (a common idiom for 'no timeout') will silently have it
cast to s64, turning it into -1. After the first spurious wake, the condition
if (__timeout <= 0) triggers and it returns immediately. For S64_MAX, the
addition __time_now + __timeout overflows into a negative number, resulting
in the same immediate failure:
include/asm-generic/barrier.h:smp_cond_load_relaxed_timeout() {
...
s64 __timeout = (s64)timeout_ns;
...
if (__time_now <= 0 || __timeout <= 0) {
VAL = READ_ONCE(*__PTR);
break;
...
}
Should we fix the interface to correctly handle standard infinite values rather
than leaving this API trap?
> diff --git a/lib/tests/barrier-timeout-test.c b/lib/tests/barrier-timeout-test.c
> index 4226fb6456b35..ec78f85330062 100644
> --- a/lib/tests/barrier-timeout-test.c
> +++ b/lib/tests/barrier-timeout-test.c
[ ... ]
> +static void test_smp_cond_expiry(struct kunit *test)
> +{
> + const struct smp_cond_expiry_params *p = test->param_value;
> + struct clock_state clk = {
> + .start_time = 0,
> + .end_time = 0,
> + .extra = p->clk_inc,
> + .niters = 0,
> + };
> + s64 runtime;
> +
> + flag = 0;
> + smp_cond_load_relaxed_timeout(&flag,
> + 0,
> + synthetic_clock(&clk),
> + p->timeout);
> +
> + runtime = (u64)clk.end_time - (u64)clk.start_time;
> + KUNIT_EXPECT_EQ(test, clk.niters, p->niters);
> + KUNIT_EXPECT_GE(test, runtime, p->timeout);
[Severity: High]
This is a pre-existing issue, but smp_cond_load_relaxed_timeout() effectively
doubles the intended timeout on architectures with a waiting cpu_poll_relax()
(e.g., ARM64).
The KUnit tests added here only verify the minimum runtime, which passes
despite the runtime being double. On ARM64, the late initialization of
__time_end using __time_now after cpu_poll_relax() erroneously adds the
physical sleep duration to the timeout deadline:
include/asm-generic/barrier.h:smp_cond_load_relaxed_timeout() {
...
for (;;) {
...
cpu_poll_relax(__PTR, VAL, (u64)__timeout);
...
__time_now = (s64)(time_expr_ns);
if (unlikely(__time_end == 0))
__time_end = __time_now + __timeout;
...
}
Because __time_now is already Start + timeout_ns when WFET wakes, the new
deadline becomes Start + 2 * timeout_ns, causing the loop to sleep a second
time.
Could the tests be updated to also enforce an upper bound on the runtime to
catch these latency issues, or could we fix the macro itself to initialize
__time_end before polling?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260714073041.40250-1-ankur.a.arora@oracle.com?part=15
prev parent reply other threads:[~2026-07-14 8:03 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-14 7:30 [PATCH v14 00/15] barrier: Add smp_cond_load_{relaxed,acquire}_timeout() Ankur Arora
2026-07-14 7:30 ` [PATCH v14 01/15] asm-generic: barrier: Add smp_cond_load_relaxed_timeout() Ankur Arora
2026-07-14 7:42 ` sashiko-bot
2026-07-14 8:11 ` bot+bpf-ci
2026-07-14 7:30 ` [PATCH v14 02/15] arm64: barrier: Support smp_cond_load_relaxed_timeout() Ankur Arora
2026-07-14 7:50 ` sashiko-bot
2026-07-14 7:30 ` [PATCH v14 03/15] arm64/delay: move some constants out to a separate header Ankur Arora
2026-07-14 7:30 ` [PATCH v14 04/15] arm64: support WFET in smp_cond_load_relaxed_timeout() Ankur Arora
2026-07-14 7:53 ` sashiko-bot
2026-07-14 7:30 ` [PATCH v14 05/15] arm64: rqspinlock: Remove private copy of smp_cond_load_acquire_timewait() Ankur Arora
2026-07-14 7:44 ` sashiko-bot
2026-07-14 7:30 ` [PATCH v14 06/15] asm-generic: barrier: Add smp_cond_load_acquire_timeout() Ankur Arora
2026-07-14 7:53 ` sashiko-bot
2026-07-14 7:30 ` [PATCH v14 07/15] atomic: Add atomic_cond_read_*_timeout() Ankur Arora
2026-07-14 7:47 ` sashiko-bot
2026-07-14 7:30 ` [PATCH v14 08/15] locking/atomic: scripts: build atomic_long_cond_read_*_timeout() Ankur Arora
2026-07-14 7:30 ` [PATCH v14 09/15] bpf/rqspinlock: switch check_timeout() to a clock interface Ankur Arora
2026-07-14 7:30 ` [PATCH v14 10/15] bpf/rqspinlock: Use smp_cond_load_acquire_timeout() Ankur Arora
2026-07-14 8:11 ` bot+bpf-ci
2026-07-14 7:30 ` [PATCH v14 11/15] sched: add need-resched timed wait interface Ankur Arora
2026-07-14 7:30 ` [PATCH v14 12/15] cpuidle/poll_state: Wait for need-resched via tif_need_resched_relaxed_wait() Ankur Arora
2026-07-14 8:11 ` bot+bpf-ci
2026-07-14 7:30 ` [PATCH v14 13/15] arm64/delay: enable testing smp_cond_load_relaxed_timeout() Ankur Arora
2026-07-14 7:58 ` sashiko-bot
2026-07-14 7:30 ` [PATCH v14 14/15] barrier: add tests for smp_cond_load_*_timeout() Ankur Arora
2026-07-14 7:55 ` sashiko-bot
2026-07-14 8:11 ` bot+bpf-ci
2026-07-14 7:30 ` [PATCH v14 15/15] barrier: add clock tests for smp_cond_load_relaxed_timeout() Ankur Arora
2026-07-14 8:03 ` 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=20260714080301.DB9651F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=ankur.a.arora@oracle.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 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.