mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] misc: fastrpc: fix self-deadlock in fastrpc_notify_users()
@ 2026-11-30  3:52 Shawn Guo
  2026-11-30  8:10 ` Ekansh Gupta
  0 siblings, 1 reply; 2+ messages in thread
From: Shawn Guo @ 2026-11-30  3:52 UTC (permalink / raw)
  To: Srinivas Kandagatla
  Cc: Ekansh Gupta, Arnd Bergmann, Greg Kroah-Hartman,
	Anandu Krishnan E, linux-arm-msm, dri-devel, linux-kernel,
	Shawn Guo, stable

fastrpc_notify_users() holds user->lock while it walks the pending and
interrupted lists, and calls fastrpc_context_schedule_put_work() for
each context. That helper takes ctx->fl->lock, which is the same lock,
so the CPU spins on a lock it already holds. Since the caller,
fastrpc_rpmsg_remove(), also holds cctx->lock with interrupts disabled,
the CPU is stuck with IRQs off. Any invoker woken by the preceding
complete() then spins on fl->lock as well.

This is hit on every remoteproc stop of a DSP with an active fastrpc
user, e.g. on Nord Ride:

  echo stop > /sys/class/remoteproc/remoteproc1/state
  rcu: INFO: rcu_preempt detected stalls on CPUs/tasks:
  ...
  Call trace:
   queued_spin_lock_slowpath+0x248/0x340 (P)
   fastrpc_internal_invoke+0xa8c/0x13e0 [fastrpc]
   fastrpc_device_ioctl+0x6e8/0x10c0 [fastrpc]

Add __fastrpc_context_schedule_put_work() for callers that already
hold fl->lock, and use it in fastrpc_notify_users().

Fixes: 3f645f6884b5 ("misc: fastrpc: fix context leak and hang on signal-interrupted invoke")
Cc: stable@vger.kernel.org
Signed-off-by: Shawn Guo <shengchao.guo@oss.qualcomm.com>
---
 drivers/misc/fastrpc.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 5375847d8c9a..be183e55faa1 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -661,18 +661,24 @@ static void fastrpc_context_put_wq(struct work_struct *work)
 	fastrpc_context_put(ctx);
 }
 
+/* Caller must hold ctx->fl->lock. */
+static void __fastrpc_context_schedule_put_work(struct fastrpc_invoke_ctx *ctx)
+{
+	lockdep_assert_held(&ctx->fl->lock);
+
+	if (ctx->put_work_scheduled)
+		return;
+
+	ctx->put_work_scheduled = true;
+	schedule_work(&ctx->put_work);
+}
+
 /* Schedules put_work at most once per ctx; racing callers may both try. */
 static void fastrpc_context_schedule_put_work(struct fastrpc_invoke_ctx *ctx)
 {
-	bool do_schedule;
-
 	spin_lock(&ctx->fl->lock);
-	do_schedule = !ctx->put_work_scheduled;
-	ctx->put_work_scheduled = true;
+	__fastrpc_context_schedule_put_work(ctx);
 	spin_unlock(&ctx->fl->lock);
-
-	if (do_schedule)
-		schedule_work(&ctx->put_work);
 }
 
 /* References held by ctx are left intact; only list membership changes. */
@@ -2808,7 +2814,7 @@ static void fastrpc_notify_users(struct fastrpc_user *user)
 	list_for_each_entry(ctx, &user->pending, node) {
 		ctx->retval = -EPIPE;
 		complete(&ctx->work);
-		fastrpc_context_schedule_put_work(ctx);
+		__fastrpc_context_schedule_put_work(ctx);
 	}
 	/*
 	 * Invoker ref for a parked context is released by fastrpc_user_free()
@@ -2817,7 +2823,7 @@ static void fastrpc_notify_users(struct fastrpc_user *user)
 	list_for_each_entry(ctx, &user->interrupted, node) {
 		ctx->retval = -EPIPE;
 		complete(&ctx->work);
-		fastrpc_context_schedule_put_work(ctx);
+		__fastrpc_context_schedule_put_work(ctx);
 	}
 	spin_unlock(&user->lock);
 }
-- 
2.43.0


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

end of thread, other threads:[~2026-11-30  8:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30  3:52 [PATCH] misc: fastrpc: fix self-deadlock in fastrpc_notify_users() Shawn Guo
2026-11-30  8:10 ` Ekansh Gupta

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®