]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
netdevsim: use u64_stats_t with u64_stats_sync properly
authorDavid Yang <mmyangfl@gmail.com>
Fri, 23 Jan 2026 21:10:55 +0000 (05:10 +0800)
committerJakub Kicinski <kuba@kernel.org>
Tue, 27 Jan 2026 03:53:36 +0000 (19:53 -0800)
On 64bit arches, struct u64_stats_sync is empty and provides no help
against load/store tearing. Convert to u64_stats_t to ensure atomic
operations.

Signed-off-by: David Yang <mmyangfl@gmail.com>
Link: https://patch.msgid.link/20260123211101.2929547-1-mmyangfl@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/netdevsim/netdevsim.h
drivers/net/netdevsim/psp.c

index 46c67983c5171146f4b719588a954dbb46c2b413..f767fc8a75053984fa2d28f8964dbe31fc8a92b7 100644 (file)
@@ -109,10 +109,10 @@ struct netdevsim {
        int rq_reset_mode;
 
        struct {
-               u64 rx_packets;
-               u64 rx_bytes;
-               u64 tx_packets;
-               u64 tx_bytes;
+               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;
                struct psp_dev *dev;
                u32 spi;
index 727da06101caac00a22a096e733a7f06e995a598..0b4d717253b08036904beba7b228c6137f610e89 100644 (file)
@@ -72,10 +72,12 @@ nsim_do_psp(struct sk_buff *skb, struct netdevsim *ns,
                skb->decrypted = 1;
 
                u64_stats_update_begin(&ns->psp.syncp);
-               ns->psp.tx_packets++;
-               ns->psp.rx_packets++;
-               ns->psp.tx_bytes += skb->len - skb_inner_transport_offset(skb);
-               ns->psp.rx_bytes += skb->len - skb_inner_transport_offset(skb);
+               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);
        } else {
                struct ipv6hdr *ip6h __maybe_unused;
@@ -183,10 +185,10 @@ static void nsim_get_stats(struct psp_dev *psd, struct psp_dev_stats *stats)
 
        do {
                start = u64_stats_fetch_begin(&ns->psp.syncp);
-               stats->rx_bytes = ns->psp.rx_bytes;
-               stats->rx_packets = ns->psp.rx_packets;
-               stats->tx_bytes = ns->psp.tx_bytes;
-               stats->tx_packets = ns->psp.tx_packets;
+               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));
 }