BPF List
 help / color / mirror / Atom feed
From: Ankur Arora <ankur.a.arora@oracle.com>
To: sashiko-reviews@lists.linux.dev
Cc: Ankur Arora <ankur.a.arora@oracle.com>, bpf@vger.kernel.org
Subject: Re: [PATCH v16 01/16] asm-generic: barrier: Add smp_cond_load_relaxed_timeout()
Date: Sat, 17 Oct 2026 00:18:08 -0700	[thread overview]
Message-ID: <87jyngre1b.fsf@oracle.com> (raw)
In-Reply-To: <sashiko-outbox-173919@kernel.org>


sashiko-bot@kernel.org writes:

> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [High] locking: smp_cond_load_relaxed_timeout breaks control dependency for ACQUIRE semantics
> --
>
> commit 33828050548c87a2007a049070718fdd9167df34
> Author: Ankur Arora <ankur.a.arora@oracle.com>
>
> asm-generic: barrier: Add smp_cond_load_relaxed_timeout()
>
> This commit adds smp_cond_load_relaxed_timeout(), extending
> smp_cond_load_relaxed() to allow waiting for a duration with a periodic
> time-check. It uses cpu_poll_relax() in a loop and defers the potentially
> costly time evaluation to a slowpath.
>
>> diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
>> index b99cb57dfcccc..ac0a8b5e0ffe7 100644
>> --- a/include/asm-generic/barrier.h
>> +++ b/include/asm-generic/barrier.h
> [ ... ]
>> +#ifndef smp_cond_load_relaxed_timeout
>> +#define __smp_cond_load_relaxed_timeout(ptr, cond_expr,			\
>> +				      time_expr_ns, timeout_ns)		\
>> +({									\
>> +	typeof(ptr) __PTR = (ptr);					\
>> +	__unqual_scalar_typeof(*(ptr)) VAL;				\
>> +	u32 __scl_count = 0, __scl_spin = SMP_TIMEOUT_POLL_COUNT;	\
>> +	u64 __scl_timeout = NSEC_PER_USEC, __scl_time_end = 0;		\
>> +	s64 __scl_time_now;						\
>> +	bool __scl_timed_out = false;					\
>> +									\
>> +	for (;;) {							\
>> +		VAL = READ_ONCE(*__PTR);				\
>> +		if (cond_expr || __scl_timed_out)			\
>
> [Severity: High]
> In include/asm-generic/barrier.h, __smp_cond_load_relaxed_timeout() evaluates
> cond_expr alongside __scl_timed_out. Does this break the control dependency
> required for ACQUIRE semantics?
>
> If __scl_timed_out is true from the previous iteration, this branch is taken
> independently of cond_expr. Because the branch outcome is independent of the
> loaded value VAL, the compiler can optimize the exit into an unconditional
> break, meaning the CPU has no hardware-level control dependency to enforce.
>
> Since smp_cond_load_acquire_timeout() (added in a subsequent patch) relies on
> smp_cond_load_relaxed_timeout() to provide a control dependency on the loaded
> value which is then upgraded to an ACQUIRE barrier by
> smp_acquire__after_ctrl_dep(), this could allow subsequent critical section
> memory accesses to be reordered before the lock acquisition load.
>
> If the returned VAL concurrently satisfies the caller's acquisition check
> at the exact moment of timeout, the caller will enter the critical section
> without hardware-enforced LOAD-STORE ordering.

Yes this is a bit of an open question.

>> +			break;						\
>> +		cpu_poll_relax(__PTR, VAL, (u64)__scl_timeout);		\
>> +		if (++__scl_count < __scl_spin)				\
>> +			continue;					\
> [ ... ]
>> +		if (__scl_time_now <= 0 ||				\
>> +		    __scl_time_end <= __scl_time_now) {			\
>> +			__scl_timed_out = true;				\
>> +			continue;					\
>> +		}							\
> [ ... ]
>> +	}								\
>> +	(typeof(*(ptr)))VAL;						\
>> +})
>> +
>> +#define smp_cond_load_relaxed_timeout(ptr, cond_expr,			\
>> +				      time_expr_ns, timeout_ns)		\
>> +({									\
>> +	s64 __scl_timeout_ns = (s64)(timeout_ns);			\
>> +	__unqual_scalar_typeof(*(ptr)) VAL;				\
>> +									\
>> +	if (unlikely(__scl_timeout_ns < 0))				\
>> +		VAL = READ_ONCE(*(ptr));				\
>
> [Severity: High]
> In include/asm-generic/barrier.h, smp_cond_load_relaxed_timeout() handles
> negative timeouts. Does this negative timeout path also bypass the control
> dependency?
>
> Because this path executes VAL = READ_ONCE(*(ptr)); and returns without
> executing a conditional branch on VAL, no control dependency is established
> for the acquire barrier to upgrade.

smp_cond_load_relaxed_timeout() is not called from the acquire path.

>> +	else								\
>> +		VAL = __smp_cond_load_relaxed_timeout(ptr, cond_expr,	\
>> +						      time_expr_ns,	\
>> +						      __scl_timeout_ns);\
>> +	(typeof(*(ptr)))VAL;						\
>> +})
>> +#endif


