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

vlan: adopt u64_stats_t

As explained in commit 316580b69d0a ("u64_stats: provide u64_stats_t type")
we should use u64_stats_t and related accessors to avoid load/store tearing.

Add READ_ONCE() when reading rx_errors & tx_dropped.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Eric Dumazet and committed by
Jakub Kicinski
09cca53c d62607c3

+29 -29
+9 -9
drivers/net/macvlan.c
··· 575 575 576 576 pcpu_stats = this_cpu_ptr(vlan->pcpu_stats); 577 577 u64_stats_update_begin(&pcpu_stats->syncp); 578 - pcpu_stats->tx_packets++; 579 - pcpu_stats->tx_bytes += len; 578 + u64_stats_inc(&pcpu_stats->tx_packets); 579 + u64_stats_add(&pcpu_stats->tx_bytes, len); 580 580 u64_stats_update_end(&pcpu_stats->syncp); 581 581 } else { 582 582 this_cpu_inc(vlan->pcpu_stats->tx_dropped); ··· 949 949 p = per_cpu_ptr(vlan->pcpu_stats, i); 950 950 do { 951 951 start = u64_stats_fetch_begin_irq(&p->syncp); 952 - rx_packets = p->rx_packets; 953 - rx_bytes = p->rx_bytes; 954 - rx_multicast = p->rx_multicast; 955 - tx_packets = p->tx_packets; 956 - tx_bytes = p->tx_bytes; 952 + rx_packets = u64_stats_read(&p->rx_packets); 953 + rx_bytes = u64_stats_read(&p->rx_bytes); 954 + rx_multicast = u64_stats_read(&p->rx_multicast); 955 + tx_packets = u64_stats_read(&p->tx_packets); 956 + tx_bytes = u64_stats_read(&p->tx_bytes); 957 957 } while (u64_stats_fetch_retry_irq(&p->syncp, start)); 958 958 959 959 stats->rx_packets += rx_packets; ··· 964 964 /* rx_errors & tx_dropped are u32, updated 965 965 * without syncp protection. 966 966 */ 967 - rx_errors += p->rx_errors; 968 - tx_dropped += p->tx_dropped; 967 + rx_errors += READ_ONCE(p->rx_errors); 968 + tx_dropped += READ_ONCE(p->tx_dropped); 969 969 } 970 970 stats->rx_errors = rx_errors; 971 971 stats->rx_dropped = rx_errors;
+3 -3
include/linux/if_macvlan.h
··· 46 46 47 47 pcpu_stats = get_cpu_ptr(vlan->pcpu_stats); 48 48 u64_stats_update_begin(&pcpu_stats->syncp); 49 - pcpu_stats->rx_packets++; 50 - pcpu_stats->rx_bytes += len; 49 + u64_stats_inc(&pcpu_stats->rx_packets); 50 + u64_stats_add(&pcpu_stats->rx_bytes, len); 51 51 if (multicast) 52 - pcpu_stats->rx_multicast++; 52 + u64_stats_inc(&pcpu_stats->rx_multicast); 53 53 u64_stats_update_end(&pcpu_stats->syncp); 54 54 put_cpu_ptr(vlan->pcpu_stats); 55 55 } else {
+5 -5
include/linux/if_vlan.h
··· 118 118 * @tx_dropped: number of tx drops 119 119 */ 120 120 struct vlan_pcpu_stats { 121 - u64 rx_packets; 122 - u64 rx_bytes; 123 - u64 rx_multicast; 124 - u64 tx_packets; 125 - u64 tx_bytes; 121 + u64_stats_t rx_packets; 122 + u64_stats_t rx_bytes; 123 + u64_stats_t rx_multicast; 124 + u64_stats_t tx_packets; 125 + u64_stats_t tx_bytes; 126 126 struct u64_stats_sync syncp; 127 127 u32 rx_errors; 128 128 u32 tx_dropped;
+3 -3
net/8021q/vlan_core.c
··· 63 63 rx_stats = this_cpu_ptr(vlan_dev_priv(vlan_dev)->vlan_pcpu_stats); 64 64 65 65 u64_stats_update_begin(&rx_stats->syncp); 66 - rx_stats->rx_packets++; 67 - rx_stats->rx_bytes += skb->len; 66 + u64_stats_inc(&rx_stats->rx_packets); 67 + u64_stats_add(&rx_stats->rx_bytes, skb->len); 68 68 if (skb->pkt_type == PACKET_MULTICAST) 69 - rx_stats->rx_multicast++; 69 + u64_stats_inc(&rx_stats->rx_multicast); 70 70 u64_stats_update_end(&rx_stats->syncp); 71 71 72 72 return true;
+9 -9
net/8021q/vlan_dev.c
··· 128 128 129 129 stats = this_cpu_ptr(vlan->vlan_pcpu_stats); 130 130 u64_stats_update_begin(&stats->syncp); 131 - stats->tx_packets++; 132 - stats->tx_bytes += len; 131 + u64_stats_inc(&stats->tx_packets); 132 + u64_stats_add(&stats->tx_bytes, len); 133 133 u64_stats_update_end(&stats->syncp); 134 134 } else { 135 135 this_cpu_inc(vlan->vlan_pcpu_stats->tx_dropped); ··· 713 713 p = per_cpu_ptr(vlan_dev_priv(dev)->vlan_pcpu_stats, i); 714 714 do { 715 715 start = u64_stats_fetch_begin_irq(&p->syncp); 716 - rxpackets = p->rx_packets; 717 - rxbytes = p->rx_bytes; 718 - rxmulticast = p->rx_multicast; 719 - txpackets = p->tx_packets; 720 - txbytes = p->tx_bytes; 716 + rxpackets = u64_stats_read(&p->rx_packets); 717 + rxbytes = u64_stats_read(&p->rx_bytes); 718 + rxmulticast = u64_stats_read(&p->rx_multicast); 719 + txpackets = u64_stats_read(&p->tx_packets); 720 + txbytes = u64_stats_read(&p->tx_bytes); 721 721 } while (u64_stats_fetch_retry_irq(&p->syncp, start)); 722 722 723 723 stats->rx_packets += rxpackets; ··· 726 726 stats->tx_packets += txpackets; 727 727 stats->tx_bytes += txbytes; 728 728 /* rx_errors & tx_dropped are u32 */ 729 - rx_errors += p->rx_errors; 730 - tx_dropped += p->tx_dropped; 729 + rx_errors += READ_ONCE(p->rx_errors); 730 + tx_dropped += READ_ONCE(p->tx_dropped); 731 731 } 732 732 stats->rx_errors = rx_errors; 733 733 stats->tx_dropped = tx_dropped;