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

From
Wu. JackBB (GSM) <hidden>
Date
2026-11-30 08:03:09
Also in
linux-arm-kernel, linux-doc, linux-mediatek, lkml
Reply to
netdev-bot+sashiko@kernel.org, 2026-11-29
Thanks for the review.
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.
No change.  The lifetime rule is already stated where the pointer is
stored, in the comment in mtk_port_trb_init(), and the teardown order
that satisfies it is in the commit message; your trace of that order is
correct.  The done-before-wake window is covered by the same order:
every completer is joined before any port is freed.
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.
No change.  As you traced, every producer already bounds the length
(WWAN writes are split to tx_mtu, the handshake messages are small and
fixed), and the length is chosen by the host, so the check could never
fire.  port->tx_mtu is stored in this patch because the ENABLE
completion is where the queue reports it; its reader arrives with the
WWAN ports.
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?
Will fix in v14: the guard is removed.  Both callers pass a non-NULL skb
and rxq->arg is always the port that armed the queue, so it could not
fire, and it was the only exit that did not follow the rx_done contract.
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().
No change.  The tx_seq overlap is unreachable for the reasons you list,
and rx_seq only feeds a rate-limited warning: the packet is delivered to
the port either way.
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?
Will fix in v14: the branch is removed.  Every port is disabled before
its last reference is dropped, as you traced, so ->exit() had nothing to
do in this patch; the callback is dropped here and comes back with the
WWAN port, which needs it for mutex_destroy().
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.
Will fix in v14: mtk_port_common_close() no longer clears PORT_S_OPEN,
so each close path clears it exactly once: mtk_port_internal_close()
with its test_and_clear_bit(), and the WWAN close under w_lock.

Thanks,
Jack
--
pw-bot: cr
Thread (17 messages) 17 messages, 4 authors, last reply 2d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help