🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24084

Re: [PATCH net-next v13 4/6] net: wwan: t9xx: Add control port

#24084
From: netdev-bot+sashiko
Date: Sun, 29 Nov 2026 07:39
253 lines
16844 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 `rx_done` contract is documented as "consumes the skb; the
  return value is informational" on both `struct trb_open_priv` and…
- [Low] mtk_port_ch_enable() resets port->tx_seq and port->rx_seq with
  plain stores while the TRB kthread…
- [Low] The concern: struct mtk_port is kfree()d in mtk_port_release()
  while TRBs (trb->priv) or armed RX queues (rxq->arg) still point at…
- [Low] mtk_port_internal_close() clears PORT_S_OPEN twice: once with
  test_and_clear_bit() and again in mtk_port_common_close().
- [Low] mtk_port_release() runs with the global mtk_port_mngr_grp_mtx
  held and calls ->exit().
- [Low] mtk_port_send_data() does not compare skb->len with port->tx_mtu,
  and mtk_cldma_submit_tx() writes data_buff_len = cpu_to_le16(skb->len)…

--

net: wwan: t9xx: Add control port

This patch adds the port I/O layer and the port manager to the t9xx WWAN
driver. Together they build and tear down the port table and move control
data to and from CLDMA through TRBs. It also gives struct trb a kref so
the TRB handler holds a reference while it dispatches, and it stamps the
TX sequence number when the packet is handed to the hardware.

> diff --git a/drivers/net/wwan/t9xx/mtk_port.c b/drivers/net/wwan/t9xx/mtk_port.c
> new file mode 100644
> index 0000000000000..410bd4d506a7b
> --- /dev/null
> +++ b/drivers/net/wwan/t9xx/mtk_port.c
> @@ -0,0 +1,641 @@

[ ... ]

> +/* Called with mtk_port_mngr_grp_mtx held. */
> +void mtk_port_release(struct kref *port_kref)
> +{
> +	struct mtk_port *port;
> +
> +	port = container_of(port_kref, struct mtk_port, kref);
> +	mtk_port_get_ops(port->info.type)->exit(port);
> +	kfree(port);
> +}

[Severity: Low]
Can the port be freed here while a TRB (trb->priv) or an armed RX queue
(rxq->arg) still points at it?

mtk_port_trb_init() takes no reference on the port. Also,
mtk_port_ch_trb_complete() publishes trb->done before it touches the
port's waitqueue:

	smp_store_release(&trb->done, true);
	wake_up_all(&port->trb_wq);

So a waiter that sees done and returns could, in principle, overlap with
the wake_up_all().

At this commit nothing calls ->enable() or submits a TRB, so this path is
not live yet. Later in the series, mtk_trans_ctrl_exit() calls
mtk_pcie_hif_exit() before mtk_ctrl_exit()->mtk_port_mngr_exit(). That
quiesces CLDMA, stops the TRB thread and flushes pending TRBs, and the
FSM thread has already been stopped. That order looks like it prevents
the overlap.

Would a comment near mtk_port_release() help? It could say that ports
may only be freed after the HIF teardown has joined every completer.

[ ... ]

