Netdev List
 help / color / mirror / Atom feed
* [PATCH net] net: wwan: iosm: return the callback result of synchronous tasks
@ 2026-11-27  3:48 David Westen
  2026-11-28  3:49 ` netdev-bot+sashiko
  0 siblings, 1 reply; 3+ messages in thread
From: David Westen @ 2026-11-27  3:48 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, David Westen

ipc_task_queue_send_task() is documented to return the callback's
result, but returns 0 whenever the callback succeeds.
ipc_protocol_msg_send() uses that result as the message ring slot that
points to its on-stack response, so a timeout clears slot 0 and leaves
the real slot pointing to the returned stack frame. A late reply then
calls complete() on it:

  BUG: unable to handle page fault for address: fffffffffffffff8
  RIP: 0010:complete+0x9c/0x2b0
  Call Trace:
   <IRQ>
   ipc_protocol_msg_process
   ipc_imem_tq_irq_cb
   ipc_task_queue_handler

Return the callback result. The other callers see the same values as
before.

Reproduced on an XMM7360 by forcing pipe open and close timeouts.

Fixes: 3b575260cb86 ("net: iosm: bottom half")
Signed-off-by: David Westen <davidlwesten@gmail.com>
---

Notes:
    The bug was found in an AI-assisted review of the driver. The
    investigation, the test changes, the patch and this changelog were done
    with an AI coding assistant (Claude Opus 5.5). I ran the tests and
    reviewed the result.

 drivers/net/wwan/iosm/iosm_ipc_task_queue.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/net/wwan/iosm/iosm_ipc_task_queue.c b/drivers/net/wwan/iosm/iosm_ipc_task_queue.c
index 7cb2f6a506d9..069075481825 100644
--- a/drivers/net/wwan/iosm/iosm_ipc_task_queue.c
+++ b/drivers/net/wwan/iosm/iosm_ipc_task_queue.c
@@ -162,10 +162,8 @@ int ipc_task_queue_send_task(struct iosm_imem *imem,
 			copy, size, is_copy);
 		if (is_copy)
 			kfree(copy);
-		goto out;
 	}
 
-	ret = 0;
 out:
 	return ret;
 }
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net: wwan: iosm: return the callback result of synchronous tasks
  2026-11-27  3:48 [PATCH net] net: wwan: iosm: return the callback result of synchronous tasks David Westen
@ 2026-11-28  3:49 ` netdev-bot+sashiko
  2026-11-28 16:32   ` David Westen
  0 siblings, 1 reply; 3+ messages in thread
From: netdev-bot+sashiko @ 2026-11-28  3:49 UTC (permalink / raw)
  To: davidlwesten
  Cc: netdev, loic.poulain, ryazanov.s.a, johannes, andrew+netdev,
	davem, edumazet, kuba, pabeni, m.chetan.kumar

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 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).

- [High] The fix still leaves a way for a late device reply to call
  complete() on a returned stack frame.
- [Medium] The patch now passes the callback result through unchanged,
  and ipc_protocol_msg_send() uses it as the rsp_ring index.

--

net: wwan: iosm: return the callback result of synchronous tasks

This patch makes ipc_task_queue_send_task() return the callback result
instead of 0 when the task was queued and completed. ipc_protocol_msg_send()
uses that value as the rsp_ring index. With this change, a timeout clears
the slot that actually points at its on-stack response.

> diff --git a/drivers/net/wwan/iosm/iosm_ipc_task_queue.c b/drivers/net/wwan/iosm/iosm_ipc_task_queue.c
> index 7cb2f6a506d9f..069075481825e 100644
> --- a/drivers/net/wwan/iosm/iosm_ipc_task_queue.c
> +++ b/drivers/net/wwan/iosm/iosm_ipc_task_queue.c
> @@ -162,10 +162,8 @@ int ipc_task_queue_send_task(struct iosm_imem *imem,
>  			copy, size, is_copy);
>  		if (is_copy)
>  			kfree(copy);
> -		goto out;
>  	}
>  
> -	ret = 0;
>  out:
>  	return ret;
>  }

[Severity: High]
The index is now correct. Can a late reply still call complete() on a
returned stack frame if the remove task itself fails to queue?

The timeout path in ipc_protocol_msg_send() ignores the return value of
the remove call:

drivers/net/wwan/iosm/iosm_ipc_protocol.c:ipc_protocol_msg_send() {
    ...
	case 0:
		ipc_task_queue_send_task(ipc_protocol->imem,
					 ipc_protocol_tq_msg_remove, index,
					 NULL, 0, true);
		dev_err(ipc_protocol->dev, "msg timeout");
    ...
	return 0;
}

If the 256-entry task ring is full, ipc_task_queue_add_task() takes the
"queue is full" branch. It then returns -EIO without ever running
ipc_protocol_tq_msg_remove():

	if (nextpos != ipc_task->q_rpos) {
		...
	}
	...
	} else {
		dev_err(ipc_imem->ipc_task->dev, "queue is full");
	}

In that case rsp_ring[index] still points at the on-stack struct ipc_rsp
response after ipc_protocol_msg_send() has returned 0. When the device
answers later, ipc_protocol_msg_process() does:

		if (rsp_ring[i]) {
			rsp_ring[i]->status =
				le32_to_cpu(msg->common.completion_status);
			complete(&rsp_ring[i]->completion);
			rsp_ring[i] = NULL;
		}

That looks like the same oops shown in the commit message, which says:

    so a timeout clears slot 0 and leaves the real slot pointing to the
    returned stack frame. A late reply then calls complete() on it

Should the failed enqueue be handled too? Some options would be retrying,
clearing the slot under a lock the tasklet also takes, or not returning
while rsp_ring[index] can still reference the stack.

[Severity: Medium]
Now that the exact callback result is used as an rsp_ring index, is the
read of that result in ipc_task_queue_add_task() safe?

drivers/net/wwan/iosm/iosm_ipc_task_queue.c:ipc_task_queue_add_task() {
    ...
		if (wait) {
			wait_for_completion(&completion);
			result = ipc_task->args[pos].response;
		}
    ...
}

This reads args[pos] without q_lock and without checking that the slot
still belongs to this caller.

ipc_task_queue_handler() calls complete(), clears the entry and moves
q_rpos past pos right away:

		if (args->completion)
			complete(args->completion);
		...
		q_rpos = (q_rpos + 1) % IPC_THREAD_QUEUE_SIZE;
		ipc_task->q_rpos = q_rpos;

So slot pos can be reused before the woken waiter runs. If the ring
wraps, a new producer writes args[pos].response = -1 under q_lock. The
tasklet may then store another callback's result in that slot.

One way this could happen: the queue is nearly full and the tasklet runs
on the waiter's CPU. The tasklet keeps looping in softirq while
IRQ-context producers refill slot pos, and the waiter cannot read its
result in the meantime. Whether this shows up on real systems depends on
load and timing.

If the waiter reads -1, ipc_protocol_msg_send() returns an error even
though the message was sent and rsp_ring[real_index] = &response.

If it reads another task's result, the timeout path clears the wrong
slot.

Either way, a later device reply would call complete() on a returned
stack frame.

The comment in ipc_task_queue_handler() relies on timing ("queue will not
rotate again to ipc_task same element within such short time") rather
than on synchronization.

Would it be more robust to keep the response in caller-owned storage, for
example next to the on-stack completion, instead of re-reading the shared
ring slot?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261127034849.11770-1-davidlwesten%40gmail.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net: wwan: iosm: return the callback result of synchronous tasks
  2026-11-28  3:49 ` netdev-bot+sashiko
