Intel-Wired-Lan Archive on 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 3/4] ice: store cached PHC time in ice_adapter
Date: Wed, 18 Nov 2026 00:44:56 +0000	[thread overview]
Message-ID: <sashiko-outbox-219870@kernel.org> (raw)
In-Reply-To: <20261117-jk-e825-e830-timecounter-v3-3-87ea4c86a249@intel.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] ice: 32-bit build failure in ice_ptp_extend_32b_ts() on 64-bit
  update_time
--

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

ice: store cached PHC time in ice_adapter

This commit moves the cached PHC time and its update timestamp from
per-PF and per-Rx-ring fields into a shared struct ice_phc embedded in
struct ice_adapter, updated by the clock-owning PF under a mutex and read
locklessly during timestamp extension.

> diff --git a/drivers/net/ethernet/intel/ice/ice_adapter.h b/drivers/net/ethernet/intel/ice/ice_adapter.h
> index ce1fe08462652..ade829c05000a 100644
> --- a/drivers/net/ethernet/intel/ice/ice_adapter.h
> +++ b/drivers/net/ethernet/intel/ice/ice_adapter.h
> @@ -35,6 +35,25 @@ struct ice_port_list {
>  	struct srcu_struct srcu;
>  };
>  
> +/**
> + * struct ice_phc - PTP Hardware Clock fields
> + * @cached_time: Cached copy of the PHC time for timestamp extension
> + * @update_time: Monotonic time when PHC was laste updated
> + * @lock: For protecting updates to the PHC fields.
> + *
> + * Readers are lockless and rely on READ_ONCE/WRITE_ONCE for the cached_time
> + * and smp_acquire/smp_release for the update_time field.
> + *
> + * Writers must acquire the lock mutex to ensure that the periodic task cannot
> + * write back an out-of-date cached value after a clock adjustment.
> + */
> +struct ice_phc {
> +	u64 cached_time;
> +	ktime_t update_time;
> +	/* Serialize updates to cached_time */
> +	struct mutex lock;
> +};

[ ... ]

> diff --git a/drivers/net/ethernet/intel/ice/ice_ptp.c b/drivers/net/ethernet/intel/ice/ice_ptp.c
> index bf37c2a7ff863..d07dcf619bb18 100644
> --- a/drivers/net/ethernet/intel/ice/ice_ptp.c
> +++ b/drivers/net/ethernet/intel/ice/ice_ptp.c
> @@ -309,13 +310,26 @@ int ice_ptp_read_src_clk_reg(struct ice_pf *pf,
>   * This is prevented by (a) periodically updating the cached PHC time once
>   * a second, and (b) discarding any Tx timestamp packet if it has waited for
>   * a timestamp for more than one second.
> + *
> + * Return: the extended timestamp value, or 0 if phc->update_time is stale.
>   */
> -static u64 ice_ptp_extend_32b_ts(u64 cached_phc_time, u32 in_tstamp)
> +static u64 ice_ptp_extend_32b_ts(struct ice_phc *phc,
> +				 u32 in_tstamp, bool trace_rx)
>  {
> +	u64 ns, cached_phc_time;
>  	u32 delta, phc_time_lo;
> -	u64 ns;
> +	ktime_t update_time;
>  
> -	/* Extract the lower 32 bits of the PHC time */
> +	/* Discard the timestamp if update_time hasn't been initialized */
> +	update_time = smp_load_acquire(&phc->update_time);
> +	if (!update_time)
> +		return 0;
> +
> +	/* Discard the hardware timestamp if the cached PHC time is too old */
> +	if (ktime_ms_delta(ktime_get_coarse(), update_time) > 2000)
> +		return 0;
> +
> +	cached_phc_time = READ_ONCE(phc->cached_time);

[Severity: High]
Does calling smp_load_acquire() and smp_store_release() (in
ice_ptp_update_cached_phctime()) on phc->update_time break 32-bit builds?

ktime_t is a 64-bit s64 on all architectures, whereas smp_load_acquire()
and smp_store_release() enforce compiletime_assert_atomic_type(), which
requires a native word size up to sizeof(long).  On 32-bit builds with
CONFIG_ICE and CONFIG_PTP_1588_CLOCK enabled, compilation fails with
"Need native word sized stores/loads for atomicity".

In addition, lockless READ_ONCE() and WRITE_ONCE() accesses on 64-bit
phc->cached_time and phc->update_time are not atomic on 32-bit
architectures and can tear when ice_ptp_extend_32b_ts() runs concurrently
with ice_ptp_update_cached_phctime().  The follow-up commit "ice: use
struct timecounter for E825 and E830" keeps these smp_load_acquire() and
smp_store_release() calls on phc->update_time.  Protecting the fields
with a seqcount_t or u64_stats_sync (or storing a word-sized jiffies
timestamp when a 64-bit read isn't needed) would avoid both the build
failure and 64-bit tearing.

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

  reply	other threads:[~2026-11-18  0:45 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 [this message]
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

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-219870@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox