net: wwan: iosm: fix S3 resume by re-binding the driver around it
Subsystems (5)
PATCH 1/1 net: wwan: iosm: fix S3 resume by re-binding the driver around it
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, so the modem is probed again once it has booted. Suspend-to-idle keeps the modem powered and is still handled by the suspend/resume callbacks. The target state isn't known yet when the PM notifier runs, so use the default suspend mode to tell S3 from suspend-to-idle.
---
Notes:
Tested on an XMM7360 (ThinkPad X1 Carbon 6th gen, deep sleep) with this patch applied to 7.2.15: after resume the modem is probed again and comes up without an ACPI reset. Not tested on the XMM7560.
The investigation and the patch 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 change and the changelog together, and I ran the tests.
drivers/net/wwan/iosm/iosm_ipc_pcie.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/net/wwan/iosm/iosm_ipc_pcie.c +7 -2
@@ -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 loses power in S3 and S4 and boots 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;
base-commit: aa40afa831ebfe45e40a23721711059f2ac584d4
Signature · 1 line
2.56.0
[email protected]
AI reviewThank 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 (1) · Medium: 2 · 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] pm_notify() in drivers/net/wwan/iosm/iosm_ipc_pcie.c decides whether to unbind the driver on PM_SUSPEND_PREPARE by checking…
- [Medium] The changelog limits the problem to "platforms where S3 cuts power to the WWAN card".
Pre-existing issues:
- [High] ipc_imem_cleanup() (drivers/net/wwan/iosm/iosm_ipc_imem.c:1231-1266) cancels…
--
net: wwan: iosm: fix S3 resume by re-binding the driver around it
This patch extends pm_notify() in the iosm driver. When the default suspend mode is not suspend-to-idle, the PCI driver is now unregistered on PM_SUSPEND_PREPARE and registered again on PM_POST_SUSPEND. This is the same approach the driver already uses for hibernation, and it means a modem that lost power in S3 gets probed again after resume.
drivers/net/wwan/iosm/iosm_ipc_pcie.c void ipc_pcie_kfree_skb(struct iosm_pcie *ipc_pcie, struct sk_buff *skb) · line 539
Quoted 12 lines
drivers/net/wwan/iosm/iosm_ipc_pcie.c +3
-1@@ -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 loses power in S3 and S4 and boots again on resume, which +* the suspend/resume callbacks can't handle, so probe it again. +*/
[Severity: Medium]
The changelog limits the problem to "platforms where S3 cuts power to the WWAN card". This comment says the modem loses power in S3 everywhere. Is that true on every iosm platform?
The condition below has no platform, PCI device ID or BIOS RTD3 check. It therefore also covers INTEL_CP_DEVICE_7560_ID, which the notes say was not tested.
The driver already treats modem sleep power as platform dependent:
drivers/net/wwan/iosm/iosm_ipc_pcie.c:ipc_pcie_read_bios_cfg() {
...
if (object->integer.value == 3)
sleep_state = IPC_PCIE_D3L2;
...
}ipc_pcie_suspend_cb() and ipc_pcie_resume_cb() use that setting to pick the D0L12 or D3L2 path. ipc_imem_pm_resume() also already re-reads the exec stage:
if (ipc_protocol_resume(ipc_imem->ipc_protocol)) {
stage = ipc_mmio_get_exec_stage(ipc_imem->mmio);
ipc_imem_phase_update_check(ipc_imem, stage);Because the driver is now unbound before every S3, none of these paths can run during S3.
Some platforms keep the M.2 slot powered in S3. On those, the endpoint has no driver during suspend, so pci_pm_suspend_noirq() skips pci_prepare_to_sleep(). The modem then stays in D0 with no PME armed. Every S3 cycle would also destroy and recreate the WWAN netdevs and the /dev/wwan* ports, and drop any active data sessions.
Could this be gated on ipc_pcie->d3l2_support or a platform check? And since the patch is tagged Cc: stable, could the changelog mention this change in behaviour?
drivers/net/wwan/iosm/iosm_ipc_pcie.c void ipc_pcie_kfree_skb(struct iosm_pcie *ipc_pcie, struct sk_buff *skb) · line 541
Quoted 2 lines
drivers/net/wwan/iosm/iosm_ipc_pcie.c +2
-0+if (mode ==PM_HIBERNATION_PREPARE || mode ==PM_RESTORE_PREPARE || + (mode ==PM_SUSPEND_PREPARE && !pm_suspend_default_s2idle ())) {
[Severity: Medium]
Can pm_suspend_default_s2idle() tell S3 apart from s2idle here? It only reports which state the "mem" label maps to:
kernel/power/suspend.c:pm_suspend_default_s2idle() {
return mem_sleep_current == PM_SUSPEND_TO_IDLE;
}state_store() only looks at mem_sleep_current when the string is "mem":
kernel/power/main.c:state_store() {
...
if (state == PM_SUSPEND_MEM)
state = mem_sleep_current;
...
}"freeze" and "standby" go to pm_suspend() as PM_SUSPEND_TO_IDLE and PM_SUSPEND_STANDBY directly.
So take mem_sleep=deep with "freeze" or "standby" written to /sys/power/state, or mem_sleep=shallow with "mem". The system enters s2idle or S1 and the modem keeps power, but pm_notify() still calls pci_unregister_driver(). That skips the ipc_pcie_suspend_cb() handling. With no driver bound, pci_pm_suspend_noirq() then only does this:
if (!pm) {
pci_save_state(pci_dev);
goto set_unknown;
}The endpoint stays in D0 with no PME armed. On PM_POST_SUSPEND the modem is probed again even though it was never power cycled.
The reverse case also exists. Some callers invoke pm_suspend(PM_SUSPEND_MEM) directly and never consult mem_sleep_current. Examples are test_wakealarm() for test_suspend=mem, drivers/char/apm-emulation.c, drivers/firmware/arm_scmi/scmi_power_control.c and drivers/soc/xilinx/zynqmp_power.c.
If the default is s2idle, could these paths enter real S3 without the unbind? That would leave the original "PORT open refused, phase A-CD_READY" failure reachable.
The changelog says "Suspend-to-idle keeps the modem powered and is still handled by the suspend/resume callbacks". That doesn't match the cases above.
drivers/net/wwan/iosm/iosm_ipc_pcie.c void ipc_pcie_kfree_skb(struct iosm_pcie *ipc_pcie, struct sk_buff *skb) · line 543
Quoted 2 lines
drivers/net/wwan/iosm/iosm_ipc_pcie.c +0
-0if (pci_registered) {pci_unregister_driver (&iosm_ipc_driver);
[Severity: High]
This is a pre-existing issue and was not introduced by this patch. However, this teardown path used to run only on rmmod and hibernation. With this patch it runs on every S3 cycle.
ipc_imem_cleanup() cancels four hrtimers, but not adb_timer:
drivers/net/wwan/iosm/iosm_ipc_imem.c:ipc_imem_cleanup() {
...
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_mux_deinit(ipc_imem->mux);
...
ipc_imem_device_ipc_uninit(ipc_imem);
...
}With MUX_AGGREGATION (the 7560), the UL path arms adb_timer for 500 us through ipc_imem_adb_timer_start(). PM_SUSPEND_PREPARE runs before tasks are frozen, so UL traffic can still be flowing right up to teardown.
The sequence would be:
pm_notify(PM_SUSPEND_PREPARE)
pci_unregister_driver()
ipc_pcie_remove()
ipc_pcie_cleanup()
ipc_imem_cleanup()
ipc_mux_deinit()
kfree(ipc_mux), ipc_imem->mux is not cleared
ipc_imem_device_ipc_uninit()
usleep_range() for up to 30 ms, tasklet still alive
adb_timer fires
ipc_imem_adb_timer_cb()
ipc_task_queue_send_task(ipc_imem_tq_adb_timer_cb)
tasklet runs
ipc_imem_tq_adb_timer_cb()
ipc_mux_ul_adb_finish(ipc_imem->mux) <- freed mux
Could this write into the freed iosm_mux through ul_adb->adbh, skb_put() and channel->ul_list?
ipc_imem_cleanup() later does kfree(ipc_imem->ipc_task), and ipc_pcie_deinit() then frees ipc_pcie->imem. If the timer were still pending at that point, could the hrtimer embedded in the freed imem also corrupt the timer base?
Should ipc_imem_cleanup() call hrtimer_cancel(&ipc_imem->adb_timer) along with the other timers before this path runs on every S3?
Quoted 2 lines
drivers/net/wwan/iosm/iosm_ipc_pcie.c +0
-0pci_registered = false; }
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116031148.333990-1-davidlwesten%40gmail.com
Quoted 8 lines
- [Medium]
pm_notify()indrivers/net/wwan/iosm/iosm_ipc_pcie.cdecides whether to unbind the driver onPM_SUSPEND_PREPAREby checking…
- [Medium] The changelog limits the problem to "platforms where S3 cuts power to the WWAN card".Pre-existing issues:
- [High]ipc_imem_cleanup()(drivers/net/wwan/iosm/iosm_ipc_imem.c:1231-1266) cancels…
Thanks for the review, these were good points. I tried the suggestions and will send a v2; details below.
Quoted 3 lines
Could this be gated on
ipc_pcie->d3l2_supportor a platform check? And since the patch is tagged Cc: stable, could the changelog mention this change in behaviour?
I looked at gating on d3l2_support first, but it doesn't match the power behavior here: the X1 Carbon 6th gen reports D0L12 and the modem still loses power in S3.
So I tried checking the hardware instead: on resume, read the exec stage before touching the modem, and only re-bind the driver from PM_POST_SUSPEND if it no longer reads RUN. That covered every sleep state and left platforms that keep the modem powered alone, and it worked in most runs. The catch is that the re-bind then tears down a modem that has already booted again. When a port was still open at that point, port close sent PIPE_CLOSE messages to the new firmware, they timed out, and the modem crashed:
iosm 0000:03:00.0: modem lost power while suspended (stage 0xfeedb007), probing it again iosm 0000:03:00.0: msg timeout
iosm 0000:03:00.0: msg timeout
(exec stage now 0xbadc0ded, the probe then fails)
Making the teardown safe against that would mean changing every path that talks to the modem during removal, which seemed like a lot of change for a stable fix. Unbinding before S3 tears the driver down while the modem still answers and has worked reliably, so v2 keeps it. The trade-off is that on platforms that keep the slot powered in S3, the modem is probed again on resume, which drops data sessions and recreates the ports. As you suggested, the changelog will spell that out.
If you'd rather see the resume-time check, I'm happy to work on that instead.
Quoted 2 lines
Can
pm_suspend_default_s2idle()tell S3 apart from s2idle here? It only reports which state the "mem" label maps to:
Good catch, it's the default mode, not the target state. The target isn't known yet when PM_SUSPEND_PREPARE is sent, and pm_suspend_via_firmware() is only set later, in platform_suspend_begin(), so I didn't find a better signal for the notifier. In the cases you list the patch either probes the modem again when it didn't need to, or behaves as before. I'll describe those limits in the changelog and correct the suspend-to-idle sentence.
Quoted 2 lines
Should
ipc_imem_cleanup()callhrtimer_cancel(&ipc_imem->adb_timer)along with the other timers before this path runs on every S3?
Yes, thanks for spotting it. v2 adds a patch for that ahead of this one. I could only build-test it, since the XMM7360 doesn't use UL aggregation.
pw-bot: cr