Netdev List
 help / color / mirror / Atom feed
From: Pavel Begunkov <asml.silence@gmail.com>
To: 徐晗翔 <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: Mon, 23 Nov 2026 13:50:08 +0000	[thread overview]
Message-ID: <c60f3a12-4a54-43ec-b1e4-45bf43deff57@gmail.com> (raw)
In-Reply-To: <375d4b.2ad09.1a202324f3e.Coremail.xuhx@hust.edu.cn>

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).

-- 
Pavel Begunkov


      reply	other threads:[~2026-11-23 13:50 UTC|newest]

Thread overview: 6+ 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 [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=c60f3a12-4a54-43ec-b1e4-45bf43deff57@gmail.com \
    --to=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