ice: protect init and calibrating check in ice_ptp_request_ts
authorJacob Keller <jacob.e.keller@intel.com>
Mon, 5 Dec 2022 19:52:47 +0000 (11:52 -0800)
committerTony Nguyen <anthony.l.nguyen@intel.com>
Thu, 8 Dec 2022 21:12:54 +0000 (13:12 -0800)
commit3ad5c10bf21d1d69ac1117a89b3ce2271a832b34
tree92d027c95df50f891a3d9f082be67a3d8b1d84a6
parentf0ae124019faaa03f8b4c3fbe52ae35ab3a8dbda
ice: protect init and calibrating check in ice_ptp_request_ts

When requesting a new timestamp, the ice_ptp_request_ts function does not
hold the Tx tracker lock while checking init and calibrating. This means
that we might issue a new timestamp request just after the Tx timestamp
tracker starts being deinitialized. This could lead to incorrect access of
the timestamp structures. Correct this by moving the init and calibrating
checks under the lock, and updating the flows which modify these fields to
use the lock.

Note that we do not need to hold the lock while checking for tx->init in
ice_ptp_tx_tstamp. This is because the teardown function will use
synchronize_irq after clearing the flag to ensure that the threaded
interrupt completes. Either a) the tx->init flag will be cleared before the
ice_ptp_tx_tstamp function starts, thus it will exit immediately, or b) the
threaded interrupt will be executing and the synchronize_irq will wait
until the threaded interrupt has completed at which point we know the init
field has definitely been set and new interrupts will not execute the Tx
timestamp thread function.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
drivers/net/ethernet/intel/ice/ice_ptp.c
drivers/net/ethernet/intel/ice/ice_ptp.h