diff options
| author | Jakub Kicinski <kuba@kernel.org> | 2026-06-02 12:57:50 -0700 |
|---|---|---|
| committer | Jakub Kicinski <kuba@kernel.org> | 2026-06-02 12:57:51 -0700 |
| commit | a9f2d4607403a2b0d20b71a784455463e132d3d0 (patch) | |
| tree | cc1c43358e02b8f955e15d8ce9b11768c5fb267e | |
| parent | 5893cc75a19146b1365867dcf7f01ed420f702ed (diff) | |
| parent | 163bea8010bdf785b6dadeab0cb199e94e1f99bd (diff) | |
| download | linux-a9f2d4607403a2b0d20b71a784455463e132d3d0.tar.gz linux-a9f2d4607403a2b0d20b71a784455463e132d3d0.zip | |
Merge branch 'netdevsim-psp-fix-issues-with-stats-collection'
Daniel Zahka says:
====================
netdevsim: psp: fix issues with stats collection
It has come to my attention via a sashiko review of my net-next series
for aes-gcm in netdevsim [1] that there were preexisting issues with
netdevsim's implementation of psp statistics.
API usage issues:
1. not calling u64_stats_init() on the u64_stats_sync object during
init
2. not serializing usage of the writer side API during stats update
Logical Bugs:
1. We were incrementing rx stats on the sending devices stats
counters.
Fix the first set of issues by removing the u64_stats_t api entirely,
and keep track of stats with atomics. Fix the second issue by charging
events to the right netdevsim object.
[1]: https://sashiko.dev/#/patchset/20260508-nsim-psp-crypto-v1-0-4b50ed09b794%40gmail.com
TAP version 13
1..28
ok 1 psp.data_basic_send_v0_ip4
ok 2 psp.data_basic_send_v0_ip6
ok 3 psp.data_basic_send_v1_ip4
ok 4 psp.data_basic_send_v1_ip6
ok 5 psp.data_basic_send_v2_ip4
ok 6 psp.data_basic_send_v2_ip6
ok 7 psp.data_basic_send_v3_ip4
ok 8 psp.data_basic_send_v3_ip6
ok 9 psp.data_mss_adjust_ip4
ok 10 psp.data_mss_adjust_ip6
ok 11 psp.dev_list_devices
ok 12 psp.dev_get_device
ok 13 psp.dev_get_device_bad
ok 14 psp.dev_rotate
ok 15 psp.dev_rotate_spi
ok 16 psp.assoc_basic
ok 17 psp.assoc_bad_dev
ok 18 psp.assoc_sk_only_conn
ok 19 psp.assoc_sk_only_mismatch
ok 20 psp.assoc_sk_only_mismatch_tx
ok 21 psp.assoc_sk_only_unconn
ok 22 psp.assoc_version_mismatch
ok 23 psp.assoc_twice
ok 24 psp.data_send_bad_key
ok 25 psp.data_send_disconnect
ok 26 psp.data_stale_key
ok 27 psp.removal_device_rx
ok 28 psp.removal_device_bi
# Totals: pass:28 fail:0 xfail:0 xpass:0 skip:0 error:0
Dump stats on both devs tx on one should match rx on other:
local dev:
id=5 ifindex=2 stats={'dev-id': 5, 'key-rotations': 0,
'stale-events': 0, 'rx-packets': 1226, 'rx-bytes': 39244,
'rx-auth-fail': 0, 'rx-error': 0, 'rx-bad': 0, 'tx-packets': 1931,
'tx-bytes': 2478908, 'tx-error': 0}
remote dev:
id=3 ifindex=2 stats={'dev-id': 3, 'key-rotations': 0, 'stale-events':
0, 'rx-packets': 1931, 'rx-bytes': 2478908, 'rx-auth-fail': 0,
'rx-error': 0, 'rx-bad': 0, 'tx-packets': 1226, 'tx-bytes': 39244,
'tx-error': 0}
====================
Link: https://patch.msgid.link/20260529-fix-psp-stats-v2-0-3a194eacf18e@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
| -rw-r--r-- | drivers/net/netdevsim/netdevsim.h | 10 | ||||
| -rw-r--r-- | drivers/net/netdevsim/psp.c | 27 |
2 files changed, 15 insertions, 22 deletions
diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index d909c4160ea1..4c9cc96dcec3 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -22,7 +22,6 @@ #include <linux/list.h> #include <linux/netdevice.h> #include <linux/ptp_mock.h> -#include <linux/u64_stats_sync.h> #include <net/devlink.h> #include <net/udp_tunnel.h> #include <net/xdp.h> @@ -115,11 +114,10 @@ struct netdevsim { int rq_reset_mode; struct { - u64_stats_t rx_packets; - u64_stats_t rx_bytes; - u64_stats_t tx_packets; - u64_stats_t tx_bytes; - struct u64_stats_sync syncp; + atomic64_t rx_packets; + atomic64_t rx_bytes; + atomic64_t tx_packets; + atomic64_t tx_bytes; struct psp_dev __rcu *dev; struct dentry *rereg; struct mutex rereg_lock; diff --git a/drivers/net/netdevsim/psp.c b/drivers/net/netdevsim/psp.c index c6000ebc6bc8..59c990fdc79e 100644 --- a/drivers/net/netdevsim/psp.c +++ b/drivers/net/netdevsim/psp.c @@ -22,6 +22,7 @@ nsim_do_psp(struct sk_buff *skb, struct netdevsim *ns, struct psp_dev *peer_psd; struct psp_assoc *pas; struct net *net; + int psp_len; void **ptr; rcu_read_lock(); @@ -48,6 +49,10 @@ nsim_do_psp(struct sk_buff *skb, struct netdevsim *ns, goto out_unlock; } + psp_len = skb->len - skb_inner_transport_offset(skb); + atomic64_inc(&ns->psp.tx_packets); + atomic64_add(psp_len, &ns->psp.tx_bytes); + /* Now pretend we just received this frame */ peer_psd = rcu_dereference(peer_ns->psp.dev); if (peer_psd && peer_psd->config.versions & (1 << pas->version)) { @@ -72,14 +77,8 @@ nsim_do_psp(struct sk_buff *skb, struct netdevsim *ns, refcount_inc(&(*psp_ext)->refcnt); skb->decrypted = 1; - u64_stats_update_begin(&ns->psp.syncp); - u64_stats_inc(&ns->psp.tx_packets); - u64_stats_inc(&ns->psp.rx_packets); - u64_stats_add(&ns->psp.tx_bytes, - skb->len - skb_inner_transport_offset(skb)); - u64_stats_add(&ns->psp.rx_bytes, - skb->len - skb_inner_transport_offset(skb)); - u64_stats_update_end(&ns->psp.syncp); + atomic64_inc(&peer_ns->psp.rx_packets); + atomic64_add(psp_len, &peer_ns->psp.rx_bytes); } else { struct ipv6hdr *ip6h __maybe_unused; struct iphdr *iph; @@ -188,20 +187,16 @@ static void nsim_assoc_del(struct psp_dev *psd, struct psp_assoc *pas) static void nsim_get_stats(struct psp_dev *psd, struct psp_dev_stats *stats) { struct netdevsim *ns = psd->drv_priv; - unsigned int start; /* WARNING: do *not* blindly zero stats in real drivers! * All required stats must be reported by the device! */ memset(stats, 0, sizeof(struct psp_dev_stats)); - do { - start = u64_stats_fetch_begin(&ns->psp.syncp); - stats->rx_bytes = u64_stats_read(&ns->psp.rx_bytes); - stats->rx_packets = u64_stats_read(&ns->psp.rx_packets); - stats->tx_bytes = u64_stats_read(&ns->psp.tx_bytes); - stats->tx_packets = u64_stats_read(&ns->psp.tx_packets); - } while (u64_stats_fetch_retry(&ns->psp.syncp, start)); + stats->rx_bytes = atomic64_read(&ns->psp.rx_bytes); + stats->rx_packets = atomic64_read(&ns->psp.rx_packets); + stats->tx_bytes = atomic64_read(&ns->psp.tx_bytes); + stats->tx_packets = atomic64_read(&ns->psp.tx_packets); } static struct psp_dev_ops nsim_psp_ops = { |
