]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
wifi: mac80211: use u64_stats_t with u64_stats_sync properly
authorDavid Yang <mmyangfl@gmail.com>
Fri, 23 Jan 2026 20:38:40 +0000 (04:38 +0800)
committerJohannes Berg <johannes.berg@intel.com>
Tue, 27 Jan 2026 12:43:49 +0000 (13:43 +0100)
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/20260123203845.2915525-1-mmyangfl@gmail.com
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
net/mac80211/rx.c
net/mac80211/sta_info.c
net/mac80211/sta_info.h

index ac437256f5d5c4b34601fd4c8a6f6f80469b2522..30b9b4d763578feea179ad33be5174fc3fc19209 100644 (file)
@@ -1880,7 +1880,7 @@ ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
        link_sta->rx_stats.fragments++;
 
        u64_stats_update_begin(&link_sta->rx_stats.syncp);
-       link_sta->rx_stats.bytes += rx->skb->len;
+       u64_stats_add(&link_sta->rx_stats.bytes, rx->skb->len);
        u64_stats_update_end(&link_sta->rx_stats.syncp);
 
        if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
@@ -2785,7 +2785,7 @@ ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
                 * frame, so count MSDUs.
                 */
                u64_stats_update_begin(&rx->link_sta->rx_stats.syncp);
-               rx->link_sta->rx_stats.msdu[rx->seqno_idx]++;
+               u64_stats_inc(&rx->link_sta->rx_stats.msdu[rx->seqno_idx]);
                u64_stats_update_end(&rx->link_sta->rx_stats.syncp);
        }
 
@@ -4878,8 +4878,8 @@ static void ieee80211_rx_8023(struct ieee80211_rx_data *rx,
         * frame, so count MSDUs.
         */
        u64_stats_update_begin(&stats->syncp);
-       stats->msdu[rx->seqno_idx]++;
-       stats->bytes += orig_len;
+       u64_stats_inc(&stats->msdu[rx->seqno_idx]);
+       u64_stats_add(&stats->bytes, orig_len);
        u64_stats_update_end(&stats->syncp);
 
        if (fast_rx->internal_forward) {
index 1a995bc301b19a7108da972b8b36c84d5f05184a..22e8561ad6fc2021cfa3f71c66e2628796c7283f 100644 (file)
@@ -360,7 +360,9 @@ static void sta_accumulate_removed_link_stats(struct sta_info *sta, int link_id)
        struct link_sta_info *link_sta = wiphy_dereference(sta->local->hw.wiphy,
                                                           sta->link[link_id]);
        struct ieee80211_link_data *link;
+       unsigned int start;
        int ac, tid;
+       u64 value;
        u32 thr;
 
        for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
@@ -369,8 +371,13 @@ static void sta_accumulate_removed_link_stats(struct sta_info *sta, int link_id)
                sta->rem_link_stats.tx_bytes += link_sta->tx_stats.bytes[ac];
        }
 
+       do {
+               start = u64_stats_fetch_begin(&link_sta->rx_stats.syncp);
+               value = u64_stats_read(&link_sta->rx_stats.bytes);
+       } while (u64_stats_fetch_retry(&link_sta->rx_stats.syncp, start));
+
        sta->rem_link_stats.rx_packets += link_sta->rx_stats.packets;
-       sta->rem_link_stats.rx_bytes += link_sta->rx_stats.bytes;
+       sta->rem_link_stats.rx_bytes += value;
        sta->rem_link_stats.tx_retries += link_sta->status_stats.retry_count;
        sta->rem_link_stats.tx_failed += link_sta->status_stats.retry_failed;
        sta->rem_link_stats.rx_dropped_misc += link_sta->rx_stats.dropped;
@@ -380,8 +387,13 @@ static void sta_accumulate_removed_link_stats(struct sta_info *sta, int link_id)
                sta->rem_link_stats.expected_throughput += thr;
 
        for (tid = 0; tid < IEEE80211_NUM_TIDS; tid++) {
-               sta->rem_link_stats.pertid_stats.rx_msdu +=
-                       link_sta->rx_stats.msdu[tid];
+               do {
+                       start = u64_stats_fetch_begin(&link_sta->rx_stats.syncp);
+                       value = u64_stats_read(&link_sta->rx_stats.msdu[tid]);
+               } while (u64_stats_fetch_retry(&link_sta->rx_stats.syncp,
+                                              start));
+
+               sta->rem_link_stats.pertid_stats.rx_msdu += value;
                sta->rem_link_stats.pertid_stats.tx_msdu +=
                        link_sta->tx_stats.msdu[tid];
                sta->rem_link_stats.pertid_stats.tx_msdu_retries +=
@@ -2578,7 +2590,7 @@ static inline u64 sta_get_tidstats_msdu(struct ieee80211_sta_rx_stats *rxstats,
 
        do {
                start = u64_stats_fetch_begin(&rxstats->syncp);
-               value = rxstats->msdu[tid];
+               value = u64_stats_read(&rxstats->msdu[tid]);
        } while (u64_stats_fetch_retry(&rxstats->syncp, start));
 
        return value;
@@ -2654,7 +2666,7 @@ static inline u64 sta_get_stats_bytes(struct ieee80211_sta_rx_stats *rxstats)
 
        do {
                start = u64_stats_fetch_begin(&rxstats->syncp);
-               value = rxstats->bytes;
+               value = u64_stats_read(&rxstats->bytes);
        } while (u64_stats_fetch_retry(&rxstats->syncp, start));
 
        return value;
index 5288d52866510cff72160689d2db194e11a96b5d..b1edf8ed102f6ef335e7cf61238daac232d0dc3f 100644 (file)
@@ -434,8 +434,8 @@ struct ieee80211_sta_rx_stats {
        s8 chain_signal_last[IEEE80211_MAX_CHAINS];
        u32 last_rate;
        struct u64_stats_sync syncp;
-       u64 bytes;
-       u64 msdu[IEEE80211_NUM_TIDS + 1];
+       u64_stats_t bytes;
+       u64_stats_t msdu[IEEE80211_NUM_TIDS + 1];
 };
 
 /*