๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #10589

Re: [PATCH net] net: stmmac: keep est_lock across PTP clock adjustment

#10589
From: netdev-bot+sashiko
Date: Tue, 03 Nov 2026 17:41
132 lines
12973 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.

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?

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261102-stmmac-ptp-est-lock-v1-1-76fbc0cb230d%40oss.qualcomm.com
Technical Details
Message-ID: <179372771896.488856.1466229272637573919@kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-355876-linux-kernel-netdev=dewy.ru
References: <20261102-stmmac-ptp-est-lock-v1-1-76fbc0cb230d@oss.qualcomm.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-355876-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] net: stmmac: keep est_lock across PTP clock adjustment
Date: Tue, 03 Nov 2026 17:41:58 +0000
Organization: Usenet Network
Message-ID: <179372771896.488856.1466229272637573919@kernel.org>
References: <20261102-stmmac-ptp-est-lock-v1-1-76fbc0cb230d@oss.qualcomm.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3237858"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:CK9mY8/sgGM2bjtiV22BZ5sKpes= sha256:GH8sRtOZZtIozzycalfiqrlZjEHlDOc8M/1gI770Ea8=
	sha1:OA/SskKMOEHlEkXpd24H+TCe5Bw= sha256:uU/54YCjrNcUJd/oGSz6C6r2qYJ6fPZNGDtHuNxu5XM=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 3CDC11129BE; Tue,  3 Nov 2026 22:01:54 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id RkoygFlYvYFB;
	Tue,  3 Nov 2026 22:01:50 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-355876-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id 10D1A112623; Tue,  3 Nov 2026 22:01:42 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id A6C9B2D42E; Tue,  3 Nov 2026 17:42:02 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1793727721;
	b=RO9nVWcDXkhla8mqNkWoqKU7RZVJg2KbPGtHoL1uJvy1BDGSRaKOqkSNvsElQEkFpk90
	 CDHbQjo9j+/eE32pncD470WjzypKcZFCdnbMEKc6qqw9bPexLYbnb9UVNWNUvk3JNmN+V
	 LST89sbCsAkOQKnC/m33v6046pfAkV1Nm8RY3X85btVuD2a/e8V0en8F8AdaKgoukcVCw
	 8R4do4pNwkt/UxEWlawdnlI9DjicKNiVtig+IbJQLwSYf8h2oLT7+v8shmyVpy0k2FR04
	 UDKPLEuXTEWFSMMClhOUOhU8Ve8TdYmOCSSWJMGcB8urG1L08+uLGJojjqjeJXKkNOQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793727721;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=JNql26aG9tHWF88Mct64KKU+7DOWTgodN+wsEguXuiY=;
	b=LuKUsXBtp2ja4VWiLuUGYK12Tqm04dMTkb29lN4Kf7+REI0lTx89itsfcpF0nOzVm6U6
	 y4aBi5ZPG7AnwDApP/oQ26h7zGEEXLWCb5yDwdVbZ88ChD09lYgEP4rVRb20IYlYEHB+y
	 beXa1mG2X0V2GXFTQaFfS2B5R2hd1Ifmnmora0r96fGZ+9SPnXAquBdNMMnBQUs3GZpsG
	 X5GxLwRdqYQU5mQCFxD/YE45wba80NPePyCPjrYhazRlM1EhX+y8pASB62cUCuzoocz0A
	 Swm2/5IJwAWjqFqTDxyKG2MgfJ1GhyOoa9khCbE4/Sp1zFL8/Pj5Q4oQittBKVNmnSg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=MWm7cxrA;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id B5D5B606A32E;
	Tue,  3 Nov 2026 17:42:01 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=MWm7cxrA
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793727720;
	b=W6y7zKzo9p99yFWGHOOVIooOL9NMOObjGhX6Ku7PgLjwF0B+ACSq8FEd0BTZzpDzvvN2
	 66xbmUzS01WbbdPWDKM1xcQyK+ALV9vSAmIv6j+UxR1WwzOIPhXzpYqrn4QRq2GgaDjmX
	 J5fBIdHb2mVEjlrIJI93f3Y48ByxzN6wU+KfMOxuloR/dT4ulRAWiNJEMNq2Z4nnE0ZtV
	 GsvOZk9Eu/IVTDIWkjNmBvBqCvABVcxcrtFbYz0BSji+SDngPq0/4f3y/jlzUs7k7+XRI
	 2UkYf/AHOvi8ZrYriIN2Kw4n1+3y4xeBUwErbn96Ba/Dzfvz+vztnEOnjdTBTy8t7Ww==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793727720;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=JNql26aG9tHWF88Mct64KKU+7DOWTgodN+wsEguXuiY=;
	b=2Q3ErxoLb+/yk1OYKjwoMD/HfJ7IAyw7UvBDXxE5f1OIbLrT1nmvowLKSluGWHOGU4+d
	 Z9fLz792cUbwZXcS6tXEkHoIhQJNewroAqO45fOy6+6GNCYQ7OwDP/XqV+t/DLFAmMo/0
	 VO0f2XkZ+mohWJK88EKh9i0cyOWjz3S31t424PTajP9sdcSY0Q6iFOUdeA5QPGXhrtv6x
	 G3tPsSkS93LXOY26rAt4+kcF4RVPTPEDSQVa2WgM3EWd/oGt778Gf2T9S3wKZw+TrPZ4l
	 7E+9Sp0vFY6OlMmVMfclfgfmItb4GDDmefPzOvP8mDCdbpvDdqzJog3zY0iA5hDuC5A==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=MWm7cxrA;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F3C8606A31B
	for <netdev@vger.kernel.org>; Tue,  3 Nov 2026 17:42:00 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7AF8A1F000C1;
	Tue,  3 Nov 2026 17:41:59 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1793727720;
	bh=JNql26aG9tHWF88Mct64KKU+7DOWTgodN+wsEguXuiY=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=MWm7cxrASKpB82B9begYNRYvlW6WNShcwrpSAcwcPupfHMU+fsYi4GDbhnP0Z2kS3
	 rpCNuls25k5rOPDCzi0bnszkzNXFg1nt7TDt/xWmsYLAKE/fc5MKPdnz1yH7UTEuNr
	 BW8q2TEtZYgz75uRFBVWq/7CjalRhs3ISrt6PbC3C9rr3wx6jqL3dtS8L0iVBPSYJ2
	 pfL95dsASBDnzvwCnrApknamKqlG/izJnO9Xb1/ve5oMzK2lJW3MaamOHJ4Fuqyyab
	 QDrQvmQzef+cgkPO5/uMZW84ymDI0xopWD9zpTVBWz654z9fcO455nGrIO5GmxJ29o
	 CiyRmJfUPB9KQ==
X-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
X-In-Reply-To: <20261102-stmmac-ptp-est-lock-v1-1-76fbc0cb230d@oss.qualcomm.com>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list