Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net: ethernet: ti: netcp: Use u64_stats_t with u64_stats_sync properly

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.

Note that does not mean the code is now tear-free: there're u32 counters
unprotected by u64_stats or anything else.

Signed-off-by: David Yang <mmyangfl@gmail.com>
Link: https://patch.msgid.link/20260123164841.2890054-1-mmyangfl@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

David Yang and committed by
Jakub Kicinski
3eef6c06 5c05b3db

+12 -12
+4 -4
drivers/net/ethernet/ti/netcp.h
··· 65 65 66 66 struct netcp_stats { 67 67 struct u64_stats_sync syncp_rx ____cacheline_aligned_in_smp; 68 - u64 rx_packets; 69 - u64 rx_bytes; 68 + u64_stats_t rx_packets; 69 + u64_stats_t rx_bytes; 70 70 u32 rx_errors; 71 71 u32 rx_dropped; 72 72 73 73 struct u64_stats_sync syncp_tx ____cacheline_aligned_in_smp; 74 - u64 tx_packets; 75 - u64 tx_bytes; 74 + u64_stats_t tx_packets; 75 + u64_stats_t tx_bytes; 76 76 u32 tx_errors; 77 77 u32 tx_dropped; 78 78 };
+8 -8
drivers/net/ethernet/ti/netcp_core.c
··· 759 759 knav_pool_desc_put(netcp->rx_pool, desc); 760 760 761 761 u64_stats_update_begin(&rx_stats->syncp_rx); 762 - rx_stats->rx_packets++; 763 - rx_stats->rx_bytes += skb->len; 762 + u64_stats_inc(&rx_stats->rx_packets); 763 + u64_stats_add(&rx_stats->rx_bytes, skb->len); 764 764 u64_stats_update_end(&rx_stats->syncp_rx); 765 765 766 766 /* push skb up the stack */ ··· 1045 1045 } 1046 1046 1047 1047 u64_stats_update_begin(&tx_stats->syncp_tx); 1048 - tx_stats->tx_packets++; 1049 - tx_stats->tx_bytes += skb->len; 1048 + u64_stats_inc(&tx_stats->tx_packets); 1049 + u64_stats_add(&tx_stats->tx_bytes, skb->len); 1050 1050 u64_stats_update_end(&tx_stats->syncp_tx); 1051 1051 dev_kfree_skb(skb); 1052 1052 pkts++; ··· 1973 1973 1974 1974 do { 1975 1975 start = u64_stats_fetch_begin(&p->syncp_rx); 1976 - rxpackets = p->rx_packets; 1977 - rxbytes = p->rx_bytes; 1976 + rxpackets = u64_stats_read(&p->rx_packets); 1977 + rxbytes = u64_stats_read(&p->rx_bytes); 1978 1978 } while (u64_stats_fetch_retry(&p->syncp_rx, start)); 1979 1979 1980 1980 do { 1981 1981 start = u64_stats_fetch_begin(&p->syncp_tx); 1982 - txpackets = p->tx_packets; 1983 - txbytes = p->tx_bytes; 1982 + txpackets = u64_stats_read(&p->tx_packets); 1983 + txbytes = u64_stats_read(&p->tx_bytes); 1984 1984 } while (u64_stats_fetch_retry(&p->syncp_tx, start)); 1985 1985 1986 1986 stats->rx_packets = rxpackets;