All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jacob Keller" <jacob.e.keller@intel.com>,
	"Intel Wired LAN" <intel-wired-lan@lists.osuosl.org>
Subject: Re: [PATCH iwl-next v3 4/4] ice: use struct timecounter for E825 and E830
Date: Wed, 18 Nov 2026 00:50:27 +0000	[thread overview]
Message-ID: <sashiko-outbox-219882@kernel.org> (raw)
In-Reply-To: <20261117-jk-e825-e830-timecounter-v3-4-87ea4c86a249@intel.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] ice: unreleased phc->lock on error path in
  ice_ptp_rebuild_owner()
- [Medium] ice: premature phc->update_time store in
  ice_ptp_read_cycles()
--

commit b8fa2e5442cd684f10151ff2ab484f07d9521f1c
Author: Jacob Keller <jacob.e.keller@intel.com>

ice: use struct timecounter for E825 and E830

This commit switches E825 and E830 devices to use a seqcount_latch-protected
timecounter and cyclecounter in struct ice_phc instead of directly adjusting
the hardware PHC timers and using the legacy timestamp extension logic.

> diff --git a/drivers/net/ethernet/intel/ice/ice_ptp.c b/drivers/net/ethernet/intel/ice/ice_ptp.c
> index d07dcf619bb18..a74a2075e5f53 100644
> --- a/drivers/net/ethernet/intel/ice/ice_ptp.c
> +++ b/drivers/net/ethernet/intel/ice/ice_ptp.c
> @@ -272,6 +272,202 @@ int ice_ptp_read_src_clk_reg(struct ice_pf *pf,
>  	return 0;
>  }
>  
> +/**
> + * ice_ptp_read_cycles - cyclecounter read() callback function
> + * @cc: the hardware cycle counter structure
> + *
> + * Read the PHC time via ice_ptp_read_src_clk_reg() and report it for use
> + * within timecounter_read() and timecounter_init().
> + *
> + * Although the cycle counter is masked to 32-bits for timestamp extension,
> + * this still reports the full 64-bit time to enable determining the phase
> + * difference between the PHC hardware value and the timecounter properly.
> + *
> + * Return: The current PHC timer value from the hardware on success.
> + *         Since failure cannot be meaningfully reported, return the previous
> + *         cycle_last value when unable to access the device.
> + */
> +u64 ice_ptp_read_cycles(struct cyclecounter *cc)
> +{
> +	struct ice_adapter *adapter;
> +	struct ice_phc *phc;
> +	struct ice_pf *pf;
> +	u64 time;
> +	int err;
> +
> +	phc = container_of(cc, struct ice_phc, cc);
> +	adapter = container_of(phc, struct ice_adapter, phc);
> +
> +	scoped_guard(rcu) {
> +		pf = rcu_dereference(adapter->ctrl_pf);
> +		if (!pf)
> +			return phc->tc[0].cycle_last;
> +
> +		err = ice_ptp_read_src_clk_reg(pf, NULL, &time);
> +		if (err)
> +			return phc->tc[0].cycle_last;
> +
> +		/* Paired with smp_load_acquire in ice_ptp_extend_32b_ts */
> +		smp_store_release(&phc->update_time, ktime_get());
> +		return time;
> +	}
> +}

[Severity: Medium]
Can publishing phc->update_time inside ice_ptp_read_cycles() allow
ice_ptp_extend_32b_ts() to extend a timestamp against an uninitialized or
stale phc->tc[1]?

In ice_phc_init() and ice_phc_refresh(), write_seqcount_latch_begin() sets
phc->seq to an odd value (directing readers to phc->tc[1]) before calling
timecounter_init() or timecounter_read() on phc->tc[0]:

CPU0                                  CPU1
ice_phc_init()
  write_seqcount_latch_begin(&phc->seq)
  timecounter_init(&phc->tc[0], ...)
    ice_ptp_read_cycles()
      smp_store_release(&phc->update_time, ...)
                                      ice_ptp_extend_32b_ts()
                                        smp_load_acquire(&phc->update_time)
                                        ice_phc_cyc2time_with_trace()
                                          seq = read_seqcount_latch(&phc->seq)
                                          /* idx == 1 */
                                          timecounter_cyc2time(&phc->tc[1], ...)
                                          <-- reads uninitialized/stale tc[1]
    phc->tc[0].cycle_last = ...
    phc->tc[0].nsec = ...
  write_seqcount_latch(&phc->seq)
  phc->tc[1].cycle_last = ...
  phc->tc[1].nsec = ...
  write_seqcount_latch_end(&phc->seq)

Because read_seqcount_latch_retry() succeeds while phc->seq remains at the
same odd value, the reader converts the hardware timestamp using the old
phc->tc[1] instead of discarding it or using the updated timecounter.
Updating phc->update_time after write_seqcount_latch_end() (or after
write_seqcount_latch() once phc->tc[0] is populated and latched) would avoid
exposing update_time before a valid timecounter snapshot is visible.

[ ... ]

> @@ -3207,14 +3519,24 @@ static int ice_ptp_rebuild_owner(struct ice_pf *pf)
>  	if (phc->update_time) {
>  		s64 delta = ktime_sub(ktime_get(), phc->update_time);
>  
> -		ts = ns_to_timespec64(phc->cached_time + delta);
> +		if (phc->use_timecounter)
> +			ns = phc->tc[0].nsec + delta;
> +		else
> +			ns = phc->cached_time + delta;
>  	} else {
> -		ts = ktime_to_timespec64(ktime_get_real());
> +		ns = ktime_get_real_ns();
> +	}
> +
> +	if (phc->use_timecounter) {
> +		ice_phc_init(phc, ns);
> +	} else {
> +		struct timespec64 ts = ns_to_timespec64(ns);
> +
> +		err = ice_ptp_write_init(pf, &ts);
> +		if (err)
> +			goto err_unlock;
>  	}
>  	mutex_unlock(&phc->lock);
> -	err = ice_ptp_write_init(pf, &ts);
> -	if (err)
> -		goto err_unlock;

[Severity: Medium]
Does jumping to err_unlock when ice_ptp_write_init() fails leave phc->lock
held?  The err_unlock path only calls ice_ptp_unlock(hw), so any subsequent
attempt to acquire phc->lock on a non-timecounter device will deadlock.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117-jk-e825-e830-timecounter-v3-0-87ea4c86a249@intel.com?part=4

      reply	other threads:[~2026-11-18  0:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18  0:31 [PATCH iwl-next v3 0/4] ice: E825 timer adjustment fixes Jacob Keller
2026-11-18  0:31 ` [PATCH iwl-next v3 1/4] ice: fix computation of ETF timestamps for E830 Jacob Keller
2026-11-18  0:31 ` [PATCH iwl-next v3 2/4] ice: exit PTP callbacks early if not ICE_PTP_READY Jacob Keller
2026-11-18  0:31 ` [PATCH iwl-next v3 3/4] ice: store cached PHC time in ice_adapter Jacob Keller
2026-11-18  0:44   ` sashiko-bot
2026-11-18  0:31 ` [PATCH iwl-next v3 4/4] ice: use struct timecounter for E825 and E830 Jacob Keller
2026-11-18  0:50   ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-219882@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=jacob.e.keller@intel.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.