Re: [PATCH net v3] net: ntb_netdev: Fix statistics races

From: Eric Dumazet

Date: Sun Aug 30 2026 - 14:14:20 EST


On Sun, Aug 30, 2026 at 5:16 PM Koichiro Den <den@xxxxxxxxxxxxx> wrote:
>
> ntb_netdev updates shared net_device stats from per-QP RX and TX
> callbacks. Once multiple queues are enabled, concurrent updates can be
> lost.
>
> Use per-CPU tstats for packet and byte counters and DEV_STATS_INC() for
> less frequent drop and error counters. Callbacks can run synchronously
> in the xmit path or asynchronously from a tasklet or the memcpy kthread.
> Pin TX updates against migration in the kthread path. Use the IRQ-safe
> u64_stats helpers because netpoll can invoke the synchronous path with
> IRQs disabled.
>
> Let the core manage tstats while keeping transport teardown after
> unregister_netdev(), outside RTNL. RCU lets unregister wait for TX
> completions already updating stats, while later completions only consume
> the skb and skip accounting and queue wake.
>
> Fixes: 24d9e73c7e00 ("net: ntb_netdev: Support ethtool channels for multi-queue")
> Cc: stable@xxxxxxxxxxxxxxx
> Suggested-by: Jakub Kicinski <kuba@xxxxxxxxxx>
> Signed-off-by: Koichiro Den <den@xxxxxxxxxxxxx>
> ---
> Changes in v3:
> - Use core-managed tstats and gate TX callback work under RCU (Jakub)
> - Fix reverse xmas tree ordering overlooked in v2
>
> Changes in v2:
> - Make packet and byte updates IRQ-safe in netpoll context (Simon, Sashiko)
> - Use device-managed tstats and restore the original teardown order
>
> @Eric, thanks for reviewing v2. v3 moves tstats management back to the
> core and adds RCU protection following Jakub's suggestion, so I did not
> carry your R-b tag. Would appreciate another look when you have cycles.

SGTM, but at some point we probably want to make dev_isalive()
available instead of copy/pasting it.

Reviewed-by: Eric Dumazet <edumazet@xxxxxxxxxx>