Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: davidlwesten@gmail.com
Cc: netdev@vger.kernel.org, loic.poulain@oss.qualcomm.com,
	ryazanov.s.a@gmail.com, johannes@sipsolutions.net,
	andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, m.chetan.kumar@intel.com,
	mail@maciej.szmigiero.name
Subject: Re: [PATCH net v3 2/2] net: wwan: iosm: re-bind the driver when the modem rebooted during S3
Date: Fri, 27 Nov 2026 19:50:12 +0000	[thread overview]
Message-ID: <179580901222.3135.1177117602258269899@kernel.org> (raw)
In-Reply-To: <20261126194143.32283-3-davidlwesten@gmail.com>

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

      parent reply	other threads:[~2026-11-27 19:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179580901222.3135.1177117602258269899@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=davidlwesten@gmail.com \
    --cc=edumazet@kernel.org \
    --cc=johannes@sipsolutions.net \
    --cc=kuba@kernel.org \
    --cc=loic.poulain@oss.qualcomm.com \
    --cc=m.chetan.kumar@intel.com \
    --cc=mail@maciej.szmigiero.name \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=ryazanov.s.a@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox