> -----Original Message-----
> From: Korba, Przemyslaw <[email protected]>
> Sent: Tuesday, November 24, 2026 7:26 AM
> To: Keller, Jacob E <[email protected]>
> Cc: Loktionov, Aleksandr <[email protected]>; Nguyen, Anthony
> L <[email protected]>; Kubalewski, Arkadiusz
> <[email protected]>; [email protected]; Ilichev,
> Konstantin <[email protected]>; Olech, Milena
> <[email protected]>; Kitszel, Przemyslaw
> <[email protected]>
> Subject: RE: [PATCH iwl-net] ice: fix stale cached PHC time after a time step
> 
> 
> 
> 
> > -----Original Message-----
> > From: Keller, Jacob E <[email protected]>
> > Sent: Monday, November 23, 2026 8:05 PM
> > To: Korba, Przemyslaw <[email protected]>
> > Cc: Loktionov, Aleksandr <[email protected]>; Nguyen,
> Anthony L <[email protected]>; Kubalewski, Arkadiusz
> > <[email protected]>; [email protected]; Ilichev,
> Konstantin <[email protected]>; Olech, Milena
> > <[email protected]>; Kitszel, Przemyslaw
> <[email protected]>
> > Subject: Re: [PATCH iwl-net] ice: fix stale cached PHC time after a time 
> > step
> >
> > On 11/23/2026 2:25 AM, Korba, Przemyslaw wrote:
> > >
> > >
> > >
> > >> -----Original Message-----
> > >> From: Keller, Jacob E <[email protected]>
> > >> Sent: Saturday, November 21, 2026 12:21 AM
> > >> To: Korba, Przemyslaw <[email protected]>
> > >> Cc: Loktionov, Aleksandr <[email protected]>; Nguyen,
> Anthony L <[email protected]>; Kubalewski, Arkadiusz
> > >> <[email protected]>; [email protected];
> Ilichev, Konstantin <[email protected]>; Olech, Milena
> > >> <[email protected]>; Kitszel, Przemyslaw
> <[email protected]>
> > >> Subject: Re: [PATCH iwl-net] ice: fix stale cached PHC time after a time 
> > >> step
> > >>
> > >> Przemyslaw Korba said:> ice_ptp_update_cached_phctime() reads the
> PHC
> > >> and then stores the value
> > >>> in the cached time that is used to extend Tx and Rx timestamps. It is
> > >>> called both from the periodic work and, after the PHC time is changed,
> > >>> from the settime/adjtime paths.
> > >>>
> > >>> Nothing orders these refreshes. The periodic work can read the PHC just
> > >>> before software changes its time, be delayed, and then store its reading
> > >>> after the refresh that follows the change. The cache then holds the old
> > >>> time until the next periodic update, up to 500 ms later. Timestamps
> > >>> extended in that window keep the correct low 32 bits but take the upper
> > >>> bits from the old time, so they are off by a multiple of 2^32 ns. Two
> > >>> concurrent time changes can race in the same way.
> > >>>
> > >>> For a follower that steps a large initial offset this makes ptp4l see
> > >>> the offset remain unchanged after the step, followed by a clockcheck
> > >>> failure and a second UNCALIBRATED transition:
> > >>>
> > >>>   port 1: UNCALIBRATED to SLAVE on MASTER_CLOCK_SELECTED
> > >>>   clockcheck: clock jumped forward or running faster than expected!
> > >>>   port 1: SLAVE to UNCALIBRATED on SYNCHRONIZATION_FAULT
> > >>>   port 1: UNCALIBRATED to SLAVE on MASTER_CLOCK_SELECTED
> > >>>
> > >>> In the failing case the offset after the step was exactly 5867 * 2^32 ns
> > >>> plus noise, i.e. only the low 32 bits of the time were right.
> > >>>
> > >>> Hold a spinlock across both the PHC read and the store of the cached
> > >>> time. Whichever refresh reads the PHC last then also stores last, so an
> > >>> older reading can never overwrite a newer one. The lock is only held for
> > >>> the register read and is taken before the GLTSYN_TIME lock that
> > >>> ice_ptp_read_src_clk_reg() takes, which is never held while taking it.
> > >>>
> > >>> Steps to reproduce:
> > >>> 1. Create QinQ (802.1ad outer, 802.1Q inner) VLANs on two directly
> > >>>    connected E810 ports.
> > >>> 2. Run a PTP leader on one side and ptp4l -s on the other, with the
> > >>>    follower PHC about 7 hours behind the leader, and run iperf3 on the
> > >>>    VLAN.
> > >>> 3. Restart the follower repeatedly.
> > >>>
> > >>> This is not reliably reproducible, as it depends on the periodic work
> > >>> overlapping the step. With a 200 ms delay added between the PHC read
> and
> > >>> the store, 3 of 20 runs show the second UNCALIBRATED transition and
> > >>> SYNCHRONIZATION_FAULT without this change.
> > >>>
> > >>> With a random delay of up to 100 ms added at the same place, and 4
> > >>> parallel "phc_ctl adj 1" loops running for 20 seconds, the stored value
> > >>> went backwards 579 times in 1509 stores without this change, and 0
> > >>> times in 399 stores with it.
> > >>>
> > >>> Tested on E810-C.
> > >>>
> > >>> Fixes: 77a781155a65 ("ice: enable receive hardware timestamping")
> > >>> Reviewed-by: Milena Olech <[email protected]>
> > >>> Signed-off-by: Przemyslaw Korba <[email protected]>
> > >>> ---
> > >>>  drivers/net/ethernet/intel/ice/ice_adapter.c | 1 +
> > >>>  drivers/net/ethernet/intel/ice/ice_adapter.h | 4 ++++
> > >>>  drivers/net/ethernet/intel/ice/ice_ptp.c     | 9 +++++++++
> > >>>  3 files changed, 14 insertions(+)
> > >>>
> > >>> diff --git a/drivers/net/ethernet/intel/ice/ice_adapter.c
> b/drivers/net/ethernet/intel/ice/ice_adapter.c
> > >>> index 207e4fe97be7..9874380b642d 100644
> > >>> --- a/drivers/net/ethernet/intel/ice/ice_adapter.c
> > >>> +++ b/drivers/net/ethernet/intel/ice/ice_adapter.c
> > >>> @@ -91,6 +91,7 @@ static struct ice_adapter *ice_adapter_new(struct
> pci_dev *pdev)
> > >>>         timecounter_init(&adapter->phc.tc, &adapter->phc.cc, 0);
> > >>>
> > >>>         seqlock_init(&adapter->phc.tc_lock);
> > >>> +       spin_lock_init(&adapter->phc.cache_lock);
> > >>>
> > >>
> > >> I think v4 of my timecounter series fixes this because each update is
> > >> protected by the phc->lock.
> > >>
> > >> The periodic update takes that lock in ice_ptp_update_cached_phctime,
> > >> and readers get a consistent view because of the write_seqcount_latch.
> > >>
> > >> The updates to the cached time only ever happen under the phc->lock
> > >> mutex and the read for the time to save also happens under lock. Thus, I
> > >> think this patch should not be needed with that timecounter series.
> > >>
> > >> Do you agree?
> > >>
> > >
> > > Yeah, I agree. one caveat though - your series targets iwl-next, I think 
> > > we'd
> need this
> > > stale cached PHC time fix backported, no?
> > >
> >
> > Fair. The problem is that other fixes we have for PTP landed on next as
> > well, and the main target customer I have is going to take the tree that
> > has all the fixes. Timecounter is a bit too big to backport.
> >
> > I'm ok with backporting this fix, but it will probably cause
> > complication on merging because we'll want to drop the unnecessary extra
> > lock once we have the timecounter fix :\
> >
> 
> Yeah, I'd suggest let's wait for your timecounter and lock series to merge and
> not pull this patch in
> for now, then we can think about backport. How about that?
> 

Sounds good.

Reply via email to