From 92d6297530789ecbf9cde30380e8bf2f386401ea Mon Sep 17 00:00:00 2001 From: Vinayak Katoch Date: Fri, 27 Nov 2026 15:34:09 +0530 Subject: [PATCH 1/2] FROMLIST: misc: fastrpc: make put_work scheduling lock-free fastrpc_context_schedule_put_work() guards the once-only schedule_work() with fl->lock. That helper is called from fastrpc_rpmsg_callback(), which runs in hard-IRQ context on the glink rx interrupt, while every other user of fl->lock takes it with a plain spin_lock() in process context with interrupts enabled. If the glink interrupt fires on a CPU that is already holding fl->lock, for example fastrpc_context_put_wq() -> fastrpc_context_free() or fastrpc_free_map() running in a kworker on that CPU, the handler spins on the lock the interrupted code holds. The holder can never run again, so the CPU hangs with interrupts masked, an RCU stall is reported for it, and the system is eventually reset by the watchdog. It is easy to hit because schedule_work() queues onto the local CPU's worker pool, so the worker that takes fl->lock tends to run on the very CPU that receives the glink interrupt. The same helper is also called by fastrpc_notify_users() while it holds user->lock, and ctx->fl == user, so a context left on fl->pending or fl->interrupted when the channel is removed deadlocks on the same lock there too. The flag is only used to make sure put_work is queued once, so no lock is needed. Turn it into an atomic_t and claim it with atomic_xchg(). Whichever caller sees the old value 0 queues the work; any later or racing caller sees 1 and does nothing. This makes the helper safe from hard-IRQ context and with fl->lock already held. Link: https://lore.kernel.org/all/20261127-fix-put-work-irq-deadlock-v1-1-3aa66fe4f2c9@oss.qualcomm.com/ Fixes: 3f645f6884b5 ("misc: fastrpc: fix context leak and hang on signal-interrupted invoke") Cc: stable@vger.kernel.org Tested-by: Shawn Guo Reviewed-by: Ekansh Gupta Signed-off-by: Vinayak Katoch --- drivers/misc/fastrpc.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index c1a6cc2a33624..2bb990f6921b0 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -279,8 +279,8 @@ struct fastrpc_invoke_ctx { bool is_work_done; /* process updates poll memory instead of glink response */ bool is_polled; - /* set once put_work has been scheduled for this ctx, guarded by fl->lock */ - bool put_work_scheduled; + /* set once put_work is queued; atomic as it's set from IRQ context */ + atomic_t put_work_scheduled; struct kref refcount; struct list_head node; /* list of ctxs */ struct completion work; @@ -680,17 +680,13 @@ static void fastrpc_context_put_wq(struct work_struct *work) fastrpc_context_put(ctx); } -/* Ensures put_work is scheduled at most once per ctx; racing callers may both try. */ +/* + * Schedules put_work at most once per ctx. Must stay lock-free: it runs from + * the glink rx hard-IRQ and from fastrpc_notify_users() with fl->lock held. + */ 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; - spin_unlock(&ctx->fl->lock); - - if (do_schedule) + if (!atomic_xchg(&ctx->put_work_scheduled, 1)) schedule_work(&ctx->put_work); } From d574cae3de7bcc833248f16895572b5fa0cc3f77 Mon Sep 17 00:00:00 2001 From: Salendarsingh Gaud Date: Wed, 2 Dec 2026 15:56:04 +0530 Subject: [PATCH 2/2] FIXUP: misc: fastrpc: use helper to schedule context put work The put_work_scheduled field was converted to atomic_t, but fastrpc_notify_users() still accesses it directly as a boolean. This results in build errors due to the incompatible atomic_t type. Use fastrpc_context_schedule_put_work() to atomically test and set the state before scheduling the work. Fixes: https://github.com/qualcomm-linux/kernel/issues/1606 Signed-off-by: Ekansh Gupta --- drivers/misc/fastrpc.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 2bb990f6921b0..672da2a64b761 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -3080,10 +3080,7 @@ static void fastrpc_notify_users(struct fastrpc_user *user) list_for_each_entry(ctx, &user->interrupted, node) { ctx->retval = -EPIPE; complete(&ctx->work); - if (!ctx->put_work_scheduled) { - ctx->put_work_scheduled = true; - schedule_work(&ctx->put_work); - } + fastrpc_context_schedule_put_work(ctx); } spin_unlock(&user->lock); }