* [PATCH net v2 1/2] net: wwan: iosm: cancel the ADB timer on cleanup
@ 2026-11-19 4:27 David Westen
2026-11-19 4:27 ` [PATCH net v2 2/2] net: wwan: iosm: fix S3 resume by re-binding the driver around it David Westen
2026-11-23 5:17 ` [PATCH net v2 1/2] net: wwan: iosm: cancel the ADB timer on cleanup netdev-bot+sashiko
0 siblings, 2 replies; 6+ messages in thread
From: David Westen @ 2026-11-19 4:27 UTC (permalink / raw)
To: netdev
Cc: loic.poulain, ryazanov.s.a, johannes, andrew+netdev, davem,
edumazet, kuba, pabeni, m.chetan.kumar, linux-kernel, mail,
nihaal, David Westen, stable
ipc_imem_cleanup() cancels the other imem hrtimers but not adb_timer,
which the UL aggregation path arms for 500 us. If it is still pending
when the device is removed, its callback queues a task that finishes
the ADB on the freed MUX, and the hrtimer itself is freed with the
imem.
Cancel it along with the other timers.
Fixes: 1f52d7b62285 ("net: wwan: iosm: Enable M.2 7360 WWAN card support")
Cc: stable@vger.kernel.org
Signed-off-by: David Westen <davidlwesten@gmail.com>
---
Notes:
Build-tested, and run as part of this series on an XMM7360 that uses
MUX aggregation, so the timer is armed there. I haven't reproduced the
race itself.
It comes before the S3 fix in the next patch, which makes this teardown
run on every S3.
drivers/net/wwan/iosm/iosm_ipc_imem.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/net/wwan/iosm/iosm_ipc_imem.c b/drivers/net/wwan/iosm/iosm_ipc_imem.c
index 4405c8531888..20f8da53a3ea 100644
--- a/drivers/net/wwan/iosm/iosm_ipc_imem.c
+++ b/drivers/net/wwan/iosm/iosm_ipc_imem.c
@@ -1239,6 +1239,7 @@ void ipc_imem_cleanup(struct iosm_imem *ipc_imem)
hrtimer_cancel(&ipc_imem->tdupdate_timer);
hrtimer_cancel(&ipc_imem->fast_update_timer);
hrtimer_cancel(&ipc_imem->startup_timer);
+ hrtimer_cancel(&ipc_imem->adb_timer);
/* cancel the workqueue */
cancel_work_sync(&ipc_imem->run_state_worker);
base-commit: e203d8a4751d48aa00eda31e3b320ba8e0d47dbf
--
2.56.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH net v2 2/2] net: wwan: iosm: fix S3 resume by re-binding the driver around it
2026-11-19 4:27 [PATCH net v2 1/2] net: wwan: iosm: cancel the ADB timer on cleanup David Westen
@ 2026-11-19 4:27 ` David Westen
2026-11-22 20:01 ` Maciej S. Szmigiero
2026-11-23 5:17 ` netdev-bot+sashiko
2026-11-23 5:17 ` [PATCH net v2 1/2] net: wwan: iosm: cancel the ADB timer on cleanup netdev-bot+sashiko
1 sibling, 2 replies; 6+ messages in thread
From: David Westen @ 2026-11-19 4:27 UTC (permalink / raw)
To: netdev
Cc: loic.poulain, ryazanov.s.a, johannes, andrew+netdev, davem,
edumazet, kuba, pabeni, m.chetan.kumar, linux-kernel, mail,
nihaal, David Westen, stable
On platforms where S3 cuts power to the WWAN card, the modem boots
again while the system sleeps, but the driver still treats it as
running. After resume its execution stage reads BOOT, and by the
first port open the boot code has crashed into the CD_READY stage:
iosm 0000:03:00.0: PORT open refused, phase A-CD_READY
The modem then stays unusable until an ACPI reset.
Unbind the driver before S3 and bind it again after resume, as
commit 0b6f6593aa8c ("net: wwan: iosm: Fix hibernation by re-binding
the driver around it") already does for hibernation. The driver is
then torn down while the modem still answers, and the modem is probed
again once it has booted.
The target state isn't known yet when the PM notifier runs, so the
default suspend mode decides: the driver is re-bound unless "mem" maps
to suspend-to-idle, which keeps using the suspend/resume callbacks.
This changes behavior in a few cases:
- On platforms that keep the card powered in S3, the modem is now
probed again on resume, which drops data sessions and recreates its
ports.
- Entering suspend-to-idle or standby explicitly while the default is
S3 also re-binds the driver.
- A suspend to S3 that calls pm_suspend(PM_SUSPEND_MEM) directly while
the default is suspend-to-idle is not covered and fails as before.
Fixes: 1f52d7b62285 ("net: wwan: iosm: Enable M.2 7360 WWAN card support")
Cc: stable@vger.kernel.org
Signed-off-by: David Westen <davidlwesten@gmail.com>
---
Notes:
Changes in v2:
- New patch before this one: cancel the ADB timer in ipc_imem_cleanup().
- Describe the changes in behavior and the remaining limits in the
changelog, and say in the comment that the modem "may" lose power.
- I also tried detecting the power loss on resume instead; my reply to
the v1 review explains why v2 keeps unbinding before suspend.
- Correction to that reply: the XMM7360 here does use MUX aggregation
(CP capability 0x300), so the ADB timer is armed on it too.
v1: https://lore.kernel.org/r/20261116031148.333990-1-davidlwesten@gmail.com
Tested on an XMM7360 (ThinkPad X1 Carbon 6th gen, deep sleep) with this
series applied to 7.2.15: the driver is unbound before suspend, and
after resume the modem is probed again and comes up without an ACPI
reset. Not tested on the XMM7560.
The investigation and the patches were done with an AI coding assistant
(Claude Opus 5.5). It read the driver and added temporary debug logging
to record the execution stage around suspend and resume. We wrote the
changes and the changelogs together, and I ran the tests.
drivers/net/wwan/iosm/iosm_ipc_pcie.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/net/wwan/iosm/iosm_ipc_pcie.c b/drivers/net/wwan/iosm/iosm_ipc_pcie.c
index 49052eb511ba..13e81012d818 100644
--- a/drivers/net/wwan/iosm/iosm_ipc_pcie.c
+++ b/drivers/net/wwan/iosm/iosm_ipc_pcie.c
@@ -534,12 +534,17 @@ void ipc_pcie_kfree_skb(struct iosm_pcie *ipc_pcie, struct sk_buff *skb)
static int pm_notify(struct notifier_block *nb, unsigned long mode, void *_unused)
{
- if (mode == PM_HIBERNATION_PREPARE || mode == PM_RESTORE_PREPARE) {
+ /* The modem may lose power in S3 and S4 and boot again on resume,
+ * which the suspend/resume callbacks can't handle, so probe it again.
+ */
+ if (mode == PM_HIBERNATION_PREPARE || mode == PM_RESTORE_PREPARE ||
+ (mode == PM_SUSPEND_PREPARE && !pm_suspend_default_s2idle())) {
if (pci_registered) {
pci_unregister_driver(&iosm_ipc_driver);
pci_registered = false;
}
- } else if (mode == PM_POST_HIBERNATION || mode == PM_POST_RESTORE) {
+ } else if (mode == PM_POST_HIBERNATION || mode == PM_POST_RESTORE ||
+ mode == PM_POST_SUSPEND) {
if (!pci_registered) {
int ret;
--
2.56.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net v2 2/2] net: wwan: iosm: fix S3 resume by re-binding the driver around it
2026-11-19 4:27 ` [PATCH net v2 2/2] net: wwan: iosm: fix S3 resume by re-binding the driver around it David Westen
@ 2026-11-22 20:01 ` Maciej S. Szmigiero
2026-11-23 3:17 ` David Westen
2026-11-23 5:17 ` netdev-bot+sashiko
1 sibling, 1 reply; 6+ messages in thread
From: Maciej S. Szmigiero @ 2026-11-22 20:01 UTC (permalink / raw)
To: David Westen
Cc: loic.poulain, ryazanov.s.a, johannes, andrew+netdev, davem,
edumazet, kuba, pabeni, linux-kernel, nihaal, stable, netdev
On 19.11.2026 05:27, David Westen wrote:
> On platforms where S3 cuts power to the WWAN card, the modem boots
> again while the system sleeps, but the driver still treats it as
> running. After resume its execution stage reads BOOT, and by the
> first port open the boot code has crashed into the CD_READY stage:
>
> iosm 0000:03:00.0: PORT open refused, phase A-CD_READY
>
> The modem then stays unusable until an ACPI reset.
>
> Unbind the driver before S3 and bind it again after resume, as
> commit 0b6f6593aa8c ("net: wwan: iosm: Fix hibernation by re-binding
> the driver around it") already does for hibernation. The driver is
> then torn down while the modem still answers, and the modem is probed
> again once it has booted.
>
> The target state isn't known yet when the PM notifier runs, so the
> default suspend mode decides: the driver is re-bound unless "mem" maps
> to suspend-to-idle, which keeps using the suspend/resume callbacks.
> This changes behavior in a few cases:
>
> - On platforms that keep the card powered in S3, the modem is now
> probed again on resume, which drops data sessions and recreates its
> ports.
> - Entering suspend-to-idle or standby explicitly while the default is
> S3 also re-binds the driver.
I think this re-binding should never happen on s2idle, even though S3
might be the default mem sleep method.
It looks to me that the only remaining case here is the "opportunistic
sleep" code which does not use mem_sleep_current (so won't be covered by
pm_suspend_default_s2idle()) - but uses autosleep_state instead.
> - A suspend to S3 that calls pm_suspend(PM_SUSPEND_MEM) directly while
> the default is suspend-to-idle is not covered and fails as before.
Are there any such pm_suspend(PM_SUSPEND_MEM) calls in the kernel (outside
some test code)?
>
> Fixes: 1f52d7b62285 ("net: wwan: iosm: Enable M.2 7360 WWAN card support")
> Cc: stable@vger.kernel.org
> Signed-off-by: David Westen <davidlwesten@gmail.com>
> ---
>
> Notes:
> Changes in v2:
> - New patch before this one: cancel the ADB timer in ipc_imem_cleanup().
> - Describe the changes in behavior and the remaining limits in the
> changelog, and say in the comment that the modem "may" lose power.
> - I also tried detecting the power loss on resume instead; my reply to
> the v1 review explains why v2 keeps unbinding before suspend.
> - Correction to that reply: the XMM7360 here does use MUX aggregation
> (CP capability 0x300), so the ADB timer is armed on it too.
>
> v1: https://lore.kernel.org/r/20261116031148.333990-1-davidlwesten@gmail.com
>
> Tested on an XMM7360 (ThinkPad X1 Carbon 6th gen, deep sleep) with this
> series applied to 7.2.15: the driver is unbound before suspend, and
> after resume the modem is probed again and comes up without an ACPI
> reset. Not tested on the XMM7560.
>
> The investigation and the patches were done with an AI coding assistant
> (Claude Opus 5.5). It read the driver and added temporary debug logging
> to record the execution stage around suspend and resume. We wrote the
> changes and the changelogs together, and I ran the tests.
>
> drivers/net/wwan/iosm/iosm_ipc_pcie.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/wwan/iosm/iosm_ipc_pcie.c b/drivers/net/wwan/iosm/iosm_ipc_pcie.c
> index 49052eb511ba..13e81012d818 100644
> --- a/drivers/net/wwan/iosm/iosm_ipc_pcie.c
> +++ b/drivers/net/wwan/iosm/iosm_ipc_pcie.c
> @@ -534,12 +534,17 @@ void ipc_pcie_kfree_skb(struct iosm_pcie *ipc_pcie, struct sk_buff *skb)
>
> static int pm_notify(struct notifier_block *nb, unsigned long mode, void *_unused)
> {
> - if (mode == PM_HIBERNATION_PREPARE || mode == PM_RESTORE_PREPARE) {
> + /* The modem may lose power in S3 and S4 and boot again on resume,
> + * which the suspend/resume callbacks can't handle, so probe it again.
> + */
> + if (mode == PM_HIBERNATION_PREPARE || mode == PM_RESTORE_PREPARE ||
> + (mode == PM_SUSPEND_PREPARE && !pm_suspend_default_s2idle())) {
> if (pci_registered) {
> pci_unregister_driver(&iosm_ipc_driver);
> pci_registered = false;
> }
> - } else if (mode == PM_POST_HIBERNATION || mode == PM_POST_RESTORE) {
> + } else if (mode == PM_POST_HIBERNATION || mode == PM_POST_RESTORE ||
> + mode == PM_POST_SUSPEND) {
> if (!pci_registered) {
> int ret;
>
Thanks,
Maciej
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net v2 2/2] net: wwan: iosm: fix S3 resume by re-binding the driver around it
2026-11-22 20:01 ` Maciej S. Szmigiero
@ 2026-11-23 3:17 ` David Westen
0 siblings, 0 replies; 6+ messages in thread
From: David Westen @ 2026-11-23 3:17 UTC (permalink / raw)
To: Maciej S. Szmigiero
Cc: loic.poulain, ryazanov.s.a, johannes, andrew+netdev, davem,
edumazet, kuba, pabeni, linux-kernel, nihaal, stable, netdev
Hi Maciej,
Thanks for the review!
On 11/22/26 12:01 PM, Maciej S. Szmigiero wrote:
> On 19.11.2026 05:27, David Westen wrote:
>> - Entering suspend-to-idle or standby explicitly while the default is
>> S3 also re-binds the driver.
>
> I think this re-binding should never happen on s2idle, even though S3
> might be the default mem sleep method.
>
> It looks to me that the only remaining case here is the "opportunistic
> sleep" code which does not use mem_sleep_current (so won't be covered by
> pm_suspend_default_s2idle()) - but uses autosleep_state instead.
Agreed, that would be better. The problem is that the PM notifier
isn't told the target state, and pm_suspend_target_state is only set
after PM_SUSPEND_PREPARE, so the default was the closest the driver
could get on its own.
Covering both cases would need the PM core to make the target state
available before the notifiers run, like pm_suspend_notify_state in
your earlier S3 patch. Do you think that's needed for this fix, or
would it be acceptable as a follow-up?
>> - A suspend to S3 that calls pm_suspend(PM_SUSPEND_MEM) directly while
>> the default is suspend-to-idle is not covered and fails as before.
>
> Are there any such pm_suspend(PM_SUSPEND_MEM) calls in the kernel (outside
> some test code)?
I found a few: APM emulation, pseries, via-pmu, ZynqMP, SCMI power
control and the SPI slave system control driver. None of them seem to
be x86 ones.
David
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net v2 1/2] net: wwan: iosm: cancel the ADB timer on cleanup
2026-11-19 4:27 [PATCH net v2 1/2] net: wwan: iosm: cancel the ADB timer on cleanup David Westen
2026-11-19 4:27 ` [PATCH net v2 2/2] net: wwan: iosm: fix S3 resume by re-binding the driver around it David Westen
@ 2026-11-23 5:17 ` netdev-bot+sashiko
1 sibling, 0 replies; 6+ messages in thread
From: netdev-bot+sashiko @ 2026-11-23 5:17 UTC (permalink / raw)
To: davidlwesten
Cc: netdev, loic.poulain, ryazanov.s.a, johannes, andrew+netdev,
davem, edumazet, kuba, pabeni, m.chetan.kumar, linux-kernel, mail,
nihaal, stable
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 0
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 adds hrtimer_cancel(&ipc_imem->adb_timer) to
ipc_imem_cleanup() (drivers/net/wwan/iosm/iosm_ipc_imem.c:1242).
--
net: wwan: iosm: cancel the ADB timer on cleanup
This patch adds an hrtimer_cancel() for adb_timer to ipc_imem_cleanup(),
next to the cancels for the other imem hrtimers. The aim is to stop a
pending ADB timer from queueing a task that finishes the ADB on the freed
MUX, and to keep the hrtimer from being freed with the imem while it is
still enqueued.
> diff --git a/drivers/net/wwan/iosm/iosm_ipc_imem.c b/drivers/net/wwan/iosm/iosm_ipc_imem.c
> index 4405c85318880..20f8da53a3ea7 100644
> --- a/drivers/net/wwan/iosm/iosm_ipc_imem.c
> +++ b/drivers/net/wwan/iosm/iosm_ipc_imem.c
> @@ -1239,6 +1239,7 @@ void ipc_imem_cleanup(struct iosm_imem *ipc_imem)
> hrtimer_cancel(&ipc_imem->tdupdate_timer);
> hrtimer_cancel(&ipc_imem->fast_update_timer);
> hrtimer_cancel(&ipc_imem->startup_timer);
> + hrtimer_cancel(&ipc_imem->adb_timer);
[Severity: High]
Does this cancel fully close the use-after-free that the commit message
describes? When it runs, the netdev TX path, the IRQ handler and the
ipc_task tasklet are all still live. Any of them can re-arm adb_timer
before ipc_mux_deinit() frees the MUX.
ipc_imem_adb_timer_start() only checks whether the timer is already
active:
void ipc_imem_adb_timer_start(struct iosm_imem *ipc_imem)
{
if (!hrtimer_active(&ipc_imem->adb_timer)) {
...
hrtimer_start(&ipc_imem->adb_timer,
ipc_imem->hrtimer_period,
HRTIMER_MODE_REL);
}
}
The netdevs stay registered until ipc_wwan_deinit(), and the TX queues
are only stopped inside ipc_mux_deinit(). So TX traffic during cleanup can
still go through this path:
ipc_mux_ul_trigger_encode()
ipc_task_queue_send_task(ipc_mux_tq_ul_trigger_encode)
ipc_mux_tq_ul_trigger_encode()
ipc_mux_ul_data_encode() /* only checks MUX_S_ACTIVE */
ipc_imem_adb_timer_start()
The mux state stays MUX_S_ACTIVE until ipc_mux_deinit(). That means the
timer can be re-armed for 500 us at any point between this new cancel and
ipc_mux_deinit(), including during
cancel_work_sync(&ipc_imem->run_state_worker).
ipc_imem_handle_irq() also calls ipc_imem_adb_timer_start(). Its only
guard is an unsynchronized check of ipc_imem->phase at the top. The MSI
IRQs stay requested until ipc_pcie_resources_release(), which runs after
ipc_imem_cleanup() returns.
Next, ipc_mux_deinit() calls kfree(ipc_mux) and leaves ipc_imem->mux
pointing at freed memory. After that, ipc_imem_device_ipc_uninit() polls
for up to 30 ms before ipc_task_deinit() is reached:
while ((ipc_state <= IPC_MEM_DEVICE_IPC_DONT_CARE) &&
(ipc_state != IPC_MEM_DEVICE_IPC_UNINIT) &&
(timeout > 0)) {
usleep_range(1000, 1250);
...
}
Could a re-armed 500 us timer fire inside this window and run this?
ipc_imem_adb_timer_cb()
ipc_task_queue_send_task(ipc_imem_tq_adb_timer_cb)
ipc_imem_tq_adb_timer_cb()
ipc_mux_ul_adb_finish(ipc_imem->mux) /* freed MUX */
ipc_mux_ul_adb_finish() writes through the MUX with no checks. It updates
adbh->sequence_nr and adb_tx_sequence_nr, and it calls skb_put() on
ul_adb->dest_skb, among other writes.
If the timer is still pending later, its callback would use the ipc_task
that ipc_imem_cleanup() has already freed. If it is still pending when
ipc_pcie_deinit() calls kfree(ipc_pcie->imem), the hrtimer embedded in the
imem is freed while it is still enqueued.
There is also a second case. Suppose adb_timer fired just before this
cancel. hrtimer_cancel() returns once the callback has finished, but the
ipc_imem_tq_adb_timer_cb entry that the callback queued (wait=false) is
still sitting in the ipc_task queue.
Nothing flushes that queue before the MUX is freed:
- cancel_work_sync() only covers the workqueue.
- In IPC_P_OFF_REQ, ipc_imem_channel_close() skips the synchronous pipe
close messages, so ipc_mux_deinit() doesn't flush the tasklet either.
- tasklet_kill() in ipc_task_deinit() waits for an already-scheduled
tasklet to run instead of dropping it, and it is only reached after
kfree(ipc_mux).
If the tasklet is delayed (BH disabled, ksoftirqd, PREEMPT_RT), can that
stale entry run ipc_mux_ul_adb_finish() on the freed MUX?
The next patch in the series, "net: wwan: iosm: fix S3 resume by
re-binding the driver around it", doesn't change ipc_imem_cleanup(). It
does run this teardown from the PM_SUSPEND_PREPARE notifier on every
non-s2idle suspend, and that happens before tasks are frozen. With that
patch, live TX traffic during teardown becomes the normal case.
Would it make sense to stop the producers (netif TX, the IRQ and the
tasklet) before ipc_mux_deinit(), and cancel adb_timer after that point or
add a second cancel there? Two other options would be to skip
ipc_imem_adb_timer_start() once teardown has begun, and to keep
ipc_imem_tq_adb_timer_cb() from using a stale ipc_imem->mux.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119042714.505405-1-davidlwesten%40gmail.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net v2 2/2] net: wwan: iosm: fix S3 resume by re-binding the driver around it
2026-11-19 4:27 ` [PATCH net v2 2/2] net: wwan: iosm: fix S3 resume by re-binding the driver around it David Westen
2026-11-22 20:01 ` Maciej S. Szmigiero
@ 2026-11-23 5:17 ` netdev-bot+sashiko
1 sibling, 0 replies; 6+ messages in thread
From: netdev-bot+sashiko @ 2026-11-23 5:17 UTC (permalink / raw)
To: davidlwesten
Cc: netdev, loic.poulain, ryazanov.s.a, johannes, andrew+netdev,
davem, edumazet, kuba, pabeni, m.chetan.kumar, linux-kernel, mail,
nihaal, stable
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 1 · 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] Use-after-free in the remove path, which this patch now runs on
every S3 suspend while the modem is live.
- [Medium] When the card keeps power, the modem now goes into system
sleep fully awake.
- [Low] The new PM_POST_SUSPEND branch in pm_notify() registers the
driver again based only on the global `pci_registered` flag, which…
- [Low] The stable backport prerequisite is not declared.
--
net: wwan: iosm: fix S3 resume by re-binding the driver around it
This patch extends the iosm PM notifier. It now unregisters the PCI driver
on PM_SUSPEND_PREPARE, unless the default suspend mode is s2idle, and
registers it again on PM_POST_SUSPEND. This reuses the hibernation
mechanism from commit 0b6f6593aa8c, so the modem is probed again after it
reboots during S3.
> Fixes: 1f52d7b62285 ("net: wwan: iosm: Enable M.2 7360 WWAN card support")
> Cc: stable@vger.kernel.org
[Severity: Low]
Will this apply to the stable trees that this Fixes: tag selects?
Commit 0b6f6593aa8c ("net: wwan: iosm: Fix hibernation by re-binding the
driver around it") added pm_notify(), pm_notifier and pci_registered. That
commit has no Fixes: or Cc: stable tag. A tree that has 1f52d7b62285 but
not 0b6f6593aa8c has no pm_notify() at all.
Could the prerequisite be named, for example with
"Cc: stable@vger.kernel.org # depends on 0b6f6593aa8c"?
The dependency on the preceding ADB timer patch is only described below
the --- line. That patch carries the same Fixes: and stable tags, so that
part is less of a concern.
> diff --git a/drivers/net/wwan/iosm/iosm_ipc_pcie.c b/drivers/net/wwan/iosm/iosm_ipc_pcie.c
> index 49052eb511baa..13e81012d818c 100644
> --- a/drivers/net/wwan/iosm/iosm_ipc_pcie.c
> +++ b/drivers/net/wwan/iosm/iosm_ipc_pcie.c
> @@ -534,12 +534,17 @@ void ipc_pcie_kfree_skb(struct iosm_pcie *ipc_pcie, struct sk_buff *skb)
>
> static int pm_notify(struct notifier_block *nb, unsigned long mode, void *_unused)
> {
> - if (mode == PM_HIBERNATION_PREPARE || mode == PM_RESTORE_PREPARE) {
> + /* The modem may lose power in S3 and S4 and boot again on resume,
> + * which the suspend/resume callbacks can't handle, so probe it again.
> + */
> + if (mode == PM_HIBERNATION_PREPARE || mode == PM_RESTORE_PREPARE ||
> + (mode == PM_SUSPEND_PREPARE && !pm_suspend_default_s2idle())) {
> if (pci_registered) {
> pci_unregister_driver(&iosm_ipc_driver);
> pci_registered = false;
> }
[Severity: High]
Can this expose a use-after-free of ipc_imem->ipc_task on every S3
suspend?
Here pci_unregister_driver() goes through ipc_pcie_remove() into
ipc_pcie_cleanup(). That function frees the imem resources before it
releases the MSI handlers:
drivers/net/wwan/iosm/iosm_ipc_pcie.c:ipc_pcie_cleanup() {
/* Free the shared memory resources. */
ipc_imem_cleanup(ipc_pcie->imem);
ipc_pcie_resources_release(ipc_pcie);
...
}
Inside ipc_imem_cleanup(), the CP is told to go to IPC UNINIT. Then the
tasklet and its container are freed, and the pointer is not cleared:
drivers/net/wwan/iosm/iosm_ipc_imem.c:ipc_imem_cleanup() {
...
ipc_imem_device_ipc_uninit(ipc_imem);
ipc_imem_channel_reset(ipc_imem);
ipc_protocol_deinit(ipc_imem->ipc_protocol);
ipc_task_deinit(ipc_imem->ipc_task);
kfree(ipc_imem->ipc_task);
...
}
The threaded MSI handler is still registered at that point. Its only gate
is the s2idle suspend bit, and this path never sets it:
drivers/net/wwan/iosm/iosm_ipc_irq.c:ipc_msi_interrupt() {
...
if (!test_bit(0, &ipc_pcie->suspend))
ipc_imem_irq_process(ipc_pcie->imem, instance);
...
}
ipc_imem_irq_process() only checks ev_irq_pending[irq].
ipc_imem_handle_irq() clears that flag before its IPC_P_OFF_REQ early
return, so the flag doesn't block a new enqueue either.
An MSI that arrives after tasklet_kill() in ipc_task_deinit() schedules
the tasklet again just before it is kfree'd. An MSI that arrives after
kfree(ipc_imem->ipc_task) makes ipc_task_queue_add_task() read and write
the freed structure:
struct tasklet_struct *ipc_tasklet = ipc_imem->ipc_task->ipc_tasklet;
struct ipc_task_queue *ipc_task = &ipc_imem->ipc_task->ipc_queue;
...
spin_lock_irqsave(&ipc_task->q_lock, flags);
...
tasklet_schedule(ipc_tasklet);
The softirq could then run that tasklet after ipc_pcie_deinit() has also
freed imem and ipc_pcie.
The unbind and hibernation paths already use this ordering. This patch
puts it on the S3 path while the modem is running and has just been told
to go to UNINIT. Could the MSIs be quiesced or freed before
ipc_imem_cleanup() tears down the tasklet?
[Severity: Medium]
Does the modem now enter system sleep in D0 with its firmware still
running? This applies when the card keeps power in S3, or when freeze or
standby is entered while mem_sleep is deep.
The driver is unbound at PM_SUSPEND_PREPARE, so ipc_pcie_suspend_cb() no
longer runs and neither sleep handshake is sent:
switch (ipc_pcie->d3l2_support) {
case IPC_PCIE_D0L12:
ipc_pcie_suspend_s2idle(ipc_pcie);
break;
case IPC_PCIE_D3L2:
ipc_pcie_suspend(ipc_pcie);
break;
}
This skips both the IPC_MEM_DEV_PM_FORCE_SLEEP doorbell and the
ipc_imem_pm_suspend() host sleep message.
The PCI core also stops putting the device into a low power state. With no
driver bound, pci_pm_suspend_noirq() takes this branch and never reaches
pci_prepare_to_sleep():
drivers/pci/pci-driver.c:pci_pm_suspend_noirq() {
...
if (!pm) {
pci_save_state(pci_dev);
goto set_unknown;
}
...
}
Before suspend, the modem only gets IPC UNINIT from
ipc_imem_device_ipc_uninit(), which is not a sleep request.
Could this raise sleep power, or keep the platform out of S0ix during an
explicit s2idle? The changelog lists lost data sessions for these cases,
but it doesn't mention this.
> - } else if (mode == PM_POST_HIBERNATION || mode == PM_POST_RESTORE) {
> + } else if (mode == PM_POST_HIBERNATION || mode == PM_POST_RESTORE ||
> + mode == PM_POST_SUSPEND) {
> if (!pci_registered) {
> int ret;
[Severity: Low]
Can this register the driver again in the middle of a uswsusp
hibernation?
The hibernation and suspend paths now share pci_registered.
snapshot_open() sends PM_HIBERNATION_PREPARE, which unbinds iosm. It then
drops system_transition_mutex while /dev/snapshot stays open:
kernel/power/user.c:snapshot_open() {
...
error = pm_notifier_call_chain_robust(PM_HIBERNATION_PREPARE, PM_POST_HIBERNATION);
...
Unlock:
unlock_system_sleep(sleep_flags);
...
}
enter_state() only does a trylock on that mutex:
if (!mutex_trylock(&system_transition_mutex))
return -EBUSY;
Suppose a suspend to RAM starts before SNAPSHOT_FREEZE. PM_SUSPEND_PREPARE
does nothing because the driver is already unregistered. PM_POST_SUSPEND
then calls pci_register_driver() and sets pci_registered = true.
The hibernation image would then be created with iosm bound. The later
PM_POST_HIBERNATION from snapshot_release() does nothing, so the unbind
added by 0b6f6593aa8c is lost. Before this patch PM_POST_SUSPEND was
ignored, so this couldn't happen.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119042714.505405-1-davidlwesten%40gmail.com
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-23 5:17 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 4:27 [PATCH net v2 1/2] net: wwan: iosm: cancel the ADB timer on cleanup David Westen
2026-11-19 4:27 ` [PATCH net v2 2/2] net: wwan: iosm: fix S3 resume by re-binding the driver around it David Westen
2026-11-22 20:01 ` Maciej S. Szmigiero
2026-11-23 3:17 ` David Westen
2026-11-23 5:17 ` netdev-bot+sashiko
2026-11-23 5:17 ` [PATCH net v2 1/2] net: wwan: iosm: cancel the ADB timer on cleanup netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox