From: "Wu. JackBB (GSM)" <JackBB_Wu@compal.com>
To: "netdev-bot+sashiko@kernel.org" <netdev-bot+sashiko@kernel.org>
Cc: "loic.poulain@oss.qualcomm.com" <loic.poulain@oss.qualcomm.com>,
"ryazanov.s.a@gmail.com" <ryazanov.s.a@gmail.com>,
"johannes@sipsolutions.net" <johannes@sipsolutions.net>,
"andrew+netdev@lunn.ch" <andrew+netdev@lunn.ch>,
"davem@davemloft.net" <davem@davemloft.net>,
"kuba@kernel.org" <kuba@kernel.org>,
"pabeni@redhat.com" <pabeni@redhat.com>,
"wen-zhi.huang@mediatek.com" <wen-zhi.huang@mediatek.com>,
"shi-wei.yeh@mediatek.com" <shi-wei.yeh@mediatek.com>,
"Minano.tseng@mediatek.com" <Minano.tseng@mediatek.com>,
"matthias.bgg@gmail.com" <matthias.bgg@gmail.com>,
"angelogioacchino.delregno@collabora.com"
<angelogioacchino.delregno@collabora.com>,
"horms@kernel.org" <horms@kernel.org>,
"corbet@lwn.net" <corbet@lwn.net>,
"skhan@linuxfoundation.org" <skhan@linuxfoundation.org>,
"Yu. Robert (GSM)" <robert_yu@compal.com>,
"Chang. Jeff (GSM)" <Jeff_Chang@compal.com>,
"edumazet@kernel.org" <edumazet@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"linux-mediatek@lists.infradead.org"
<linux-mediatek@lists.infradead.org>,
"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>
Subject: Re: [PATCH net-next v13 4/6] net: wwan: t9xx: Add control port
Date: Mon, 30 Nov 2026 08:02:58 +0000 [thread overview]
Message-ID: <d4bbdf4c72124504aa68f3ec7c0a692c@compal.com> (raw)
In-Reply-To: <179593796621.3146.9100120473874620233@kernel.org>
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
next prev parent reply other threads:[~2026-11-30 8:03 UTC|newest]
Thread overview: 14+ 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-30 7:58 ` Wu. JackBB (GSM)
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
2026-11-30 8:02 ` Wu. JackBB (GSM) [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-30 8:04 ` Wu. JackBB (GSM)
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=d4bbdf4c72124504aa68f3ec7c0a692c@compal.com \
--to=jackbb_wu@compal.com \
--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=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-bot+sashiko@kernel.org \
--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