> 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