Re: [PATCH RFC net v11 1/6] net: account for ingress-resolved virtio net hdr state

From
sashiko-bot@kernel.org
Date
2026-12-05 04:01:51
Reply to
Showta Ishizaki, 2026-12-04
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] tun: device-wide atomic64_t rx_csum_sw causes false sharing
  in tun_struct
--

commit 565eda5d8ee04fb6c73d9fb10982bd2d4103c120
Author: Michael S. Tsirkin [off-list ref]

net: account for ingress-resolved virtio net hdr state

This commit updates callers of virtio_net_hdr_to_skb() and
virtio_net_hdr_tnl_to_skb() to treat only negative return values as errors,
and adds a per-device rx_csum_sw counter in tun exposed via ethtool -S.
quoted hunk ↗ jump to hunk
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index ae05b1e58abaa..19647fa977757 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -211,6 +211,7 @@ struct tun_struct {
 	u32 flow_count;
 	u32 rx_batched;
 	atomic_long_t rx_frame_errors;
+	atomic64_t rx_csum_sw;
 	struct bpf_prog __rcu *xdp_prog;
 	struct tun_prog __rcu *steering_prog;
 	struct tun_prog __rcu *filter_prog;
[Severity: Medium]
Can placing atomic64_t rx_csum_sw here cause false sharing on
struct tun_struct?

rx_csum_sw sits directly between rx_batched and the read-mostly RCU pointers
(xdp_prog, steering_prog, and filter_prog) with no cacheline separation, so
it shares a 64-byte cacheline with fields read on every RX and TX packet.

On a multi-queue device, accepted packets completing checksums in software
(such as non-TCP/UDP packets with VIRTIO_NET_HDR_F_NEEDS_CSUM) run
atomic64_inc(&tun->rx_csum_sw) in tun_get_user() and tun_xdp_one().  That
dirties the shared cacheline across other CPUs running fast-path RX/TX queues.

Using a per-CPU counter summed in tun_get_ethtool_stats() would avoid both
the false sharing and cross-CPU atomic contention across queues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204.rfcv11.99731.0.zakinko@snowrabbit.org?part=1
Thread (14 messages) 14 messages, 3 authors, last reply 1d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help