mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: bot+bpf-ci@kernel.org
To: tamird@kernel.org,ast@kernel.org,daniel@iogearbox.net,andrii@kernel.org,eddyz87@gmail.com,memxor@gmail.com,martin.lau@linux.dev,song@kernel.org,yonghong.song@linux.dev,jolsa@kernel.org,emil@etsalapatis.com,shuah@kernel.org,arighi@nvidia.com,xukuohai@huawei.com,andrea.righi@canonical.com,billy@starlabs.sg,void@manifault.com,ihor.solodrai@linux.dev
Cc: bpf@vger.kernel.org,linux-kselftest@vger.kernel.org,linux-kernel@vger.kernel.org,awerner32@gmail.com,zeffron@riotgames.com,andriin@fb.com,tamird@kernel.org,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf-next v3 2/8] libbpf: ringbuf: Use compiler atomics
Date: Fri, 20 Nov 2026 21:34:44 +0000 (UTC)	[thread overview]
Message-ID: <8676fc63d1b69002f39adee94811f9384c19bb8f6e89d08576e5aaab283c6aa2@mail.kernel.org> (raw)
In-Reply-To: <20261120-bpf-ringbuf-fixes-v3-2-ff7ca15d6c37@kernel.org>

[-- Attachment #1: Type: text/plain, Size: 3232 bytes --]

> libbpf: ringbuf: Use compiler atomics

TL;DR: On arm64 builds targeting RCpc (ldapr), this patch may lose stlr->ldar
ordering, allowing a missed ring buffer wakeup until the later fence patch;
the changelog's "unchanged" claim looks wrong, which matters for bisection.

> diff --git a/tools/lib/bpf/ringbuf.c b/tools/lib/bpf/ringbuf.c
> --- a/tools/lib/bpf/ringbuf.c
> +++ b/tools/lib/bpf/ringbuf.c

[ ... ]

> @@ -270,13 +270,13 @@ static int64_t ringbuf_process_ring(struct ring *r, size_t n)
>  	if (n == 0)
>  		return 0;
>  
> -	cons_pos = smp_load_acquire(r->consumer_pos);
> +	cons_pos = __atomic_load_n(r->consumer_pos, __ATOMIC_ACQUIRE);
>  	do {
>  		got_new_data = false;
> -		prod_pos = smp_load_acquire(r->producer_pos);
> +		prod_pos = __atomic_load_n(r->producer_pos, __ATOMIC_ACQUIRE);

[ ... ]

> @@ -290,14 +290,13 @@ static int64_t ringbuf_process_ring(struct ring *r, size_t n)
>  				cnt++;
>  			}
>  
> -			smp_store_release(r->consumer_pos, cons_pos);
> +			__atomic_store_n(r->consumer_pos, cons_pos, __ATOMIC_RELEASE);
>  
>  			if (cnt >= n)
>  				goto done;

The commit message says "Acquire and release ordering is unchanged".  Is
that true on arm64?

The old tools helpers in tools/arch/arm64/include/asm/barrier.h are inline
asm, so smp_store_release() emits stlr and smp_load_acquire() emits ldar.
ldar is RCsc, so a store-release followed by a load-acquire cannot be
reordered.

With __atomic_load_n(..., __ATOMIC_ACQUIRE) the compiler may emit ldapr
(RCpc) when targeting FEAT_LRCPC, for example with -march=armv8.3-a or
later, or -mcpu for cores such as Neoverse N1.  libbpf accepts these
through EXTRA_CFLAGS.

With RCpc, the release store of consumer_pos can then be reordered with
the following acquire load of producer_pos, or of the record header in
ringbuf_process_ring().

The consumer publishes cons_pos == X and then reads the old producer_pos
(or sees a BUSY header at X) and returns.  Meanwhile the kernel producer
runs bpf_ringbuf_commit():

    xchg(&hdr->len, new_len);
    smp_load_acquire(&rb->consumer_pos);

It reads the old consumer position, decides cons_pos != rec_pos and skips
irq_work_queue().  The consumer then waits without a notification even
though a record is queued.

Before this commit the stlr->ldar ordering ruled that interleaving out on
arm64.  After this commit it is possible on RCpc-targeted builds.  On
x86_64, ppc, riscv and the generic fallback the window already existed, so
the new exposure is limited to arm64.

This is fixed later in the series by commit 2010ab86a493 ("libbpf: ringbuf:
Prevent missed wakeups"), which adds __atomic_thread_fence(__ATOMIC_SEQ_CST)
after each consumer_pos publication and before the next producer_pos load.
The arm64 exposure therefore exists only at this commit, which matters for
bisection.

Could the fence patch come first, or could this patch carry the fence?
Alternatively, could the changelog note that arm64 loses the stlr->ldar
(RCsc) ordering until the next patch?


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/44815895103

  reply	other threads:[~2026-11-20 21:34 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 20:33 [PATCH bpf-next v3 0/8] bpf: Fix ring buffers and add a libbpf iterator Tamir Duberstein
2026-11-20 20:33 ` [PATCH bpf-next v3 1/8] bpf: user_ringbuf: Handle position wrap Tamir Duberstein
2026-11-20 20:33 ` [PATCH bpf-next v3 2/8] libbpf: ringbuf: Use compiler atomics Tamir Duberstein
2026-11-20 21:34   ` bot+bpf-ci [this message]
2026-11-20 20:33 ` [PATCH bpf-next v3 3/8] libbpf: ringbuf: Prevent missed wakeups Tamir Duberstein
2026-11-20 20:33 ` [PATCH bpf-next v3 4/8] libbpf: ringbuf: Add a caller-owned iterator Tamir Duberstein
2026-11-20 21:34   ` bot+bpf-ci
2026-11-20 20:33 ` [PATCH bpf-next v3 5/8] libbpf: ringbuf: Simplify iterator implementation Tamir Duberstein
2026-11-20 20:33 ` [PATCH bpf-next v3 6/8] selftests/bpf: Refactor lifetimes and test wakeups Tamir Duberstein
2026-11-20 21:34   ` bot+bpf-ci
2026-11-20 20:33 ` [PATCH bpf-next v3 7/8] selftests/bpf: Verify ringbuf callback semantics Tamir Duberstein
2026-11-20 20:33 ` [PATCH bpf-next v3 8/8] selftests/bpf: Test caller-owned ring iterators Tamir Duberstein

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=8676fc63d1b69002f39adee94811f9384c19bb8f6e89d08576e5aaab283c6aa2@mail.kernel.org \
    --to=bot+bpf-ci@kernel.org \
    --cc=andrea.righi@canonical.com \
    --cc=andrii@kernel.org \
    --cc=andriin@fb.com \
    --cc=arighi@nvidia.com \
    --cc=ast@kernel.org \
    --cc=awerner32@gmail.com \
    --cc=billy@starlabs.sg \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mason@kernel.org \
    --cc=memxor@gmail.com \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=tamird@kernel.org \
    --cc=void@manifault.com \
    --cc=xukuohai@huawei.com \
    --cc=yonghong.song@linux.dev \
    --cc=zeffron@riotgames.com \
    /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

all inboxes | Powered by JetHome®