Skip to contentSkip to conversation

net: wwan: t7xx: fix TX push kthread soft lockup on suspend and RX stop issues

PATCH In review Tim JH Chen 3 participants 13 messages Nov 20 – Nov 24

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v7 cover net: wwan: t7xx: fix TX push kthread soft lockup on suspend and RX stop issues

net: wwan: t7xx: fix NAPI completion and rx_stop ordering

Two fixes in t7xx_hif_dpmaif_rx.c.

Patch 1 completes the NAPI on the not-started early return in t7xx_dpmaif_napi_rx_poll().

Patch 2 fixes the memory ordering between t7xx_dpmaif_rx_stop() and t7xx_dpmaif_napi_rx_poll().

v7:
- Drop v6 patches 1-3. They need rework based on the review and will be sent separately.
- Patch 1 (v6 4/4): change Fixes: to 5545b7b9f294; remove the code comment.
- Patch 2: new.

v6: https://lore.kernel.org/netdev/[email protected]/

v6 -> v7:
- Patch 1 (was 3/4): drop the explicit quiesce added to t7xx_dpmaif_suspend() in v6 (interrupt mask reorder, cancel_work_sync() of the TX-done workers and of bat_release_work, hardware stop moved last). The review found it incomplete without synchronize_irq(), losing the UL-DONE unmask and able to deadlock runtime suspend. Also drop the freezer: the kthread now skips the push and waits on tx_wq when it finds the TX queue stopped after the runtime PM resume, which also covers a resume that does not restart the queues (modem exception, shutdown), where the freezer does not apply. Commit message rewritten around the mechanism visible in the captured soft lockup; subject changed accordingly.
- Patch 2 (was 1/4): use pm_runtime_get_noresume() + pm_runtime_resume() at every site instead of per-site flags, which also covers t7xx_dpmaif_irq_rx_done()/t7xx_dpmaif_napi_rx_poll(). State when -EACCES is reachable.
- Patch 3 (new): t7xx_cldma_send_skb() returned -EACCES for a successful send, so the caller freed an skb that was already on the ring; same reference handling as patch 2.
- Patch 4 (was 2/4): retry every second with the first failure of a streak logged, instead of every 20 ms; Reported-by/Closes for the field report on the v6 thread.
- Patch 5 (was 4/4): Fixes: changed to 5545b7b9f294 ("net: wwan:
t7xx: Add NAPI support"); code comment removed; user-visible impact added to the commit message.
- Patch 6 (new): fix the memory ordering between t7xx_dpmaif_rx_stop() and t7xx_dpmaif_napi_rx_poll(), found by the v6 review, and keep the pending PIT release count of a poll that is in flight when the queue is stopped.
- v6: https://lore.kernel.org/netdev/[email protected]/
v5 -> v6:
- Drop the "freezer as a global quiesce" direction: remove every WQ_FREEZABLE annotation added in v4/v5. Marking the data-plane workqueues freezable can deadlock the suspend, because a flush_work()/cancel_work_sync() issued from a context the freezer does not freeze (the FSM kthread, or an unbind holding device_lock) blocks until thaw_workqueues(). (Reported on v5 review.)
- Instead quiesce the DPMAIF data plane explicitly in the system suspend callback: mask interrupts, cancel_work_sync() the TX-done workers, call t7xx_dpmaif_rx_stop() to drain the in-flight NAPI RX poll (the freezer cannot park a softirq), then cancel bat_release_work and stop the hardware last.
- Keep the PM freezer only for the lone TX push kthread, and use kthread_freezable_should_stop() instead of try_to_freeze().
- Fold in the pre-existing fixes previously deferred to a separate
series: the -EACCES runtime PM usage-count underflow (patch 1), the TX push kthread self-exit use-after-free (patch 2), and a NAPI that is never completed on the not-started RX poll early return (patch 4). This revision is therefore a 4-patch series.
- Do not touch t7xx_hif_cldma.c. Restrict the commit messages to the DPMAIF data path; the CLDMA control path uses a different mechanism and is called out as out of scope.
v4 -> v5:
- Fix freeze deadlock in t7xx_do_tx_hw_push(): when the TX-done workqueue (WQ_FREEZABLE) is frozen first it stops draining the DRB ring; the kthread then loops indefinitely in the ring-full retry branch and never reaches try_to_freeze(), causing a freezer timeout and suspend abort. (Simon Horman)
- Extend WQ_FREEZABLE to the BAT-release and CLDMA TX/RX workqueues. (Simon Horman) [reverted in v6, see above]
- Note the -EACCES underflow and the stale kthread pointer as pre-existing issues to be addressed separately. [done in v6, patches 1-2]
v3 -> v4:
- Drop the tx_pm_lock / state-snapshot approach entirely and use the PM freezer instead. The previous approach deadlocked through the runtime PM wait queue and opened ISR windows by writing dpmaif_ctrl->state in suspend/resume.
v2 -> v3: process fixes (Fixes tag, changelog placement).
v1 -> v2: save/restore pre-suspend state; wrap pm_runtime with a mutex.

Tim JH Chen (6):
net: wwan: t7xx: fix TX push kthread soft lockup on system suspend
net: wwan: t7xx: fix runtime PM usage count underflow on -EACCES
net: wwan: t7xx: fix skb double free when CLDMA send sees -EACCES
net: wwan: t7xx: do not exit the TX push kthread on resume failure
net: wwan: t7xx: complete NAPI on the not-started RX poll early return
net: wwan: t7xx: fix memory ordering in t7xx_dpmaif_rx_stop()

 drivers/net/wwan/t7xx/t7xx_hif_cldma.c     | 12 +++++-
 drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c | 35 ++++++++++-----
 drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c | 50 ++++++++++++++++++----
 3 files changed, 75 insertions(+), 22 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v7 1/6 net: wwan: t7xx: fix TX push kthread soft lockup on system suspend

t7xx_dpmaif_suspend() stops the TX queues (que_started = false) but leaves dpmaif_ctrl->state at DPMAIF_STATE_PWRON. The TX push kthread only sleeps while the TX lists are empty or state != PWRON, so when skbs are still queued at the time the suspend callback runs its wait condition stays true and every iteration completes without doing anything and without sleeping: pm_runtime_resume_and_get() returns 0 without resuming anything (the PCI core resumed the device before the suspend callback, and once runtime PM is disabled in the late phase an active device is reported as already resumed); t7xx_pci_disable_sleep() completes at once because md_pm_state is no longer MTK_PM_RESUMED; t7xx_do_tx_hw_push() returns immediately because no queue is started. There is no scheduling point in that loop, so the kthread spins on its CPU for the rest of the suspend/resume cycle.

With s2idle and ASPM L1 enabled this was seen as a soft lockup after about a thousand suspend/resume cycles (the 981st in the capture below). The lockup was reported at different points of the suspend: while the device callbacks were still running, right after this driver's own suspend callback had stopped the queues, and after the wakeup interrupt but before any resume callback had run. Captured with kdump on an unmodified 6.19 kernel:

mtk_t7xx 0000:56:00.0: PM: pci_pm_suspend returned 0 after 39260 usecs
...

  watchdog: BUG: soft lockup - CPU#4 stuck for 26s! [dpmaif_tx_hw_pu:764]
  RIP: 0010:ktime_get_mono_fast_ns+0x2e/0xe0
  Call Trace:
   ? t7xx_pci_enable_sleep+0x44/0x90 [mtk_t7xx]
   t7xx_dpmaif_tx_hw_push_thread+0x1f9/0x490 [mtk_t7xx]
   kthread+0x10b/0x220
   ret_from_fork+0x159/0x1d0
   ret_from_fork_asm+0x1a/0x30

Other captures sample the same loop in t7xx_pci_disable_sleep() or in the runtime PM put; all other CPUs are idle.

The same loop runs after a resume that does not restart the queues (a modem exception found in the PM resume state, or shutdown) until the FSM takes the DPMAIF out of DPMAIF_STATE_PWRON.

Once pm_runtime_resume_and_get() has returned, a runtime suspended device has been resumed and its queues restarted, so a TX queue that is still stopped at that point was stopped by a system suspend or by an exception. Skip the push in that case and wait on tx_wq until the queue is restarted or the thread is stopped; t7xx_dpmaif_resume() and t7xx_dpmaif_start() already wake tx_wq after restarting the queues.

The check is not folded into the thread's main wait condition on
purpose: a runtime suspended device also has its queues stopped and relies on this thread calling pm_runtime_resume_and_get() to be resumed when skbs are queued.

Fixes 46e8f49ed7b3 ("net: wwan: t7xx: Introduce power management")
---
 drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c +17 -3
index 236d632cf591..798e4e95004f 100644
@@ -445,6 +445,7 @@ static void t7xx_do_tx_hw_push(struct dpmaif_ctrl *dpmaif_ctrl)
 static int t7xx_dpmaif_tx_hw_push_thread(void *arg)
 {
 	struct dpmaif_ctrl *dpmaif_ctrl = arg;
+	bool txq_stopped;
 	int ret;
 
 	while (!kthread_should_stop()) {
@@ -464,10 +465,23 @@ static int t7xx_dpmaif_tx_hw_push_thread(void *arg)
 		if (ret < 0 && ret != -EACCES)
 			return ret;
 
-		t7xx_pci_disable_sleep(dpmaif_ctrl->t7xx_dev);
-		t7xx_do_tx_hw_push(dpmaif_ctrl);
-		t7xx_pci_enable_sleep(dpmaif_ctrl->t7xx_dev);
+		/* A runtime suspended device was resumed above and had its queues
+		 * restarted, so a stopped queue here belongs to a system suspend
+		 * or an exception: wait for t7xx_dpmaif_resume() or
+		 * t7xx_dpmaif_start() to restart it instead of spinning.
+		 */
+		txq_stopped = !t7xx_select_tx_queue(dpmaif_ctrl);
+		if (!txq_stopped) {
+			t7xx_pci_disable_sleep(dpmaif_ctrl->t7xx_dev);
+			t7xx_do_tx_hw_push(dpmaif_ctrl);
+			t7xx_pci_enable_sleep(dpmaif_ctrl->t7xx_dev);
+		}
 		pm_runtime_put_autosuspend(dpmaif_ctrl->dev);
+
+		if (txq_stopped)
+			wait_event_interruptible(dpmaif_ctrl->tx_wq,
+						 t7xx_select_tx_queue(dpmaif_ctrl) ||
+						 kthread_should_stop());
 	}
 
 	return 0;
Signature · 1 line
2.43.0
#2 lore raw

PATCH v7 2/6 net: wwan: t7xx: fix runtime PM usage count underflow on -EACCES

In reply to Tim JH Chen

t7xx_dpmaif_tx_hw_push_thread(), t7xx_dpmaif_tx_done(), t7xx_dpmaif_bat_release_work() and t7xx_dpmaif_irq_rx_done() treat -EACCES from pm_runtime_resume_and_get() as success and proceed to access the hardware. That is intentional, but pm_runtime_resume_and_get() has already dropped the usage count it took before returning -EACCES, so the pm_runtime_put_autosuspend() at the end of each context (in t7xx_dpmaif_napi_rx_poll() for the RX interrupt) drops a reference that was never held.

Take the reference with pm_runtime_get_noresume() and resume with pm_runtime_resume(), so that exactly one reference is held on every path that touches the hardware, and drop it only on the errors that abort the operation.

-EACCES is only returned while runtime PM is disabled and the device is not active. Not observed; found by review.

Fixes 46e8f49ed7b3 ("net: wwan: t7xx: Introduce power management")
---
 drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c | 11 ++++++++---
 drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c | 14 ++++++++++----
 2 files changed, 18 insertions(+), 7 deletions(-)
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +8 -3
index 5af90ca6e063..77770869d575 100644
@@ -911,8 +911,10 @@ void t7xx_dpmaif_irq_rx_done(struct dpmaif_ctrl *dpmaif_ctrl, const unsigned int
 	 * which can't be done from softirq context the poll function
 	 * is running in.
 	 */
-	ret = pm_runtime_resume_and_get(ctrl->dev);
+	pm_runtime_get_noresume(ctrl->dev);
+	ret = pm_runtime_resume(ctrl->dev);
 	if (ret < 0 && ret != -EACCES) {
+		pm_runtime_put_noidle(ctrl->dev);
 		dev_err(ctrl->dev, "Failed to resume device: %d\n", ret);
 		return;
 	}
@@ -1068,9 +1070,12 @@ static void t7xx_dpmaif_bat_release_work(struct work_struct *work)
 	struct dpmaif_rx_queue *rxq;
 	int ret;
 
-	ret = pm_runtime_resume_and_get(dpmaif_ctrl->dev);
-	if (ret < 0 && ret != -EACCES)
+	pm_runtime_get_noresume(dpmaif_ctrl->dev);
+	ret = pm_runtime_resume(dpmaif_ctrl->dev);
+	if (ret < 0 && ret != -EACCES) {
+		pm_runtime_put_noidle(dpmaif_ctrl->dev);
 		return;
+	}
 
 	t7xx_pci_disable_sleep(dpmaif_ctrl->t7xx_dev);
 
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c +10 -4
index 798e4e95004f..48558b98e7c6 100644
@@ -162,9 +162,12 @@ static void t7xx_dpmaif_tx_done(struct work_struct *work)
 	struct dpmaif_hw_info *hw_info;
 	int ret;
 
-	ret = pm_runtime_resume_and_get(dpmaif_ctrl->dev);
-	if (ret < 0 && ret != -EACCES)
+	pm_runtime_get_noresume(dpmaif_ctrl->dev);
+	ret = pm_runtime_resume(dpmaif_ctrl->dev);
+	if (ret < 0 && ret != -EACCES) {
+		pm_runtime_put_noidle(dpmaif_ctrl->dev);
 		return;
+	}
 
 	/* The device may be in low power state. Disable sleep if needed */
 	t7xx_pci_disable_sleep(dpmaif_ctrl->t7xx_dev);
@@ -461,9 +464,12 @@ static int t7xx_dpmaif_tx_hw_push_thread(void *arg)
 				break;
 		}
 
-		ret = pm_runtime_resume_and_get(dpmaif_ctrl->dev);
-		if (ret < 0 && ret != -EACCES)
+		pm_runtime_get_noresume(dpmaif_ctrl->dev);
+		ret = pm_runtime_resume(dpmaif_ctrl->dev);
+		if (ret < 0 && ret != -EACCES) {
+			pm_runtime_put_noidle(dpmaif_ctrl->dev);
 			return ret;
+		}
 
 		/* A runtime suspended device was resumed above and had its queues
 		 * restarted, so a stopped queue here belongs to a system suspend
Signature · 1 line
2.43.0
#3 lore raw

Re: [PATCH net v7 2/6] net: wwan: t7xx: fix runtime PM usage count underflow on -EACCES

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 (1) · Low: 1

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] At this commit, t7xx_cldma_send_skb() (drivers/net/wwan/t7xx/t7xx_hif_cldma.c) still has the bug this patch…
- [Low] net: wwan: t7xx: inaccurate Fixes tag citing 46e8f49ed7b3 for runtime PM bug

Pre-existing issues:
- [Medium] t7xx_dpmaif_irq_rx_done() takes a runtime PM reference and hands it to the NAPI poll by calling napi_schedule(&rxq->napi).

--

net: wwan: t7xx: fix runtime PM usage count underflow on -EACCES

This commit replaces pm_runtime_resume_and_get() with pm_runtime_get_noresume() plus pm_runtime_resume() in four DPMAIF TX/RX contexts. A usage count reference is now still held when -EACCES is treated as success. The reference is dropped with pm_runtime_put_noidle() only on errors that abort the operation.

Quoted 4 lines

t7xx_dpmaif_tx_hw_push_thread(), t7xx_dpmaif_tx_done(), t7xx_dpmaif_bat_release_work() and t7xx_dpmaif_irq_rx_done() treat -EACCES from pm_runtime_resume_and_get() as success and proceed to access the hardware.

[Severity: Medium]
Was a fifth caller with the same pattern left out here? At this commit, t7xx_cldma_send_skb() in drivers/net/wwan/t7xx/t7xx_hif_cldma.c still does:

drivers/net/wwan/t7xx/t7xx_hif_cldma.c:t7xx_cldma_send_skb() {
    ...
	ret = pm_runtime_resume_and_get(md_ctrl->dev);
	if (ret < 0 && ret != -EACCES)
		return ret;
    ...
allow_sleep:
	t7xx_pci_enable_sleep(md_ctrl->t7xx_dev);
	pm_runtime_put_autosuspend(md_ctrl->dev);
	return ret;
}

On the -EACCES path, pm_runtime_resume_and_get() has already given back its reference. Every exit then goes through allow_sleep, so wouldn't the pm_runtime_put_autosuspend() there drop a reference that was never taken? The path is t7xx_port_wwan_write() or t7xx_port_fastboot_write() -> t7xx_cldma_send_skb().

The next patch in the series, "net: wwan: t7xx: fix skb double free when CLDMA send sees -EACCES", converts this site to the same pm_runtime_get_noresume() + pm_runtime_resume() pattern. So the end of the series looks correct.

Could the CLDMA conversion be folded into this patch, or at least mentioned in the commit message? Then this commit would fully fix the underflow it describes.

Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +0 -0
index 5af90ca6e0631..77770869d5750 100644
@@ -911,8 +911,10 @@ void t7xx_dpmaif_irq_rx_done(struct dpmaif_ctrl *dpmaif_ctrl, const unsigned int
 	 * which can't be done from softirq context the poll function

drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c void t7xx_dpmaif_irq_rx_done(struct dpmaif_ctrl *dpmaif_ctrl, const unsigned int · line 920

Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +3 -1
 	 * is running in.
 	 */
-	ret = pm_runtime_resume_and_get(ctrl->dev);
+	pm_runtime_get_noresume(ctrl->dev);
+	ret = pm_runtime_resume(ctrl->dev);
 	if (ret < 0 && ret != -EACCES) {
+		pm_runtime_put_noidle(ctrl->dev);
 		dev_err(ctrl->dev, "Failed to resume device: %d\n", ret);
 		return;
 	}

[Severity: Low]
Is the Fixes: tag pointing at the right commit? 46e8f49ed7b3 ("net: wwan: t7xx: Introduce power management") only added the system sleep dev_pm_ops callbacks (suspend, resume, freeze, thaw, poweroff, restore) and the PM entity registration. It does not add any runtime PM calls, and it does not touch t7xx_hif_dpmaif_rx.c or t7xx_hif_dpmaif_tx.c.

The pm_runtime_resume_and_get() calls that ignore -EACCES and are then paired with an unconditional pm_runtime_put_autosuspend() look like they came from two later commits:

d10b3a695ba0 ("net: wwan: t7xx: Runtime PM")
t7xx_dpmaif_bat_release_work(), t7xx_dpmaif_tx_done() and t7xx_dpmaif_tx_hw_push_thread()

364d0221f178 ("net: wwan: t7xx: Fix Runtime PM resume sequence")

    t7xx_dpmaif_irq_rx_done()

Should the trailers cite those two commits instead? The stable tooling uses Fixes: to decide which trees need this patch. Anyone running git blame later would also be sent to a commit that has nothing to do with the usage count underflow.

[Severity: Medium]
This is a pre-existing issue and was not introduced by this patch. The reference taken here is passed on to the NAPI poll right after this block:

	napi_schedule(&rxq->napi);

The return value is ignored. If NAPI_STATE_SCHED is already set, napi_schedule() does nothing. In that case t7xx_dpmaif_napi_rx_poll() never reaches the pm_runtime_put_autosuspend() that would drop this reference.

Can this leak the runtime PM usage count and keep the modem from runtime suspending?

SCHED can stay set in two ways. The first is a closed netdev, while DPMAIF RX-done interrupts can still arrive:

t7xx_ccmni_close()
t7xx_ccmni_disable_napi()
napi_disable()

The second is the !rxq->que_started early return in t7xx_dpmaif_napi_rx_poll(), which returns without calling napi_complete_done():

	if (!rxq->que_started) {
		atomic_set(&rxq->rx_processing, 0);
		pm_runtime_put_autosuspend(rxq->dpmaif_ctrl->dev);
		dev_err(...);
		return work_done;
	}

The same leak already existed on the normal success path before this patch. This patch adds the same handoff on the -EACCES path.

The que_started part is fixed later in the series by "net: wwan: t7xx:
complete NAPI on the not-started RX poll early return", which adds napi_complete_done() to that early return.

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120015556.131547-1-tim770802%40gmail.com
#4 lore raw

PATCH v7 3/6 net: wwan: t7xx: fix skb double free when CLDMA send sees -EACCES

In reply to Tim JH Chen

t7xx_cldma_send_skb() tolerates -EACCES from pm_runtime_resume_and_get() and goes on to queue the skb on the GPD ring, but it keeps that -EACCES in ret across a successful send and returns it. The callers treat a non-zero return as "not sent" and free the skb (t7xx_port_fastboot_write(), t7xx_port_wwan_write()), while t7xx_cldma_gpd_tx_collect() frees it again once the hardware is done with it: a double free.

The same path also drops a runtime PM reference that was never taken, since pm_runtime_resume_and_get() releases its reference before returning -EACCES.

Take the reference with pm_runtime_get_noresume() and resume with pm_runtime_resume(), so that one reference is always held across the send, and clear ret after the resume so that only a failure of the send itself is reported.

-EACCES is only returned while runtime PM is disabled and the device is not active. Not observed; found by review.

Fixes 46e8f49ed7b3 ("net: wwan: t7xx: Introduce power management")
---
 drivers/net/wwan/t7xx/t7xx_hif_cldma.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/net/wwan/t7xx/t7xx_hif_cldma.c +10 -2
index e1b37deb6d9b..5b4b9ed4a95b 100644
@@ -926,9 +926,17 @@ int t7xx_cldma_send_skb(struct cldma_ctrl *md_ctrl, int qno, struct sk_buff *skb
 	if (qno >= CLDMA_TXQ_NUM)
 		return -EINVAL;
 
-	ret = pm_runtime_resume_and_get(md_ctrl->dev);
-	if (ret < 0 && ret != -EACCES)
+	pm_runtime_get_noresume(md_ctrl->dev);
+	ret = pm_runtime_resume(md_ctrl->dev);
+	if (ret < 0 && ret != -EACCES) {
+		pm_runtime_put_noidle(md_ctrl->dev);
 		return ret;
+	}
+
+	/* ret holds the resume status (1 for an active device, -EACCES with
+	 * runtime PM disabled), not the result of the send below.
+	 */
+	ret = 0;
 
 	t7xx_pci_disable_sleep(md_ctrl->t7xx_dev);
 	queue = &md_ctrl->txq[qno];
Signature · 1 line
2.43.0
#5 lore raw

Re: [PATCH net v7 3/6] net: wwan: t7xx: fix skb double free when CLDMA send sees -EACCES

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Critical: 1 · High: 0 · Medium: 0 · Low: 1

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Critical] The patch fixes only one way to hit the skb double free; another one remains.
- [Low] net: wwan: t7xx: wrong Fixes tag and caller names in commit message

--

net: wwan: t7xx: fix skb double free when CLDMA send sees -EACCES

This patch changes t7xx_cldma_send_skb() to take the runtime PM reference with pm_runtime_get_noresume() and to resume with pm_runtime_resume(), so one reference is held across the send. It also clears ret after the resume, so a tolerated -EACCES is not returned for an skb that was already queued. Returning that -EACCES made the callers free the skb a second time.

Quoted 11 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c +1 -2
index e1b37deb6d9bf..5b4b9ed4a95b9 100644
@@ -926,9 +926,17 @@ int t7xx_cldma_send_skb(struct cldma_ctrl *md_ctrl, int qno, struct sk_buff *skb
 	if (qno >= CLDMA_TXQ_NUM)
 		return -EINVAL;
 
-	ret = pm_runtime_resume_and_get(md_ctrl->dev);
-	if (ret < 0 && ret != -EACCES)
+	pm_runtime_get_noresume(md_ctrl->dev);

drivers/net/wwan/t7xx/t7xx_hif_cldma.c int t7xx_cldma_send_skb(struct cldma_ctrl *md_ctrl, int qno, struct sk_buff *skb · line 939

Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c +9 -0
+	ret = pm_runtime_resume(md_ctrl->dev);
+	if (ret < 0 && ret != -EACCES) {
+		pm_runtime_put_noidle(md_ctrl->dev);
 		return ret;
+	}
+
+	/* ret holds the resume status (1 for an active device, -EACCES with
+	 * runtime PM disabled), not the result of the send below.
+	 */
+	ret = 0;

[Severity: Low]
This isn't a runtime problem, but the commit message needs a couple of corrections before this goes to stable.

The Fixes tag points at 46e8f49ed7b3 ("net: wwan: t7xx: Introduce power management"). As far as I can tell, that commit only added the system sleep callbacks:

t7xx_cldma_suspend()
t7xx_cldma_suspend_late()
t7xx_cldma_resume_early()
t7xx_cldma_resume()

It did not touch t7xx_cldma_send_skb() and did not add any runtime PM calls.

Three pieces of t7xx_cldma_send_skb() came in with d10b3a695ba0 ("net:
wwan: t7xx: Runtime PM"):

- the pm_runtime_resume_and_get() call
- the ret != -EACCES check
- the matching pm_runtime_put_autosuspend()

Should the tag be the following instead?

Fixes d10b3a695ba0 ("net: wwan: t7xx: Runtime PM")

An incorrect Fixes tag sends the backport to the wrong set of stable branches.

The message also names t7xx_port_fastboot_write() and t7xx_port_wwan_write() as the callers that free the skb on a non-zero return. Neither function appears to exist in the tree. The actual callers are:

- t7xx_port_fastboot_tx() in t7xx_port_wwan.c, which frees tx_skb
- t7xx_port_ctrl_tx() in t7xx_port_wwan.c, which frees cloned
- port_ctl_send_msg_to_md() in t7xx_port_ctrl_msg.c, which frees the skb with dev_kfree_skb_any()

Could you update the description to name those, so the double-free explanation can be checked against the code?

[Severity: Critical]
This fixes the -EACCES case. Can the same double free still happen through the -ETIMEDOUT return later in t7xx_cldma_send_skb()?

In the first branch of the do/while loop, the skb is placed on the ring before the sleep-disable wait is checked:

drivers/net/wwan/t7xx/t7xx_hif_cldma.c:t7xx_cldma_send_skb() {
    ...
			queue->budget--;
			t7xx_cldma_gpd_handle_tx_request(queue, tx_req, skb);
			queue->tx_next = list_next_entry_circular(tx_req, gpd_ring, entry);
			spin_unlock_irqrestore(&queue->ring_lock, flags);

			if (!t7xx_pci_sleep_disable_complete(md_ctrl->t7xx_dev)) {
				ret = -ETIMEDOUT;
				break;
			}
    ...
}

By this point t7xx_cldma_gpd_handle_tx_request() has DMA-mapped skb->data, set GPD_FLAGS_HWO if the queue is active, and stored tx_req->skb = skb.

If the modem does not ack the DS lock within PM_SLEEP_DIS_TIMEOUT_MS (20 ms), the function returns -ETIMEDOUT. The skb stays on the ring, still mapped and with HWO set.

The callers treat any non-zero return as "not sent" and free the skb:

  t7xx_port_fastboot_tx()    -> dev_kfree_skb(tx_skb)
  t7xx_port_ctrl_tx()        -> dev_kfree_skb(cloned)
  port_ctl_send_msg_to_md()  -> dev_kfree_skb_any(skb)

Later, t7xx_cldma_gpd_tx_collect() sees HWO cleared and req->skb non-NULL. It then calls dma_unmap_single() and dev_kfree_skb_any() on the already-freed skb. On reset, t7xx_cldma_clear_txq() frees req->skb in the same way.

Until then, the next t7xx_cldma_hw_start_send() or queue resume would let the modem DMA from the freed buffer.

The new comment says ret should only report the result of the send below. Should every return after a successful queue report success? The other option is to take the request back off the ring (unmap, clear HWO, clear tx_req->skb, restore budget and tx_next) before returning an error.

The later patches in this series do not appear to touch t7xx_hif_cldma.c, so this path would remain at the end of the series.

Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c +0 -0
 	t7xx_pci_disable_sleep(md_ctrl->t7xx_dev);
 	queue = &md_ctrl->txq[qno];
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120015556.131547-1-tim770802%40gmail.com
#6 lore raw

PATCH v7 4/6 net: wwan: t7xx: do not exit the TX push kthread on resume failure

In reply to Tim JH Chen

t7xx_dpmaif_tx_hw_push_thread() returns, ending the kthread, when the runtime PM resume fails with anything other than -EACCES. kthread_run() keeps no extra reference to the task, so the task_struct can be reaped or reused while dpmaif_ctrl->tx_thread still points at it. A later t7xx_dpmaif_tx_thread_rel() then calls kthread_stop() on the stale pointer. It also stops TX permanently and silently.

This was hit in the field after a runtime suspend failure ("SAP suspend error: -110") left dev->power.runtime_error set: every resume returned -EINVAL, the thread exited, and a later write to the PCI remove attribute crashed in kthread_stop() with a NULL worker_private. The remove then hung in D state holding pci_rescan_remove_lock and the machine could not shut down cleanly.

Log the failure and retry every second instead of exiting. Only the first failure of a streak is logged. The wait ends early on kthread_stop(), so the thread stays alive until t7xx_dpmaif_tx_thread_rel() tears it down. Recovering from a sticky runtime_error is a separate problem and is not attempted here.

Fixes 46e8f49ed7b3 ("net: wwan: t7xx: Introduce power management")
---
 drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c +13 -1
index 48558b98e7c6..00e456bdd808 100644
@@ -448,6 +448,7 @@ static void t7xx_do_tx_hw_push(struct dpmaif_ctrl *dpmaif_ctrl)
 static int t7xx_dpmaif_tx_hw_push_thread(void *arg)
 {
 	struct dpmaif_ctrl *dpmaif_ctrl = arg;
+	bool resume_failed = false;
 	bool txq_stopped;
 	int ret;
 
@@ -468,8 +469,19 @@ static int t7xx_dpmaif_tx_hw_push_thread(void *arg)
 		ret = pm_runtime_resume(dpmaif_ctrl->dev);
 		if (ret < 0 && ret != -EACCES) {
 			pm_runtime_put_noidle(dpmaif_ctrl->dev);
-			return ret;
+			/* Do not exit: t7xx_dpmaif_tx_thread_rel() kthread_stop()s
+			 * this task. Retry until the resume works or we are stopped.
+			 */
+			if (!resume_failed)
+				dev_err(dpmaif_ctrl->dev,
+					"Failed to resume for TX push: %d\n", ret);
+			resume_failed = true;
+			wait_event_interruptible_timeout(dpmaif_ctrl->tx_wq,
+							 kthread_should_stop(),
+							 HZ);
+			continue;
 		}
+		resume_failed = false;
 
 		/* A runtime suspended device was resumed above and had its queues
 		 * restarted, so a stopped queue here belongs to a system suspend
Signature · 1 line
2.43.0
#7 lore raw

Re: [PATCH net v7 4/6] net: wwan: t7xx: do not exit the TX push kthread on resume failure

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…

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] net: wwan: t7xx: wrong Fixes tag for
t7xx_dpmaif_tx_hw_push_thread() exit

--

Quoted 14 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c +6 -1
@@ -468,8 +469,19 @@ static int t7xx_dpmaif_tx_hw_push_thread(void *arg)
 		ret = pm_runtime_resume(dpmaif_ctrl->dev);
 		if (ret < 0 && ret != -EACCES) {
 			pm_runtime_put_noidle(dpmaif_ctrl->dev);
-			return ret;
+			/* Do not exit: t7xx_dpmaif_tx_thread_rel() kthread_stop()s
+			 * this task. Retry until the resume works or we are stopped.
+			 */
+			if (!resume_failed)
+				dev_err(dpmaif_ctrl->dev,
+					"Failed to resume for TX push: %d\n", ret);

drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c static int t7xx_dpmaif_tx_hw_push_thread(void *arg) · line 487

Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c +6 -0
+			resume_failed = true;
+			wait_event_interruptible_timeout(dpmaif_ctrl->tx_wq,
+							 kthread_should_stop(),
+							 HZ);
+			continue;
 		}
+		resume_failed = false;
 
 		/* A runtime suspended device was resumed above and had its queues
 		 * restarted, so a stopped queue here belongs to a system suspend

[Severity: Low]
The Fixes tag seems to point at the wrong commit. As far as I can tell, 46e8f49ed7b3 ("net: wwan: t7xx: Introduce power management") only added the system suspend/resume PM entity callbacks. It did not touch t7xx_hif_dpmaif_tx.c at all.

The pm_runtime_resume() call in t7xx_dpmaif_tx_hw_push_thread() came in with d10b3a695ba0 ("net: wwan: t7xx: Runtime PM"). So did the early return when ret < 0 && ret != -EACCES. That return is what lets the kthread exit and leaves dpmaif_ctrl->tx_thread pointing at a dead task.

The tag drives stable backport selection, so it matters which trees this lands in. Could you confirm with git blame and, if you agree, change it to:

Fixes d10b3a695ba0 ("net: wwan: t7xx: Runtime PM")
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120015556.131547-1-tim770802%40gmail.com
#8 lore raw

PATCH v7 5/6 net: wwan: t7xx: complete NAPI on the not-started RX poll early return

In reply to Tim JH Chen

When the RX queue is not started, t7xx_dpmaif_napi_rx_poll() returns 0 without calling napi_complete_done(). A poll that returns less than the budget must complete the NAPI itself, so NAPI_STATE_SCHED stays set:
every later napi_schedule() from t7xx_dpmaif_irq_rx_done() is a no-op and leaks the runtime PM reference it just took, no further RX poll runs on that queue, and a later napi_synchronize() in t7xx_ccmni_disable_napi() does not return.

This early return is taken after t7xx_dpmaif_rx_stop() clears que_started, for example on the modem exception path.

Call napi_complete_done() before returning.

Fixes 5545b7b9f294 ("net: wwan: t7xx: Add NAPI support")
---
 drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +1 -0
index 77770869d575..a7d6289415b1 100644
@@ -848,6 +848,7 @@ int t7xx_dpmaif_napi_rx_poll(struct napi_struct *napi, const int budget)
 		atomic_set(&rxq->rx_processing, 0);
 		pm_runtime_put_autosuspend(rxq->dpmaif_ctrl->dev);
 		dev_err(rxq->dpmaif_ctrl->dev, "Work RXQ: %d has not been started\n", rxq->index);
+		napi_complete_done(napi, work_done);
 		return work_done;
 	}
 
Signature · 1 line
2.43.0
#9 lore raw

PATCH v7 6/6 net: wwan: t7xx: fix memory ordering in t7xx_dpmaif_rx_stop()

In reply to Tim JH Chen

t7xx_dpmaif_napi_rx_poll() sets rx_processing, issues smp_mb(), then reads que_started. t7xx_dpmaif_rx_stop() reads rx_processing first and clears que_started afterwards. With this order the stop can read rx_processing == 0 while a new poll reads que_started == true, and the poll runs after t7xx_dpmaif_rx_stop() returns.

Clear que_started before waiting for rx_processing, so the two sides use the same store, smp_mb(), load order. Use WRITE_ONCE()/READ_ONCE() on the two accesses that form this handshake; the other accesses of que_started are on the same side of the barrier or on paths that t7xx_dpmaif_rx_stop() serialises through rx_processing.

With the new order a poll that is already past its que_started check when the queue is stopped finishes its pass with que_started == false, which used to be rare (only after the stop timed out). In that state t7xx_dpmaifq_release_pit_entry() returned 0 without touching the hardware and the caller zeroed pit_remain_release_cnt, so the entries consumed by that pass would never be released to the hardware. Move the check to t7xx_dpmaif_pit_release_and_add() and keep the pending count, so the entries are released by the first poll after the queue is restarted. The hardware is still up during that pass because t7xx_dpmaif_rx_stop() waits for it before the hardware is stopped.

Fixes d642b012df70 ("net: wwan: t7xx: Add data path interface")
---
 drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c | 23 ++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +15 -8
index a7d6289415b1..d70ef315f5f5 100644
@@ -240,9 +240,6 @@ static int t7xx_dpmaifq_release_pit_entry(struct dpmaif_rx_queue *rxq,
 	unsigned int old_rel_idx, new_rel_idx, hw_wr_idx;
 	int ret;
 
-	if (!rxq->que_started)
-		return 0;
-
 	if (rel_entry_num >= rxq->pit_size_cnt) {
 		dev_err(rxq->dpmaif_ctrl->dev, "Invalid PIT release index\n");
 		return -EINVAL;
@@ -565,6 +562,14 @@ static int t7xx_dpmaif_pit_release_and_add(struct dpmaif_rx_queue *rxq)
 	if (rxq->pit_remain_release_cnt < DPMAIF_PIT_CNT_THRESHOLD)
 		return 0;
 
+	/* The queue is stopped: keep the count, the entries are released by
+	 * the first poll after the queue has been restarted.
+	 * t7xx_dpmaif_rx_stop() waits for this poll before the hardware is
+	 * stopped.
+	 */
+	if (!READ_ONCE(rxq->que_started))
+		return 0;
+
 	ret = t7xx_dpmaifq_release_pit_entry(rxq, rxq->pit_remain_release_cnt);
 	if (ret)
 		return ret;
@@ -844,7 +849,7 @@ int t7xx_dpmaif_napi_rx_poll(struct napi_struct *napi, const int budget)
 	/* Ensure rx_processing is changed to 1 before actually begin RX flow */
 	smp_mb();
 
-	if (!rxq->que_started) {
+	if (!READ_ONCE(rxq->que_started)) {
 		atomic_set(&rxq->rx_processing, 0);
 		pm_runtime_put_autosuspend(rxq->dpmaif_ctrl->dev);
 		dev_err(rxq->dpmaif_ctrl->dev, "Work RXQ: %d has not been started\n", rxq->index);
@@ -1127,14 +1132,16 @@ void t7xx_dpmaif_rx_stop(struct dpmaif_ctrl *dpmaif_ctrl)
 		struct dpmaif_rx_queue *rxq = &dpmaif_ctrl->rxq[i];
 		int timeout, value;
 
+		WRITE_ONCE(rxq->que_started, false);
+		/* Order the que_started store before the rx_processing load.
+		 * Pairs with the smp_mb() in t7xx_dpmaif_napi_rx_poll().
+		 */
+		smp_mb();
+
 		timeout = readx_poll_timeout_atomic(atomic_read, &rxq->rx_processing, value,
 						    !value, 0, DPMAIF_CHECK_INIT_TIMEOUT_US);
 		if (timeout)
 			dev_err(dpmaif_ctrl->dev, "Stop RX SW failed\n");
-
-		/* Ensure RX processing has stopped before we set rxq->que_started to false */
-		smp_mb();
-		rxq->que_started = false;
 	}
 }
 
Signature · 1 line
2.43.0
#10 lore raw

Re: [PATCH net v7 6/6] net: wwan: t7xx: fix memory ordering in t7xx_dpmaif_rx_stop()

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.

Critical: 0 · High: 2 · Medium: 0 · Low: 2

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [High] The patch still relies on the ad-hoc rx_processing flag (set when the poll starts, cleared when it ends) to tell…
- [High] net: wwan: t7xx: sleep_disable_count leak on multi-pass poll stop
- [Low] The patch adds a comment in t7xx_dpmaif_pit_release_and_add() saying "t7xx_dpmaif_rx_stop() waits for this poll before the hardware…
- [Low] The commit message explains why only some que_started accesses get READ_ONCE()/WRITE_ONCE(): "the other accesses of que_started are…

--

net: wwan: t7xx: fix memory ordering in t7xx_dpmaif_rx_stop()

This patch changes t7xx_dpmaif_rx_stop() to clear que_started and issue smp_mb() before it waits for rx_processing. That matches the store/smp_mb()/load order in t7xx_dpmaif_napi_rx_poll(). It also moves the que_started check from t7xx_dpmaifq_release_pit_entry() into t7xx_dpmaif_pit_release_and_add(), so the pending PIT release count is kept while the queue is stopped.

Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +0 -0
index a7d6289415b1c..d70ef315f5f5d 100644

[ ... ]

drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c static int t7xx_dpmaif_pit_release_and_add(struct dpmaif_rx_queue *rxq) · line 572

Quoted 12 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +8 -0
@@ -565,6 +562,14 @@ static int t7xx_dpmaif_pit_release_and_add(struct dpmaif_rx_queue *rxq)
 	if (rxq->pit_remain_release_cnt < DPMAIF_PIT_CNT_THRESHOLD)
 		return 0;
 
+	/* The queue is stopped: keep the count, the entries are released by
+	 * the first poll after the queue has been restarted.
+	 * t7xx_dpmaif_rx_stop() waits for this poll before the hardware is
+	 * stopped.
+	 */
+	if (!READ_ONCE(rxq->que_started))
+		return 0;
+

[Severity: Low]
Is the last sentence of this comment accurate? The commit message makes the same claim:

"The hardware is still up during that pass because t7xx_dpmaif_rx_stop() waits for it before the hardware is stopped."

Both callers of t7xx_dpmaif_rx_stop() seem to stop the DL queues first. Here is t7xx_dpmaif_suspend():

drivers/net/wwan/t7xx/t7xx_hif_dpmaif.c:t7xx_dpmaif_suspend() {
	t7xx_dpmaif_tx_stop(dpmaif_ctrl);
	t7xx_dpmaif_hw_stop_all_txq(&dpmaif_ctrl->hw_info);
	t7xx_dpmaif_hw_stop_all_rxq(&dpmaif_ctrl->hw_info);
	t7xx_dpmaif_disable_irq(dpmaif_ctrl);
	t7xx_dpmaif_rx_stop(dpmaif_ctrl);
	...
}

t7xx_dpmaif_hw_stop_all_rxq() calls t7xx_dpmaif_dl_all_q_en(hw_info, false).

On the modem stop path, t7xx_dpmaif_md_state_callback() calls t7xx_dpmaif_stop_hw() on MD_STATE_WAITING_TO_STOP. That happens before MD_STATE_STOPPED or MD_STATE_EXCEPTION reaches:

t7xx_dpmaif_stop()->t7xx_dpmaif_stop_sw()->t7xx_dpmaif_rx_stop()

So a poll pass that finishes with que_started == false appears to always run after the DL queues have been disabled.

The early return looks harmless today, but for other reasons. The device is still in D0 during the PM entity suspend, and on modem stop t7xx_dpmaif_rx_clear() throws the count away.

Could the comment and the changelog describe the actual ordering?

Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +0 -0
 	ret = t7xx_dpmaifq_release_pit_entry(rxq, rxq->pit_remain_release_cnt);
 	if (ret)
 		return ret;

[ ... ]

drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c void t7xx_dpmaif_rx_stop(struct dpmaif_ctrl *dpmaif_ctrl) · line 1135

Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +1 -0
@@ -1127,14 +1132,16 @@ void t7xx_dpmaif_rx_stop(struct dpmaif_ctrl *dpmaif_ctrl)
 		struct dpmaif_rx_queue *rxq = &dpmaif_ctrl->rxq[i];
 		int timeout, value;
 
+		WRITE_ONCE(rxq->que_started, false);

[Severity: High]
Does this early exit now leak the sleep lock taken by an earlier pass of the same poll session?

A pass of t7xx_dpmaif_napi_rx_poll() only drops what it takes on entry in the completing branch. A pass that returns budget, sets once_more, or takes the sleep_lock_pending reschedule path returns with rx_processing still 1 and keeps its t7xx_pci_disable_sleep() reference:

t7xx_dpmaif_napi_rx_poll() {
	...
	if (!rxq->sleep_lock_pending)
		t7xx_pci_disable_sleep(t7xx_dev);

	ret = try_wait_for_completion(&t7xx_dev->sleep_lock_acquire);
	if (!ret) {
		napi_complete_done(napi, work_done);
		rxq->sleep_lock_pending = true;
		napi_schedule(napi);
		return work_done;
	}
	...
}

Before this patch, t7xx_dpmaif_rx_stop() waited for rx_processing to drop before clearing que_started. The continuation passes still saw que_started == true and the session ended in the branch that calls t7xx_pci_enable_sleep(). Only a stop that had already timed out could land in this early exit in the middle of a session.

With the store moved in front of the wait, the next pass after t7xx_dpmaif_rx_stop() clears que_started takes this early exit instead. That's the normal outcome whenever the stop arrives between passes, and on the suspend path the NAPI is still scheduled after t7xx_dpmaif_hw_stop_all_rxq() and t7xx_dpmaif_disable_irq(). The branch calls pm_runtime_put_autosuspend() and napi_complete_done(), but it never calls t7xx_pci_enable_sleep() and doesn't reset sleep_lock_pending.

In the budget and once_more cases sleep_lock_pending is false, so the first poll after the restart takes a fresh reference and the one from the aborted session is never dropped. Doesn't that leave sleep_disable_count permanently above zero, so t7xx_pci_enable_sleep() never lets the modem enter deep sleep again? In the deferred case the stale sleep_lock_pending cancels the extra count on the first poll after a restart, but only by accident, and the reference stays held until then.

The aborted session also leaves behind any PIT entries it hadn't consumed yet. On the modem stop path t7xx_dpmaif_stop_rxq() then sees pit_rd_idx != pit_wr_idx, busy-loops for DPMAIF_MAX_CHECK_COUNT iterations and logs an error. The dev_err() in this branch now also fires on an ordinary stop.

This branch also clears rx_processing before calling pm_runtime_put_autosuspend() and napi_complete_done(), so t7xx_dpmaif_rx_stop() can return while the poll is still inside them.

Should this early exit only apply when no session is in progress, and otherwise release what the earlier passes took (t7xx_pci_enable_sleep(), sleep_lock_pending)? Or would it be simpler to let the session drain before que_started is cleared?

[Severity: Low]
The commit message says:

"the other accesses of que_started are on the same side of the barrier or on paths that t7xx_dpmaif_rx_stop() serialises through rx_processing."

Does that hold for every reader?

t7xx_dpmaifq_rx_notify_hw() queues bat_release_work on every pass. t7xx_dpmaif_bat_release_work() never sets rx_processing, and t7xx_dpmaif_rx_stop() does not flush or cancel that work. The work reads que_started with plain loads:

t7xx_dpmaif_release_bat_entry() {
	...
	if (!rxq->que_started || !rel_entry_num)
		return -EINVAL;
	...
}

It does the same in t7xx_dpmaif_update_bat_wr_idx(), reached through t7xx_dpmaif_rx_buf_alloc().

With the new ordering, the plain read in t7xx_dpmaifq_poll_pit() also runs at the same time as this WRITE_ONCE() whenever the queue is stopped during a pass. Plain stores also remain in t7xx_dpmaif_start_txrx_qs() and t7xx_dpmaif_stop_rxq().

Won't KCSAN report these as data races?

If the final pass queues bat_release_work after que_started has been cleared, the work could also fail with -EINVAL. When bid_cnt reaches DPMAIF_BAT_CNT_THRESHOLD, it would log "Release PKT BAT failed: -22" or "Release BAT entry failed: -22".

The bat_release_work race existed before this patch, but the changelog now says it doesn't.

The kernel-doc of t7xx_dpmaif_rx_stop() still says "Wait for all the RX work to finish executing and mark the RX queue as paused". The function only waits for the NAPI poll, and it now marks the queue paused before waiting. Should the kernel-doc be updated too?

drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c void t7xx_dpmaif_rx_stop(struct dpmaif_ctrl *dpmaif_ctrl) · line 1137

Quoted 13 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +5 -4
+		/* Order the que_started store before the rx_processing load.
+		 * Pairs with the smp_mb() in t7xx_dpmaif_napi_rx_poll().
+		 */
+		smp_mb();
+
 		timeout = readx_poll_timeout_atomic(atomic_read, &rxq->rx_processing, value,
 						    !value, 0, DPMAIF_CHECK_INIT_TIMEOUT_US);
 		if (timeout)
 			dev_err(dpmaif_ctrl->dev, "Stop RX SW failed\n");
-
-		/* Ensure RX processing has stopped before we set rxq->que_started to false */
-		smp_mb();
-		rxq->que_started = false;

[Severity: High]
Can t7xx_dpmaif_rx_stop() still return while a poll is running?

It treats one read of rx_processing == 0 as proof that no poll is active. But in the completing branch of t7xx_dpmaif_napi_rx_poll(), rx_processing is cleared only after NAPI completion and the IRQ unmask:

t7xx_dpmaif_napi_rx_poll() {
	...
	} else if (work_done < budget) {
		napi_complete_done(napi, work_done);
		t7xx_dpmaif_clr_ip_busy_sts(&rxq->dpmaif_ctrl->hw_info);
		t7xx_dpmaif_dlq_unmask_rx_done(&rxq->dpmaif_ctrl->hw_info, rxq->index);
		t7xx_pci_enable_sleep(rxq->dpmaif_ctrl->t7xx_dev);
		pm_runtime_put_autosuspend(rxq->dpmaif_ctrl->dev);
		atomic_set(&rxq->rx_processing, 0);
	}
	...
}

Once napi_complete_done() has run and the IRQ is unmasked, a new RX-done IRQ can schedule the same NAPI on another CPU. One path is t7xx_dpmaif_isr_thread()->t7xx_dpmaif_irq_cb()->t7xx_dpmaif_irq_rx_done() ->napi_schedule(), for example after an IRQ affinity change. Busy polling is another. The interleaving would be:

CPU1 (new poll)
atomic_set(&rxq->rx_processing, 1);
smp_mb();
READ_ONCE(rxq->que_started) == true
starts collecting

CPU0 (old poll tail)
atomic_set(&rxq->rx_processing, 0); overwrites CPU1's 1

CPU2 (t7xx_dpmaif_rx_stop)
WRITE_ONCE(rxq->que_started, false);
smp_mb();
reads rx_processing == 0 and returns

At this point CPU1 is still in t7xx_dpmaif_rx_start().

On the t7xx_dpmaif_stop() path, t7xx_dpmaif_rx_clear() calls t7xx_dpmaif_stop_rxq(). That clears pit_base and bat_base with memset, zeroes the BAT bitmap, and resets pit_rd_idx, pit_release_rd_idx and pit_remain_release_cnt while CPU1 is still updating them.

Because of the deferral added in this patch, a stale pit_remain_release_cnt written by CPU1 after that reset is kept. It is then handed to the hardware once t7xx_dpmaif_start() sets que_started again.

On the suspend path, CPU1 would keep accessing DPMAIF MMIO after the entity suspend has returned.

Setting rx_processing on entry and clearing it on exit is effectively an ad-hoc lock. The driver already uses napi_synchronize() and napi_disable() in t7xx_ccmni_disable_napi(). Would it be better to synchronize with NAPI directly, or at least to clear rx_processing before napi_complete_done()?

Separately, rx_processing stays at 1 when the poll returns budget or takes the sleep_lock_pending reschedule path. If NAPI is disabled before the next poll runs, won't t7xx_dpmaif_rx_stop() busy-wait for the full DPMAIF_CHECK_INIT_TIMEOUT_US and log "Stop RX SW failed"?

Quoted 2 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +0 -0
 	}
 }
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120015556.131547-1-tim770802%40gmail.com
#11 lore raw
In reply to Tim JH Chen
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- Whether the issue was actually triggered, or is only theoretical (e.g. found by LLM and not proven at runtime). If it was triggered please include the symptoms, like the stack trace or kernel messages.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.

Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
#12 lore raw
Quoted 3 lines

- Whether the issue was actually triggered, or is only theoretical (e.g. found by LLM and not proven at runtime). If it was triggered please include the symptoms, like the stack trace or kernel messages.

Per patch:

1/6: Triggered. Soft lockup in an s2idle rtcwake loop (SIM registered, ASPM L1 enabled) on 6.19 with the unmodified driver, on the 981st cycle, captured with kdump:

  watchdog: BUG: soft lockup - CPU#4 stuck for 26s! [dpmaif_tx_hw_pu:764]
  RIP: 0010:ktime_get_mono_fast_ns+0x2e/0xe0
  Call Trace:
   ? t7xx_pci_enable_sleep+0x44/0x90 [mtk_t7xx]
   t7xx_dpmaif_tx_hw_push_thread+0x1f9/0x490 [mtk_t7xx]
   kthread+0x10b/0x220

With the series applied, 10024 cycles of the same loop completed without a soft lockup.

2/6 and 3/6: Not observed; found by code review. -EACCES is only returned while runtime PM is disabled and the device is not active, and I have not seen these paths hit at runtime.

4/6: Triggered in the field, reported by Andreas Haerter on the v6 thread (Closes: link in the patch). After "SAP suspend error: -110" every runtime resume failed, the TX push kthread exited, and a later write to the PCI remove attribute crashed in kthread_stop() with a NULL worker_private and then hung in D state.

5/6: The symptom was triggered, the exact path is not proven. In two overnight runs on 6.19 with an earlier test build that did not have this patch, a modem exception was followed by closing the wwan netdev hanging in napi_synchronize() with rtnl held, and every other rtnl user hung behind it:

NetworkManager:
msleep
t7xx_ccmni_disable_napi+0x42
t7xx_ccmni_close
__dev_close_many
__dev_change_flags
netif_change_flags
do_setlink
__rtnl_newlink
rtnl_newlink

The not-started early return that this patch fixes is the path I believe left NAPI_STATE_SCHED set, but I did not capture the poll itself. With the patch applied, "Work RXQ: 1 has not been started" was logged twice in a later run without a hang, but no modem exception occurred in that run, so the exception case is not verified on hardware.

6/6: Not observed; found by code review.