mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Shawn Guo <shengchao.guo@oss.qualcomm.com>
To: Anandu Krishnan E <anandu.e@oss.qualcomm.com>
Cc: Srinivas Kandagatla <srini@kernel.org>,
	Amol Maheshwari <amahesh@qti.qualcomm.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jorge Ramirez-Ortiz <jorge.ramirez@oss.qualcomm.com>,
	linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org,
	linux-kernel@vger.kernel.org, stable@kernel.org,
	Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
Subject: Re: [PATCH v2] misc: fastrpc: fix context leak and hang on signal-interrupted invoke
Date: Mon, 30 Nov 2026 11:58:04 +0800	[thread overview]
Message-ID: <awz0TMG1-NdBWqyZ@QCOM-aGQu4IUr3Y> (raw)
In-Reply-To: <20260701-master-v2-1-566bf8b7bd16@oss.qualcomm.com>

On Wed, Jul 01, 2026 at 01:41:25PM +0530, Anandu Krishnan E wrote:
> fastrpc invokes work by sending an RPC message to the DSP and blocking
> in wait_for_completion_interruptible() until the DSP responds. If a
> signal arrives during this wait, the syscall returns -ERESTARTSYS and
> the invoke context which holds the in-flight DMA buffers and
> completion state is left stranded in fl->pending.
> 
> On the next syscall attempt (either auto-restarted by the kernel via
> SA_RESTART or manually retried by user-space after EINTR), a fresh
> context is allocated and the RPC message is re-sent to the DSP. This
> has two consequences:
> 
>   - The original context leaks in fl->pending until the file is closed.
>   - The DSP receives a duplicate invocation. If the DSP was mid-way
>     through processing the first request and had issued a reverse RPC
>     call back to the host, the retry sends a new forward request
>     instead of the expected reverse-RPC response. The DSP thread
>     waiting for that response is never woken, causing a hang.
> 
> Fix this by saving the interrupted context to a new fl->interrupted
> list on -ERESTARTSYS. When the same thread retries the invoke with a
> matching sc, restore the context and jump directly to the wait,
> skipping context allocation and message re-send.
> 
> Three additional bugs are also fixed:
> 
> 1. fastrpc_context_save_interrupted() did not drop the extra kref that
>    fastrpc_invoke_send() took, so the worker's put only reached 1 and
>    the context was never freed.  Drop the reference in save_interrupted()
>    so the worker's put reaches 0 and triggers context_free.
> 
> 2. The bail path skipped context cleanup on -ETIMEDOUT, leaking the
>    context.  Remove the -ETIMEDOUT exception so timed-out contexts are
>    freed like any other error path.
> 
> 3. fastrpc_context_free() did not remove the context from fl->interrupted
>    before freeing it.  A context freed via a racing channel removal left
>    a dangling node in the list.  Add list_del_init() guarded by fl->lock
>    before releasing resources.
> 
> Also drain fl->interrupted on process exit, complete any sleeping
> contexts with -EPIPE and schedule put_wq to drop the worker ref when
> the rpmsg channel is removed, and add dev_warn() on TIMEOUT and
> ERESTARTSYS to aid post-mortem debugging.
> 
> Remove the obsolete invoke_interrupted_mmaps mechanism from
> fastrpc_channel_ctx; context resources are now kept alive through the
> context refcount rather than by migrating mmaps to a channel-level list.
> 
> Fixes: 387f625585d1 ("misc: fastrpc: handle interrupted contexts")
> Cc: stable@kernel.org
> Co-developed-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
> Signed-off-by: Anandu Krishnan E <anandu.e@oss.qualcomm.com>

This causes a regression on Nord with stopping adsp, and I sent a patch[1]
fixing it.

root@qcom-armv8a:~# cat /proc/asound/cards
 0 [NORDRIDE       ]: nord - NORD-RIDE
                      NORD-RIDE
