🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #23654

Re: [PATCH net v6 2/8] net: dsa: sja1105: keep pin function on PEROUT disable

#23654
From: netdev-bot+sashiko
Date: Fri, 27 Nov 2026 16:47
234 lines
17154 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The changelog does not match what was submitted, and it leaves
  out the trigger and the impact.
- [Low] The author identity 'ahmadexp <ahmadexp@gmail.com>' does not
  match the Signed-off-by 'Ahmad Byagowi <ahmadexp@gmail.com>'.
- [Low] In sja1105_per_out_enable()
  (drivers/net/dsa/sja1105/sja1105_ptp.c), the patch wraps the…

Pre-existing issues:
- [Medium] This problem wasn't introduced by this patch, but
  sja1105_per_out_enable() still switches the shared PTP_CLK pin to…
- [Medium] This problem wasn't introduced by this patch, but the PTP_CLK
  pin-function state avb->cas_master, kept in the shared in-memory…
- [Medium] This problem wasn't introduced by this patch, but
  sja1105_per_out_enable() copies ptp_data->cmd into a local cmd at line…
- [Medium] This problem wasn't introduced by this patch, but on P/Q/R/S
  parts sja1105_per_out_enable(on=true) switches the PTP_CLK pin to…

--

net: dsa: sja1105: keep pin function on PEROUT disable

This patch changes sja1105_per_out_enable() so that it moves the shared
PTP_CLK pin to the PEROUT function only when the periodic output is being
enabled. Disabling now stops the generator without reprogramming the pin.
Before this, the pin could be switched away from EXTTS by a disable request.

> Disabling periodic output currently selects PTP_PF_PEROUT even when the shared PTP_CLK pin is configured for external timestamping. Only select the PEROUT function when enabling the output; disable should stop the generator without reprogramming the pin.
>
> A coding assistant helped identify this related pin-direction side effect, develop the correction and regression test, and prepare this changelog. The source-derived test checks the actual callback behavior with configuration writes stubbed.

[Severity: Low]
Is the regression test mentioned here included in the submission? The patch
only touches drivers/net/dsa/sja1105/sja1105_ptp.c. Reviewers have nothing
to read or run for "the source-derived test".

The phrase "this related pin-direction side effect" seems to point at the
sibling patch "net: dsa: sja1105: keep pin function on EXTTS disable". If
this commit is read on its own, for example by a stable backporter, what is
it related to?

Could the changelog also say how the bug is triggered and what users see?
On P/Q/R/S parts, userspace can send PTP_PEROUT_REQUEST(2) with a zero
period, or write a zero period to the sysfs period file, while EXTTS is
armed. Before this fix that path was:

ptp_perout_request()
  ops->enable(ops, &req, perout->period.sec || perout->period.nsec)
    sja1105_per_out_enable(on = false)
      sja1105_change_ptp_clk_pin_func(priv, PTP_PF_PEROUT)
        avb->cas_master = 1

The pin then became an output. extts_enabled stayed true and the poll timer
kept running, but external edges were no longer captured. The switch could
also drive the pin against an external PPS source.

Both body paragraphs are single lines well over 75 columns, which checkpatch
flags as COMMIT_LOG_LONG_LINE. Documentation/process/coding-assistants.rst
asks for checkpatch-clean submissions and for a statement of what could not
be tested. Was this fix tried on real hardware?

> Fixes: 747e5eb31d59 ("net: dsa: sja1105: configure the PTP_CLK pin as EXT_TS or PER_OUT")
> Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>

[Severity: Low]
The commit author is "ahmadexp <ahmadexp@gmail.com>", but the sign-off is
"Ahmad Byagowi <ahmadexp@gmail.com>". For this case checkpatch warns:

  From:/Signed-off-by: email name mismatch

Could the From: name be changed to match the sign-off? Netdev usually asks
for a resend so the DCO identity is clear. The sibling patches in the series
seem to have the same mismatch.

