From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796136447; b=UmTMBnfFwN4z1LwZ6x7TgfWUlh+5elCQVjj6ly6WqrSZcHX8kr2+N/cGS2lOasfLqfGs ofbzn/L4lOKzQwnIuOYclfCkSYqpiIIGOVYmM3mGp0lUFa8uxWwbX2y2/l6Q69Tj6Z83Q 8CllBu20kL/JQOn2es6Lu/jbwIGjr9zHmTTtMZAu1LyrX4d8tNovERpdRi23TMdUPccoz ckBMqSOZr8T1PkpbGm28iaOu7Y7nN6bTzbcYpPgEvJVhed1OQAqeyxfnnjpvP0+VwwVqI upJOZhMFIeP+rBxk2653XNpq5fzBFElw6XRa+SoNxhgyaTD2szR8oxwj7baYEhYi+2w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796136447; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=8WTIiZWZ6SLnUbuUw8RoJcrE8Tc/sYKdbCBg1MeskW4=; b=0FDM+KnV2TvQjLqOTrZvijy/9OhyJdDBfVbHZONebWR+oHJr5LgKAVUxm8fudqye6KvD k0vLP16hFc1rzKQO0m7yOUYNGEeaMis8rB++qU3WglY4JRRxfIfeivRh9RpRn9kMacGlw uRr8iUzpMqLaAKEk5hltOzkdHhIaFhlVFuy1Mz91MNIUycyBNznSgaY+2EI7Om39MoVrx 5U0Dyqnsh7uKeAvMn52mWHfTDilENTk1289J8k4t/MtCt+sB0jmBhLq5K1cZrwMr9JU0d y4/wxBUEIYVtm2vhsaJDtSfrGJzxdyzm2C3l+jHPd6+lacWJIardNLr7rmRrF9s/mFA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bMF9vQIa; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1513606A31A for ; Tue, 1 Dec 2026 14:47:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bMF9vQIa Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1A9A1F0089A; Tue, 1 Dec 2026 14:47:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796136446; bh=8WTIiZWZ6SLnUbuUw8RoJcrE8Tc/sYKdbCBg1MeskW4=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=bMF9vQIaL4il7XuICosGHoXL8zc1aAYJnbPaqbWNsJiLFzCeSpF55Bt3Dm6g1W3B9 bbFDqmfxo3K4ZATK6qtTxdnc9WGJpT4mPQj/b5MUfp7zpJELmtJsIgthzHVfs4MCsE tYAJXtbzEFji/t8qH8xVzUlx3ojUL0fYTEtJmciBo7cNsKMt4P6U7AfULeFQXW+EXZ 7YQy752t60gil5bTT0guWhb+nGdnnqqWLSCrjA0KumiCeEMev7TTh9gRIWZM2bwE4B rGzXNt17NWYohRX28gT06bWsirDZh9u/hHOwaktDqKeXFD3R4GPRJrgYD6XN5WnDZI l80YCSFXTMRKg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] bpf: ringbuf: add wakeup coalescing Reply-To: sashiko-reviews@lists.linux.dev To: "Michael S. Tsirkin" Cc: bpf@vger.kernel.org In-Reply-To: <5663e1035f52f0b358710721c1c77e5c73552a2e.1796135892.git.mst@redhat.com> References: <5663e1035f52f0b358710721c1c77e5c73552a2e.1796135892.git.mst@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 14:47:26 +0000 X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 5 potential issues to consider: - [High] bpf: consumer wakeup stall in bpf_ringbuf_commit() when threshold > 1 - [Medium] bpf: missing bounds check and runtime update for ringbuf wakeup sysctl - [Medium] bpf: false sharing on pending_cnt in bpf_ringbuf_commit() - [Low] bpf: extern declaration of sysctl_bpf_ringbuf_wakeup_threshold in .c file - [Low] bpf: non-standard multi-line comment format in bpf_ringbuf_commit() -- commit 1b7b76ef2815dac5ca7b8f1973374e0f676f7ce2 Author: Michael S. Tsirkin bpf: ringbuf: add wakeup coalescing This commit adds per-ringbuf pending record counting and a kernel.bpf_ringbuf_wakeup_threshold sysctl to coalesce irq_work consumer wakeups in bpf_ringbuf_commit(). > diff --git a/kernel/bpf/ringbuf.c b/kernel/bpf/ringbuf.c > index 447863ece26a3..afd968d06e7c7 100644 > --- a/kernel/bpf/ringbuf.c > +++ b/kernel/bpf/ringbuf.c > @@ -14,6 +14,8 @@ > #include > #include > =20 > +extern int sysctl_bpf_ringbuf_wakeup_threshold; [Severity: Low] Should sysctl_bpf_ringbuf_wakeup_threshold be declared in a shared header such as include/linux/bpf.h rather than with extern in kernel/bpf/ringbuf.c? Defining it in kernel/bpf/syscall.c without a visible header declaration prevents the compiler from type-checking the definition against its declaration and triggers a sparse -Wdecl warning. > + > #define RINGBUF_CREATE_FLAG_MASK (BPF_F_NUMA_NODE | BPF_F_RB_OVERWRITE) > =20 > /* non-mmap()'able part of bpf_ringbuf (everything up to consumer page) = */ > @@ -29,6 +31,8 @@ struct bpf_ringbuf { > wait_queue_head_t waitq; > struct irq_work work; > u64 mask; > + atomic_t pending_cnt; > + u32 wakeup_threshold; > struct page **pages; > int nr_pages; > bool overwrite_mode; [Severity: Medium] Does placing pending_cnt in the first cacheline of struct bpf_ringbuf cause false sharing with read-mostly fields like mask and overwrite_mode? Because bpf_ringbuf_commit() writes to rb->pending_cnt on every commit without BPF_RB_NO_WAKEUP (including an unconditional atomic_set() to 0 when cons_pos !=3D rec_pos, even when pending_cnt is already 0 or wakeup_threshold is 1), concurrent producers will repeatedly invalidate the cacheline read on every reserve and commit. [ ... ] > @@ -573,15 +579,29 @@ static void bpf_ringbuf_commit(void *sample, u64 fl= ags, bool discard) > xchg(&hdr->len, new_len); > =20 > /* if consumer caught up and is waiting for our record, notify about > - * new data availability > + * new data availability. With coalescing, we batch wakeups when > + * consumer is idle to reduce bpfrb context switches under bursty > + * VFS traffic (Falcon). > */ [Severity: Low] This isn't a bug, but BPF multi-line comment style puts the opening /* on its own line with the text starting on the next line, and the reference to "(Falcon)" lacks context in the kernel tree. > rec_pos =3D (void *)hdr - (void *)rb->data; > cons_pos =3D smp_load_acquire(&rb->consumer_pos) & rb->mask; > =20 > - if (flags & BPF_RB_FORCE_WAKEUP) > - irq_work_queue(&rb->work); > - else if (cons_pos =3D=3D rec_pos && !(flags & BPF_RB_NO_WAKEUP)) > + if (flags & BPF_RB_FORCE_WAKEUP) { > + atomic_set(&rb->pending_cnt, 0); > irq_work_queue(&rb->work); > + } else if (!(flags & BPF_RB_NO_WAKEUP)) { > + if (cons_pos =3D=3D rec_pos) { > + int pending =3D atomic_inc_return(&rb->pending_cnt); > + if (pending =3D=3D 1) { > + irq_work_queue(&rb->work); > + } else if (pending >=3D rb->wakeup_threshold) { > + atomic_set(&rb->pending_cnt, 0); > + irq_work_queue(&rb->work); > + } > + } else { > + atomic_set(&rb->pending_cnt, 0); > + } > + } > } [Severity: High] Can this permanently stall consumer wakeups when rb->wakeup_threshold > 1? cons_pos =3D=3D rec_pos is only true when the record being committed is at rb->consumer_pos (the consumer had caught up to all prior records). When record 1 is committed into an empty ring buffer, pending becomes 1 and irq_work_queue() wakes the consumer, leaving rb->pending_cnt at 1. After the consumer drains record 1, advances rb->consumer_pos, and goes back to sleep, record 2 arrives with cons_pos =3D=3D rec_pos again and increments rb->pending_cnt to 2. For any wakeup_threshold > 2, record 2 does not wake the sleeping consumer (and for wakeup_threshold =3D=3D 2, record 2 sta= ys unconsumed if no third record arrives). Because the consumer remains asleep, rb->consumer_pos stops advancing at record 2. Every subsequent record 3, 4, ... has rec_pos !=3D cons_pos, so it takes the else branch, resets rb->pending_cnt to 0, and never calls irq_work_queue(). In non-overwrite mode, bpf_ringbuf_has_space() prevents producer_pos from wrapping around to cons_pos, so the ring buffer fills to capacity and drops all future records while the consumer hangs in poll(). > diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c > index 0bdb4288beb29..78d50d28bd14f 100644 > --- a/kernel/bpf/syscall.c > +++ b/kernel/bpf/syscall.c [ ... ] > @@ -6917,6 +6919,13 @@ static const struct ctl_table bpf_syscall_table[] = =3D { > .mode =3D 0644, > .proc_handler =3D bpf_stats_handler, > }, > + { > + .procname =3D "bpf_ringbuf_wakeup_threshold", > + .data =3D &sysctl_bpf_ringbuf_wakeup_threshold, > + .maxlen =3D sizeof(sysctl_bpf_ringbuf_wakeup_threshold), > + .mode =3D 0644, > + .proc_handler =3D proc_dointvec, > + }, > }; [Severity: Medium] Should this sysctl use proc_dointvec_minmax with .extra1 =3D SYSCTL_ONE? With proc_dointvec, writing a negative value converts to a huge unsigned u32 in rb->wakeup_threshold, which signed int pending in bpf_ringbuf_commit() is then compared against using unsigned comparison. Also, because bpf_ringbuf_alloc() latches sysctl_bpf_ringbuf_wakeup_thresho= ld only at map creation time, changing the sysctl at runtime has no effect on existing ring buffers. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/5663e1035f52f0b3587= 10721c1c77e5c73552a2e.1796135892.git.mst@redhat.com?part=3D1