From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796167490; b=SFFPaeHI58EQfwen10UVZp1RriMd8DQXHLFIp2UWHY8AIQl3L2pP0uA69ApN1cEyuidf siwKoF/5p0pfsAdhQe43wXhdUhZldgj63hcYMhpgJ6g6PXnJxWGCMgGDkdaJZ7rGpmJoI nahhFJoovP/eZMJ2bhXjUwvVT53DFecnQVEHtwFDfSOTnTYrIsQ+HmtUdXIUyHFsbd1Da 71JBK8lQbA3aUKBplZhlhW3ozAVnENQ21hWqULlg1w2/hIZm+HYAELc+I8H/V1qVhRHxN YvuYOqxYil9hR0gj4mQJbjNbrinuoUiEDlZqRoVrYMRJrsBbWYzlHzTR3YrHbOcIKrg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796167490; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=4ELhXTxYLkr3V4XGIzjgXbfiPuFrD/DcejFdc49siE8=; b=5DKMldTCAdPthYZpG6dxIu3V0FXahx1Ky3xzw4XB+pgtItdXFUXgWzn5pJwYLZae4fGM Cr9W1Mz4Es0V2yLwZmR39AUaqqcDp/Blk2LPEC+qoNBl3LyRIkTmcOn++PkZ56hmoAHm5 dGkrlHxCdqkv0IeeWb92IgfRv83fj5b8+xiKh/goJWXRfJ+EtR4fhpxIxQPZrO9LwZjBl TX/9bt3tZcSMk4wDD8+bwz/C4VR7VGp6nesnuAPJ0+FXbcV3OaIkYP61+LfJGkzwiHQS3 dZk9datqT17WMBZiFI+79LMLVc9xy+j6CihpI5sFlbvClMnUUP1u/vBRJOrtABMQSrQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=JdAbDnz4; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 91C17606A331; Tue, 1 Dec 2026 23:24:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=JdAbDnz4 Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2DD11F00897; Tue, 1 Dec 2026 23:24:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796167490; bh=4ELhXTxYLkr3V4XGIzjgXbfiPuFrD/DcejFdc49siE8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=JdAbDnz4/vRwqDX2dVpnrM4EkRqd9AIVa9XTQXE/kfBuNzZdGliG36l2Km6hAY3IL GzT6FIgnuFEQmlUoaUvBNTZbtH7ZtNaogMkjkuIvBUejYUNjIGMn+SEH8MS5JGksB4 q4+NQbkAAAyJqyZ4WiiRoH7LObtuh2WQaSY2+swSHYwWcSCveyGEE9+OLdRwZ0qkaJ /nM+HxYn4mZsUZr3X5Uo8YkhsBDJFk+y94R7fl7UBJyzk5otwQqu8VVWk+H4siEpui tOgOp3RoltUJfsGpqzlbU96hwKhMGuKcSr15L2efm0xbY7wa2/wWAxisAFd4ZDIOlk eDfDKyC6g/8PA== From: srini@kernel.org To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, Vinayak Katoch , stable@vger.kernel.org, Shawn Guo , Ekansh Gupta , Srinivas Kandagatla Subject: [PATCH 1/1] misc: fastrpc: make put_work scheduling lock-free Date: Tue, 1 Dec 2026 23:24:34 +0000 Message-ID: <20261201232434.537327-2-srini@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261201232434.537327-1-srini@kernel.org> References: <20261201232434.537327-1-srini@kernel.org> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Vinayak Katoch 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. Fixes: 28b1f55cba43("misc: fastrpc: fix context leak and hang on signal-interrupted invoke") Cc: stable@vger.kernel.org Signed-off-by: Vinayak Katoch Tested-by: Shawn Guo Reviewed-by: Ekansh Gupta Signed-off-by: Srinivas Kandagatla --- 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 56284a7e42ca..ca5af64f3931 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -276,8 +276,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; @@ -656,17 +656,13 @@ static void fastrpc_context_put_wq(struct work_struct *work) fastrpc_context_put(ctx); } -/* Schedules put_work 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); } -- 2.53.0