This series fixes a context leak and DSP hang that occur when a
fastrpc invoke syscall is interrupted by a signal (patch 3), plus two
independent, pre-existing bugs the refcounting audit for that fix
surfaced along the way (patches 1 and 2).

Signed-off-by: Anandu Krishnan E <[email protected]>
---
Changes in v4:
- Split the single patch into a 3-patch series. Patches 1 and 2 are
  standalone, pre-existing bugs the refcounting audit for this series
  surfaced - dead code in fastrpc_user_free() and a worker-reference
  leak on SSR for ordinary (never-interrupted) pending contexts - each
  with its own Fixes: tag, landing ahead of the actual
  interrupted-invoke fix in patch 3.
- Fixed a hang inherited from v1-v3: fastrpc_invoke_send() failure
  shared the same bail: label as a post-send wait interruption, so a
  message that rpmsg_send() itself never delivered to the DSP could
  still be parked as resumable, and a retry would then wait forever
  for a response that was never going to arrive. fastrpc_invoke_send()
  failure now gets its own dedicated cleanup path instead, without
  needing an extra flag to tell the two cases apart.
- fastrpc_device_release() now also accounts for a successful
  fastrpc_release_current_dsp_process(): if the DSP confirms it is
  done with the whole process, the worker reference on any parked
  context is dropped immediately instead of always waiting for a
  later event.
- fastrpc_user_free() no longer unlinks fl from cctx->users
  unconditionally at fd close; it now does so only once fl truly has
  no references left, so a context still awaiting a DSP response
  after fd close remains reachable by a later SSR.
- Extended the same unreachable-orphan fix to timed-out kernel
  invokes (-ETIMEDOUT), which had the identical problem on
  fl->pending.
- fastrpc_context_restore_interrupted() now uses kref_get_unless_zero()
  when reclaiming a matched context on retry, closing a race where a
  concurrent drain (SSR, fd close, or a delayed DSP response) could
  already have dropped the context's last reference and be waiting on
  the same lock to unlink it.
- Link to v3: 
https://lore.kernel.org/all/20261002-anandu-fastrpc-interrupted-invoke-v3-v3-1-31e90439d...@oss.qualcomm.com/

Changes in v3:
- fastrpc_context_save_interrupted() no longer drops a reference when
  parking the context, fixing a kref double-put that left the context
  under-refcounted.
- Restoring an interrupted context now matches on both handle and sc,
  not sc alone, so a stale/differently-shaped retry cannot be handed a
  buffer layout it didn't allocate.
- A mismatched handle/sc on retry now falls through to allocating a
  fresh context instead of returning -EINVAL, so a thread issuing a
  different call after an interrupted one is never permanently
  wedged.
- Added a put_work_scheduled flag, checked and set under fl->lock, to
  guard against fastrpc_notify_users() and fastrpc_rpmsg_callback()
  both scheduling put_work for the same context.
- fastrpc_device_release() now drains fl->interrupted and drops the
  invoker's reference on each parked context before releasing its own
  reference on fl, fixing a leak of both fl and the context if the fd
  is closed while a context is still parked.
- fastrpc_device_release()'s and fastrpc_user_free()'s drain loops now
  use list_del_init() instead of list_del(), avoiding a poisoned-node
  list_empty() check in fastrpc_context_free().
- fastrpc_invoke_send() can return -ERESTARTSYS from rpmsg_send()
  itself before the message is ever delivered to the DSP. This is now
  distinguished with a `sent` flag so only a completion-wait
  interruption after a successful send is parked as resumable.
- ctx->args is now repointed at the retry's args on resume instead of
  pointing at the original call's already-freed buffers; an
  args_owned flag lets fastrpc_context_free() free ctx->args if a
  parked context is drained/abandoned without ever being resumed.
- Link to v2: 
https://lore.kernel.org/all/[email protected]/

Changes in v2:
- Fix kref imbalance: fastrpc_context_save_interrupted() now drops the
  extra reference taken by fastrpc_invoke_send(), so the worker's put
  correctly reaches 0 and triggers context_free.
- Fix -ETIMEDOUT context leak: remove the ETIMEDOUT exception from the
  bail path so timed-out kernel invocations go through the same
  list_del_init + context_put cleanup as all other error paths.
- Fix dangling node: fastrpc_context_free() now calls list_del_init()
  under fl->lock before releasing resources, preventing a dangling node
  in fl->interrupted if a racing channel removal fires put_wq.
- fastrpc_notify_users() now calls schedule_work(&ctx->put_work) for
  interrupted contexts to drop the worker ref on channel removal.
- Add dev_warn() on TIMEOUT and ERESTARTSYS for post-mortem debugging.
- Use list_del_init() instead of list_del() in the bail path.
- Link to v1: 
https://lore.kernel.org/all/[email protected]/
---
To: Srinivas Kandagatla <[email protected]>
To: Ekansh Gupta <[email protected]>
To: Arnd Bergmann <[email protected]>
To: Greg Kroah-Hartman <[email protected]>
To: Jorge Ramirez-Ortiz <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: Srinivas Kandagatla <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
Anandu Krishnan E (3):
      misc: fastrpc: remove dead context drain in fastrpc_user_free()
      misc: fastrpc: drop the DSP-response reference on channel removal
      misc: fastrpc: fix context leak and hang on signal-interrupted invoke

 drivers/misc/fastrpc.c | 187 ++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 146 insertions(+), 41 deletions(-)
---
base-commit: 749a4de370409464cf8501ec5b2451df45c84eb4
change-id: 20261117-interrupted-invoke-v4-f2e5be78eba8

Best regards,
--  
Anandu Krishnan E <[email protected]>

Reply via email to