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 02/16] arm64: barrier: Support smp_cond_load_relaxed_timeout()
Date: Sat, 17 Oct 2026 00:37:54 -0700	[thread overview]
Message-ID: <87zewcpyjx.fsf@oracle.com> (raw)
In-Reply-To: <sashiko-outbox-173922@kernel.org>


sashiko-bot@kernel.org writes:

> Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
> - [High] arm64/barrier: massive timekeeping contention in spin loops without event stream
> - [Medium] arm64: barrier: missing export of arch_timer_evtstrm_available() breaks modules
> - [Medium] arm64: noinstr violation in cpuidle via cpu_poll_relax()
> --
>
> commit 7a1bb257570118eb8f711a76f172539e20eeaac8
> Author: Ankur Arora <ankur.a.arora@oracle.com>
>
> arm64: barrier: Support smp_cond_load_relaxed_timeout()
>
> This commit supports waiting in smp_cond_load_relaxed_timeout() via
> __cmpwait_relaxed() when the event-stream is available, falling back to
> cpu_relax() otherwise. It defines CPU_POLL_RELAX_WAITS to indicate that
> there is an optimized wait implementation.
>
>> diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h
>> index 9495c4441a46b..e2263c754a550 100644
>> --- a/arch/arm64/include/asm/barrier.h
>> +++ b/arch/arm64/include/asm/barrier.h
>
> [ ... ]
>
>> @@ -219,6 +220,27 @@ do {									\
>>  	(typeof(*ptr))VAL;						\
>>  })
>>
>> +/* Re-declared here to avoid include dependency. */
>> +extern bool arch_timer_evtstrm_available(void);
>> +
>> +/*
>> + * In the common case, cpu_poll_relax() sits waiting in __cmpwait_relaxed()
>> + * for @ptr value to change.
>> + *
>> + * State this by defining CPU_POLL_RELAX_WAITS. This enables a time-check
>> + * optimization in smp_cond_load_{relaxed,acquire}_timeout(). Note that this
>> + * is not ideal for the cpu_relax() fallback but that's not a production
>> + * configuration.
>> + */
>> +#define CPU_POLL_RELAX_WAITS
>
> [Severity: High]
> Does defining CPU_POLL_RELAX_WAITS here cause massive timekeeping contention
> when the event stream is disabled?
>
> When CPU_POLL_RELAX_WAITS is defined, include/asm-generic/barrier.h sets
> SMP_TIMEOUT_POLL_COUNT to 1. This causes the loop in
> __smp_cond_load_relaxed_timeout() to evaluate the expensive time_expr_ns
> on every single iteration.
>
> If the event stream is disabled, cpu_poll_relax() drops back to a fast
> cpu_relax() yield. Evaluating the time expression (e.g. reading timer hardware
> or seqcounts) on every fast spin loop iteration across multiple CPUs can cause
> massive lock contention and interconnect flooding.
>
> Is it accurate that disabling the event stream is "not a production
> configuration"? It can be disabled via Kconfig
> (CONFIG_ARM_ARCH_TIMER_EVTSTREAM=n), kernel command line

And as the Kconfig doc for CONFIG_ARM_ARCH_TIMER_EVTSTREAM says:
  "This must be disabled for hardware validation purposes to detect any
   hardware anomalies of missing events."

> (clocksource.arm_arch_timer.evtstrm=0),

Same thing for this where the kernel-parameters.txt says "so that code
using WFE-based polling loops can be debugged more effectively on
production systems"

> or under hypervisors that lack virtual event stream support.

Common hypervisors KVM/QEMU, Xen support this. Even beyond this
cpu_relax() on arm64 doesn't do much (is a yield) so increasing the
SMP_TIMEOUT_POLL_COUNT doesn't do much.

The correct solution for a case like this would be to detect this
case (or have a new kernel parameter) that disables polling at init.

That's out of scope for this series.

>> +
>> +#define cpu_poll_relax(ptr, val, timeout_ns) do {			\
>> +	if (arch_timer_evtstrm_available())				\
>
> [Severity: Medium]
> Does this break the build for loadable kernel modules that use the new
> smp_cond_load_relaxed_timeout() or smp_cond_load_acquire_timeout() macros?
>
> This macro injects a direct call to arch_timer_evtstrm_available() into the
> caller's context. However, arch_timer_evtstrm_available() is defined in
> drivers/clocksource/arm_arch_timer.c and lacks an EXPORT_SYMBOL_GPL directive.
>
> Without the export, standard loadable modules using the generic barrier
> timeout API will fail to build with undefined symbol errors.

Yes. Can be fixed when there are users.

> [Severity: Medium]
> Can this introduce a noinstr violation in the idle entry path?
>
> arch_timer_evtstrm_available() is an out-of-line, instrumentable function
> since it is not marked noinstr.
>
> When smp_cond_load_relaxed_timeout() is used in poll_idle()
> (in drivers/cpuidle/poll_state.c), it is executed in a noinstr context
> because poll_idle() is marked __cpuidle, which places it in the
> .cpuidle.text section. Objtool strictly validates .cpuidle.text as noinstr.

Oddly enough I didn't see any objtool errors.

> Calling an instrumentable function directly from the idle spin-loop macro
> risks tracing recursion and objtool validation errors.

Will check.

>> +		__cmpwait_relaxed(ptr, val);				\
>> +	else								\
>> +		cpu_relax();						\
>> +} while (0)
>> +
>>  #include <asm-generic/barrier.h>
>>
>>  #endif	/* __ASSEMBLER__ */


--
ankur

  reply	other threads:[~2026-10-17  7:37 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
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 [this message]
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=87zewcpyjx.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