* [PATCH net v3 0/2] net: wwan: iosm: fix S3 resume by re-binding the driver after it
@ 2026-11-26 19:41 David Westen
2026-11-26 19:41 ` [PATCH net v3 1/2] net: wwan: iosm: free the MUX after the netdevs that use it David Westen
2026-11-26 19:41 ` [PATCH net v3 2/2] net: wwan: iosm: re-bind the driver when the modem rebooted during S3 David Westen
0 siblings, 2 replies; 7+ messages in thread
From: David Westen @ 2026-11-26 19:41 UTC (permalink / raw)
To: netdev
Cc: Loic Poulain, Sergey Ryazanov, Johannes Berg, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
M Chetan Kumar, Maciej S. Szmigiero, David Westen
On platforms where S3 cuts power to the WWAN card, the modem boots again
on its own while the driver still treats it as running, and the modem
can't be used after resume until the driver is re-bound. Patch 2 detects
this on resume and re-binds the driver then. Patch 1 fixes a
use-after-free in the cleanup, which the re-bind would hit with wwan0 up.
v2 unbound the driver before every S3 suspend. That runs the cleanup
against a modem that is still running, and the AI review and my tests
showed how many ways that goes wrong: the modem kept writing into the
freed MUX buffers (DMA faults with a strict IOMMU), and timers, tasks
and MSIs could outlive what they use. Fixing that properly means
reworking the cleanup. v3 instead lets the modem lose power, as it did
before, and re-binds the driver after resume, when the modem no longer
holds any of the driver's memory.
Changes in v3:
- Re-bind after resume, and only if the modem rebooted, instead of
unbinding before every S3 suspend. Nothing changes where the card
keeps power in S3 (AI review), or for s2idle, opportunistic sleep and
an explicit freeze or standby (Maciej).
- Dropped "cancel the ADB timer on cleanup". Closing that race for a
normal unbind needs a larger rework of the cleanup; patch 2 keeps the
re-bind out of it, and out of the MSI race the AI review found.
- New patch 1.
On the ThinkPad X1 Carbon 6th gen I tested on, S3 takes the same suspend
path as s2idle, and the modem crashes before it loses power. That is
where the CD_READY in patch 2's log comes from. The s2idle series [1]
removes that crash, but the modem still boots again after S3, so both
are needed there. They don't depend on each other.
Tested on an XMM7360 in that ThinkPad:
- With KASAN, lockdep and a strict IOMMU: re-bound and connected again
after each of five S3 cycles, also with wwan0 up through the suspend;
no re-bind after s2idle; three unbinds with wwan0 up and traffic. No
reports.
- Together with the s2idle series, on a kernel without debug options:
the same, and s2idle connected again without a re-bind.
Not tested: the XMM7560 (MUX aggregation), platforms that use the D3L2
path, and hibernation, which this series doesn't change. Known limits:
- On the D3L2 path, interrupts from the rebooted modem reach the driver
until its resume callback runs, as without this series.
- A modem that stays in its boot stage after losing power delays the end
of resume by up to 10 s before the re-bind.
- For a normal unbind, the cleanup races with the ADB timer and with
MSIs are unchanged.
- Re-binding three times or more without a power cycle can leave the
link without downlink until the bearer is reconnected. That happens
without this series too, and doesn't affect S3, where the modem loses
power.
Patch 2 builds on commit 0b6f6593aa8c ("net: wwan: iosm: Fix hibernation
by re-binding the driver around it").
[1] https://lore.kernel.org/r/20261124172505.41520-1-davidlwesten@gmail.com
v2: https://lore.kernel.org/r/20261119042714.505405-1-davidlwesten@gmail.com
v1: https://lore.kernel.org/r/20261116031148.333990-1-davidlwesten@gmail.com
The investigation and the patches were done with an AI coding assistant
(Claude Opus 5.5). We wrote the patches together, and I ran the tests.
David Westen (2):
net: wwan: iosm: free the MUX after the netdevs that use it
net: wwan: iosm: re-bind the driver when the modem rebooted during S3
drivers/net/wwan/iosm/iosm_ipc_imem.c | 54 ++++++++++++++++++++--
drivers/net/wwan/iosm/iosm_ipc_imem.h | 18 ++++++++
drivers/net/wwan/iosm/iosm_ipc_imem_ops.c | 4 ++
drivers/net/wwan/iosm/iosm_ipc_irq.c | 3 ++
drivers/net/wwan/iosm/iosm_ipc_mux_codec.c | 6 +++
drivers/net/wwan/iosm/iosm_ipc_pcie.c | 37 +++++++++++++++
drivers/net/wwan/iosm/iosm_ipc_protocol.c | 3 ++
7 files changed, 121 insertions(+), 4 deletions(-)
--
2.56.0
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH net v3 1/2] net: wwan: iosm: free the MUX after the netdevs that use it 2026-11-26 19:41 [PATCH net v3 0/2] net: wwan: iosm: fix S3 resume by re-binding the driver after it David Westen @ 2026-11-26 19:41 ` David Westen 2026-11-27 19:50 ` netdev-bot+sashiko 2026-11-26 19:41 ` [PATCH net v3 2/2] net: wwan: iosm: re-bind the driver when the modem rebooted during S3 David Westen 1 sibling, 1 reply; 7+ messages in thread From: David Westen @ 2026-11-26 19:41 UTC (permalink / raw) To: netdev Cc: Loic Poulain, Sergey Ryazanov, Johannes Berg, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, M Chetan Kumar, Maciej S. Szmigiero, David Westen ipc_imem_cleanup() frees the MUX before it removes the netdevs, so closing a netdev that is up uses the freed MUX: BUG: KASAN: slab-use-after-free in ipc_mux_close_session Call Trace: ipc_mux_close_session ipc_wwan_link_stop __dev_close_many wwan_unregister_ops ipc_wwan_deinit ipc_imem_cleanup ipc_pcie_remove Free the MUX last, after debugfs, the ports and the netdevs. Closing the netdev then tells the modem to close the session, so that it stops writing into the MUX buffers before they are freed. The reply is ignored, as for the port closes. Ring the doorbell for the command at once, as the cleanup has already cancelled the TD update timer. Reproduced with KASAN on an XMM7360 by unbinding the driver while wwan0 is up. With this change, three such unbinds show no report. Fixes: 3670970dd8c6 ("net: iosm: shared memory IPC interface") Signed-off-by: David Westen <davidlwesten@gmail.com> --- drivers/net/wwan/iosm/iosm_ipc_imem.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/net/wwan/iosm/iosm_ipc_imem.c b/drivers/net/wwan/iosm/iosm_ipc_imem.c index 4405c8531888..3ab409166c50 100644 --- a/drivers/net/wwan/iosm/iosm_ipc_imem.c +++ b/drivers/net/wwan/iosm/iosm_ipc_imem.c @@ -178,7 +178,8 @@ void ipc_imem_msg_send_feature_set(struct iosm_imem *ipc_imem, void ipc_imem_td_update_timer_start(struct iosm_imem *ipc_imem) { /* Use the TD update timer only in the runtime phase */ - if (!ipc_imem->enter_runtime || ipc_imem->td_update_timer_suspended) { + if (!ipc_imem->enter_runtime || ipc_imem->td_update_timer_suspended || + ipc_imem->phase == IPC_P_OFF_REQ) { /* trigger the doorbell irq on CP directly. */ ipc_protocol_doorbell_trigger(ipc_imem->ipc_protocol, IPC_HP_TD_UPD_TMR_START); @@ -1244,10 +1245,10 @@ void ipc_imem_cleanup(struct iosm_imem *ipc_imem) cancel_work_sync(&ipc_imem->run_state_worker); if (test_and_clear_bit(FULLY_FUNCTIONAL, &ipc_imem->flag)) { - ipc_mux_deinit(ipc_imem->mux); ipc_debugfs_deinit(ipc_imem); - ipc_wwan_deinit(ipc_imem->wwan); ipc_port_deinit(ipc_imem->ipc_port); + ipc_wwan_deinit(ipc_imem->wwan); + ipc_mux_deinit(ipc_imem->mux); } if (test_and_clear_bit(IOSM_DEVLINK_INIT, &ipc_imem->flag)) -- 2.56.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH net v3 1/2] net: wwan: iosm: free the MUX after the netdevs that use it 2026-11-26 19:41 ` [PATCH net v3 1/2] net: wwan: iosm: free the MUX after the netdevs that use it David Westen @ 2026-11-27 19:50 ` netdev-bot+sashiko 0 siblings, 0 replies; 7+ messages in thread From: netdev-bot+sashiko @ 2026-11-27 19:50 UTC (permalink / raw) To: davidlwesten Cc: netdev, loic.poulain, ryazanov.s.a, johannes, andrew+netdev, davem, edumazet, kuba, pabeni, m.chetan.kumar, mail Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider. Critical: 0 · High: 0 (1) · Medium: 4 (1) · 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). - [Medium] During ipc_imem_cleanup(), each netdev that is up now runs a blocking MUX CLOSE_SESSION command. - [Medium] The commit message says closing the netdev tells the modem to close the session "so that it stops writing into the MUX buffers… - [Medium] The CLOSE_SESSION command issued by the netdev close runs asynchronously in tasklet context, and nothing in ipc_imem_cleanup()… - [Medium] The new IPC_P_OFF_REQ branch in ipc_imem_td_update_timer_start() assumes… Pre-existing issues: - [High] This problem wasn't introduced by this patch, but ipc_mux_deinit() frees the MUX and nothing clears ipc_imem->mux. - [Medium] Concern: ipc_imem_cleanup() cancels td_alloc_timer, tdupdate_timer, fast_update_timer and startup_timer but never… -- net: wwan: iosm: free the MUX after the netdevs that use it This patch reorders ipc_imem_cleanup() so the MUX is freed after debugfs, the ports and the wwan netdevs. It fixes a KASAN use-after-free that hits when a netdev that is up gets closed during unbind. It also makes ipc_imem_td_update_timer_start() ring the doorbell directly during the IPC_P_OFF_REQ phase. > diff --git a/drivers/net/wwan/iosm/iosm_ipc_imem.c b/drivers/net/wwan/iosm/iosm_ipc_imem.c > index 4405c85318880..3ab409166c506 100644 > --- a/drivers/net/wwan/iosm/iosm_ipc_imem.c > +++ b/drivers/net/wwan/iosm/iosm_ipc_imem.c > @@ -178,7 +178,8 @@ void ipc_imem_msg_send_feature_set(struct iosm_imem *ipc_imem, > void ipc_imem_td_update_timer_start(struct iosm_imem *ipc_imem) > { > /* Use the TD update timer only in the runtime phase */ > - if (!ipc_imem->enter_runtime || ipc_imem->td_update_timer_suspended) { > + if (!ipc_imem->enter_runtime || ipc_imem->td_update_timer_suspended || > + ipc_imem->phase == IPC_P_OFF_REQ) { > /* trigger the doorbell irq on CP directly. */ > ipc_protocol_doorbell_trigger(ipc_imem->ipc_protocol, > IPC_HP_TD_UPD_TMR_START); [Severity: Medium] Does this doorbell reach the modem when the CP is in device sleep? ipc_protocol_doorbell_trigger() goes through ipc_pm_signal_hpda_doorbell() with host_slp_check=true. If the link is asleep, ipc_pm_trigger() calls ipc_pm_link_activate(). That function only sends the wakeup sleep-control IRQ and returns false: drivers/net/wwan/iosm/iosm_ipc_pm.c:ipc_pm_link_activate() { ... ipc_cp_irq_sleep_control(ipc_pm->pcie, IPC_MEM_DEV_PM_WAKEUP); ipc_pm->ap_state = IPC_MEM_DEV_PM_ACTIVE_WAIT; goto not_active; ... } ipc_pm_signal_hpda_doorbell() then only latches the update: if (!ipc_pm_trigger(ipc_pm, IPC_PM_UNIT_IRQ, true)) { ipc_pm->pending_hpda_update = true; ... return; } Only ipc_pm_on_link_wake() flushes pending_hpda_update. It is reached via ipc_imem_slp_control_exec() from ipc_imem_handle_irq(), which returns early for the whole cleanup: if (old_phase == IPC_P_OFF_REQ) { Take an idle wwan0 with the modem in device sleep, which is enabled by default via ipc_imem_msg_send_device_sleep(). In that state, would CLOSE_SESSION be written to the UL TD ring without the HP doorbell ever firing, and the PM handshake be left in IPC_MEM_DEV_PM_ACTIVE_WAIT? Whether the CP still processes the TD ring after the wakeup IRQ, without an HP doorbell, depends on the firmware. > @@ -1244,10 +1245,10 @@ void ipc_imem_cleanup(struct iosm_imem *ipc_imem) > cancel_work_sync(&ipc_imem->run_state_worker); > > if (test_and_clear_bit(FULLY_FUNCTIONAL, &ipc_imem->flag)) { > - ipc_mux_deinit(ipc_imem->mux); > ipc_debugfs_deinit(ipc_imem); > - ipc_wwan_deinit(ipc_imem->wwan); > ipc_port_deinit(ipc_imem->ipc_port); > + ipc_wwan_deinit(ipc_imem->wwan); [Severity: Medium] Can this stall unbind for a full second per active session while RTNL is held? ipc_imem_cleanup() sets ipc_imem->phase = IPC_P_OFF_REQ before it gets here, and the MUX is now still MUX_S_ACTIVE when the netdevs are closed: wwan_unregister_ops() <- rtnl_lock() unregister_netdevice_many() ipc_wwan_link_stop() ipc_imem_sys_wwan_close() ipc_mux_close_session() ipc_mux_schedule(MUX_E_MUX_SESSION_CLOSE) ipc_mux_session_close() ipc_mux_dl_acb_send_cmds(..., blocking=true) ipc_mux_acb_send() ipc_mux_acb_send() waits on channel->ul_sem for up to IPC_MUX_CMD_RUN_DEFAULT_TIMEOUT (1000 ms). For a MUX command, only ipc_mux_dl_cmdresps_decode_process() completes ul_sem. It is reached only via ipc_imem_dl_pipe_process() from ipc_imem_handle_irq(), which drops every MSI in IPC_P_OFF_REQ: if (old_phase == IPC_P_OFF_REQ) { dev_dbg(... "Ignoring MSI. Deinit sequence in progress!" ...); return; So the wait always runs out. After the timeout, ipc_mux_acb_send() logs "ch[%d] timeout" and sends UEVENT_MDM_TIMEOUT right after MDM_NOT_READY. ipc_mux_session_close() then logs "CLOSE_SESSION send failed". This repeats for each session that is up, up to IPC_MEM_MUX_IP_SESSION_ENTRIES, all under RTNL. Nothing gates it on the link being active, so surprise removal hits it too. The port closes behave much the same, since ipc_protocol_msg_send() waits 500 ms per pipe. So "The reply is ignored, as for the port closes" is accurate, but those waits do not happen under RTNL. The later patch in the series ("re-bind the driver when the modem rebooted during S3") short-circuits ipc_mux_dl_acb_send_cmds() only when IOSM_MODEM_GONE is set, so a normal unbind still stalls. Should the session close be skipped or made non-blocking during cleanup? If not, should the commit message at least mention the stall? > + ipc_mux_deinit(ipc_imem->mux); [Severity: Medium] The commit message says closing the netdev "tells the modem to close the session, so that it stops writing into the MUX buffers before they are freed". Is that ordering actually enforced? In IPC_P_OFF_REQ the CLOSE_SESSION reply is never decoded, so the host never learns whether the modem acted on it. The wait in ipc_mux_acb_send() is interruptible, and only a 0 return counts as failure. A pending signal makes it return -ERESTARTSYS at once: if (wait_for_completion_interruptible_timeout (completion, msecs_to_jiffies(wait_time_milliseconds)) == 0) { When the last session closes, ipc_mux_channel_close() calls ipc_imem_channel_close(). That skips the PIPE_CLOSE messages but still frees the TD buffers: if (ipc_imem->phase == IPC_P_RUN) { ipc_imem_pipe_close(ipc_imem, &channel->ul_pipe); ipc_imem_pipe_close(ipc_imem, &channel->dl_pipe); } ipc_imem_pipe_cleanup(ipc_imem, &channel->ul_pipe); ipc_imem_pipe_cleanup(ipc_imem, &channel->dl_pipe); ipc_imem_pipe_cleanup() -> ipc_protocol_pipe_cleanup() unmaps and frees the UL and DL skbs. That includes the CLOSE_SESSION ACB that was just doorbelled and the DL buffers the reply would be written into. The modem is told IPC_UNINIT only later, in ipc_imem_device_ipc_uninit(). Freeing the MUX pipe buffers without a device handshake predates this patch, but the patch adds a new TD that the device is told to process. If the modem reads the ACB or writes the response after these buffers are freed, can that cause an IOMMU fault? Without an IOMMU, can it cause a DMA write into freed memory? [Severity: Medium] Can the queued CLOSE_SESSION command still touch the MUX after ipc_mux_deinit() frees it? ipc_mux_acb_send() queues the command asynchronously: int ret = ipc_task_queue_send_task(ipc_mux->imem, ipc_mux_tq_cmd_send, 0, &ipc_mux->acb, sizeof(ipc_mux->acb), false); ipc_mux_tq_cmd_send() later does: struct iosm_mux *ipc_mux = ipc_imem->mux; ... skb_queue_tail(&ipc_mux->channel->ul_list, acb->skb); Only the interruptible wait above orders this before the free. If a signal is pending, that wait returns at once and the netdev teardown continues. ipc_mux_deinit() then calls kfree(ipc_mux) without clearing ipc_imem->mux. The tasklet is killed only later, in ipc_task_deinit(), which runs after the sleeping ipc_imem_device_ipc_uninit(). If the ipc_task tasklet has not run by the time of the kfree, ipc_mux_tq_cmd_send() would dereference the freed MUX. That is the same class of bug this patch is fixing. Does the MUX free need to happen after the task queue is drained, rather than just later in the sequence? [Severity: Medium] This isn't a bug introduced by this patch, but ipc_imem_cleanup() cancels four of the hrtimers and never cancels adb_timer: hrtimer_cancel(&ipc_imem->td_alloc_timer); hrtimer_cancel(&ipc_imem->tdupdate_timer); hrtimer_cancel(&ipc_imem->fast_update_timer); hrtimer_cancel(&ipc_imem->startup_timer); ipc_imem_adb_timer_start() has no IPC_P_OFF_REQ guard like the one added to ipc_imem_td_update_timer_start(). ipc_imem_tq_adb_timer_cb() calls ipc_mux_ul_adb_finish(ipc_imem->mux) on a pointer that is never cleared. ipc_mux_tq_ul_trigger_encode() can still arm adb_timer if it was queued before the phase store, and the phase check is a plain, unordered load. This patch makes the window much smaller, because ipc_mux_deinit() now runs after the port and netdev teardown. A use-after-free would now need the tasklet to be starved for that whole period. Only the MUX_AGGREGATION (7560) path uses adb_timer. The later patch in the series only adds an IOSM_MODEM_GONE check to ipc_imem_adb_timer_start(). Should adb_timer be cancelled along with the other timers? [Severity: High] This is a pre-existing issue, but ipc_mux_deinit() frees the MUX without clearing ipc_imem->mux. Does that leave a reachable use-after-free on the error path of ipc_imem_run_state_worker()? err_ipc_mux_deinit: ipc_mux_deinit(ipc_imem->mux); err_out: ipc_uevent_send(ipc_imem->dev, UEVENT_CD_READY_LINK_DOWN); ipc_imem_wwan_channel_init() can fail in three ways: the CP version reads back as -1, ipc_wwan_init() fails to allocate, or wwan_register_ops() fails. In each case the MUX is freed, FULLY_FUNCTIONAL is not set, and ipc_imem->mux is left dangling. The modem stays in the run phase, so later MSIs reach ipc_imem_handle_irq() in IPC_P_RUN: if (ipc_mux_ul_data_encode(ipc_imem->mux)) { ipc_imem_td_update_timer_start(ipc_imem); if (ipc_imem->mux->protocol == MUX_AGGREGATION) ipc_mux_ul_data_encode() handles a NULL pointer but not a dangling one. The ipc_imem->mux check in ipc_imem_sys_wwan_close() also assumes the pointer is cleared after the free. Would setting ipc_imem->mux to NULL after ipc_mux_deinit() fix this? It would also harden the cleanup path that this patch reorders. -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126194143.32283-1-davidlwesten%40gmail.com ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH net v3 2/2] net: wwan: iosm: re-bind the driver when the modem rebooted during S3 2026-11-26 19:41 [PATCH net v3 0/2] net: wwan: iosm: fix S3 resume by re-binding the driver after it David Westen 2026-11-26 19:41 ` [PATCH net v3 1/2] net: wwan: iosm: free the MUX after the netdevs that use it David Westen @ 2026-11-26 19:41 ` David Westen 2026-11-27 13:49 ` Maciej S. Szmigiero 2026-11-27 19:50 ` netdev-bot+sashiko 1 sibling, 2 replies; 7+ messages in thread From: David Westen @ 2026-11-26 19:41 UTC (permalink / raw) To: netdev Cc: Loic Poulain, Sergey Ryazanov, Johannes Berg, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, M Chetan Kumar, Maciej S. Szmigiero, David Westen On platforms where S3 cuts power to the WWAN card, the modem boots again while the driver still treats it as running, and the first port open after resume fails: iosm 0000:03:00.0: PORT open refused, phase A-CD_READY The driver takes this from a stale stage in the shared memory: on an XMM7360, the modem writes CD_READY there before it loses power. The modem itself is fine. On resume, read the stage from the MMIO area. If the modem booted again, mark it as gone: the driver then neither talks to it nor waits for it, and the cleanup only releases memory. Once the modem has reached the run stage, re-bind the driver, so that probe finds it as after a cold boot. Nothing changes where the card keeps power, and a crashed modem is left alone. Tested with S3 on an XMM7360 in a ThinkPad X1 Carbon 6th gen, with KASAN, lockdep and a strict IOMMU: five cycles, also with wwan0 up through the suspend. Fixes: 7e98d785ae61 ("net: iosm: entry point") Signed-off-by: David Westen <davidlwesten@gmail.com> --- drivers/net/wwan/iosm/iosm_ipc_imem.c | 47 +++++++++++++++++++++- drivers/net/wwan/iosm/iosm_ipc_imem.h | 18 +++++++++ drivers/net/wwan/iosm/iosm_ipc_imem_ops.c | 4 ++ drivers/net/wwan/iosm/iosm_ipc_irq.c | 3 ++ drivers/net/wwan/iosm/iosm_ipc_mux_codec.c | 6 +++ drivers/net/wwan/iosm/iosm_ipc_pcie.c | 37 +++++++++++++++++ drivers/net/wwan/iosm/iosm_ipc_protocol.c | 3 ++ 7 files changed, 117 insertions(+), 1 deletion(-) diff --git a/drivers/net/wwan/iosm/iosm_ipc_imem.c b/drivers/net/wwan/iosm/iosm_ipc_imem.c index 3ab409166c50..673c5ad403e7 100644 --- a/drivers/net/wwan/iosm/iosm_ipc_imem.c +++ b/drivers/net/wwan/iosm/iosm_ipc_imem.c @@ -208,6 +208,9 @@ void ipc_imem_hrtimer_stop(struct hrtimer *hr_timer) */ void ipc_imem_adb_timer_start(struct iosm_imem *ipc_imem) { + if (test_bit(IOSM_MODEM_GONE, &ipc_imem->flag)) + return; + if (!hrtimer_active(&ipc_imem->adb_timer)) { ipc_imem->hrtimer_period = ktime_set(0, IOSM_AGGR_MUX_ADB_FINISH_TIMEOUT_NSEC); @@ -1042,6 +1045,44 @@ void ipc_imem_pm_s2idle_sleep(struct iosm_imem *ipc_imem, bool sleep) ipc_protocol_s2idle_sleep(ipc_imem->ipc_protocol, sleep); } +bool ipc_imem_modem_rebooted(struct iosm_imem *ipc_imem) +{ + if (!test_bit(FULLY_FUNCTIONAL, &ipc_imem->flag)) + return false; + + switch (ipc_mmio_get_exec_stage(ipc_imem->mmio)) { + case IPC_MEM_EXEC_STAGE_RUN: + return ipc_mmio_get_ipc_state(ipc_imem->mmio) == + IPC_MEM_DEVICE_IPC_UNINIT; + case IPC_MEM_EXEC_STAGE_CRASH: + case IPC_MEM_EXEC_STAGE_CD_READY: + case IPC_MEM_EXEC_STAGE_INVALID: + return false; + default: + return true; + } +} + +bool ipc_imem_wait_for_run(struct iosm_imem *ipc_imem) +{ + int timeout = IPC_MODEM_BOOT_TIMEOUT; + + for (;;) { + switch (ipc_mmio_get_exec_stage(ipc_imem->mmio)) { + case IPC_MEM_EXEC_STAGE_RUN: + return true; + case IPC_MEM_EXEC_STAGE_CRASH: + case IPC_MEM_EXEC_STAGE_CD_READY: + return false; + default: + break; + } + if (!--timeout) + return false; + msleep(20); + } +} + void ipc_imem_pm_resume(struct iosm_imem *ipc_imem) { enum ipc_mem_exec_stage stage; @@ -1204,6 +1245,9 @@ static void ipc_imem_device_ipc_uninit(struct iosm_imem *ipc_imem) int timeout = IPC_MODEM_UNINIT_TIMEOUT_MS; enum ipc_mem_device_ipc_state ipc_state; + if (test_bit(IOSM_MODEM_GONE, &ipc_imem->flag)) + return; + /* When PCIe link is up set IPC_UNINIT * of the modem otherwise ignore it when PCIe link down happens. */ @@ -1440,7 +1484,8 @@ struct iosm_imem *ipc_imem_init(struct iosm_pcie *pcie, unsigned int device_id, void ipc_imem_irq_process(struct iosm_imem *ipc_imem, int irq) { /* Debounce IPC_EV_IRQ. */ - if (ipc_imem && !ipc_imem->ev_irq_pending[irq]) { + if (ipc_imem && !ipc_imem->ev_irq_pending[irq] && + !test_bit(IOSM_MODEM_GONE, &ipc_imem->flag)) { ipc_imem->ev_irq_pending[irq] = true; ipc_task_queue_send_task(ipc_imem, ipc_imem_tq_irq_cb, irq, NULL, 0, false); diff --git a/drivers/net/wwan/iosm/iosm_ipc_imem.h b/drivers/net/wwan/iosm/iosm_ipc_imem.h index 5664ac507c90..3f6d1ccf2a7c 100644 --- a/drivers/net/wwan/iosm/iosm_ipc_imem.h +++ b/drivers/net/wwan/iosm/iosm_ipc_imem.h @@ -102,6 +102,8 @@ struct ipc_chnl_cfg; #define FULLY_FUNCTIONAL 0 #define IOSM_DEVLINK_INIT 1 +/* The modem rebooted: don't talk to it or wait for it until the re-bind */ +#define IOSM_MODEM_GONE 2 /* List of the supported UL/DL pipes. */ enum ipc_mem_pipes { @@ -404,6 +406,22 @@ void ipc_imem_pm_s2idle_sleep(struct iosm_imem *ipc_imem, bool sleep); */ void ipc_imem_pm_suspend(struct iosm_imem *ipc_imem); +/** + * ipc_imem_modem_rebooted - Check whether the modem booted again + * @ipc_imem: Pointer to imem data-struct + * + * Returns: true if it did after the driver had brought it up + */ +bool ipc_imem_modem_rebooted(struct iosm_imem *ipc_imem); + +/** + * ipc_imem_wait_for_run - Wait up to about 10 s for the run stage + * @ipc_imem: Pointer to imem data-struct + * + * Returns: true if the modem reached it + */ +bool ipc_imem_wait_for_run(struct iosm_imem *ipc_imem); + /** * ipc_imem_pm_resume - The HAL shall inform the shared memory layer * that the device is active. diff --git a/drivers/net/wwan/iosm/iosm_ipc_imem_ops.c b/drivers/net/wwan/iosm/iosm_ipc_imem_ops.c index 109cf8930488..8cff81919480 100644 --- a/drivers/net/wwan/iosm/iosm_ipc_imem_ops.c +++ b/drivers/net/wwan/iosm/iosm_ipc_imem_ops.c @@ -218,6 +218,9 @@ void ipc_imem_sys_port_close(struct iosm_imem *ipc_imem, return; } + if (test_bit(IOSM_MODEM_GONE, &ipc_imem->flag)) + goto close; + /* If there are any pending TDs then wait for Timeout/Completion before * closing pipe. */ @@ -267,6 +270,7 @@ void ipc_imem_sys_port_close(struct iosm_imem *ipc_imem, ipc_imem->app_notify_dl_pend = 0; } +close: /* Due to wait for completion in messages, there is a small window * between closing the pipe and updating the channel is closed. In this * small window there could be HP update from Host Driver. Hence update diff --git a/drivers/net/wwan/iosm/iosm_ipc_irq.c b/drivers/net/wwan/iosm/iosm_ipc_irq.c index 702f50a48151..d9d0e28fafae 100644 --- a/drivers/net/wwan/iosm/iosm_ipc_irq.c +++ b/drivers/net/wwan/iosm/iosm_ipc_irq.c @@ -25,6 +25,9 @@ static void ipc_write_dbell_reg(struct iosm_pcie *ipc_pcie, int irq_n, u32 data) void ipc_doorbell_fire(struct iosm_pcie *ipc_pcie, int irq_n, u32 data) { + if (ipc_pcie->imem && test_bit(IOSM_MODEM_GONE, &ipc_pcie->imem->flag)) + return; + ipc_write_dbell_reg(ipc_pcie, irq_n, data); } diff --git a/drivers/net/wwan/iosm/iosm_ipc_mux_codec.c b/drivers/net/wwan/iosm/iosm_ipc_mux_codec.c index 0bbd41263cc2..a31f6fa7ea55 100644 --- a/drivers/net/wwan/iosm/iosm_ipc_mux_codec.c +++ b/drivers/net/wwan/iosm/iosm_ipc_mux_codec.c @@ -150,6 +150,9 @@ int ipc_mux_dl_acb_send_cmds(struct iosm_mux *ipc_mux, u32 cmd_type, u8 if_id, union mux_type_cmdh cmdh; int ret = 0; + if (test_bit(IOSM_MODEM_GONE, &ipc_mux->imem->flag)) + return -EIO; + acb->if_id = if_id; ret = ipc_mux_acb_alloc(ipc_mux); if (ret) @@ -1525,6 +1528,9 @@ int ipc_mux_ul_trigger_encode(struct iosm_mux *ipc_mux, int if_id, struct mux_session *session = &ipc_mux->session[if_id]; int ret = -EINVAL; + if (test_bit(IOSM_MODEM_GONE, &ipc_mux->imem->flag)) + return -EIO; + if (ipc_mux->channel && ipc_mux->channel->state != IMEM_CHANNEL_ACTIVE) { dev_err(ipc_mux->dev, diff --git a/drivers/net/wwan/iosm/iosm_ipc_pcie.c b/drivers/net/wwan/iosm/iosm_ipc_pcie.c index 49052eb511ba..767a609462b4 100644 --- a/drivers/net/wwan/iosm/iosm_ipc_pcie.c +++ b/drivers/net/wwan/iosm/iosm_ipc_pcie.c @@ -427,6 +427,10 @@ static int __maybe_unused ipc_pcie_resume_cb(struct device *dev) ipc_pcie = pci_get_drvdata(pdev); + /* pm_notify() re-binds the driver for a modem that booted again */ + if (ipc_imem_modem_rebooted(ipc_pcie->imem)) + set_bit(IOSM_MODEM_GONE, &ipc_pcie->imem->flag); + switch (ipc_pcie->d3l2_support) { case IPC_PCIE_D0L12: ipc_pcie_resume_s2idle(ipc_pcie); @@ -532,6 +536,37 @@ void ipc_pcie_kfree_skb(struct iosm_pcie *ipc_pcie, struct sk_buff *skb) dev_kfree_skb(skb); } +static void ipc_pcie_rebind_if_rebooted(struct pci_dev *pdev) +{ + struct iosm_pcie *ipc_pcie; + bool rebooted = false; + + device_lock(&pdev->dev); + if (pdev->dev.driver == &iosm_ipc_driver.driver) { + ipc_pcie = pci_get_drvdata(pdev); + rebooted = test_bit(IOSM_MODEM_GONE, &ipc_pcie->imem->flag); + /* Let probe find it in the run stage, as after a cold boot */ + if (rebooted && !ipc_imem_wait_for_run(ipc_pcie->imem)) + dev_warn(&pdev->dev, "modem not running after resume"); + } + device_unlock(&pdev->dev); + + if (rebooted && device_reprobe(&pdev->dev)) + dev_err(&pdev->dev, "re-binding the driver failed"); +} + +static void ipc_pcie_rebind_rebooted(void) +{ + const struct pci_device_id *id; + struct pci_dev *pdev; + + for (id = iosm_ipc_ids; id->vendor; id++) { + pdev = NULL; + while ((pdev = pci_get_device(id->vendor, id->device, pdev))) + ipc_pcie_rebind_if_rebooted(pdev); + } +} + static int pm_notify(struct notifier_block *nb, unsigned long mode, void *_unused) { if (mode == PM_HIBERNATION_PREPARE || mode == PM_RESTORE_PREPARE) { @@ -551,6 +586,8 @@ static int pm_notify(struct notifier_block *nb, unsigned long mode, void *_unuse pci_registered = true; } } + } else if (mode == PM_POST_SUSPEND) { + ipc_pcie_rebind_rebooted(); } return 0; diff --git a/drivers/net/wwan/iosm/iosm_ipc_protocol.c b/drivers/net/wwan/iosm/iosm_ipc_protocol.c index 527355a671b6..a49a45ed0b0d 100644 --- a/drivers/net/wwan/iosm/iosm_ipc_protocol.c +++ b/drivers/net/wwan/iosm/iosm_ipc_protocol.c @@ -69,6 +69,9 @@ int ipc_protocol_msg_send(struct iosm_protocol *ipc_protocol, /* Trap if called from non-preemptible context */ might_sleep(); + if (test_bit(IOSM_MODEM_GONE, &ipc_protocol->imem->flag)) + return -EIO; + response.status = IPC_MEM_MSG_CS_INVALID; init_completion(&response.completion); -- 2.56.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH net v3 2/2] net: wwan: iosm: re-bind the driver when the modem rebooted during S3 2026-11-26 19:41 ` [PATCH net v3 2/2] net: wwan: iosm: re-bind the driver when the modem rebooted during S3 David Westen @ 2026-11-27 13:49 ` Maciej S. Szmigiero 2026-11-27 16:46 ` David Westen 2026-11-27 19:50 ` netdev-bot+sashiko 1 sibling, 1 reply; 7+ messages in thread From: Maciej S. Szmigiero @ 2026-11-27 13:49 UTC (permalink / raw) To: David Westen Cc: netdev, Loic Poulain, Sergey Ryazanov, Johannes Berg, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni On 26.11.2026 20:41, David Westen wrote: > On platforms where S3 cuts power to the WWAN card, the modem boots > again while the driver still treats it as running, and the first port > open after resume fails: > > iosm 0000:03:00.0: PORT open refused, phase A-CD_READY > > The driver takes this from a stale stage in the shared memory: on an > XMM7360, the modem writes CD_READY there before it loses power. The > modem itself is fine. > > On resume, read the stage from the MMIO area. If the modem booted > again, mark it as gone: the driver then neither talks to it nor waits > for it, and the cleanup only releases memory. Once the modem has > reached the run stage, re-bind the driver, so that probe finds it as > after a cold boot. Nothing changes where the card keeps power, and a > crashed modem is left alone. > > Tested with S3 on an XMM7360 in a ThinkPad X1 Carbon 6th gen, with > KASAN, lockdep and a strict IOMMU: five cycles, also with wwan0 up > through the suspend. > > Fixes: 7e98d785ae61 ("net: iosm: entry point") > Signed-off-by: David Westen <davidlwesten@gmail.com> > --- > drivers/net/wwan/iosm/iosm_ipc_imem.c | 47 +++++++++++++++++++++- > drivers/net/wwan/iosm/iosm_ipc_imem.h | 18 +++++++++ > drivers/net/wwan/iosm/iosm_ipc_imem_ops.c | 4 ++ > drivers/net/wwan/iosm/iosm_ipc_irq.c | 3 ++ > drivers/net/wwan/iosm/iosm_ipc_mux_codec.c | 6 +++ > drivers/net/wwan/iosm/iosm_ipc_pcie.c | 37 +++++++++++++++++ > drivers/net/wwan/iosm/iosm_ipc_protocol.c | 3 ++ > 7 files changed, 117 insertions(+), 1 deletion(-) > That's a much more intrusive change than simply re-binding the driver and to be honest, feels like a hack around various paths in the iosm driver that may be touching a modem that lost its power and then crashed. Also, wouldn't the problematic things that you describe in your cover letter as happening at modem unbind during suspend also happen without any power transition if the iosm module is simply unloaded from the kernel (presumably with modem still connected)? If yes, then this new approach is simply papering over bugs in the iosm module cleanup that really should be fixed at some point independently from any suspend/resume transition issues. If no, then we should see what makes the okay/buggy difference there. Thanks, Maciej ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net v3 2/2] net: wwan: iosm: re-bind the driver when the modem rebooted during S3 2026-11-27 13:49 ` Maciej S. Szmigiero @ 2026-11-27 16:46 ` David Westen 0 siblings, 0 replies; 7+ messages in thread From: David Westen @ 2026-11-27 16:46 UTC (permalink / raw) To: Maciej S. Szmigiero, David Westen Cc: netdev, Loic Poulain, Sergey Ryazanov, Johannes Berg, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni Hi Maciej, Thanks for taking the time to review this again! On 27.11.2026 14:49, Maciej S. Szmigiero wrote: > That's a much more intrusive change than simply re-binding the driver > and to be honest, feels like a hack around various paths in the iosm > driver that may be touching a modem that lost its power and then crashed. Fair point about the size. The aim was to avoid behavioral changes unless the modem rebooted, and, unlike v2, now also avoid possibly re-binding on s2idle or opportunistic sleep. On my laptop, the order is the other way around: the modem crashes during suspend entry, from the FORCE_SLEEP doorbell (which my s2idle series removes), and writes CD_READY to the shared memory. Then it loses power and boots again during resume. So after resume the modem is fine, and only that stale CD_READY says otherwise. A plain re-bind of the unmodified driver after S3 worked in my tests, but those had no port open and wwan0 down; with this patch I also tested wwan0 up through the suspend. The checks are there because the driver and the modem are out of sync until the re-bind, so the cleanup shouldn't wait for replies or send commands the rebooted modem knows nothing about. If you prefer the plain re-bind, I'll keep only the detection and the re-bind, and test that with a port open and wwan0 up before sending v4. > Also, wouldn't the problematic things that you describe in your cover > letter as happening at modem unbind during suspend also happen without > any power transition if the iosm module is simply unloaded from the > kernel (presumably with modem still connected)? Yes, rmmod and hibernation run the same cleanup, and both problems are already in mainline: unbinding with wwan0 up hits the use-after-free that patch 1 fixes, and unbinding under traffic lets the modem DMA into the freed MUX buffers. I reproduced them with my v2 patches applied, which leave that part of the cleanup unchanged. > If yes, then this new approach is simply papering over bugs in the > iosm module cleanup that really should be fixed at some point > independently from any suspend/resume transition issues. Agreed they need fixing, and I'd like to rework the teardown for net-next. But the re-bind doesn't hide them: a modem that lost power holds none of the driver's memory, and the remaining races are as exposed as with rmmod today. Thanks, David ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net v3 2/2] net: wwan: iosm: re-bind the driver when the modem rebooted during S3 2026-11-26 19:41 ` [PATCH net v3 2/2] net: wwan: iosm: re-bind the driver when the modem rebooted during S3 David Westen 2026-11-27 13:49 ` Maciej S. Szmigiero @ 2026-11-27 19:50 ` netdev-bot+sashiko 1 sibling, 0 replies; 7+ messages in thread From: netdev-bot+sashiko @ 2026-11-27 19:50 UTC (permalink / raw) To: davidlwesten Cc: netdev, loic.poulain, ryazanov.s.a, johannes, andrew+netdev, davem, edumazet, kuba, pabeni, m.chetan.kumar, mail Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider. Critical: 0 · High: 1 · Medium: 1 · Low: 4 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] When IOSM_MODEM_GONE is set, the new early `return -EIO` in ipc_protocol_msg_send() (iosm_ipc_protocol.c:72-73) removes the only… - [Medium] The re-bind runs synchronously inside the PM_POST_SUSPEND notifier. - [Low] ipc_imem_wait_for_run() stops early only on RUN, CRASH or CD_READY. - [Low] ipc_imem_wait_for_run() reuses IPC_MODEM_BOOT_TIMEOUT as its loop bound. - [Low] ipc_pcie_resume_cb() sets IOSM_MODEM_GONE with a plain set_bit(). - [Low] ipc_pcie_rebind_if_rebooted() holds device_lock(&pdev->dev) for the whole ipc_imem_wait_for_run() poll, up to 500 x msleep(20), about… -- net: wwan: iosm: re-bind the driver when the modem rebooted during S3 On resume, this patch reads the exec stage from MMIO. If the modem booted again during S3, it sets a new IOSM_MODEM_GONE flag that stops doorbells, IRQ processing, messages and the pending-data waits. From the PM_POST_SUSPEND notifier it then waits for the modem to reach the run stage and re-binds the driver with device_reprobe(). > diff --git a/drivers/net/wwan/iosm/iosm_ipc_imem.c b/drivers/net/wwan/iosm/iosm_ipc_imem.c > index 3ab409166c506..673c5ad403e79 100644 > --- a/drivers/net/wwan/iosm/iosm_ipc_imem.c > +++ b/drivers/net/wwan/iosm/iosm_ipc_imem.c [ ... ] > @@ -1042,6 +1045,44 @@ void ipc_imem_pm_s2idle_sleep(struct iosm_imem *ipc_imem, bool sleep) > ipc_protocol_s2idle_sleep(ipc_imem->ipc_protocol, sleep); > } > > +bool ipc_imem_modem_rebooted(struct iosm_imem *ipc_imem) > +{ > + if (!test_bit(FULLY_FUNCTIONAL, &ipc_imem->flag)) > + return false; > + > + switch (ipc_mmio_get_exec_stage(ipc_imem->mmio)) { > + case IPC_MEM_EXEC_STAGE_RUN: > + return ipc_mmio_get_ipc_state(ipc_imem->mmio) == > + IPC_MEM_DEVICE_IPC_UNINIT; > + case IPC_MEM_EXEC_STAGE_CRASH: > + case IPC_MEM_EXEC_STAGE_CD_READY: > + case IPC_MEM_EXEC_STAGE_INVALID: > + return false; > + default: > + return true; > + } > +} > + > +bool ipc_imem_wait_for_run(struct iosm_imem *ipc_imem) > +{ > + int timeout = IPC_MODEM_BOOT_TIMEOUT; [Severity: Low] This isn't a bug, but iosm_ipc_imem.h documents IPC_MODEM_BOOT_TIMEOUT as the wait for the IPC_INIT handshake: /* Timeout in 20 msec to wait for the modem to boot up to * IPC_MEM_DEVICE_IPC_INIT state. * unit : milliseconds (500 * ipc_util_msleep(20)) */ #define IPC_MODEM_BOOT_TIMEOUT 500 Here the constant bounds a poll of the exec stage for RUN after a full reboot. The new kernel-doc, "Wait up to about 10 s for the run stage", only stays correct while the constant is 500. Would a separate constant for this wait be clearer? > + > + for (;;) { > + switch (ipc_mmio_get_exec_stage(ipc_imem->mmio)) { > + case IPC_MEM_EXEC_STAGE_RUN: > + return true; > + case IPC_MEM_EXEC_STAGE_CRASH: > + case IPC_MEM_EXEC_STAGE_CD_READY: > + return false; > + default: > + break; > + } [Severity: Low] Should IPC_MEM_EXEC_STAGE_INVALID also end this loop early? ipc_imem_modem_rebooted() above treats INVALID as a stage to leave alone. Here, INVALID (0xFFFFFFFF from a device that stopped responding), BOOT, PSI and EBL all fall into the default case. They are polled for the full 500 x msleep(20). ipc_pcie_rebind_if_rebooted() only warns when this returns false, and then reprobes anyway: if (rebooted && !ipc_imem_wait_for_run(ipc_pcie->imem)) dev_warn(&pdev->dev, "modem not running after resume"); ... if (rebooted && device_reprobe(&pdev->dev)) In these cases the wait adds about 10 s under device_lock, inside the PM notifier, and the outcome is the same. The loop also assumes every supported modem gets back to RUN on its own after losing power. That was tested on the XMM7360, but ipc_pcie_rebind_rebooted() also covers INTEL_CP_DEVICE_7560_ID. Would a device that stays in ROM waiting for the host hit the full timeout on every resume? While the flag is set, doorbells are suppressed and IRQs are dropped, so nothing on the driver side can move the stage forward. Probe already handles a device found in the BOOT stage in ipc_imem_init(). > + if (!--timeout) > + return false; > + msleep(20); > + } > +} [ ... ] > diff --git a/drivers/net/wwan/iosm/iosm_ipc_pcie.c b/drivers/net/wwan/iosm/iosm_ipc_pcie.c > index 49052eb511baa..767a609462b4f 100644 > --- a/drivers/net/wwan/iosm/iosm_ipc_pcie.c > +++ b/drivers/net/wwan/iosm/iosm_ipc_pcie.c > @@ -427,6 +427,10 @@ static int __maybe_unused ipc_pcie_resume_cb(struct device *dev) > > ipc_pcie = pci_get_drvdata(pdev); > > + /* pm_notify() re-binds the driver for a modem that booted again */ > + if (ipc_imem_modem_rebooted(ipc_pcie->imem)) > + set_bit(IOSM_MODEM_GONE, &ipc_pcie->imem->flag); [Severity: Low] Is a plain set_bit() here enough to stop the driver from talking to the rebooted modem? Device interrupts are enabled again after the resume_noirq phase, before this callback runs. An MSI in that window makes ipc_imem_irq_process() queue ipc_imem_tq_irq_cb while the flag is still clear. That task, or one already queued or running on another CPU, then runs ipc_imem_handle_irq() against the stale shared memory. Every new reader does a lockless test_bit() and then acts. For example, in ipc_doorbell_fire(): if (ipc_pcie->imem && test_bit(IOSM_MODEM_GONE, &ipc_pcie->imem->flag)) return; ipc_write_dbell_reg(ipc_pcie, irq_n, data); There is no synchronize_irq() and no drain of the IPC task queue after the bit is set. Does the commit message's "the driver then neither talks to it nor waits for it" actually hold? [ ... ] > @@ -532,6 +536,37 @@ void ipc_pcie_kfree_skb(struct iosm_pcie *ipc_pcie, struct sk_buff *skb) > dev_kfree_skb(skb); > } > > +static void ipc_pcie_rebind_if_rebooted(struct pci_dev *pdev) > +{ > + struct iosm_pcie *ipc_pcie; > + bool rebooted = false; > + > + device_lock(&pdev->dev); > + if (pdev->dev.driver == &iosm_ipc_driver.driver) { > + ipc_pcie = pci_get_drvdata(pdev); > + rebooted = test_bit(IOSM_MODEM_GONE, &ipc_pcie->imem->flag); > + /* Let probe find it in the run stage, as after a cold boot */ > + if (rebooted && !ipc_imem_wait_for_run(ipc_pcie->imem)) > + dev_warn(&pdev->dev, "modem not running after resume"); > + } > + device_unlock(&pdev->dev); > + > + if (rebooted && device_reprobe(&pdev->dev)) > + dev_err(&pdev->dev, "re-binding the driver failed"); > +} [Severity: Low] Does the ipc_imem_wait_for_run() poll need to run with device_lock() held? The poll only reads MMIO, but it can sleep for up to 500 x msleep(20) while holding the lock. Anything else that takes this device's lock blocks for that long. That includes sysfs bind/unbind and device_release_driver() from pciehp or AER removal. The lock is then dropped before device_reprobe(). device_reprobe() re-reads dev->driver and detaches whatever is bound at that moment. Userspace is already thawed at this point. Could a sysfs unbind/bind or a driver_override change between device_unlock() and device_reprobe() make the dev->driver check above stale? [ ... ] > @@ -551,6 +586,8 @@ static int pm_notify(struct notifier_block *nb, unsigned long mode, void *_unuse > pci_registered = true; > } > } > + } else if (mode == PM_POST_SUSPEND) { > + ipc_pcie_rebind_rebooted(); > } [Severity: Medium] Is it ok to do this work synchronously in the PM_POST_SUSPEND notifier? The notifier runs after tasks are thawed and before the console is restored: kernel/power/suspend.c:suspend_finish() { suspend_thaw_processes(); filesystems_thaw(); pm_notifier_call_chain(PM_POST_SUSPEND); pm_restore_console(); } enter_state() releases system_transition_mutex only after this returns. Here, pm_notify()->ipc_pcie_rebind_rebooted()-> ipc_pcie_rebind_if_rebooted() polls ipc_imem_wait_for_run() for up to about 10 s. Then device_reprobe() runs a full remove and probe, and probe can poll again for up to 500 x msleep(20) in ipc_imem_ipc_init_check(). Several things can then wait up to about 20 s on the modem: the write to /sys/power/state, the console restore, and any new suspend attempt, which gets -EBUSY from mutex_trylock(). During that window userspace is running against the old driver instance. ipc_imem_sys_port_open() still refuses opens because the stage it sees is stale or not RUN. That is the "PORT open refused" symptom from the commit message. Messages fail with -EIO. After that, all ports and wwan0 are torn down and created again. Could the re-bind be deferred to a work item instead? The commit message also doesn't mention the delay or that wwan0 and the ports are recreated. > diff --git a/drivers/net/wwan/iosm/iosm_ipc_protocol.c b/drivers/net/wwan/iosm/iosm_ipc_protocol.c > index 527355a671b64..a49a45ed0b0de 100644 > --- a/drivers/net/wwan/iosm/iosm_ipc_protocol.c > +++ b/drivers/net/wwan/iosm/iosm_ipc_protocol.c > @@ -69,6 +69,9 @@ int ipc_protocol_msg_send(struct iosm_protocol *ipc_protocol, > /* Trap if called from non-preemptible context */ > might_sleep(); > > + if (test_bit(IOSM_MODEM_GONE, &ipc_protocol->imem->flag)) > + return -EIO; [Severity: High] Can this early return let ipc_imem_pipe_close() free the pipe rings while the IPC tasklet is still writing into them? Before this patch, ipc_imem_pipe_close() waited for the tasklet to run the IPC_MSG_PREP_PIPE_CLOSE task, because msg_send queues it with ipc_task_queue_send_task(..., wait=true). The task queue is FIFO and a tasklet never runs on two CPUs at once. So any earlier UL work on the channel had finished before the cleanup ran: drivers/net/wwan/iosm/iosm_ipc_imem.c:ipc_imem_pipe_close() { ... pipe->is_open = false; ipc_protocol_msg_send(ipc_imem->ipc_protocol, IPC_MSG_PREP_PIPE_CLOSE, &prep_args); ipc_imem_pipe_cleanup(ipc_imem, pipe); } With IOSM_MODEM_GONE set, msg_send now returns -EIO right away. Then ipc_imem_pipe_cleanup()->ipc_protocol_pipe_cleanup() frees pipe->skbr_start with kfree() and pipe->tdr_start with dma_free_coherent(), and sets both to NULL. On the tasklet side, ipc_imem_ul_write_td() only does a lockless state check before using the rings: if (channel->state != IMEM_CHANNEL_ACTIVE) continue; ... ipc_protocol_ul_td_send(ipc_imem->ipc_protocol, pipe, ul_list); and ipc_protocol_ul_td_send() writes into them: td = &pipe->tdr_start[head]; ... pipe->skbr_start[head] = skb; The new goto close in ipc_imem_sys_port_close() does only a plain store, channel->state = IMEM_CHANNEL_CLOSING, just before the free. A tasklet that has already seen ACTIVE keeps going. UL tasklet work can still be queued while the flag is set. ipc_imem_sys_cdev_write() has no IOSM_MODEM_GONE check and queues ipc_imem_tq_cdev_write with wait=false. That task walks all active channels, not just the writer's: CPU1 (IPC tasklet) CPU2 ipc_imem_tq_cdev_write() (queued by a write to port A) ipc_imem_ul_send() ipc_imem_ul_write_td() sees port B channel ACTIVE port B closed (wwan_port_op_stop, or ipc_port_deinit() in reprobe) ipc_imem_sys_port_close() goto close ipc_imem_pipe_close() ipc_protocol_msg_send() -> -EIO ipc_protocol_pipe_cleanup() frees tdr_start, skbr_start ipc_protocol_ul_td_send() writes pipe->tdr_start[head] writes pipe->skbr_start[head] Wouldn't CPU1 then write into freed slab or DMA memory, or dereference NULL plus head, and also leak the stored skb? -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126194143.32283-1-davidlwesten%40gmail.com ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-27 19:50 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-26 19:41 [PATCH net v3 0/2] net: wwan: iosm: fix S3 resume by re-binding the driver after it David Westen 2026-11-26 19:41 ` [PATCH net v3 1/2] net: wwan: iosm: free the MUX after the netdevs that use it David Westen 2026-11-27 19:50 ` netdev-bot+sashiko 2026-11-26 19:41 ` [PATCH net v3 2/2] net: wwan: iosm: re-bind the driver when the modem rebooted during S3 David Westen 2026-11-27 13:49 ` Maciej S. Szmigiero 2026-11-27 16:46 ` David Westen 2026-11-27 19:50 ` 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