Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: jackbb_wu@compal.com
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
Subject: Re: [PATCH net-next v13 4/6] net: wwan: t9xx: Add control port
Date: Sun, 29 Nov 2026 07:39:26 +0000	[thread overview]
Message-ID: <179593796621.3146.9100120473874620233@kernel.org> (raw)
In-Reply-To: <20261125-t9xx_driver_v1-v13-4-92d9be5fb51e@compal.com>

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

  reply	other threads:[~2026-11-29  7:39 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  6:27 [PATCH net-next v13 0/6] net: wwan: t9xx: Add MediaTek T9XX WWAN driver Jack Wu via B4 Relay
2026-11-25  6:27 ` [PATCH net-next v13 1/6] net: wwan: t9xx: Add PCIe core Jack Wu via B4 Relay
2026-11-29  7:39   ` netdev-bot+sashiko
2026-11-25  6:27 ` [PATCH net-next v13 2/6] net: wwan: t9xx: Add control plane transaction layer framework Jack Wu via B4 Relay
2026-11-25  6:27 ` [PATCH net-next v13 3/6] net: wwan: t9xx: Add control DMA interface Jack Wu via B4 Relay
2026-11-29  7:39   ` netdev-bot+sashiko
2026-11-25  6:27 ` [PATCH net-next v13 4/6] net: wwan: t9xx: Add control port Jack Wu via B4 Relay
2026-11-29  7:39   ` netdev-bot+sashiko [this message]
2026-11-25  6:27 ` [PATCH net-next v13 5/6] net: wwan: t9xx: Add FSM thread Jack Wu via B4 Relay
2026-11-29  7:39   ` netdev-bot+sashiko
2026-11-25  6:27 ` [PATCH net-next v13 6/6] net: wwan: t9xx: Add AT & MBIM WWAN ports Jack Wu via B4 Relay

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=179593796621.3146.9100120473874620233@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=Jeff_Chang@compal.com \
    --cc=Minano.tseng@mediatek.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=jackbb_wu@compal.com \
    --cc=johannes@sipsolutions.net \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=loic.poulain@oss.qualcomm.com \
    --cc=matthias.bgg@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=robert_yu@compal.com \
    --cc=ryazanov.s.a@gmail.com \
    --cc=shi-wei.yeh@mediatek.com \
    --cc=skhan@linuxfoundation.org \
    --cc=wen-zhi.huang@mediatek.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