From: Lorenzo Bianconi <lorenzo.bianconi@oss.qualcomm.com>
To: netdev-bot+sashiko@kernel.org
Cc: maxime.chevallier@bootlin.com, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com, mcoquelin.stm32@gmail.com,
alexandre.torgue@foss.st.com, richardcochran@gmail.com,
netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH net] net: stmmac: keep est_lock across PTP clock adjustment
Date: Tue, 3 Nov 2026 22:33:09 +0100 [thread overview]
Message-ID: <aupTFHhGMYg0hsFN@lore-desk> (raw)
In-Reply-To: <179372771896.488856.1466229272637573919@kernel.org>
[-- Attachment #1: Type: text/plain, Size: 5647 bytes --]
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider.
>
> Critical: 0 · High: 0 · Medium: 1 (1) · Low: 0
>
> If you believe none of the issues are legitimate, please reply to each
> issue of Medium severity or higher and explain why the AI is wrong.
> If any of them are legitimate and you plan to respin, please let patchwork
> know by including "pw-bot: cr" as a separate line at the end of your reply
> (one such reply per series is enough).
>
> - [Medium] This patch closes the EST-vs-clock-step window only in
> stmmac_adjust_time(), which serves adjtime/ADJ_SETOFFSET.
>
> Pre-existing issues:
> - [Medium] stmmac_adjust_time() discards the return value of every step
> in its disable/step/re-base sequence and always returns 0.
>
> --
>
> net: stmmac: keep est_lock across PTP clock adjustment
>
> Before this patch, stmmac_adjust_time() dropped priv->est_lock while it
> stepped the PTP clock. A concurrent tc_taprio_configure() could then
> program EST with a base time taken from the clock before the step. The
> patch keeps est_lock held across the whole disable/step/reprogram
> sequence.
>
> > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
> > index a37405534bebf..6ad6c2f52a0d2 100644
> > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
> > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
> > @@ -73,14 +73,12 @@ static int stmmac_adjust_time(struct ptp_clock_info *ptp, s64 delta)
> > if (priv->est && priv->est->enable)
> > stmmac_est_configure(priv, priv, priv->est,
> > priv->plat->clk_ptp_rate, false);
>
> [Severity: Medium]
> This isn't a bug introduced by this patch, but stmmac_adjust_time()
> ignores the return value of all three steps in this sequence and always
> returns 0.
This is a pre-existing issue and it needs to be addressed with a dedicated
patch.
>
> The disable call above can fail before EST_EEST is cleared.
> est_configure() returns early on a zero ptp_rate or on an est_write()
> SRWO poll timeout, and both returns come before the EST_CONTROL write:
>
> drivers/net/ethernet/stmicro/stmmac/stmmac_est.c:est_configure() {
> if (!ptp_rate) {
> netdev_warn(priv->dev, "Invalid PTP rate");
> return -EINVAL;
> }
>
> ret |= est_write(est_addr, EST_BTR_LOW, cfg->btr[0], false);
> ...
> if (ret)
> return ret;
> ...
> else
> ctrl &= ~EST_EEST;
>
> writel(ctrl, est_addr + EST_CONTROL);
> ...
> }
>
> In that case, is the clock stepped with the old schedule still armed?
>
> stmmac_adjust_systime() can return -ETIMEDOUT if PTP_TCR_TSUPDT never
> clears. Even then, the code recomputes the base time and re-enables EST.
>
> If __stmmac_setup_est() fails, it logs "failed to re-configure EST" and
> the error is dropped. EST_EEST and EST_INT_EN can then stay cleared while
> priv->est->enable stays true.
>
> In all three cases, ptp_clock_adjtime() reports success to userspace.
>
> Commit 23d96de472f7 says that the third case is intentional: "On a
> failed re-apply the open and resume callers abort, while
> stmmac_adjust_time() keeps the offload configured." Should the disable
> and adjust_systime failures still be propagated, though?
>
> > - mutex_unlock(&priv->est_lock);
> >
> > write_lock_irqsave(&priv->ptp_lock, flags);
> > stmmac_adjust_systime(priv, priv->ptpaddr, sec, nsec, neg_adj, xmac);
> > write_unlock_irqrestore(&priv->ptp_lock, flags);
> >
> > /* Calculate new basetime and re-configured EST after PTP time adjust. */
> > - mutex_lock(&priv->est_lock);
> > if (priv->est && priv->est->enable)
> > __stmmac_setup_est(priv);
> > mutex_unlock(&priv->est_lock);
>
> [Severity: Medium]
> This closes the window for adjtime, but what about the settime64 path?
> The commit message says:
>
> Keep est_lock held for the whole disable/step/reprogram sequence so no
> other EST user can program the block while the clock is being stepped.
>
> stmmac_set_time() also steps the PHC, but it only takes ptp_lock:
>
> drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c:stmmac_set_time() {
> ...
> write_lock_irqsave(&priv->ptp_lock, flags);
> stmmac_init_systime(priv, priv->ptpaddr, ts->tv_sec, ts->tv_nsec);
> write_unlock_irqrestore(&priv->ptp_lock, flags);
>
> return 0;
> }
>
> It never takes est_lock, never disables EST before the step and never
> calls __stmmac_setup_est() afterwards.
>
> tc_taprio_configure() holds est_lock, reads the clock with gettimex64(),
> computes priv->est->btr[] with stmmac_calc_tas_basetime(), and then calls
> stmmac_est_configure(..., true). A concurrent
> clock_settime()->ptp_clock_settime()->stmmac_set_time() is not excluded
> by est_lock, so it can step the clock between that read and the
> programming.
>
> Doesn't that leave the same stale base time race open through settime64?
>
> There is a second effect. A taprio schedule installed before a
> clock_settime() is never re-based, so it keeps its old base time until
> taprio is reconfigured.
>
> Should stmmac_set_time() use the same disable/step/__stmmac_setup_est()
> sequence under est_lock? Should the commit message mention this path?
The reported issue is valid, but it is a pre-existing problem out of scope for
this patch (it needs to be addressed with a dedicated patch).
Regards,
Lorenzo
>
> --
> Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261102-stmmac-ptp-est-lock-v1-1-76fbc0cb230d%40oss.qualcomm.com
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
prev parent reply other threads:[~2026-11-03 21:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 17:37 [PATCH net] net: stmmac: keep est_lock across PTP clock adjustment Lorenzo Bianconi
2026-11-02 17:44 ` netdev-bot+sinfo
2026-11-02 21:51 ` Lorenzo Bianconi
2026-11-03 17:41 ` netdev-bot+sashiko
2026-11-03 21:33 ` Lorenzo Bianconi [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=aupTFHhGMYg0hsFN@lore-desk \
--to=lorenzo.bianconi@oss.qualcomm.com \
--cc=alexandre.torgue@foss.st.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=maxime.chevallier@bootlin.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=netdev-bot+sashiko@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
/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