]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
netdevsim: psp: update rx stats on the peer netdevsim
authorDaniel Zahka <daniel.zahka@gmail.com>
Fri, 29 May 2026 13:15:27 +0000 (06:15 -0700)
committerJakub Kicinski <kuba@kernel.org>
Tue, 2 Jun 2026 19:57:30 +0000 (12:57 -0700)
nsim_do_psp() handles both tx and rx psp processing in the sending
device's nsim_start_xmit() path. The existing code has a logical bug,
where we erroneously increment rx_bytes and rx_packets on the sending
devices stats, instead of the peer device.

Additionally, compute psp_len after psp_dev_encapsulate() and before
psp_dev_rcv(), which modifies the header region of the skb. The
existing calculation was actually correct, because psp_dev_rcv()
leaves skb_inner_transport_header pointing at the tcp header, but this
is fragile and confusing as there is no actual inner transport header
after psp_dev_rcv has removed udp encapsulation.

Fixes: 178f0763c5f3 ("netdevsim: implement psp device stats")
Cc: <stable+noautosel@kernel.org> # netdevsim is a test harness, it's never loaded on production systems
Signed-off-by: Daniel Zahka <daniel.zahka@gmail.com>
Link: https://patch.msgid.link/20260529-fix-psp-stats-v2-1-3a194eacf18e@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/netdevsim/psp.c

index c6000ebc6bc8ffbe4630e902108581908085c9e7..c6c1acaa99a3a36820cf7ccf236167f274cb677b 100644 (file)
@@ -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,12 @@ nsim_do_psp(struct sk_buff *skb, struct netdevsim *ns,
                goto out_unlock;
        }
 
+       psp_len = skb->len - skb_inner_transport_offset(skb);
+       u64_stats_update_begin(&ns->psp.syncp);
+       u64_stats_inc(&ns->psp.tx_packets);
+       u64_stats_add(&ns->psp.tx_bytes, psp_len);
+       u64_stats_update_end(&ns->psp.syncp);
+
        /* 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 +79,10 @@ 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);
+               u64_stats_update_begin(&peer_ns->psp.syncp);
+               u64_stats_inc(&peer_ns->psp.rx_packets);
+               u64_stats_add(&peer_ns->psp.rx_bytes, psp_len);
+               u64_stats_update_end(&peer_ns->psp.syncp);
        } else {
                struct ipv6hdr *ip6h __maybe_unused;
                struct iphdr *iph;