--
ankur

  reply	other threads:[~2026-10-17  7:18 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-16  7:08 [PATCH v16 00/16] barrier: Add smp_cond_load_{relaxed,acquire}_timeout() Ankur Arora
2026-10-16  7:08 ` [PATCH v16 01/16] asm-generic: barrier: Add smp_cond_load_relaxed_timeout() Ankur Arora
2026-10-16  7:21   ` sashiko-bot
2026-10-17  7:18     ` Ankur Arora [this message]
2026-10-16  7:55   ` bot+bpf-ci
2026-10-16  7:08 ` [PATCH v16 02/16] arm64: barrier: Support smp_cond_load_relaxed_timeout() Ankur Arora
2026-10-16  7:24   ` sashiko-bot
2026-10-17  7:37     ` Ankur Arora
2026-10-16  7:08 ` [PATCH v16 03/16] arm64/delay: move, fixup usecs_to_cycles() Ankur Arora
2026-10-16  7:16   ` sashiko-bot
2026-10-16  7:55   ` bot+bpf-ci
2026-10-16 12:22   ` Catalin Marinas
2026-10-17  7:19     ` Ankur Arora
2026-10-16  7:08 ` [PATCH v16 04/16] arm64: support WFET in smp_cond_load_relaxed_timeout() Ankur Arora
2026-10-16  7:27   ` sashiko-bot
2026-10-16  7:55   ` bot+bpf-ci
2026-10-16  7:08 ` [PATCH v16 05/16] arm64: rqspinlock: Remove private copy of smp_cond_load_acquire_timewait() Ankur Arora
2026-10-16  7:08 ` [PATCH v16 06/16] asm-generic: barrier: Add smp_cond_load_acquire_timeout() Ankur Arora
2026-10-16  7:21   ` sashiko-bot
2026-10-16  7:08 ` [PATCH v16 07/16] atomic: Add atomic_cond_read_*_timeout() Ankur Arora
2026-10-16  7:25   ` sashiko-bot
2026-10-16  7:08 ` [PATCH v16 08/16] locking/atomic: scripts: build atomic_long_cond_read_*_timeout() Ankur Arora
2026-10-16  7:08 ` [PATCH v16 09/16] bpf/rqspinlock: switch check_timeout() to a clock interface Ankur Arora
2026-10-16  7:08 ` [PATCH v16 10/16] bpf/rqspinlock: Use smp_cond_load_acquire_timeout() Ankur Arora
2026-10-16  7:08 ` [PATCH v16 11/16] sched: add need-resched timed wait interface Ankur Arora
2026-10-16  7:08 ` [PATCH v16 12/16] cpuidle/poll_state: Wait for need-resched via tif_need_resched_relaxed_wait() Ankur Arora
2026-10-16  7:08 ` [PATCH v16 13/16] arm64/delay: enable testing smp_cond_load_relaxed_timeout() Ankur Arora
2026-10-16  7:20   ` sashiko-bot
2026-10-16  7:08 ` [PATCH v16 14/16] barrier: add tests for smp_cond_load_*_timeout() Ankur Arora
2026-10-16  7:55   ` bot+bpf-ci
2026-10-16  7:08 ` [PATCH v16 15/16] barrier: timeout validity checks for smp_cond_load_relaxed_timeout() Ankur Arora
2026-10-16  7:19   ` sashiko-bot
2026-10-16  7:55   ` bot+bpf-ci
2026-10-16  7:08 ` [PATCH v16 16/16] barrier: timeout validity checks for smp_cond_load_acquire_timeout() Ankur Arora

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=87jyngre1b.fsf@oracle.com \
    --to=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox