From: "Clément Léger" <cleger@meta.com>
To: "Pavel Begunkov" <asml.silence@gmail.com>, 徐晗翔 <xuhx@hust.edu.cn>
Cc: io-uring@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, Jens Axboe <axboe@kernel.dk>
Subject: Re: io_uring/zcrx: copy statistics lose updates when one ifq is shared by multiple rings (Data race)
Date: Tue, 24 Nov 2026 18:17:12 +0100 [thread overview]
Message-ID: <7d6fec4b-e9d7-4d95-91b7-0319d44b25ad@meta.com> (raw)
In-Reply-To: <c60f3a12-4a54-43ec-b1e4-45bf43deff57@gmail.com>
On 11/23/26 14:50, Pavel Begunkov wrote:
> >
> On 11/22/26 07:39, 徐晗翔 wrote:
>> An io_uring zero-copy RX ifq can be exported by one ring and imported by
>> another. Both rings then perform receive-zc on their own TCP sockets,
>> but they share the same struct io_zcrx_ifq and therefore the same
>> ifq->notif_stats. The statistics update is not atomic:
>>
>> static void zcrx_stat_add(__u64 *p, s64 v)
>> {
>> WRITE_ONCE(*p, READ_ONCE(*p) + v);
>> }
>>
>> io_uring/zcrx.c:1337-1340. It is called for copy_count and copy_bytes
>> from io_zcrx_copy_frag() at zcrx.c:1770-1771. There is no ifq-level
>> lock in this path. lock_sock() in io_zcrx_tcp_recvmsg() is per TCP
>> socket, the ring's uring_lock is per ring, alloc_lock only protects
>> fallback niov allocation and is released before the copy, and
>> ctx_lock/notification is taken after the statistics update and is not
>> involved when event_desc.type_mask == 0. Two CPUs can therefore read
>> the same old value, add their own increments, and write back the same
>> new value: one update is lost.
>>
>> The effect is limited to the UAPI cumulative copy statistics
>> (struct zcrx_stats at include/uapi/linux/io_uring/zcrx.h:83-86). The
>> values are user-mappable diagnostic data; the race does not control
>> buffer lifetime, DMA, reference counts, or packet contents.
> It is racy, and IIRC Clement dropped atomicity at some point, perhaps
> for performance reasons. I don't think it really matters though, the
> main purposes of the stat is to be a flag saying "something is wrong,
> setup steering rules". What's your use case? For precise statistics
> I'd rather prefer to add a trace point, which would be able to do it
> the right way (e.g. per-cpu counters).
Indeed, I used atomic first but then we dropped it. I don't remember
exactly but we didn't consider export/import at that time. It make sense
though so atomic would be fine as well although with an additional cost.
I'll let Pavel be the judge but agreed that we do not really care about
the value itself (there is nothing the userspace can really do about it
except check that "it's a lot").
Clément
prev parent reply other threads:[~2026-11-24 17:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <4c7f9772.192e1.1a17d5c2ed5.Coremail.xuhx@hust.edu.cn>
[not found] ` <2026102727-data-sequel-ce41@gregkh>
2026-11-03 11:57 ` net: rtnetlink: rtnl_link_unregister() vs in-flight RTM_GETLINK dump readers -- v7.3 lacks the synchronize_rcu() fix (Fixes: 6b57ff21a310 family); A/B reproduction on stock 7.3 徐晗翔
2026-11-03 15:49 ` Eric Dumazet
2026-11-04 15:03 ` Sasha Levin
2026-11-03 12:07 ` wifi: wilc1000: SDIO/SPI remove destroys the srcu_struct before wiphy_unregister() -- late cfg80211 callbacks write through dangling srcu state (unfixed upstream; controlled + natural Oops) 徐晗翔
2026-11-22 7:39 ` io_uring/zcrx: copy statistics lose updates when one ifq is shared by multiple rings (Data race) 徐晗翔
2026-11-23 13:50 ` Pavel Begunkov
2026-11-24 17:17 ` Clément Léger [this message]
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=7d6fec4b-e9d7-4d95-91b7-0319d44b25ad@meta.com \
--to=cleger@meta.com \
--cc=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=io-uring@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=xuhx@hust.edu.cn \
/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