ieee80211_calc_rx_airtime() and ieee80211_rate_expected_tx_airtime() multiply the duration of an AVG_PKT_SIZE frame, in 1/1024 us, by the frame length in a u32. The product is the airtime in us times 2^20, so it wraps once the airtime reaches 4096 us. At HT MCS0 a 4096 byte A-MPDU comes out as 945 us instead of 5041 us. mt76x0, mt76x2 and mt7603 compute RX airtime in software and pass the length of a whole A-MPDU to ieee80211_calc_rx_airtime(), so a station that sends at a low rate is charged a fraction of its airtime. Do the multiplication in 64 bits. Where it did not wrap, the result is the same. Found by the hosted Sashiko review of v1. Fixes: db3e1c40cf2f ("mac80211: Import airtime calculation code from mt76") Fixes: f01cfbaf9b29 ("mac80211: improve AQL aggregation estimation for low data rates") Signed-off-by: Julius Bairaktaris --- v2: - New. The GSO estimate of v1 1/4 wrapped here. net/mac80211/airtime.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/net/mac80211/airtime.c b/net/mac80211/airtime.c index ee5dc524347c..55bc451d4a9d 100644 --- a/net/mac80211/airtime.c +++ b/net/mac80211/airtime.c @@ -616,9 +616,7 @@ u32 ieee80211_calc_rx_airtime(struct ieee80211_hw *hw, if (!duration) return 0; - duration *= len; - duration /= AVG_PKT_SIZE; - duration /= 1024; + duration = div_u64(mul_u32_u32(duration, len), AVG_PKT_SIZE * 1024); return duration + overhead; } @@ -813,8 +811,7 @@ u32 ieee80211_rate_expected_tx_airtime(struct ieee80211_hw *hw, else agg_shift = 6; - duration *= len; - duration /= AVG_PKT_SIZE; + duration = div_u64(mul_u32_u32(duration, len), AVG_PKT_SIZE); duration += (overhead * 1024 >> agg_shift); return duration; -- 2.53.0