From: Maxime Chevallier <maxime.chevallier@bootlin.com>
To: Lorenzo Bianconi <lorenzo.bianconi@oss.qualcomm.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Maxime Coquelin <mcoquelin.stm32@gmail.com>,
Alexandre Torgue <alexandre.torgue@foss.st.com>,
"Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>,
Kory Maincent <kory.maincent@bootlin.com>
Cc: netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH net v2] net: stmmac: serialize PTP timestamping configuration with priv->lock
Date: Mon, 5 Oct 2026 11:08:44 +0200 [thread overview]
Message-ID: <38937aef-76e9-440f-97f6-4ea68f9b2091@bootlin.com> (raw)
In-Reply-To: <20261005-stmmac-hwtstamp-missing-lock-v2-1-3b3bf4fe3f45@oss.qualcomm.com>
Hi Lorenzo,
On 10/5/26 10:11, Lorenzo Bianconi wrote:
> stmmac_dl_ts_coarse_set() runs under devl_lock only while
> stmmac_hwtstamp_set() runs under RTNL. They read/write
> systime_flags/tsfupdt_coarse and run stmmac_config_hw_tstamping().
>
> stmmac_dl_ts_coarse_set() snapshots priv->systime_flags, programs
> PTP_TCR, PTP_SSIR and PTP_TAR, and only then publishes tsfupdt_coarse
> and systime_flags. A concurrent stmmac_hwtstamp_set() can read the
> stale tsfupdt_coarse, build fine-mode flags, program PTP_TCR in fine
> mode and set hwts_rx_en.
>
> Take priv->lock in both stmmac_dl_ts_coarse_set() and
> stmmac_hwtstamp_set() so the timestamping configuration is updated
> under a single lock.
>
> Fixes: 6920fa0c764d ("net: stmmac: Add a devlink attribute to control timestamping mode")
> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@oss.qualcomm.com>
Thanks for fixing this,
Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Maxime
> ---
> Changes in v2:
> - Use proper Fixes tag.
> - Link to v1: https://lore.kernel.org/r/20261002-stmmac-hwtstamp-missing-lock-v1-1-189ce151a624@oss.qualcomm.com
> ---
> drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 43 ++++++++++++++---------
> 1 file changed, 27 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index 9741f97fa37a..a6793054a179 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> @@ -685,14 +685,7 @@ static int stmmac_hwtstamp_set(struct net_device *dev,
> u32 snap_type_sel = 0;
> u32 ts_master_en = 0;
> u32 ts_event_en = 0;
> -
> - if (!(priv->dma_cap.time_stamp || priv->adv_ts)) {
> - NL_SET_ERR_MSG_MOD(extack, "No support for HW time stamping");
> - priv->hwts_tx_en = 0;
> - priv->hwts_rx_en = 0;
> -
> - return -EOPNOTSUPP;
> - }
> + int ret = 0;
>
> if (!netif_running(dev)) {
> NL_SET_ERR_MSG_MOD(extack,
> @@ -700,13 +693,23 @@ static int stmmac_hwtstamp_set(struct net_device *dev,
> return -ENODEV;
> }
>
> - netdev_dbg(priv->dev, "%s config flags:0x%x, tx_type:0x%x, rx_filter:0x%x\n",
> - __func__, config->flags, config->tx_type, config->rx_filter);
> -
> if (config->tx_type != HWTSTAMP_TX_OFF &&
> config->tx_type != HWTSTAMP_TX_ON)
> return -ERANGE;
>
> + netdev_dbg(priv->dev, "%s config flags:0x%x, tx_type:0x%x, rx_filter:0x%x\n",
> + __func__, config->flags, config->tx_type, config->rx_filter);
> +
> + mutex_lock(&priv->lock);
> +
> + if (!(priv->dma_cap.time_stamp || priv->adv_ts)) {
> + NL_SET_ERR_MSG_MOD(extack, "No support for HW time stamping");
> + priv->hwts_tx_en = 0;
> + priv->hwts_rx_en = 0;
> + ret = -EOPNOTSUPP;
> + goto unlock;
> + }
> +
> if (priv->adv_ts) {
> switch (config->rx_filter) {
> case HWTSTAMP_FILTER_NONE:
> @@ -829,7 +832,8 @@ static int stmmac_hwtstamp_set(struct net_device *dev,
> break;
>
> default:
> - return -ERANGE;
> + ret = -ERANGE;
> + goto unlock;
> }
> } else {
> switch (config->rx_filter) {
> @@ -859,8 +863,10 @@ static int stmmac_hwtstamp_set(struct net_device *dev,
> stmmac_config_hw_tstamping(priv, priv->ptpaddr, priv->systime_flags);
>
> priv->tstamp_config = *config;
> +unlock:
> + mutex_unlock(&priv->lock);
>
> - return 0;
> + return ret;
> }
>
> /**
> @@ -7753,9 +7759,12 @@ static int stmmac_dl_ts_coarse_set(struct devlink *dl, u32 id,
> {
> struct stmmac_devlink_priv *dl_priv = devlink_priv(dl);
> struct stmmac_priv *priv = dl_priv->stmmac_priv;
> - u32 systime_flags = priv->systime_flags;
> + u32 systime_flags;
> int ret;
>
> + mutex_lock(&priv->lock);
> +
> + systime_flags = priv->systime_flags;
> if (ctx->val.vbool)
> systime_flags &= ~PTP_TCR_TSCFUPDT;
> else
> @@ -7768,13 +7777,15 @@ static int stmmac_dl_ts_coarse_set(struct devlink *dl, u32 id,
> if (ret) {
> NL_SET_ERR_MSG_MOD(extack,
> "failed to reconfigure PTP adjustment");
> - return ret;
> + goto unlock;
> }
>
> priv->tsfupdt_coarse = ctx->val.vbool;
> priv->systime_flags = systime_flags;
> +unlock:
> + mutex_unlock(&priv->lock);
>
> - return 0;
> + return ret;
> }
>
> static int stmmac_dl_ts_coarse_get(struct devlink *dl, u32 id,
>
> ---
> base-commit: aaaaf87ea99b8766c9a8aa0e71aa42e6bc8a5320
> change-id: 20261002-stmmac-hwtstamp-missing-lock-b6a7979c643c
>
> Best regards,
next prev parent reply other threads:[~2026-10-05 9:09 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-05 8:11 [PATCH net v2] net: stmmac: serialize PTP timestamping configuration with priv->lock Lorenzo Bianconi
2026-10-05 8:13 ` netdev-bot+sinfo
2026-10-05 8:21 ` Lorenzo Bianconi
2026-10-05 9:08 ` Maxime Chevallier [this message]
2026-10-06 12:45 ` Lorenzo Bianconi
2026-10-07 20:13 ` netdev-bot+sashiko
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=38937aef-76e9-440f-97f6-4ea68f9b2091@bootlin.com \
--to=maxime.chevallier@bootlin.com \
--cc=alexandre.torgue@foss.st.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=kory.maincent@bootlin.com \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=lorenzo.bianconi@oss.qualcomm.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rmk+kernel@armlinux.org.uk \
/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