> diff --git a/drivers/net/dsa/sja1105/sja1105_ptp.c b/drivers/net/dsa/sja1105/sja1105_ptp.c
> index da35805152e05..7c07f76caccf4 100644
> --- a/drivers/net/dsa/sja1105/sja1105_ptp.c
> +++ b/drivers/net/dsa/sja1105/sja1105_ptp.c
> @@ -733,9 +733,11 @@ static int sja1105_per_out_enable(struct sja1105_private *priv,
>  
>  	mutex_lock(&ptp_data->lock);

[Severity: Medium]
This isn't a bug introduced by this patch, but the local cmd is copied from
ptp_data->cmd before this mutex_lock():

sja1105_per_out_enable() {
	...
	struct sja1105_ptp_cmd cmd = ptp_data->cmd;
	...
	mutex_lock(&ptp_data->lock);
	...
}

sja1105_ptp_commit() later writes the whole copy, ptpclkadd included. If
adjtime or settime runs while this caller is waiting on the mutex, can a
stale ptpclkadd be written back to the hardware?

For example, with the cached mode at SET:

perout                          adjtime
cmd = ptp_data->cmd (SET)
mutex_lock() blocks
                                mutex_lock()
                                sja1105_ptp_mode_set(ADD)
                                write delta
                                mutex_unlock()
sja1105_ptp_commit(&cmd)
  hardware back in SET mode

The cache now says ADD, so the next adjtime skips the mode switch in
sja1105_ptp_mode_set():

	if (ptp_data->cmd.ptpclkadd == mode)
		return 0;

Its delta is then written in SET mode, and the PHC is set to roughly the
delta value. In the mirrored case, the next settime is applied as an add.

sja1105_ptp_reset() makes the same unlocked copy. Should both copies be
taken after mutex_lock()?

>  
> -	rc = sja1105_change_ptp_clk_pin_func(priv, PTP_PF_PEROUT);
> -	if (rc)
> -		goto out;
> +	if (on) {
> +		rc = sja1105_change_ptp_clk_pin_func(priv, PTP_PF_PEROUT);
> +		if (rc)
> +			goto out;
> +	}

[Severity: Medium]
This is a pre-existing issue, but the enable path still switches the shared
PTP_CLK pin to output without checking the function the PTP core records in
sja1105_ptp_pin.func. ptp_perout_request() and ptp_extts_request() only
check the index and flags before they call ops->enable(). That leaves the
driver as the only place this could be enforced.

If EXTTS is armed and a PEROUT request with a non-zero period arrives on
index 0, avb->cas_master becomes 1. PTP_PIN_GETFUNC still reports EXTTS and
extts_enabled stays true. Does EXTTS then stop capturing without any error
while its poll keeps running?

The reverse case looks possible too. sja1105_extts_enable(on) sets
cas_master to 0 while the PEROUT generator started by startptpcp may still
be running.

This is how 747e5eb31d59 was designed, with the request choosing the pin
direction, and the changelog keeps that on purpose ("Only select the PEROUT
function when enabling the output"). Should these requests be checked
against the pin assignment?

[Severity: Medium]
This isn't a bug introduced by this patch either. On P/Q/R/S parts the pin
is switched to output here before the request has been checked. Later
failures jump to out, and out only drops the mutex:

		if (pin_duration > U32_MAX) {
			rc = -ERANGE;
			goto out;
		}

Failures from __sja1105_ptp_gettimex() and from the PTPPINST and PTPPINDUR
SPI writes take the same exit.

With a period above about 68.7 seconds, the caller gets -ERANGE. Does the
pin stay driven as an output even though startptpcp was never issued? That
would break an armed EXTTS. It would also undo the safe input default that
sja1105_init_avb_params() sets:

	avb->cas_master = false;

Could the period check, and ideally the register programming, move before
the pin direction change? Restoring the old direction on error would also
work.

[Severity: Medium]
This is a pre-existing issue, but sja1105_change_ptp_clk_pin_func() is
called here with ptp_data->lock held, while sja1105_extts_enable() calls it
with no driver lock at all:

sja1105_extts_enable() {
	...
	if (on) {
		rc = sja1105_change_ptp_clk_pin_func(priv, PTP_PF_EXTTS);
		if (rc)
			return rc;
	}

	priv->ptp_data.extts_enabled = on;
	...
}

The PTP core's pincfg_mux does not help here. The sysfs handlers
extts_enable_store() and period_store() call ops->enable() directly.

Can the read-modify-write of avb->cas_master in
sja1105_change_ptp_clk_pin_func() then overlap with a PEROUT enable running
at the same time?

It also looks like this can run during sja1105_static_config_reload(),
which relies on ptp_data.lock:

	/* No PTP operations can run right now */
	mutex_lock(&priv->ptp_data.lock);

If so, a dynamic AVB_PARAMS write could land in the middle of the switch
reset. The uploaded static config could also pick up a half-updated pin
direction.

extts_enabled is written here without ptp_data->lock as well, while
sja1105_rxtstamp_work() reads it under that lock.

>  
>  	if (on) {

[Severity: Low]
This isn't a bug, but the new if (on) block is followed right away by this
existing if (on) block. Could the sja1105_change_ptp_clk_pin_func() call go
inside the existing block, after its local declarations?

>  		struct timespec64 pin_duration_ts = {

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126-timecard-driver-v6-0-ahmadexp%40gmail.com
Technical Details
Message-ID: <179579807942.3135.16880746922338290793@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-372852-linux-kernel-netdev=dewy.ru
References: <20261126-timecard-driver-v6-2-ahmadexp@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-372852-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v6 2/8] net: dsa: sja1105: keep pin function on PEROUT disable
Date: Fri, 27 Nov 2026 16:47:59 +0000
Organization: Usenet Network
Message-ID: <179579807942.3135.16880746922338290793@kernel.org>
References: <20261126-timecard-driver-v6-2-ahmadexp@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="775757"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:v27qb4vpWk1u8mG/Q9+nnYWGuBc= sha256:FS9wGJasRps4XLiTiBmuuJPsbSjcrHQ/LsufW0c8LL8=
	sha1:5jhhgN69f/Vro/qZL2d9sq96gDo= sha256:7mgKWdvsjZtH39v1gMTbwYdwLj5LQHK+sR+l1sHw5wE=
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 C4DEB125F60; Fri, 27 Nov 2026 19:48:32 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.501
X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31
	tests=[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 WXxjKpCCksN9;
	Fri, 27 Nov 2026 19:48:28 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-372852-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 99688125F63; Fri, 27 Nov 2026 19:48:19 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 847882F58D; Fri, 27 Nov 2026 16:48:13 +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=1795798082;
	b=gegTqst7FBY/g+evkTb61s2XsYtIZLkBJLtwIO6wXm0zLeveu5l74EI4q1CaOfjxTZFN
	 WYVL0Y+HV7GmmmXnpVCiif1vzWxZgxbe0SPwdiaZuTnnX4YdSQf4NadKTBlVzAx/kmKRm
	 yxwNFmTbIjLv1lwCwGQLv5pc13wHRjcIYVh9uYs7RAAY0jhrnz8ManPB3S+Pq9KxRoVCS
	 I3Te9vCkfvza1QzOBbFhN72Eo3GLmPfcm6y0F9+lMgB0fdmCk2JdihcRYZ4p3n890b6gf
	 /bUlpLh4khV4TSMiPxgxKlrjNSDa3JJBYX03TkvqCPb1Wz6LjNHyLGpVgts3MqWhY0A==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795798082;
	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=C/Qd5lMs5hCPwque2VUzBd9ODA1TFoImJKWtFoQYGIY=;
	b=lfWIUrOLSNPc2FM0Ps5NYYkfnxGxCIQBgdl45XkNBoon+hEacjMZE5dGJkXkPBoHpc/g
	 F84g3wzMPD0WBGMCiFQP8HBOAFanSn1IRfqNXgmKFRP70+/Ac+s8cUp7laU/djqpVHanK
	 ReVt3jwpta7bGTnqxQQkrNqXcHbKbzIjcncn5p1AXHq7+qeps8c3BT1Jxz2jtuSag7/7m
	 HmPyha3ddJd20bCAlFgcyg6yrpl16wijjC3gx0+ABcMY7ypfWtpKgq/jYXIu1vkfZTYue
	 fLMK0LnfP0s+/YwR7LfhVt4Hd+xiPMKdDXeglX5NSWxak6tqX2deV/2mtOEBf10k5NQ==
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=dUkbNebU;
	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 7338C606A332;
	Fri, 27 Nov 2026 16:48:02 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=dUkbNebU
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=1795798081;
	b=g8akm6ih/HzD1/BIRJ9vqu+oC5u2b/0vcHwVJ+i0VlD9CNJNncl5TV4MCNEhpH8/pkPD
	 b9J7u2QWDsidBpeoZ/P3Nh9wZbMgQbxLPSs4PRfzzL9eZ33FDquBvK2rczlxvtmN+hJxJ
	 bBG6ZRoy6Z4rDJbAGagUEdSEptDddQtyf2JpUYxlKLlpx+ErcuiMFfIMf4V3SqyZSojkG
	 jwCwOKQJuVRov69KLjY4x/9bgRVAgx09eKH8FH97R5BRiP5iNO+r0DjZsTVtqiLtSe1mA
	 nxJUmhOoqjaVoVP3fXwWbZZZvTj93kUWV0OrhBYPhDmtLZh27ClhEq8D3fdzs/Bl0+w==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795798081;
	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=C/Qd5lMs5hCPwque2VUzBd9ODA1TFoImJKWtFoQYGIY=;
	b=O4ApLjpVc4xRRH5aUdBZouDklUVgXDzZI1LI9RS5l9OuNXaqmqdCAHIXLPXE/3x7O8ok
	 tG7INwJp79+qRcHTf2NFkoyPsxFxTR6UbV73vgHtWr1iUVS8ExobbAvs3eydoqaRua5oz
	 6bwKrUbuHa9nnK3D10snp8OzCMzCdJ7bV9s0LUOj4qL0Ate/zlkiPq6bVMezmZzSRcpVM
	 aq62IHeQrvjf1JZQrpn+1znedqnVYqz76PgAr9raLtXuMhP7NLUz56R5jZucGrFPtsPLC
	 GsMttmPr+bCBuDbza9JaE1XgzkvGfMhWQ+Nw79jN8xH5IiLBP+OUYKZUn7xP8/QueNQ==
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=dUkbNebU;
	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 90EBC606A324;
	Fri, 27 Nov 2026 16:48:01 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1CC41F00899;
	Fri, 27 Nov 2026 16:47:59 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795798080;
	bh=C/Qd5lMs5hCPwque2VUzBd9ODA1TFoImJKWtFoQYGIY=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=dUkbNebUkk4R6TDEAi+wB8Yv0uNTD95/J3Fz5UqRrNpBeseL2JLThxcWNlTEhyPst
	 MMQs2otBYgon18jSIQn4zQU086YFvl4fVf9YAWfybanXU8yWHYLvhRThPVr7kp7vR0
	 kiJRAjexX6jqSgHivRXotEmVqnm2eWdIkn02NtfbQc2OwPu+UfKyHgsyBjAKbTd7xs
	 mi+12un40TZIubATxdw5z6vKf7g8QGWC3L09PQfCgBLOK4WiWCMz7EkEtg83KCLB51
	 6y3Wgu+b5l1EAYjkc/awSS61vdai7d+w6r5TChmTX9FWBfCQQRUqIl8KuMqLzhHGYm
	 YPvtkPugPzYgw==
X-Cc: netdev@vger.kernel.org, richardcochran@gmail.com, davem@davemloft.net,
 edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
 vladimir.oltean@nxp.com, vadim.fedorenko@linux.dev, andrew@lunn.ch,
 linux-kernel@vger.kernel.org, arkadiusz.kubalewski@intel.com,
 jiri@resnulli.us, jonathan.lemon@gmail.com
X-In-Reply-To: <20261126-timecard-driver-v6-2-ahmadexp@gmail.com>
X-sashiko-severity: Low
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