> +int mtk_port_send_data(struct mtk_port *port, void *data, bool blocking, bool force_send)
> +{

[ ... ]

> +	/* add ccci header */
> +	ret = mtk_port_add_header(skb);
> +	if (!ret)
> +		ret = mtk_port_status_check(port);
> +	if (!ret)
> +		ret = mtk_pcie_hif_submit_skb(port_mngr->ctrl_blk->mdev, skb,
> +					      force_send);

[Severity: Low]
Is there a reason mtk_port_send_data() does not compare skb->len with
port->tx_mtu before it submits? mtk_cldma_submit_tx() also writes
data_buff_len = cpu_to_le16(skb->len) with no MTU check.

As far as I can tell, every TX producer in the series already bounds the
length:

- mtk_port_common_write(), added in "Add AT & MBIM WWAN ports", splits
  payloads into tx_mtu-sized packets.
- The FSM's HS1 and HS3 messages are far below
  Q_MTU_3_5K - MTK_CCCI_H_ELEN.

The port->tx_mtu value set in mtk_port_ch_enable() is not used at this
commit.

A check here would only be defense in depth. The missing check in
mtk_cldma_submit_tx() comes from the earlier CLDMA patch.

[ ... ]

> +static int mtk_port_rx_dispatch(struct sk_buff *skb, void *priv)
> +{
> +	struct mtk_port_mngr *port_mngr;
> +	struct mtk_ccci_header *ccci_h;
> +	struct mtk_port *port = priv;
> +	int ret = -EPROTO;
> +	u16 channel;
> +
> +	if (!skb || !priv) {
> +		pr_err("Invalid input value in rx dispatch\n");
> +		return -EINVAL;
> +	}

[Severity: Low]
This isn't a bug, but the rx_done contract in struct trb_open_priv says:

	/* consumes the skb; the return value is informational */
	int (*rx_done)(struct sk_buff *skb, void *priv);

This early return does not free a non-NULL skb when priv is NULL.

priv comes from rxq->arg, which mtk_cldma_open() copies from trb->priv.
mtk_port_trb_init() always sets that to a port that mtk_port_ch_enable()
has already dereferenced, so the guard looks unreachable.

Should the guard free the skb, or be removed?

[ ... ]

> +int mtk_port_ch_enable(struct mtk_port *port)
> +{

[ ... ]

> +	/* The modem restarts its sequence numbering with the channel, and
> +	 * the first packet after it is not checked.
> +	 */
> +	port->tx_seq = 0;
> +	port->rx_seq = MTK_INVALID_RX_SEQ;

[Severity: Low]
Can these plain stores race with the TRB kthread in
mtk_port_tx_seq_stamp() and mtk_port_tx_seq_advance(), or with
mtk_port_rx_dispatch()? None of these accesses are synchronized.

For tx_seq it looks unreachable:

- ->enable() returns early when PORT_S_ENABLE is set.
- TX needs PORT_S_ENABLE and PORT_S_WR via mtk_port_status_check().
- A TX skb that passes the status check in mtk_port_send_data() and is
  queued after the flush fails in mtk_cldma_submit_tx() because the txq
  is closed.
- At the end of the series FSM_STATE_OFF is terminal, so no re-enable
  follows.

The overlap that remains is on rx_seq. It needs this sequence: an ENABLE
times out, the follow-up mtk_port_ch_disable() submit fails, and a later
enable gets -EBUSY while the RX queue armed by the first ENABLE is still
running. The worst effect seems to be one spurious or missed
out-of-order warning from mtk_port_check_rx_seq().

At this commit nothing calls ->enable().

[ ... ]

> diff --git a/drivers/net/wwan/t9xx/mtk_port_io.c b/drivers/net/wwan/t9xx/mtk_port_io.c
> new file mode 100644
> index 0000000000000..912b04c24784c
> --- /dev/null
> +++ b/drivers/net/wwan/t9xx/mtk_port_io.c
> @@ -0,0 +1,236 @@

[ ... ]

> +static void mtk_port_internal_exit(struct mtk_port *port)
> +{
> +	if (test_bit(PORT_S_ENABLE, &port->status))
> +		mtk_port_get_ops(port->info.type)->disable(port);
> +}

[Severity: Low]
mtk_port_release() calls ->exit() with the global mtk_port_mngr_grp_mtx
held. If PORT_S_ENABLE were still set here, ->disable() would reach
mtk_port_ch_disable(). That function allocates with GFP_KERNEL, takes
trans->submit_lock, and waits up to MTK_DFLT_TRB_TIMEOUT.

Would that create a mtk_port_mngr_grp_mtx -> submit_lock lock ordering?

>From what I can see the branch is never taken:

- The last kref_put() comes after mtk_port_tbl_destroy() has run
  ->disable() on every port.
- The FSM thread, the only caller of ->enable(), is stopped before
  mtk_port_mngr_exit().
- In the mtk_port_mngr_init() error path, no port was ever enabled.

Is this branch needed, given that callers always disable first?

[ ... ]

> +static void mtk_port_common_close(struct mtk_port *port)
> +{
> +	clear_bit(PORT_S_OPEN, &port->status);
> +
> +	set_bit(PORT_S_FLUSH, &port->status);
> +	wake_up_all(&port->trb_wq);
> +}

[ ... ]

> +int mtk_port_internal_close(void *i_port)
> +{

[ ... ]

> +	/* Claim the close: a second caller must not drop the reference again.
> +	 * mtk_port_common_close() clears the bit itself, for every port type.
> +	 */
> +	if (!test_and_clear_bit(PORT_S_OPEN, &port->status)) {
> +		pr_err("Port(%s) has been closed\n", port->info.name);
> +		ret = -EBADF;
> +		goto end;
> +	}
> +
> +	mtk_port_common_close(port);
> +	mtk_port_put_locked(port);

[Severity: Low]
PORT_S_OPEN is cleared twice on this path: once by test_and_clear_bit()
here, and again by clear_bit() in mtk_port_common_close().

If an open ran between the two clears, could it lose its OPEN claim, end
up with PORT_S_FLUSH set, and leak its port reference?

That would need a concurrent open and close on the same internal port.
In the series the only internal user is the FSM:
mtk_fsm_ctrl_ch_start() and mtk_fsm_ctrl_ch_stop() run on the FSM
kthread, or after kthread_stop(). WWAN open and close are serialized by
the WWAN core's ops_lock.

So the second clear_bit() looks redundant rather than racy.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125-t9xx_driver_v1-v13-0-92d9be5fb51e%40compal.com
Technical Details
Message-ID: <179593796621.3146.9100120473874620233@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373400-linux-kernel-netdev=dewy.ru
References: <20261125-t9xx_driver_v1-v13-4-92d9be5fb51e@compal.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373400-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v13 4/6] net: wwan: t9xx: Add control port
Date: Sun, 29 Nov 2026 07:39:26 +0000
Organization: Usenet Network
Message-ID: <179593796621.3146.9100120473874620233@kernel.org>
References: <20261125-t9xx_driver_v1-v13-4-92d9be5fb51e@compal.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1128867"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:NEUOQFqwcCNV8B6SDObbhScL6Qc= sha256:J/ZgAma5bZTa2opUdF2JtJX/C+ZzS/slNIwfswmcVj8=
	sha1:ivBrIggBGku+JREq2ANxATLc1U4= sha256:6/ZPk66IMnwpH5isd599YwMwsuHxsDHYKs1ZFxQbK7A=
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 CA80B125F93; Sun, 29 Nov 2026 10:54:08 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.5
X-Spam-Status: No, score=-3.5 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,
	URIBL_BLOCKED=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 ihRb5JxmosdH;
	Sun, 29 Nov 2026 10:54:02 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-373400-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id B9263125F94; Sun, 29 Nov 2026 10:53:53 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id 71DB3601B2A; Sun, 29 Nov 2026 07:39:31 +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=1795937969;
	b=DJL9RUo0FO4zG4QvRMecE2F92XHfBmCqcoS3Ulmiy3sucZsDZeGWbtASuJr2WCnSc1jK
	 7+tJFTEDruVG3+YbT5o++wREc1cSY1vqwX5Y//1qzl5KyEqQiDMWgFidqv2z7E6EYAJDU
	 70MmqQw25oZ7GIl1VAj0/m513zJg9Ys6WOBfgKzQhXC/YdCPLLiWHmGk9ocHfZoceW7Lm
	 41HjG39cfg5xA97wqusr8EzPFgrFhb+4icD/6mKzMGIL5m/x3L7c8pBP3JI2kqPM8GseV
	 OmYgeJA3relrugM6bEU/mshFE23QVEIQaJu9XPnxynAcD9aujw6sxaasTUGISL51xcQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795937969;
	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=BhdpN3tlHymuKkWH635WOnKJqKoxs5AlhVR25mx8ef0=;
	b=xxkqQuZlGjtF/3twNOzUV7g0JfUgmmZmbzwUv0GjirfEtf8O4DpJMmeTCX16yPnCZQRr
	 n/CSSmkyH5eNcPN0MlPxjYRvNHO/4QgD91SeD4Ry8nyUV1bSeBWRwDRzXr8AZGQ4GWBst
	 MlVJAVFFL6G1OT2SMTNwVquKtqSn5Fb8F5JxFOKQzCDVmkuzrngrsHwGV+sDocVE8OBEV
	 5hYabisbwGNwaEQbhSvciv4rFTmzzV+OZ7UbbvjF1FsnKOYxbuUMyp0AQOrCVeuhQOvMP
	 vR3Qx6AATD6IpLE218oK++8C6BeCNEb7AZoogGIznkix/KXV9jbns471Qo+QfdUzBBw==
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=dNG6Lzo2;
	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 1054E606A68B;
	Sun, 29 Nov 2026 07:39:29 +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=dNG6Lzo2
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=1795937968;
	b=yproE3TiHziUkAkKgZUGYGqBVCvwzEp8l4RNh6qyk1l3dgJ0HngaI2bmGGhnDsnpP+Pf
	 DJeKm6EyKGO97xgXPiIWxhKeWEY1h9H0iZfZbpzWsi4gmDmKVunFPvqrZFN5k4agqjuUn
	 0lokSqPfsD712/VQq6u7KTeinestTB8Rb91XMQ7OOVBMuRFMZ2HJXFnodpG49rH8z8Fqa
	 oct9Y+L9lj4dT6Q60G2SvX/y22qmoKcv2ysE1zIR7aZDUlOFuTVvbstHYYZ+PtxW0B2KB
	 SZT00oqJlss2Y0wW6Rqbho/nVvfZPxC8z0YN5CSXn8DDGpUf69XgmbiUuPMjDbh7k0A==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795937968;
	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=BhdpN3tlHymuKkWH635WOnKJqKoxs5AlhVR25mx8ef0=;
	b=LuK1dJ0uqaMp0NKDsjpzvAUaQZefAtioDy+OPB26rJlKB/KDeNTJA8+ZimLIBNfKjxTK
	 R2tJDeJPSVLW3fjlmhxXqg0l9/of1pIvG501v85bfIYVgoy/0/cRrAET37RgDoggbCDoA
	 52brnNwzJoq5XlWuvL9+eJprfGdAp2AkWcBjt9dXoVN2WhaFLVBd3TvJDuYNt5Rgw/v3K
	 NC/fxqzRxFNZIK2yCdICouqznpiJorkmwbFPx2WkzBNHlV3o+5i+BuukDPDP6JdjN+W9D
	 gN2uEAVdan80yQlxJyewuF45wPbQqpY032TZW5EQYSwjy/aniJh7YsC/ifJlJrfhTHg==
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=dNG6Lzo2;
	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 312C3606A331;
	Sun, 29 Nov 2026 07:39:28 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id A41531F000C1;
	Sun, 29 Nov 2026 07:39:26 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795937967;
	bh=BhdpN3tlHymuKkWH635WOnKJqKoxs5AlhVR25mx8ef0=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=dNG6Lzo2tv7rkK52VtZWMVUGHgYHMuO2j0Zx/b1BM1H5tjQCGRCEoYNxvoVsYqa3U
	 Oqu+PHQRj2E9jIk2XrVldVPO0rEKlPxRJATiiNZWEwVuqE9RqbApd+qJX2tAS7ZgFA
	 8YT0rX8Cj4w+bIB4fNhBhY08f6W9MWSwvkHjRrL3pnevHB5aEu73vdRM+o004D0dU/
	 OGHrrgSLICcc8ZNOb62q5zS1N2hRMJ303AamG+2woXU/yuCK2PEPKDnp9h2ZuVTp1n
	 DSxXkLZI2aJXKW8Qag+U5Tvu6HXPvZW3+9LqKPiC5mRH8zu7Gg1p2oOX0taA232w4p
	 xNVWwFbC00b/w==
X-Cc: loic.poulain@oss.qualcomm.com, ryazanov.s.a@gmail.com,
 johannes@sipsolutions.net, andrew+netdev@lunn.ch, davem@davemloft.net,
 kuba@kernel.org, pabeni@redhat.com, wen-zhi.huang@mediatek.com,
 shi-wei.yeh@mediatek.com, Minano.tseng@mediatek.com, matthias.bgg@gmail.com,
 angelogioacchino.delregno@collabora.com, horms@kernel.org, corbet@lwn.net,
 skhan@linuxfoundation.org, robert_yu@compal.com, Jeff_Chang@compal.com,
 edumazet@kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
 linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org,
 linux-doc@vger.kernel.org
X-In-Reply-To: <20261125-t9xx_driver_v1-v13-4-92d9be5fb51e@compal.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