@ 2026-11-28 16:32   ` David Westen
  0 siblings, 0 replies; 3+ messages in thread
From: David Westen @ 2026-11-28 16:32 UTC (permalink / raw)
  To: netdev-bot+sashiko, davidlwesten
  Cc: netdev, loic.poulain, ryazanov.s.a, johannes, andrew+netdev,
	davem, edumazet, kuba, pabeni, m.chetan.kumar

On Sat, Nov 28, 2026 at 03:49:14AM +0000, netdev-bot+sashiko@kernel.org wrote:
> [Severity: High]
> The index is now correct. Can a late reply still call complete() on a
> returned stack frame if the remove task itself fails to queue?

Yes, but this isn't new. Before this patch, a timeout cleared slot 0
if the remove task was queued and nothing if it wasn't, so unless the
message was in slot 0, a late reply could reach the stack frame either
way. This patch fixes the queued case. The queue-full case is a
separate bug, where the return value of the remove task is ignored,
and is unchanged here.

> [Severity: Medium]
> Now that the exact callback result is used as an rsp_ring index, is the
> read of that result in ipc_task_queue_add_task() safe?

No, but this patch doesn't make it worse. A waiter that reads -1 already
returned an error while rsp_ring[index] still pointed at its response.
Before this patch, any other value led to slot 0 being cleared on a
timeout, which was already wrong.

Thanks,
David

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-28 16:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27  3:48 [PATCH net] net: wwan: iosm: return the callback result of synchronous tasks David Westen
2026-11-28  3:49 ` netdev-bot+sashiko
2026-11-28 16:32   ` David Westen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox