From: netdev-bot+sashiko@kernel.org
To: tim770802@gmail.com
Cc: netdev@vger.kernel.org, chandrashekar.devegowda@intel.com,
haijun.liu@mediatek.com, ricardo.martinez@linux.intel.com,
loic.poulain@oss.qualcomm.com, ryazanov.s.a@gmail.com,
johannes@sipsolutions.net, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com, ilpo.jarvinen@linux.intel.com,
sreehari.kancharla@linux.intel.com,
m.chetan.kumar@linux.intel.com, horms@kernel.org,
linux-kernel@vger.kernel.org, tim.jh.chen@wnc.com.tw,
Chih.Hung.Huang@wnc.com.tw
Subject: Re: [PATCH net v7 6/6] net: wwan: t7xx: fix memory ordering in t7xx_dpmaif_rx_stop()
Date: Tue, 24 Nov 2026 02:29:43 +0000 [thread overview]
Message-ID: <179548738379.3135.10590455313123691119@kernel.org> (raw)
In-Reply-To: <20261120015556.131547-7-tim770802@gmail.com>
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.
> diff --git a/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c b/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c
> index a7d6289415b1c..d70ef315f5f5d 100644
> --- a/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c
> +++ b/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c
[ ... ]
> @@ -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?
> ret = t7xx_dpmaifq_release_pit_entry(rxq, rxq->pit_remain_release_cnt);
> if (ret)
> return ret;
[ ... ]
> @@ -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?
> + /* 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"?
> }
> }
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120015556.131547-1-tim770802%40gmail.com
next prev parent reply other threads:[~2026-11-24 2:29 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 1:55 [PATCH net v7 0/6] net: wwan: t7xx: fix TX push kthread soft lockup on suspend and RX stop issues Tim JH Chen
2026-11-20 1:55 ` [PATCH net v7 1/6] net: wwan: t7xx: fix TX push kthread soft lockup on system suspend Tim JH Chen
2026-11-20 1:55 ` [PATCH net v7 2/6] net: wwan: t7xx: fix runtime PM usage count underflow on -EACCES Tim JH Chen
2026-11-24 2:29 ` netdev-bot+sashiko
2026-11-20 1:55 ` [PATCH net v7 3/6] net: wwan: t7xx: fix skb double free when CLDMA send sees -EACCES Tim JH Chen
2026-11-24 2:29 ` netdev-bot+sashiko
2026-11-20 1:55 ` [PATCH net v7 4/6] net: wwan: t7xx: do not exit the TX push kthread on resume failure Tim JH Chen
2026-11-24 2:29 ` netdev-bot+sashiko
2026-11-20 1:55 ` [PATCH net v7 5/6] net: wwan: t7xx: complete NAPI on the not-started RX poll early return Tim JH Chen
2026-11-20 1:55 ` [PATCH net v7 6/6] net: wwan: t7xx: fix memory ordering in t7xx_dpmaif_rx_stop() Tim JH Chen
2026-11-24 2:29 ` netdev-bot+sashiko [this message]
2026-11-20 2:03 ` [PATCH net v7 0/6] net: wwan: t7xx: fix TX push kthread soft lockup on suspend and RX stop issues netdev-bot+sinfo
2026-11-20 2:42 ` Tim JH Chen
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=179548738379.3135.10590455313123691119@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=Chih.Hung.Huang@wnc.com.tw \
--cc=andrew+netdev@lunn.ch \
--cc=chandrashekar.devegowda@intel.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=haijun.liu@mediatek.com \
--cc=horms@kernel.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=johannes@sipsolutions.net \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=loic.poulain@oss.qualcomm.com \
--cc=m.chetan.kumar@linux.intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=ricardo.martinez@linux.intel.com \
--cc=ryazanov.s.a@gmail.com \
--cc=sreehari.kancharla@linux.intel.com \
--cc=tim.jh.chen@wnc.com.tw \
--cc=tim770802@gmail.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