ARM Sunxi Platform Development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "James Hilliard" <james.hilliard1@gmail.com>
Cc: linux-sunxi@lists.linux.dev, bpf@vger.kernel.org
Subject: Re: [PATCH net v4 05/15] net: stmmac: serialize and retain PHC configuration across reset
Date: Sun, 27 Sep 2026 15:50:05 +0000	[thread overview]
Message-ID: <20260927155005.9D1FA1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260926-submit-stmmac-reset-fixes-v1-v4-5-ec1c0250b3c9@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] net: stmmac: divide by zero in stmmac_ptp_restore() on single-shot PEROUT
- [Medium] net: stmmac: frequency adjustment lost in stmmac_dl_ts_coarse_set()
--

commit 04a85bc09b8c93cccea45ce07b1d943738de8a9b
Author: James Hilliard <james.hilliard1@gmail.com>
Subject: net: stmmac: serialize and retain PHC configuration across reset

This commit retains PHC configuration such as frequency correction, PEROUT
requests, and EXTTS selection across hardware resets. It serializes
timestamp writers and devlink mode updates using a new mutex, and adds a
common replay helper for reset transactions.

> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
[ ... ]
> @@ -7708,6 +7722,8 @@ static int stmmac_dl_ts_coarse_set(struct devlink *dl, u32 id,
>  	 * reconfigure the systime, subsecond increment and addend.
>  	 */
>  	stmmac_update_subsecond_increment(priv);
> +	write_unlock_irqrestore(&priv->ptp_lock, flags);
> +	mutex_unlock(&priv->ptp_mutex);
>  
>  	return 0;
>  }

[Severity: Medium]
Does this code lose the currently active frequency adjustment when the devlink
coarse mode is changed?

When a user sets the devlink phc_coarse_adj parameter,
stmmac_dl_ts_coarse_set() calls stmmac_update_subsecond_increment().
Looking at stmmac_update_subsecond_increment(), it reconfigures the hardware
with priv->default_addend without accounting for the active adjustment:

stmmac_update_subsecond_increment() {
    ...
    priv->default_addend = div_u64(temp, priv->plat->clk_ptp_rate);
    stmmac_config_addend(priv, priv->ptpaddr, priv->default_addend);
}

Since it does not reapply the cached priv->ptp_scaled_ppm, would this cause
the hardware to run unadjusted while the cached ptp_scaled_ppm implies to
the PTP daemon that an active adjustment is still present?

> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
[ ... ]
> +int stmmac_ptp_restore(struct stmmac_priv *priv)
> +{
[ ... ]
> +	for (i = 0; !ret && i < STMMAC_PPS_MAX; i++) {
> +		struct stmmac_pps_cfg cfg = priv->pps[i];
> +
> +		if (!(priv->ptp_perout & BIT(i)))
> +			continue;
> +		stmmac_get_systime(priv, priv->ptpaddr, &ns);
> +		period = timespec64_to_ns(&cfg.period);
> +		/* Retain phase, but move an expired target into the future. */
> +		cfg.start = stmmac_calc_tas_basetime(timespec64_to_ktime(cfg.start),
> +						     ns + PTP_SAFE_TIME_OFFSET_NS, period);

[Severity: High]
Can this cause a division by zero panic when restoring a single-shot PEROUT
request?

If a user configures a single-shot PTP PEROUT pulse, its period is 0.
When a MAC reset occurs later (such as an MTU change), stmmac_ptp_restore()
attempts to replay the PEROUT request and passes the period (0) as the
cycle_time argument to stmmac_calc_tas_basetime().

Looking at stmmac_calc_tas_basetime() in stmmac_tc.c:

struct timespec64 stmmac_calc_tas_basetime(...) {
    ...
    } else {
        s64 n;
        ktime_t base_time;

        n = div64_s64(ktime_sub_ns(current_time, old_base_time),
                      cycle_time);

If the target time is in the past, taking this else branch with
cycle_time = 0 will trigger a 64-bit divide error. Should single-shot
requests skip this phase recalculation?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260926-submit-stmmac-reset-fixes-v1-v4-0-ec1c0250b3c9@gmail.com?part=5

  reply	other threads:[~2026-09-27 15:50 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-26 15:48 [PATCH net v4 00/15] net: stmmac: preserve datapath state across MTU and resume failures James Hilliard
2026-09-26 15:48 ` [PATCH net v4 01/15] net: stmmac: unwind the WoL IRQ after a safety IRQ request failure James Hilliard
2026-09-26 15:48 ` [PATCH net v4 02/15] net: stmmac: reuse the MDIO reset GPIO on resume James Hilliard
2026-09-30  4:51   ` netdev-bot+sashiko
2026-09-26 15:48 ` [PATCH net v4 03/15] net: phylink: allow stopping a suspended instance James Hilliard
2026-09-30  4:51   ` netdev-bot+sashiko
2026-09-26 15:48 ` [PATCH net v4 04/15] xsk: freeze deferred pool teardown during system sleep James Hilliard
2026-09-30  4:51   ` netdev-bot+sashiko
2026-09-26 15:49 ` [PATCH net v4 05/15] net: stmmac: serialize and retain PHC configuration across reset James Hilliard
2026-09-27 15:50   ` sashiko-bot [this message]
2026-09-30  4:51   ` netdev-bot+sashiko
2026-09-26 15:49 ` [PATCH net v4 06/15] net: stmmac: leave the datapath running for normal-size MTU changes James Hilliard
2026-09-26 15:49 ` [PATCH net v4 07/15] net: stmmac: unwind partially allocated DMA configurations James Hilliard
2026-09-30  4:51   ` netdev-bot+sashiko
2026-09-26 15:49 ` [PATCH net v4 08/15] net: stmmac: keep DMA configurations at stable addresses James Hilliard
2026-09-30  4:51   ` netdev-bot+sashiko
2026-09-26 15:49 ` [PATCH net v4 09/15] net: stmmac: track datapath and power ownership across failed reopening James Hilliard
2026-09-27 15:50   ` sashiko-bot
2026-09-30  4:51   ` netdev-bot+sashiko
2026-09-26 15:49 ` [PATCH net v4 10/15] net: stmmac: use the tracked datapath restart for XSK pool changes James Hilliard
2026-09-30  4:51   ` netdev-bot+sashiko
2026-09-26 15:49 ` [PATCH net v4 11/15] net: stmmac: restore TC offloads before restarting DMA James Hilliard
2026-09-30  4:51   ` netdev-bot+sashiko
2026-09-26 15:49 ` [PATCH net v4 12/15] xsk: allow drivers to retain DMA mappings independently of pools James Hilliard
2026-09-26 15:49 ` [PATCH net v4 13/15] net: stmmac: retain DMA memory until hardware shutdown completes James Hilliard
2026-09-27 15:50   ` sashiko-bot
2026-09-30  4:51   ` netdev-bot+sashiko
2026-09-26 15:49 ` [PATCH net v4 14/15] net: stmmac: prepare device-local DMA interrupt quiescence James Hilliard
2026-09-30  4:52   ` netdev-bot+sashiko
2026-09-26 15:49 ` [PATCH net v4 15/15] net: stmmac: retain DMA resources across MTU changes James Hilliard
2026-09-27 15:50   ` sashiko-bot
2026-09-30  4:52   ` netdev-bot+sashiko
2026-09-26 16:00 ` [PATCH net v4 00/15] net: stmmac: preserve datapath state across MTU and resume failures Maxime Chevallier

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=20260927155005.9D1FA1F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=james.hilliard1@gmail.com \
    --cc=linux-sunxi@lists.linux.dev \
    --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