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.

netdevsim: 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.

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>

authored by

David Yang and committed by
Jakub Kicinski
5c05b3db a84a1fe0

+14 -12
+4 -4
drivers/net/netdevsim/netdevsim.h
··· 109 109 int rq_reset_mode; 110 110 111 111 struct { 112 - u64 rx_packets; 113 - u64 rx_bytes; 114 - u64 tx_packets; 115 - u64 tx_bytes; 112 + u64_stats_t rx_packets; 113 + u64_stats_t rx_bytes; 114 + u64_stats_t tx_packets; 115 + u64_stats_t tx_bytes; 116 116 struct u64_stats_sync syncp; 117 117 struct psp_dev *dev; 118 118 u32 spi;
+10 -8
drivers/net/netdevsim/psp.c
··· 72 72 skb->decrypted = 1; 73 73 74 74 u64_stats_update_begin(&ns->psp.syncp); 75 - ns->psp.tx_packets++; 76 - ns->psp.rx_packets++; 77 - ns->psp.tx_bytes += skb->len - skb_inner_transport_offset(skb); 78 - ns->psp.rx_bytes += skb->len - skb_inner_transport_offset(skb); 75 + u64_stats_inc(&ns->psp.tx_packets); 76 + u64_stats_inc(&ns->psp.rx_packets); 77 + u64_stats_add(&ns->psp.tx_bytes, 78 + skb->len - skb_inner_transport_offset(skb)); 79 + u64_stats_add(&ns->psp.rx_bytes, 80 + skb->len - skb_inner_transport_offset(skb)); 79 81 u64_stats_update_end(&ns->psp.syncp); 80 82 } else { 81 83 struct ipv6hdr *ip6h __maybe_unused; ··· 185 183 186 184 do { 187 185 start = u64_stats_fetch_begin(&ns->psp.syncp); 188 - stats->rx_bytes = ns->psp.rx_bytes; 189 - stats->rx_packets = ns->psp.rx_packets; 190 - stats->tx_bytes = ns->psp.tx_bytes; 191 - stats->tx_packets = ns->psp.tx_packets; 186 + stats->rx_bytes = u64_stats_read(&ns->psp.rx_bytes); 187 + stats->rx_packets = u64_stats_read(&ns->psp.rx_packets); 188 + stats->tx_bytes = u64_stats_read(&ns->psp.tx_bytes); 189 + stats->tx_packets = u64_stats_read(&ns->psp.tx_packets); 192 190 } while (u64_stats_fetch_retry(&ns->psp.syncp, start)); 193 191 } 194 192