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: [email protected]
Signed-off-by: Shawn Guo <[email protected]>
---
 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

Reply via email to