root@qcom-armv8a:~# echo stop > /sys/class/remoteproc/remoteproc1/state
[   69.280356] rcu: INFO: rcu_preempt detected stalls on CPUs/tasks:
[   69.286634] rcu:     6-...0: (1 GPs behind) idle=6fec/1/0x4000000000000000 softirq=1101/1102 fqs=1051
[   69.295836] rcu:     16-....: (5256 ticks this GP) idle=6b9c/1/0x4000000000000000 softirq=444/444 fqs=1051
[   69.305493] rcu:     (detected by 9, t=5259 jiffies, g=769, q=3680 ncpus=18)
[   69.312480] Sending NMI from CPU 9 to CPUs 6:
[   79.317699] After 10 seconds, these CPUS still haven't responded to the NMI: 6
[   79.325126] Sending NMI from CPU 9 to CPUs 16:
[   79.329707] NMI backtrace for cpu 16
[   79.329718] CPU: 16 UID: 0 PID: 965 Comm: adsprpcd Not tainted 7.4.0-rc4-next-20261127-00140-gff94c7cf1444 #14 PREEMPT(full)
[   79.329721] Hardware name: Qualcomm Technologies, Inc. SA8797P Ride (DT)
[   79.329721] pstate: 01400005 (nzcv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--)
[   79.329723] pc : queued_spin_lock_slowpath+0x248/0x340
[   79.329733] lr : _raw_spin_lock+0x5c/0x70
[   79.329734] sp : ffff80008555bbe0
[   79.329735] x29: ffff80008555bbe0 x28: ffff800083d35010 x27: ffff0008ada7ef00
[   79.329737] x26: 0000000000000000 x25: 0000000000000000 x24: ffff0008ada7ef4c
[   79.329739] x23: 0000000000000000 x22: ffff0008aad45b00 x21: ffff800083d35028
[   79.329740] x20: ffff0008aad45b74 x19: 00000000ffffffe0 x18: 0000000000000000
[   79.329742] x17: 0000000000000000 x16: ffffa854539ee710 x15: ffff800083d35200
[   79.329743] x14: ffff0008811e9080 x13: 0000000000000206 x12: ffff0008811e90a0
[   79.329745] x11: 00000000000000c0 x10: 074fe19dde1917a1 x9 : ffff0008aad45b76
[   79.329746] x8 : 0000000000000000 x7 : 0000000000000000 x6 : 0000000000000000
[   79.329747] x5 : 0000000000440000 x4 : ffff008fa85dbd40 x3 : ffff008fa85dbd40
[   79.329749] x2 : ffffa854544a9d40 x1 : 0000000000440101 x0 : ffff0008aad45b74
[   79.329750] Call trace:
[   79.329753]  queued_spin_lock_slowpath+0x248/0x340 (P)
[   79.329756]  fastrpc_internal_invoke+0xa8c/0x13e0 [fastrpc]
[   79.329764]  fastrpc_device_ioctl+0x6e8/0x10c0 [fastrpc]
[   79.329766]  __arm64_sys_ioctl+0xa4/0x100
[   79.329771]  invoke_syscall.constprop.0+0x40/0x100
[   79.329776]  el0_svc_common.constprop.0+0x38/0xe0
[   79.329777]  do_el0_svc+0x1c/0x28
[   79.329779]  el0_svc+0x38/0x1d0
[   79.329783]  el0t_64_sync_handler+0xa0/0xe4
[   79.329785]  el0t_64_sync+0x198/0x19c
[   79.493951] rcu: rcu_preempt kthread starved for 2542 jiffies! g769 f0x0 RCU_GP_DOING_FQS(6) ->state=R ->cpu=4
[   79.504231] rcu:     Unless rcu_preempt kthread gets sufficient CPU time, OOM is now expected behavior.
[   79.513615] rcu: RCU grace-period kthread stack dump:
[   79.518819] task:rcu_preempt     state:I stack:0     pid:16    tgid:16    ppid:2      task_flags:0x208040 flags:0x00000010
[   79.530163] Call trace:
[   79.532694]  __switch_to+0xfc/0x1e0 (T)
[   79.536656]  __schedule+0x3dc/0xe20
[   79.540250]  schedule+0x34/0xdc
[   79.543489]  schedule_timeout+0x80/0x104
[   79.547540]  rcu_gp_fqs_loop+0x10c/0x450
[   79.551586]  rcu_gp_kthread+0x108/0x128
[   79.555537]  kthread+0x10c/0x120
[   79.558869]  ret_from_fork+0x10/0x20
[   79.562567] rcu: Stack dump where RCU GP kthread last ran:
[   79.568216] Sending NMI from CPU 9 to CPUs 4:
[   79.572757] NMI backtrace for cpu 4
[   79.572770] CPU: 4 UID: 0 PID: 0 Comm: swapper/4 Not tainted 7.4.0-rc4-next-20261127-00140-gff94c7cf1444 #14 PREEMPT(full)
[   79.572774] Hardware name: Qualcomm Technologies, Inc. SA8797P Ride (DT)
[   79.572776] pstate: 61400005 (nZCv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--)
[   79.572780] pc : cpuidle_enter_state+0xb0/0x380
[   79.572792] lr : cpuidle_enter_state+0xa8/0x380
[   79.572794] sp : ffff8000801a3d90
[   79.572795] x29: ffff8000801a3d90 x28: 0000000000000000 x27: 0000000000000000
[   79.572800] x26: 0000001286e2f8d2 x25: 0000000000000000 x24: 0000000000000000
[   79.572803] x23: 0000000000000001 x22: ffff000884942080 x21: ffff008fa84a17f8
[   79.572806] x20: 0000000000000001 x19: 0000001286e7cf05 x18: 0000000000000000
[   79.572809] x17: 0000000000000005 x16: ffffa854539ee4e0 x15: ffff008fa84a1b34
[   79.572812] x14: ffff008fa84a1870 x13: 0000000000000000 x12: 0000000000000002
[   79.572815] x11: ffff008fa84a1b30 x10: 0000000000000001 x9 : 0000000000000001
[   79.572818] x8 : ffff000884811438 x7 : ffff583b53ffa000 x6 : 0000000017f84251
[   79.572821] x5 : 00ffffffffffffff x4 : 0000000000000015 x3 : 000000000106cd38
[   79.572824] x2 : ffff583b53ffa000 x1 : ffff008fa84a2f80 x0 : 0000000000000000
[   79.572827] Call trace:
[   79.572829]  cpuidle_enter_state+0xb0/0x380 (P)
[   79.572832]  cpuidle_enter+0x34/0x48
[   79.572841]  do_idle+0x148/0x300
[   79.572847]  cpu_startup_entry+0x34/0x40
[   79.572849]  secondary_start_kernel+0x13c/0x15c
[   79.572857]  __secondary_switched+0xc0/0xc4

Shawn

[1] https://lore.kernel.org/all/20261130035246.4119744-1-shengchao.guo@oss.qualcomm.com/

      parent reply	other threads:[~2026-11-30  3:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-01  8:11 Anandu Krishnan E
2026-07-24 11:20 ` Srinivas Kandagatla
2026-07-27  7:12   ` Anandu Krishnan E
2026-09-17  4:18 ` Abhinav Parihar
2026-11-24 21:06 ` Srinivas Kandagatla
2026-11-30  3:58 ` Shawn Guo [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=awz0TMG1-NdBWqyZ@QCOM-aGQu4IUr3Y \
    --to=shengchao.guo@oss.qualcomm.com \
    --cc=amahesh@qti.qualcomm.com \
    --cc=anandu.e@oss.qualcomm.com \
    --cc=arnd@arndb.de \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jorge.ramirez@oss.qualcomm.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=srini@kernel.org \
    --cc=srinivas.kandagatla@oss.qualcomm.com \
    --cc=stable@kernel.org \
    /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

all inboxes | Powered by JetHome®