]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
SUNRPC: Prevent looping due to rpc_signal_task() races
authorTrond Myklebust <trond.myklebust@hammerspace.com>
Sat, 1 Feb 2025 20:00:02 +0000 (15:00 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 7 Mar 2025 17:25:27 +0000 (18:25 +0100)
[ Upstream commit 5bbd6e863b15a85221e49b9bdb2d5d8f0bb91f3d ]

If rpc_signal_task() is called while a task is in an rpc_call_done()
callback function, and the latter calls rpc_restart_call(), the task can
end up looping due to the RPC_TASK_SIGNALLED flag being set without the
tk_rpc_status being set.
Removing the redundant mechanism for signalling the task fixes the
looping behaviour.

Reported-by: Li Lingfeng <lilingfeng3@huawei.com>
Fixes: 39494194f93b ("SUNRPC: Fix races with rpc_killall_tasks()")
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Anna Schumaker <anna.schumaker@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/linux/sunrpc/sched.h
include/trace/events/sunrpc.h
net/sunrpc/sched.c

index fec1e8a1570c36099729afa67cafa67e286a5d5e..eac57914dcf3200c1a6ed39ab030e3fe8b4da3e1 100644 (file)
@@ -158,7 +158,6 @@ enum {
        RPC_TASK_NEED_XMIT,
        RPC_TASK_NEED_RECV,
        RPC_TASK_MSG_PIN_WAIT,
-       RPC_TASK_SIGNALLED,
 };
 
 #define rpc_test_and_set_running(t) \
@@ -171,7 +170,7 @@ enum {
 
 #define RPC_IS_ACTIVATED(t)    test_bit(RPC_TASK_ACTIVE, &(t)->tk_runstate)
 
-#define RPC_SIGNALLED(t)       test_bit(RPC_TASK_SIGNALLED, &(t)->tk_runstate)
+#define RPC_SIGNALLED(t)       (READ_ONCE(task->tk_rpc_status) == -ERESTARTSYS)
 
 /*
  * Task priorities.
index 5e8495216689549f1c0bb377911eac4a7bb7b1a8..5fe852bd31abc90741511a73b8cc42134585cabe 100644 (file)
@@ -360,8 +360,7 @@ TRACE_EVENT(rpc_request,
                { (1UL << RPC_TASK_ACTIVE), "ACTIVE" },                 \
                { (1UL << RPC_TASK_NEED_XMIT), "NEED_XMIT" },           \
                { (1UL << RPC_TASK_NEED_RECV), "NEED_RECV" },           \
-               { (1UL << RPC_TASK_MSG_PIN_WAIT), "MSG_PIN_WAIT" },     \
-               { (1UL << RPC_TASK_SIGNALLED), "SIGNALLED" })
+               { (1UL << RPC_TASK_MSG_PIN_WAIT), "MSG_PIN_WAIT" })
 
 DECLARE_EVENT_CLASS(rpc_task_running,
 
index cef623ea150609cabf811f6945f74a9796c2dd60..9b45fbdc90cabec75582bfc1a583f4db5486eacf 100644 (file)
@@ -864,8 +864,6 @@ void rpc_signal_task(struct rpc_task *task)
        if (!rpc_task_set_rpc_status(task, -ERESTARTSYS))
                return;
        trace_rpc_task_signalled(task, task->tk_action);
-       set_bit(RPC_TASK_SIGNALLED, &task->tk_runstate);
-       smp_mb__after_atomic();
        queue = READ_ONCE(task->tk_waitqueue);
        if (queue)
                rpc_wake_up_queued_task(queue, task);