net: wwan: iosm: send the host sleep message on every suspend
Subsystems (4)
v2 cover net: wwan: iosm: send the host sleep message on every suspend
On platforms whose BIOS doesn't select D3L2, iosm tells the modem about system suspend with the FORCE_SLEEP and FORCE_ACTIVE doorbells, which the XMM7360 in a ThinkPad X1 Carbon 6th gen doesn't survive. Patch 3 always uses the ENTER_SLEEP/EXIT_SLEEP host sleep messages instead, as discussed in the v1 review. Patches 1 and 2 fix two bugs in that handshake that so far only D3L2 platforms could hit.
Changes in v2:
- New patches 1 and 2, for issues the AI review of v1 found.
- Patch 3: rewrite the commit message and remove the doorbell path with everything only it used (Loic).
- Patch 3: fix the Fixes: tag and the comment, and describe testing and hibernation in the commit message (AI review).
Tested on an XMM7360 with suspend-to-idle, including overnight. Not tested on the XMM7560 or on a platform where the doorbells work.
v1: https://lore.kernel.org/r/[email protected]
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 (3):
net: wwan: iosm: reset the host PM state when the sleep handshake
times out
net: wwan: iosm: fix the wait for the modem in the host sleep
handshake
net: wwan: iosm: always send the host sleep message on suspend
drivers/net/wwan/iosm/iosm_ipc_imem.c | 5 -- drivers/net/wwan/iosm/iosm_ipc_imem.h | 8 -- drivers/net/wwan/iosm/iosm_ipc_irq.c | 3 +- drivers/net/wwan/iosm/iosm_ipc_pcie.c | 96 ++--------------------- drivers/net/wwan/iosm/iosm_ipc_pcie.h | 14 ---- drivers/net/wwan/iosm/iosm_ipc_pm.c | 43 +++++----- drivers/net/wwan/iosm/iosm_ipc_pm.h | 7 -- drivers/net/wwan/iosm/iosm_ipc_protocol.c | 7 +- drivers/net/wwan/iosm/iosm_ipc_protocol.h | 8 -- 9 files changed, 28 insertions(+), 163 deletions(-)
base-commit: af6737b9066832a2017c281159950ba92385ce00
Signature · 1 line
2.56.0
PATCH v2 1/3 net: wwan: iosm: reset the host PM state when the sleep handshake times out
ipc_protocol_suspend() moves host_pm_state from ACTIVE to SLEEP_WAIT_D3 before it wakes the modem to send the ENTER_SLEEP message. If the modem doesn't report itself active in time, the function gives up but leaves the state at SLEEP_WAIT_D3.
From then on the driver is stuck: resume skips EXIT_SLEEP because it expects SLEEP, every later suspend is refused because it expects ACTIVE, and doorbells to the modem are held back as pending, so no data moves until the driver is bound again.
Set the state back to ACTIVE on this path, as the path where sending ENTER_SLEEP fails already does.
Found by an AI code review agent, not triggered. Tested on an XMM7360 with suspend-to-idle.
--- drivers/net/wwan/iosm/iosm_ipc_protocol.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/wwan/iosm/iosm_ipc_protocol.c +2 -0
@@ -185,6 +185,8 @@ bool ipc_protocol_suspend(struct iosm_protocol *ipc_protocol)if (!ipc_pm_wait_for_device_active (&ipc_protocol->pm)) {ipc_uevent_send (ipc_protocol->pcie->dev,UEVENT_MDM_TIMEOUT ); +/* The modem wasn't told to sleep, we are still active */ + ipc_protocol->pm.host_pm_state =IPC_MEM_HOST_PM_ACTIVE ; goto err; }
Signature · 1 line
2.56.0
PATCH v2 2/3 net: wwan: iosm: fix the wait for the modem in the host sleep handshake
In reply to David WestenBefore the ENTER_SLEEP message is sent, ipc_pm_wait_for_device_active() waits for the modem to report itself active, but:
- it tests ap_state before it sets the bit that asks the tasklet for a wake-up, so a wake-up in between is lost and the wait times out
- a wake-up that arrives after a timeout leaves the completion done, so a later wait returns at once
- an -ERESTARTSYS return from the interruptible wait counts as success
Set the bit first, paired with a barrier in the tasklet, reinitialize the completion before each wait, and wait uninterruptibly, like the wait for the ENTER_SLEEP reply does.
Found by an AI code review agent, not reproduced. Tested on an XMM7360 with suspend-to-idle.
--- drivers/net/wwan/iosm/iosm_ipc_pm.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-)
drivers/net/wwan/iosm/iosm_ipc_pm.c +20 -9
@@ -72,19 +72,25 @@ bool ipc_pm_wait_for_device_active(struct iosm_pm *ipc_pm) {bool ret_val = false; -if (ipc_pm->ap_state !=IPC_MEM_DEV_PM_ACTIVE ) { -/* Complete all memory stores before setting bit */ -smp_mb__before_atomic (); +/* Drop a completion left over from an earlier timeout */ +reinit_completion (&ipc_pm->host_sleep_complete); +/* Complete all memory stores before setting bit */ +smp_mb__before_atomic (); + +set_bit (0 , &ipc_pm->host_sleep_pend); + +/* Set the bit before testing ap_state, so that a wake-up after the +* test completes host_sleep_complete. Pairs with the barrier in +* ipc_pm_on_link_wake(). +*/ +smp_mb__after_atomic (); + +if (ipc_pm->ap_state !=IPC_MEM_DEV_PM_ACTIVE ) {/* Wait for IPC_PM_ACTIVE_TIMEOUT_MS for Device sleep state * machine to enter ACTIVE state. */ -set_bit (0 , &ipc_pm->host_sleep_pend); - -/* Complete all memory stores after setting bit */ -smp_mb__after_atomic (); - -if (!wait_for_completion_interruptible_timeout +if (!wait_for_completion_timeout (&ipc_pm->host_sleep_complete,msecs_to_jiffies (IPC_PM_ACTIVE_TIMEOUT_MS ))) { dev_err(ipc_pm->dev,
@@ -130,6 +136,11 @@ static void ipc_pm_on_link_wake(struct iosm_pm *ipc_pm, bool ack)ipc_cp_irq_sleep_control (ipc_pm->pcie,IPC_MEM_DEV_PM_ACTIVE ); +/* Order the ap_state store before the bit test, pairs with +* ipc_pm_wait_for_device_active(). +*/ +smp_mb (); +/* check the consume state !!! */ if (test_bit (CONSUME_STATE , &ipc_pm->host_sleep_pend))complete (&ipc_pm->host_sleep_complete);
Signature · 1 line
2.56.0
PATCH v2 3/3 net: wwan: iosm: always send the host sleep message on suspend
In reply to David WestenThe driver picks how to tell the modem about system suspend from a BIOS RTD3 setting: the ENTER_SLEEP and EXIT_SLEEP host sleep messages for D3L2, otherwise the FORCE_SLEEP and FORCE_ACTIVE doorbells. The doorbells don't wait for the modem, and the PCI core may put the device into D3hot either way.
On a ThinkPad X1 Carbon 6th gen, whose BIOS has no WWAN _DSM, the XMM7360 doesn't survive the doorbells: after suspend-to-idle it is in CD_READY ("PORT open refused, phase A-CD_READY") until an ACPI reset. Keeping the device in D0 doesn't help either.
Always send the host sleep messages, and remove the doorbell path, the BIOS setting and the suspend flag that only that path used. MSIs that arrive between the suspend and resume callbacks are now processed, as they already were with D3L2.
Tested on an XMM7360 with suspend-to-idle, not on the XMM7560. On kernels that don't unbind the driver around hibernation yet, hibernation also switches to the host sleep messages.
--- drivers/net/wwan/iosm/iosm_ipc_imem.c | 5 -- drivers/net/wwan/iosm/iosm_ipc_imem.h | 8 -- drivers/net/wwan/iosm/iosm_ipc_irq.c | 3 +- drivers/net/wwan/iosm/iosm_ipc_pcie.c | 96 ++--------------------- drivers/net/wwan/iosm/iosm_ipc_pcie.h | 14 ---- drivers/net/wwan/iosm/iosm_ipc_pm.c | 14 ---- drivers/net/wwan/iosm/iosm_ipc_pm.h | 7 -- drivers/net/wwan/iosm/iosm_ipc_protocol.c | 5 -- drivers/net/wwan/iosm/iosm_ipc_protocol.h | 8 -- 9 files changed, 6 insertions(+), 154 deletions(-)
drivers/net/wwan/iosm/iosm_ipc_imem.c +0 -5
@@ -1036,11 +1036,6 @@ void ipc_imem_pm_suspend(struct iosm_imem *ipc_imem)ipc_protocol_suspend (ipc_imem->ipc_protocol); } -void ipc_imem_pm_s2idle_sleep (struct iosm_imem *ipc_imem,bool sleep) -{ -ipc_protocol_s2idle_sleep (ipc_imem->ipc_protocol, sleep); -} -void ipc_imem_pm_resume (struct iosm_imem *ipc_imem) {enum ipc_mem_exec_stage stage;
drivers/net/wwan/iosm/iosm_ipc_imem.h +0 -8
@@ -389,14 +389,6 @@ struct iosm_imem {struct iosm_imem *ipc_imem_init (struct iosm_pcie *pcie,unsigned int device_id,void __iomem *mmio,struct device *dev); -/** -* ipc_imem_pm_s2idle_sleep - Set PM variables to sleep/active for -* s2idle sleep/active -* @ipc_imem: Pointer to imem data-struct -* @sleep: Set PM Variable to sleep/active -*/ -void ipc_imem_pm_s2idle_sleep (struct iosm_imem *ipc_imem,bool sleep); -/** * ipc_imem_pm_suspend - The HAL shall ask the shared memory layer * whether D3 is allowed.
drivers/net/wwan/iosm/iosm_ipc_irq.c +1 -2
@@ -40,8 +40,7 @@ static irqreturn_t ipc_msi_interrupt(int irq, void *dev_id)if (instance >= ipc_pcie->nvec)return IRQ_NONE ; -if (!test_bit (0 , &ipc_pcie->suspend)) -ipc_imem_irq_process (ipc_pcie->imem, instance); +ipc_imem_irq_process (ipc_pcie->imem, instance);return IRQ_HANDLED ; }
drivers/net/wwan/iosm/iosm_ipc_pcie.c +5 -91
138 lines not on this page · raw message
drivers/net/wwan/iosm/iosm_ipc_pcie.h +0 -14
@@ -31,16 +31,6 @@/* Total number of Maximum IPC IRQ vectors used for IPC */ #define IPC_IRQ_VECTORS IPC_MSI_VECTORS -/** -* enum ipc_pcie_sleep_state - Enum type to different sleep state transitions -* @IPC_PCIE_D0L12: Put the sleep state in D0L12 -* @IPC_PCIE_D3L2: Put the sleep state in D3L2 -*/ -enum ipc_pcie_sleep_state { -IPC_PCIE_D0L12 , -IPC_PCIE_D3L2 , -}; -/** * struct iosm_pcie - IPC_PCIE struct. * @pci: Address of the device description
@@ -58,8 +48,6 @@ enum ipc_pcie_sleep_state {* @doorbell_reg_offset: doorbell_reg_offset * @doorbell_write: doorbell write register * @doorbell_capture: doorbell capture resgister -* @suspend: S2IDLE sleep/active -* @d3l2_support: Read WWAN RTD3 BIOS setting for D3L2 support */ struct iosm_pcie {struct pci_dev *pci;
@@ -73,8 +61,6 @@ struct iosm_pcie {u32 doorbell_reg_offset;u32 doorbell_write;u32 doorbell_capture; -unsigned long suspend; -enum ipc_pcie_sleep_state d3l2_support; };/**
drivers/net/wwan/iosm/iosm_ipc_pm.c +0 -14
@@ -238,20 +238,6 @@ bool ipc_pm_prepare_host_active(struct iosm_pm *ipc_pm)return true; } -void ipc_pm_set_s2idle_sleep (struct iosm_pm *ipc_pm,bool sleep) -{ -if (sleep) { - ipc_pm->ap_state =IPC_MEM_DEV_PM_SLEEP ; - ipc_pm->cp_state =IPC_MEM_DEV_PM_SLEEP ; - ipc_pm->device_sleep_notification =IPC_MEM_DEV_PM_SLEEP ; - }else { - ipc_pm->ap_state =IPC_MEM_DEV_PM_ACTIVE ; - ipc_pm->cp_state =IPC_MEM_DEV_PM_ACTIVE ; - ipc_pm->device_sleep_notification =IPC_MEM_DEV_PM_ACTIVE ; - ipc_pm->pm_cond.link =IPC_PM_ACTIVE ; - } -} -bool ipc_pm_dev_slp_notification (struct iosm_pm *ipc_pm,u32 cp_pm_req) {if (cp_pm_req == ipc_pm->device_sleep_notification)
drivers/net/wwan/iosm/iosm_ipc_pm.h +0 -7
@@ -146,13 +146,6 @@ void ipc_pm_deinit(struct iosm_protocol *ipc_protocol);bool ipc_pm_dev_slp_notification (struct iosm_pm *ipc_pm,u32 sleep_notification); -/** -* ipc_pm_set_s2idle_sleep - Set PM variables to sleep/active -* @ipc_pm: Pointer to power management component -* @sleep: true to enter sleep/false to exit sleep -*/ -void ipc_pm_set_s2idle_sleep (struct iosm_pm *ipc_pm,bool sleep); -/** * ipc_pm_prepare_host_sleep - Prepare the PM for sleep by entering * IPC_MEM_HOST_PM_SLEEP_WAIT_D3 state.
drivers/net/wwan/iosm/iosm_ipc_protocol.c +0 -5
@@ -169,11 +169,6 @@ static int ipc_protocol_tq_wakeup_dev_slp(struct iosm_imem *ipc_imem, int arg,return 0 ; } -void ipc_protocol_s2idle_sleep (struct iosm_protocol *ipc_protocol,bool sleep) -{ -ipc_pm_set_s2idle_sleep (&ipc_protocol->pm, sleep); -} -bool ipc_protocol_suspend (struct iosm_protocol *ipc_protocol) {if (!ipc_pm_prepare_host_sleep (&ipc_protocol->pm))
drivers/net/wwan/iosm/iosm_ipc_protocol.h +0 -8
@@ -174,14 +174,6 @@ int ipc_protocol_msg_send(struct iosm_protocol *ipc_protocol,*/ bool ipc_protocol_suspend (struct iosm_protocol *ipc_protocol); -/** -* ipc_protocol_s2idle_sleep - Call PM function to set PM variables in s2idle -* sleep/active case -* @ipc_protocol: Pointer to ipc_protocol instance -* @sleep: True for sleep/False for active -*/ -void ipc_protocol_s2idle_sleep (struct iosm_protocol *ipc_protocol,bool sleep); -/** * ipc_protocol_resume - Signal to CP that host wants to resume operation. * @ipc_protocol: Pointer to ipc_protocol instance
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH net v2 1/3] net: wwan: iosm: reset the host PM state when the sleep handshake times out
In reply to David WestenThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 (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] host_sleep_complete is initialised only once, in ipc_pm_init(), and never re-initialised.
- [Medium] The rollback in ipc_protocol_suspend() (iosm_ipc_protocol.c:189) runs in process context with no lock and no…
Pre-existing issues:
- [Medium] The kernel-doc of ipc_protocol_suspend() (iosm_ipc_protocol.h:173) says "false if suspend must be aborted", but…
- [Medium] ipc_pm_wait_for_device_active() (iosm_ipc_pm.c:87) checks if (!wait_for_completion_interruptible_timeout(...)).
--
net: wwan: iosm: reset the host PM state when the sleep handshake times out
This patch sets host_pm_state back to IPC_MEM_HOST_PM_ACTIVE in ipc_protocol_suspend() when ipc_pm_wait_for_device_active() times out. This matches what the existing ENTER_SLEEP send failure path already does. Without it the driver is left in SLEEP_WAIT_D3, later suspend and resume transitions are refused, and doorbells are held back as pending.
drivers/net/wwan/iosm/iosm_ipc_protocol.c bool ipc_protocol_suspend(struct iosm_protocol *ipc_protocol) · line 186
Quoted 7 lines
drivers/net/wwan/iosm/iosm_ipc_protocol.c +0
-0@@ -185,6 +185,8 @@ bool ipc_protocol_suspend(struct iosm_protocol *ipc_protocol)if (!ipc_pm_wait_for_device_active (&ipc_protocol->pm)) {
[Severity: Medium]
This is a pre-existing issue, but can an interrupted wait skip the new reset entirely?
ipc_pm_wait_for_device_active() uses an interruptible wait and only checks for a zero return:
drivers/net/wwan/iosm/iosm_ipc_pm.c:ipc_pm_wait_for_device_active() {
...
if (!wait_for_completion_interruptible_timeout
(&ipc_pm->host_sleep_complete,
msecs_to_jiffies(IPC_PM_ACTIVE_TIMEOUT_MS))) {
...
}If the suspending task has a pending signal, the wait returns -ERESTARTSYS and the code treats that as success. The function then returns true even though ap_state never reached IPC_MEM_DEV_PM_ACTIVE. That contradicts its kernel-doc ("true if device is active, false on timeout").
In that case ipc_protocol_suspend() never enters this branch. It sends ENTER_SLEEP to a modem that is not active and sets host_pm_state to IPC_MEM_HOST_PM_SLEEP.
This appears to be fixed later in the series by "net: wwan: iosm: fix the wait for the modem in the host sleep handshake". That commit switches to wait_for_completion_timeout(), which has no negative return.
drivers/net/wwan/iosm/iosm_ipc_protocol.c bool ipc_protocol_suspend(struct iosm_protocol *ipc_protocol) · line 189
Quoted 3 lines
drivers/net/wwan/iosm/iosm_ipc_protocol.c +2
-0ipc_uevent_send (ipc_protocol->pcie->dev,UEVENT_MDM_TIMEOUT ); +/* The modem wasn't told to sleep, we are still active */ + ipc_protocol->pm.host_pm_state =IPC_MEM_HOST_PM_ACTIVE ;
[Severity: Medium]
Does restoring ACTIVE here let the next suspend consume a stale completion count?
host_sleep_complete is initialised once in ipc_pm_init() and never reinitialised. The modem's late wake-ack can arrive after the 500 ms wait has timed out but before host_sleep_pend is cleared. In that window this runs:
drivers/net/wwan/iosm/iosm_ipc_pm.c:ipc_pm_on_link_wake() {
...
if (test_bit(CONSUME_STATE, &ipc_pm->host_sleep_pend))
complete(&ipc_pm->host_sleep_complete);
...
}That leaves done=1 on the completion. Meanwhile ipc_pm_wait_for_device_active() has not yet reached:
clear_bit(0, &ipc_pm->host_sleep_pend);
Before this patch the state stayed stuck at SLEEP_WAIT_D3. Later calls to ipc_pm_prepare_host_sleep() were refused, so the count was never consumed.
With the reset to ACTIVE, the next ipc_protocol_suspend() reaches the wait again. It consumes the stale count and returns true at once, even if the modem has gone back to sleep. ENTER_SLEEP is then parked as a pending doorbell, and host_pm_state becomes IPC_MEM_HOST_PM_SLEEP although the modem was never told.
This looks to be fixed later in the series by "net: wwan: iosm: fix the wait for the modem in the host sleep handshake". That commit adds reinit_completion(&ipc_pm->host_sleep_complete) before set_bit() in ipc_pm_wait_for_device_active().
[Severity: Medium]
Is a doorbell parked during SLEEP_WAIT_D3 ever replayed after this rollback?
While host_pm_state is SLEEP_WAIT_D3, ipc_pm_signal_hpda_doorbell() with host_slp_check set only records the update:
if (host_slp_check && ipc_pm->host_pm_state != IPC_MEM_HOST_PM_ACTIVE &&
ipc_pm->host_pm_state != IPC_MEM_HOST_PM_ACTIVE_WAIT) {
ipc_pm->pending_hpda_update = true;The only automatic replay is in ipc_pm_on_link_wake(), and it requires ACTIVE:
if (ipc_pm->pending_hpda_update && ipc_pm->host_pm_state == IPC_MEM_HOST_PM_ACTIVE) ipc_pm_signal_hpda_doorbell(ipc_pm, IPC_HP_PM_TRIGGER, true);
This store runs in process context with no lock and is not serialised with the IPC tasklet. The tasklet may handle the modem's late wake-ack after the timeout but before this store. That window covers dev_err(), clear_bit() and ipc_uevent_send(). If so, the tasklet still sees SLEEP_WAIT_D3 and skips the replay.
After this store, nothing checks pending_hpda_update again. On resume, ipc_protocol_resume() returns early because ipc_pm_prepare_host_active() finds ACTIVE instead of SLEEP. So the EXIT_SLEEP doorbell that normally flushes pending updates is not sent either.
Could the parked HP update, for example a DL refill, then stay undelivered until some unrelated doorbell fires? That would be a smaller form of the "doorbells to the modem are held back as pending" symptom this commit message describes.
[Severity: Medium]
This isn't a bug introduced by this patch, but the new comment says "we are still active" while the suspend still goes ahead. Is the false return from ipc_protocol_suspend() meant to abort the suspend?
The kernel-doc in iosm_ipc_protocol.h says:
* Returns: true if host can suspend, false if suspend must be aborted.
The only caller throws the result away:
void ipc_imem_pm_suspend(struct iosm_imem *ipc_imem)
{
ipc_protocol_suspend(ipc_imem->ipc_protocol);
}ipc_pcie_suspend() then always returns 0:
ipc_imem_pm_suspend(ipc_pcie->imem); dev_dbg(ipc_pcie->dev, "SUSPEND done"); return 0;
So the PM core still puts the device into D3, even though the modem was never sent ENTER_SLEEP.
On resume, ipc_protocol_resume()->ipc_pm_prepare_host_active() expects IPC_MEM_HOST_PM_SLEEP, finds ACTIVE, logs an error and returns false. As a result, ipc_imem_pm_resume() skips ipc_imem_phase_update_check(). The same happened before this patch, when the state was left at SLEEP_WAIT_D3.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124172627.41847-1-davidlwesten%40gmail.com
[email protected]
AI reviewRe: [PATCH net v2 3/3] net: wwan: iosm: always send the host sleep message on suspend
In reply to David WestenThank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 3 · 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).
- [Medium] The patch fixes one reported case and changes behaviour for every platform.
- [Medium] With the FORCE_SLEEP doorbell fallback removed, the host sleep handshake is now the only way the modem learns about system suspend.
- [Medium] Every system suspend and resume now sends ENTER_SLEEP / EXIT_SLEEP over the IPC message ring whatever phase the modem is in.
- [Low] The commit says it removes the doorbell path.
- [Low] The patch removes the suspend-bit check from ipc_msi_interrupt() (drivers/net/wwan/iosm/iosm_ipc_irq.c), so every MSI now calls…
--
net: wwan: iosm: always send the host sleep message on suspend
This commit removes the BIOS WWAN _DSM RTD3 query and the FORCE_SLEEP / FORCE_ACTIVE doorbell suspend path. With it gone, the PM callbacks always use the ENTER_SLEEP / EXIT_SLEEP host sleep messages. It also drops the suspend flag that gated MSI processing in ipc_msi_interrupt().
Quoted 5 lines
drivers/net/wwan/iosm/iosm_ipc_irq.c +0
-0
drivers/net/wwan/iosm/iosm_ipc_irq.c static irqreturn_t ipc_msi_interrupt(int irq, void *dev_id) · line 46
Quoted 9 lines
drivers/net/wwan/iosm/iosm_ipc_irq.c +1
-2@@ -40,8 +40,7 @@ static irqreturn_t ipc_msi_interrupt(int irq, void *dev_id)if (instance >= ipc_pcie->nvec)return IRQ_NONE ; -if (!test_bit (0 , &ipc_pcie->suspend)) -ipc_imem_irq_process (ipc_pcie->imem, instance); +ipc_imem_irq_process (ipc_pcie->imem, instance);return IRQ_HANDLED ; }
[Severity: Low]
With the suspend bit check gone, every MSI now queues ipc_imem_tq_irq_cb. That includes MSIs that arrive between the suspend and resume callbacks.
Nothing replaces the check in ipc_pcie_suspend_cb(). It doesn't call disable_irq() or synchronize_irq() on the vectors, and it doesn't quiesce the ipc_task tasklet or the imem hrtimers (td_update, td_alloc, adb, fast_update).
suspend_device_irqs() in the noirq phase only syncs the hardirq handlers. It doesn't wait for a tasklet that is already scheduled.
Suppose an MSI arrives after ENTER_SLEEP completes and queues the tasklet. Can that tasklet then run ipc_imem_handle_irq() on another CPU while pci_pm_suspend_noirq() moves the device into D3hot? If so:
ipc_imem_handle_irq()
ipc_imem_phase_update()
exec stage read from the scratchpad BAR returns all-ones
ipc_imem_phase_update_check()
default case -> UEVENT_CD_READY_LINK_DOWN
The tasklet can also issue doorbell writes to a device that is changing power state, and it can re-arm the hrtimers.
The removed flag wasn't real synchronization either. The commit message also notes that D3L2 already behaved this way. For platforms that used the D0L1.2 path, though, IRQ processing during suspend is new.
Would it make sense to quiesce the vectors and the tasklet in the suspend callback?
Quoted 4 lines
drivers/net/wwan/iosm/iosm_ipc_pcie.c +0
-0
[ ... ]
Quoted 21 lines
drivers/net/wwan/iosm/iosm_ipc_pcie.c +0
-17@@ -229,34 +225,6 @@ static void ipc_pcie_config_init(struct iosm_pcie *ipc_pcie) ipc_pcie->doorbell_capture =IPC_CAPTURE_PTR_REG_0 ; } -/* This will read the BIOS WWAN RTD3 settings: -* D0L1.2/D3L2/Disabled -*/ -static enum ipc_pcie_sleep_state ipc_pcie_read_bios_cfg (struct device *dev) -{ -enum ipc_pcie_sleep_state sleep_state =IPC_PCIE_D0L12 ; -union acpi_object *object; -acpi_handle handle_acpi; - - handle_acpi =ACPI_HANDLE (dev); -if (!handle_acpi) { -pr_debug ("pci device is NOT ACPI supporting device\n" ); - goto default_ret; - } - - object =acpi_evaluate_dsm (handle_acpi, &wwan_acpi_guid,0 ,3 ,NULL ); -if (!object)
drivers/net/wwan/iosm/iosm_ipc_pcie.c static void ipc_pcie_config_init(struct iosm_pcie *ipc_pcie) · line 258
Quoted 10 lines
drivers/net/wwan/iosm/iosm_ipc_pcie.c +0
-10- goto default_ret; - -if (object->integer.value ==3 ) - sleep_state =IPC_PCIE_D3L2 ; - -ACPI_FREE (object); - -default_ret: -return sleep_state; -}
[Severity: Medium]
The reported case is a BIOS with no WWAN _DSM, where acpi_evaluate_dsm() returns NULL. ipc_pcie_read_bios_cfg() also returned IPC_PCIE_D0L12 in two other cases:
- there is no ACPI handle;
- the _DSM returns a value other than 3, i.e. firmware explicitly selects D0L1.2 or Disabled.
The patch removes the query entirely. It doesn't, for example, default to D3L2 only when the _DSM is missing. So every platform whose firmware explicitly asks for D0L1.2, and all XMM7560 systems (untested per the commit message), now use the host sleep messages.
Is there evidence that these platforms work with ENTER_SLEEP / EXIT_SLEEP?
The commit message argues:
"The doorbells don't wait for the modem"
The replacement path doesn't reliably wait either. ipc_protocol_msg_send() returns 0 when the completion times out:
case 0: /* Timeout, there was no response from the device. ... dev_err(ipc_protocol->dev, "msg timeout"); ipc_uevent_send(ipc_protocol->pcie->dev, UEVENT_MDM_TIMEOUT); break; ... return 0;
So ipc_protocol_suspend() records host_pm_state = IPC_MEM_HOST_PM_SLEEP for an ENTER_SLEEP that the modem never acknowledged.
Platforms whose suspend callback used to return immediately can now block for up to IPC_PM_ACTIVE_TIMEOUT_MS (500 ms) plus the IPC_MSG_COMPLETE_*_TIMEOUT (500 ms). They can also emit UEVENT_MDM_TIMEOUT. The commit message doesn't mention this.
The Fixes: tag points at the driver entry point. That means stable would pick up this platform-wide change based on testing on one machine.
Could the change be limited to the case where the _DSM is missing?
[ ... ]
drivers/net/wwan/iosm/iosm_ipc_pcie.c static const struct pci_device_id iosm_ipc_ids[] = { · line 347
Quoted 9 lines
drivers/net/wwan/iosm/iosm_ipc_pcie.c +0
-5@@ -340,43 +302,6 @@ static const struct pci_device_id iosm_ipc_ids[] = { };MODULE_DEVICE_TABLE (pci, iosm_ipc_ids); -/* Enter sleep in s2idle case -*/ -static int __maybe_unused ipc_pcie_suspend_s2idle (struct iosm_pcie *ipc_pcie) -{ -ipc_cp_irq_sleep_control (ipc_pcie,IPC_MEM_DEV_PM_FORCE_SLEEP );
[Severity: Low]
This isn't a bug, but ipc_pcie_suspend_s2idle() and ipc_pcie_resume_s2idle() were the only users of IPC_MEM_DEV_PM_FORCE_SLEEP and IPC_MEM_DEV_PM_FORCE_ACTIVE. The constants and their kerneldoc are still in enum ipc_mem_dev_pm_state in iosm_ipc_pm.h:
* @IPC_MEM_DEV_PM_FORCE_SLEEP: DOORBELL-IRQ-FORCE_SLEEP.
* @IPC_MEM_DEV_PM_FORCE_ACTIVE: DOORBELL-IRQ-FORCE_ACTIVE.
...
IPC_MEM_DEV_PM_FORCE_SLEEP = 7, IPC_MEM_DEV_PM_FORCE_ACTIVE,
The commit message says the doorbell path is removed. Should these be removed too?
[ ... ]
Quoted 9 lines
drivers/net/wwan/iosm/iosm_ipc_pcie.c +0
-5@@ -406,14 +331,10 @@ static int __maybe_unused ipc_pcie_suspend_cb(struct device *dev) ipc_pcie =pci_get_drvdata (pdev); -switch (ipc_pcie->d3l2_support) { -case IPC_PCIE_D0L12 : -ipc_pcie_suspend_s2idle (ipc_pcie); -break ; -case IPC_PCIE_D3L2 :
drivers/net/wwan/iosm/iosm_ipc_pcie.c static int __maybe_unused ipc_pcie_suspend_cb(struct device *dev) · line 340
Quoted 10 lines
drivers/net/wwan/iosm/iosm_ipc_pcie.c +4
-3-ipc_pcie_suspend (ipc_pcie); -break ; - } +/* The PCI core may put the device into D3, so the modem has to be +* told with the host sleep message first. +*/ +ipc_pcie_suspend (ipc_pcie);return 0 ; }
[Severity: Medium]
Without the FORCE_SLEEP doorbell, the host sleep handshake is now the only way the modem learns about system suspend. Is its result checked anywhere?
ipc_pcie_suspend_cb()
ipc_pcie_suspend() <- always returns 0
ipc_imem_pm_suspend() <- void
ipc_protocol_suspend() <- bool, "false if suspend must be aborted"The kerneldoc for ipc_pcie_suspend() says it returns a failure value on error, but it always returns 0.
ipc_protocol_suspend() resets host_pm_state to IPC_MEM_HOST_PM_ACTIVE and returns false in two cases:
- ipc_pm_wait_for_device_active() times out;
- ipc_protocol_msg_send_host_sleep() fails. That can be -EIO on a bad completion status, a full message ring in ipc_protocol_free_msg_get(), or a task-queue error.
In both cases suspend continues, and the PCI core can put the device into D3hot without the modem being told. The new comment above says that must not happen. The commit message says the same situation leaves the XMM7360 in CD_READY.
On the next resume, ipc_protocol_resume()->ipc_pm_prepare_host_active() finds host_pm_state == IPC_MEM_HOST_PM_ACTIVE instead of IPC_MEM_HOST_PM_SLEEP. It logs a dev_err and returns false. EXIT_SLEEP is then not sent, and ipc_imem_phase_update_check() is skipped.
Separately, ipc_protocol_msg_send() returns 0 on a completion timeout. An unacknowledged ENTER_SLEEP is therefore recorded as IPC_MEM_HOST_PM_SLEEP and treated as success.
Before this patch, D0L1.2 platforms, including every platform without the _DSM, always got the doorbell. This failure mode was limited to D3L2 platforms.
Should the callback fall back to the doorbell, or return an error to abort suspend, when the handshake fails?
Quoted 6 lines
drivers/net/wwan/iosm/iosm_ipc_pcie.c +0
-2@@ -427,14 +348,7 @@ static int __maybe_unused ipc_pcie_resume_cb(struct device *dev) ipc_pcie =pci_get_drvdata (pdev); -switch (ipc_pcie->d3l2_support) { -case IPC_PCIE_D0L12 :
drivers/net/wwan/iosm/iosm_ipc_pcie.c static int __maybe_unused ipc_pcie_resume_cb(struct device *dev) · line 354
Quoted 10 lines
drivers/net/wwan/iosm/iosm_ipc_pcie.c +1
-6-ipc_pcie_resume_s2idle (ipc_pcie); -break ; -case IPC_PCIE_D3L2 : -ipc_pcie_resume (ipc_pcie); -break ; - } +ipc_pcie_resume (ipc_pcie);return 0 ; }
[Severity: Medium]
Both callbacks now always send ENTER_SLEEP / EXIT_SLEEP over the IPC message ring. None of ipc_imem_pm_suspend(), ipc_imem_pm_resume(), ipc_protocol_suspend(), ipc_protocol_resume() or ipc_protocol_msg_send() checks ipc_imem->phase or the exec stage.
Elsewhere, messages are only generated in IPC_P_RUN. For example, ipc_imem_msg_send_device_sleep() is only called from the IPC_P_RUN branch of ipc_imem_handle_irq().
What happens if the modem is in ROM/PSI/EBL, CRASH or CD_READY when the system suspends?
- ipc_pm_init() starts with ap_state and host_pm_state both active, so ipc_pm_prepare_host_sleep() and ipc_pm_wait_for_device_active() pass.
- ipc_protocol_msg_hp_update() advances msg_head and rings the doorbell.
- In IPC_P_ROM, ipc_imem_handle_irq() returns after ipc_imem_rom_irq_exec() and never calls ipc_protocol_msg_process(). The other non-RUN firmware stages don't service the ring either, so no response ever completes.
- ipc_protocol_msg_send() waits IPC_MSG_COMPLETE_BOOT_DEFAULT_TIMEOUT (500 ms), emits UEVENT_MDM_TIMEOUT and returns 0.
That adds about 1 s of blocking and two spurious MDM_TIMEOUT uevents to each suspend/resume cycle.
Each cycle also leaves two ring entries that only the device can retire. ipc_protocol_tq_msg_remove() only clears rsp_ring[], and only the device advances msg_tail.
After about 63 such cycles (IPC_MEM_MSG_ENTRIES is 128), could ipc_protocol_free_msg_get() start failing with "message ring is full"? That would break the handshake and every other message.
Before this patch, D0L1.2 platforms only wrote the FORCE_SLEEP / FORCE_ACTIVE doorbell in these phases, without waiting. The commit message names CD_READY as a state the XMM7360 can be in, and a modem crash or coredump also leads to CRASH / CD_READY.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124172627.41847-1-davidlwesten%40gmail.com
Re: [PATCH net v2 1/3] net: wwan: iosm: reset the host PM state when the sleep handshake times out
In reply to [email protected]Quoted 3 lines
[Severity: Medium]
This is a pre-existing issue, but can an interrupted wait skip the new reset entirely?
Yes, and as you say, patch 2/3 fixes it by switching to wait_for_completion_timeout().
Quoted 3 lines
[Severity: Medium]
Does restoring ACTIVE here let the next suspend consume a stale completion count?
Yes, between this patch and 2/3, which adds reinit_completion() before each wait. If there is a v3, I'll put the wait fix first so that the series has no such gap.
Quoted 3 lines
[Severity: Medium]
Is a doorbell parked duringSLEEP_WAIT_D3ever replayed after this rollback?
Not until the next doorbell to the modem. The existing rollback when sending ENTER_SLEEP fails, which this patch copies, has the same gap, and either path needs the handshake to fail first. Replaying the update on rollback would have to go through the task queue, as the store isn't serialized with the tasklet. I'd rather do that as a separate change than grow this fix.
Quoted 4 lines
[Severity: Medium]
This isn't a bug introduced by this patch, but the new comment says "we are still active" while the suspend still goes ahead. Is the false return fromipc_protocol_suspend()meant to abort the suspend?
The comment is about the driver's host PM state: the modem wasn't told to sleep, so the driver must not behave as if it was. Whether a failed handshake should abort system suspend is a separate question, and the driver has never done that. Aborting would keep the whole system from suspending whenever the modem stops answering, for example after it has crashed, which seems worse than suspending without it. This patch only gets the driver out of the state where every later suspend and resume is refused.
Thanks,
David
Re: [PATCH net v2 3/3] net: wwan: iosm: always send the host sleep message on suspend
In reply to [email protected]Quoted 4 lines
[Severity: Medium]
The reported case is a BIOS with no WWAN
_DSM, whereacpi_evaluate_dsm()returns NULL.
[...]
Quoted 1 line
Could the change be limited to the case where the
_DSMis missing?
The driver only ever acted on the value 3 (D3L2). No value means "D0L1.2 requested", so anything else, including a missing _DSM, fell through to the doorbell default, and that default is what this patch replaces. Platforms whose _DSM returns 3 already use the handshake and see no change.
The reports I know of from platforms on the doorbell path are all failures. On this ThinkPad the modem doesn't survive the doorbells even when it is kept in D0, a similar report on another laptop was fixed by the same change, and f4dd5174e273 tried to fix spurious wakeups on that path and was reverted. If a platform turns up that does need the doorbells, a DMI quirk list could bring them back for it. The v1 thread has more on this:
https://lore.kernel.org/r/[email protected]
Quoted 2 lines
The replacement path doesn't reliably wait either.
ipc_protocol_msg_send()returns 0 when the completion times out:
It waits up to the message timeout for the reply, which the doorbells don't do. That an unacknowledged ENTER_SLEEP still counts as success is true, but it predates this series and is the same on D3L2 platforms.
Quoted 2 lines
The Fixes: tag points at the driver entry point. That means stable would pick up this platform-wide change based on testing on one machine.
There is no Cc: stable. If the series is backported, it should be all three patches or none, since 3/3 sends every platform through the handshake that 1/3 and 2/3 fix.
Quoted 4 lines
[Severity: Medium]
Without the
FORCE_SLEEPdoorbell, the host sleep handshake is now the only way the modem learns about system suspend. Is its result checked anywhere?
[...]
Quoted 2 lines
Should the callback fall back to the doorbell, or return an error to abort suspend, when the handshake fails?
Neither, I think. Falling back to the doorbell is what leaves the modem in CD_READY here. Returning an error would keep the whole system from suspending whenever the modem doesn't answer, for example after it has crashed. D3L2 platforms have always continued the suspend after a failed handshake, and with 1/3 the driver at least no longer gets stuck afterwards.
Quoted 6 lines
[Severity: Medium]
Both callbacks now always send
ENTER_SLEEP/EXIT_SLEEPover the IPC message ring. None ofipc_imem_pm_suspend(),ipc_imem_pm_resume(),ipc_protocol_suspend(),ipc_protocol_resume()oripc_protocol_msg_send()checksipc_imem->phaseor the exec stage.
[...]
Quoted 2 lines
After about 63 such cycles (
IPC_MEM_MSG_ENTRIESis 128), couldipc_protocol_free_msg_get()start failing with "message ring is full"?
Yes, but D3L2 platforms already behave this way today. In CRASH and CD_READY the modem is unusable whatever the driver does, and only a reset recovers it, which probes the driver again and allocates a new ring. In the boot stages the cost is the timeouts. Skipping the handshake when the phase isn't IPC_P_RUN would avoid all of this, though it wouldn't catch a crash the driver hasn't noticed yet, where the phase still reads RUN. I can send that as a follow-up, or add it to this series if that's preferred.
Thanks,
David
Paolo Abeni
maintainerQuoted 14 lines · David Westen
On platforms whose BIOS doesn't select D3L2, iosm tells the modem about system suspend with the
FORCE_SLEEPandFORCE_ACTIVEdoorbells, which the XMM7360 in a ThinkPad X1 Carbon 6th gen doesn't survive. Patch 3 always uses the ENTER_SLEEP/EXIT_SLEEP host sleep messages instead, as discussed in the v1 review. Patches 1 and 2 fix two bugs in that handshake that so far only D3L2 platforms could hit.Changes in v2:
- New patches 1 and 2, for issues the AI review of v1 found.
- Patch 3: rewrite the commit message and remove the doorbell path with everything only it used (Loic).
- Patch 3: fix the Fixes: tag and the comment, and describe testing and hibernation in the commit message (AI review).
Quoted 7 lines
Tested on an XMM7360 with suspend-to-idle, including overnight. Not tested on the XMM7560 or on a platform where the doorbells work.
v1: https://lore.kernel.org/r/[email protected]
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.
Loic: could you please have a look here?
Given the 3/3 size and the possible behavior change to me this is net-next material.
/P