[PATCH v3 1/2] wifi: iwlwifi: mvm: Fix GP2 to nanoseconds overflow on 32-bit
From: Zhan Xusheng
Date: Mon Oct 12 2026 - 01:05:40 EST
From: Zhan Xusheng <zhanxusheng@xxxxxxxxxx>
A GP2 timestamp is a u32 in microseconds and NSEC_PER_USEC is 1000L, so
three multiplications are evaluated in 32 bits and truncate for any GP2
value above 4.295 s:
u64 last_gp2_ns = mvm->ptp_data.scale_update_gp2 * NSEC_PER_USEC;
iwl_mvm_ptp_get_adj_time(mvm, gp2 * NSEC_PER_USEC);
iwl_mvm_ptp_get_adj_time(mvm, phy_data->gp2_on_air_rise * NSEC_PER_USEC);
iwl_mvm_ptp_get_adj_time() passes its argument back to
iwl_mvm_ptp_update_new_read() in microseconds, which treats a backwards
step of at least IWL_PTP_WRAP_THRESHOLD_USEC as a GP2 wraparound and
bumps wrap_counter. A gp2 of 10 s truncates to a 32-bit product of
1410065408 ns, i.e. 1410065 us, an 8589935 us step back, so the 5000 us
threshold is passed and a wraparound is recorded. Each spurious
wraparound adds IWL_PTP_GP2_WRAP microseconds, about 71.6 minutes, to
every later timestamp, and the error accumulates.
iwl_mvm_ptp_gettime() already holds its GP2 read in a u64. Cast the
three u32 sources before multiplying.
Signed-off-by: Zhan Xusheng <zhanxusheng@xxxxxxxxxx>
Fixes: a2f49f7d52a9 ("wifi: iwlwifi: mvm: implement PHC clock adjustments")
Fixes: 0e49e940d1bc ("wifi: iwlwifi: mvm: add an option to use ptp clock for rx timestamp")
---
drivers/net/wireless/intel/iwlwifi/mvm/ptp.c | 5 +++--
drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c | 4 +++-
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/ptp.c b/drivers/net/wireless/intel/iwlwifi/mvm/ptp.c
index 49dcb1388007b..c64d6327e76f1 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/ptp.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/ptp.c
@@ -47,7 +47,8 @@ static void iwl_mvm_ptp_update_new_read(struct iwl_mvm *mvm, u32 gp2)
u64 iwl_mvm_ptp_get_adj_time(struct iwl_mvm *mvm, u64 base_time_ns)
{
struct ptp_data *data = &mvm->ptp_data;
- u64 last_gp2_ns = mvm->ptp_data.scale_update_gp2 * NSEC_PER_USEC;
+ u64 last_gp2_ns = (u64)mvm->ptp_data.scale_update_gp2 *
+ NSEC_PER_USEC;
u64 res;
u64 diff;
@@ -259,7 +260,7 @@ static int iwl_mvm_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
*/
gp2 = iwl_mvm_get_systime(mvm);
data->scale_update_adj_time_ns =
- iwl_mvm_ptp_get_adj_time(mvm, gp2 * NSEC_PER_USEC);
+ iwl_mvm_ptp_get_adj_time(mvm, (u64)gp2 * NSEC_PER_USEC);
data->scale_update_gp2 = gp2;
data->wrap_counter = 0;
data->delta = 0;
diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c b/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c
index 7f0b4f5daa214..7a9a63a76f382 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c
@@ -2017,7 +2017,9 @@ static void iwl_mvm_rx_fill_status(struct iwl_mvm *mvm,
if (mvm->rx_ts_ptp && mvm->monitor_on) {
u64 adj_time =
- iwl_mvm_ptp_get_adj_time(mvm, phy_data->gp2_on_air_rise * NSEC_PER_USEC);
+ iwl_mvm_ptp_get_adj_time(mvm,
+ (u64)phy_data->gp2_on_air_rise *
+ NSEC_PER_USEC);
rx_status->mactime = div64_u64(adj_time, NSEC_PER_USEC);
rx_status->flag |= RX_FLAG_MACTIME_IS_RTAP_TS64;
--
2.43.0