Before 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. Fixes: be8c936e540f ("net: iosm: power management") Signed-off-by: David Westen --- drivers/net/wwan/iosm/iosm_ipc_pm.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/drivers/net/wwan/iosm/iosm_ipc_pm.c b/drivers/net/wwan/iosm/iosm_ipc_pm.c index 413601c72dcd..c76cb9663039 100644 --- a/drivers/net/wwan/iosm/iosm_ipc_pm.c +++ b/drivers/net/wwan/iosm/iosm_ipc_pm.c @@ -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); -- 2.56.0