SUNRPC: Set tk_rpc_status when RPC_TASK_SIGNALLED is detected
Subsystems (4)
PATCH 1/1 SUNRPC: Set tk_rpc_status when RPC_TASK_SIGNALLED is detected
Commit 39494194f93b("SUNRPC: Fix races with rpc_killall_tasks()") adds rpc_task_set_rpc_status before setting RPC_TASK_SIGNALLED in rpc_signal_task, ensuring that rpc_status is definitely set when RPC_TASK_SIGNALLED is set.
Therefore, it seems unnecessary to set rpc_status again after detecting RPC_TASK_SIGNALLED in rpc_check_timeout.
However, in some exceptional cases, invalid and endlessly looping rpc_tasks may be generated. The rpc_call_rpcerror in rpc_check_timeout can timely terminate such rpc_tasks. Removing rpc_call_rpcerror may cause the rpc_task to fall into an infinite loop.
For example, in the following situation:nfs4_close_done
// get err from server
nfs4_async_handle_exception
// goto out_restart
// umount -f
nfs_umount_begin
rpc_killall_tasks
rpc_signal_task
rpc_task_set_rpc_status
task->tk_rpc_status = -ERESTARTSYS
set_bit
// set RPC_TASK_SIGNALLED to tk_runstate
rpc_restart_call_prepare
__rpc_restart_call
task->tk_rpc_status = 0
// clear tk_rpc_status
...
rpc_prepare_task
nfs4_close_prepare
nfs4_setup_sequence
rpc_call_start
task->tk_action = call_startAt this point, an rpc_task with RPC_TASK_SIGNALLED set but tk_rpc_status as 0 will be generated. This rpc_task will fall into the following loop:call_encode --> call_transmit --> call_transmit_status --> call_status --> call_encode.
Since RPC_TASK_SIGNALLED is set, no request will be sent in call_transmit. Similarly, since RPC_TASK_SIGNALLED is set, rq_majortimeo will not be updated in call_status --> rpc_check_timeout, which will cause -ETIMEDOUT to be directly set to tk_status in call_transmit_status --> xprt_request_wait_receive --> xprt_wait_for_reply_request_def --> rpc_sleep_on_timeout --> __rpc_sleep_on_priority_timeout.
Here is the state and loop process of the rpc_task:tk_runstate:RPC_TASK_RUNNING RPC_TASK_ACTIVE RPC_TASK_NEED_RECV RPC_TASK_SIGNALLED tk_xprt->state:XPRT_CONNECTED XPRT_BOUNDtk_flagsRPC_TASK_ASYNC RPC_TASK_MOVEABLE RPC_TASK_DYNAMIC RPC_TASK_SOFT RPC_TASK_NO_RETRANS_TIMEOUT RPC_TASK_CRED_NOREF
call_encode
xprt_request_enqueue_transmit
set_bit // RPC_TASK_NEED_XMIT
task->tk_action = call_transmit
call_transmit
task->tk_action = call_transmit_status xprt_transmit
xprt_request_transmit
// check RPC_TASK_SIGNALLED and goto out_dequeue xprt_request_dequeue_transmit
xprt_request_dequeue_transmit_locked
test_and_clear_bit // RPC_TASK_NEED_XMIT
call_transmit_status
task->tk_action = call_status
xprt_request_wait_receive
xprt_wait_for_reply_request_def
xprt_request_timeout // get timeout
req->rq_majortimeo // rq_majortimeo will not be updated
rpc_sleep_on_timeout
__rpc_sleep_on_priority_timeout
task->tk_status = -ETIMEDOUT // set ETIMEDOUTcall_status
task->tk_action = call_encode
rpc_check_timeout
// check RPC_TASK_SIGNALLED and skip xprt_reset_majortimeo
Fix it by adding rpc_call_rpcerror back.
--- net/sunrpc/clnt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/sunrpc/clnt.c +3 -1
@@ -2509,8 +2509,10 @@ rpc_check_timeout(struct rpc_task *task) {struct rpc_clnt *clnt = task->tk_client; -if (RPC_SIGNALLED (task)) +if (RPC_SIGNALLED (task)) { +rpc_call_rpcerror (task, -ERESTARTSYS );return ; + }if (xprt_adjust_timeout (task->tk_rqstp) ==0 )return ;
Signature · 1 line
2.31.1
Hi,
Thanks for the patch.
Before 39494194f93b("SUNRPC: Fix races with rpc_killall_tasks()", every time we set RPC_TASK_SIGNALLED, when we go through __rpc_execute, this rpc_task will immediate break and exist.
However after that, __rpc_execute won't judge RPC_TASK_SIGNNALED, so for the case like you point out below, even after your commit rpc_check_timeout will help break and exist eventually, but this rpc_task has already do some work. I prefer reintroduce judging RPC_TASK_SIGNNALED in __rpc_execute to help exist immediatly.
Quoted 110 lines · Li Lingfeng
Commit 39494194f93b("SUNRPC: Fix races with
rpc_killall_tasks()") addsrpc_task_set_rpc_statusbefore settingRPC_TASK_SIGNALLEDinrpc_signal_task, ensuring thatrpc_statusis definitely set whenRPC_TASK_SIGNALLEDis set.
Therefore, it seems unnecessary to setrpc_statusagain after detectingRPC_TASK_SIGNALLEDinrpc_check_timeout.However, in some exceptional cases, invalid and endlessly looping
rpc_tasksmay be generated. Therpc_call_rpcerrorinrpc_check_timeoutcan timely terminate suchrpc_tasks. Removingrpc_call_rpcerrormay cause therpc_taskto fall into an infinite loop.For example, in the following situation:
nfs4_close_done
// get err from server
nfs4_async_handle_exception
// gotoout_restart// umount -f nfs_umount_begin rpc_killall_tasks rpc_signal_task rpc_task_set_rpc_status task->tk_rpc_status = -ERESTARTSYS set_bit // set RPC_TASK_SIGNALLED to tk_runstate rpc_restart_call_prepare __rpc_restart_call task->tk_rpc_status = 0 // clear tk_rpc_status ... rpc_prepare_task nfs4_close_prepare nfs4_setup_sequence rpc_call_start task->tk_action = call_startAt this point, an
rpc_taskwithRPC_TASK_SIGNALLEDset buttk_rpc_statusas 0 will be generated. Thisrpc_taskwill fall into the following loop:call_encode-->call_transmit-->call_transmit_status-->call_status-->call_encode.Since
RPC_TASK_SIGNALLEDis set, no request will be sent incall_transmit. Similarly, sinceRPC_TASK_SIGNALLEDis set,rq_majortimeowill not be updated incall_status-->rpc_check_timeout, which will cause-ETIMEDOUTto be directly set totk_statusincall_transmit_status-->xprt_request_wait_receive-->xprt_wait_for_reply_request_def-->rpc_sleep_on_timeout-->__rpc_sleep_on_priority_timeout.Here is the state and loop process of the
rpc_task:tk_runstate:RPC_TASK_RUNNINGRPC_TASK_ACTIVERPC_TASK_NEED_RECVRPC_TASK_SIGNALLEDtk_xprt->state:XPRT_CONNECTEDXPRT_BOUNDtk_flagsRPC_TASK_ASYNCRPC_TASK_MOVEABLERPC_TASK_DYNAMICRPC_TASK_SOFTRPC_TASK_NO_RETRANS_TIMEOUTRPC_TASK_CRED_NOREF
call_encode
xprt_request_enqueue_transmit
set_bit//RPC_TASK_NEED_XMIT
task->tk_action=call_transmit
call_transmit
task->tk_action=call_transmit_statusxprt_transmit
xprt_request_transmit
// checkRPC_TASK_SIGNALLEDand gotoout_dequeuexprt_request_dequeue_transmit
xprt_request_dequeue_transmit_locked
test_and_clear_bit//RPC_TASK_NEED_XMIT
call_transmit_status
task->tk_action=call_status
xprt_request_wait_receive
xprt_wait_for_reply_request_defxprt_request_timeout // get timeout req->rq_majortimeo // rq_majortimeo will not be updated rpc_sleep_on_timeout __rpc_sleep_on_priority_timeout task->tk_status = -ETIMEDOUT // set ETIMEDOUT
call_status
task->tk_action=call_encode
rpc_check_timeout
// checkRPC_TASK_SIGNALLEDand skipxprt_reset_majortimeoFix it by adding
rpc_call_rpcerrorback.Fixes 39494194f93b ("SUNRPC: Fix races with rpc_killall_tasks()")Signed-off-by Li Lingfeng <[email protected]>--- net/sunrpc/clnt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)net/sunrpc/clnt.c +3
-1@@ -2509,8 +2509,10 @@ rpc_check_timeout(struct rpc_task *task) {struct rpc_clnt *clnt = task->tk_client; -if (RPC_SIGNALLED (task)) +if (RPC_SIGNALLED (task)) { +rpc_call_rpcerror (task, -ERESTARTSYS );return ; + }if (xprt_adjust_timeout (task->tk_rqstp) ==0 )return ;
Quoted 8 lines · yangerkun
Hi,
Thanks for the patch.
Before 39494194f93b("SUNRPC: Fix races with
rpc_killall_tasks()", every time we setRPC_TASK_SIGNALLED, when we go through__rpc_execute, thisrpc_taskwill immediate break and exist.
Quoted 5 lines
However after that,
__rpc_executewon't judgeRPC_TASK_SIGNNALED, so for the case like you point out below, even after your commitrpc_check_timeoutwill help break and exist eventually, but thisrpc_taskhas already do some work. I prefer reintroduce judgingRPC_TASK_SIGNNALEDin__rpc_executeto help exist immediatly.
Thanks for your advice, I will send v2 soon.
Quoted 111 lines · Li Lingfeng
Quoted 109 lines
Commit 39494194f93b("SUNRPC: Fix races with
rpc_killall_tasks()") addsrpc_task_set_rpc_statusbefore settingRPC_TASK_SIGNALLEDinrpc_signal_task, ensuring thatrpc_statusis definitely set whenRPC_TASK_SIGNALLEDis set.
Therefore, it seems unnecessary to setrpc_statusagain after detectingRPC_TASK_SIGNALLEDinrpc_check_timeout.However, in some exceptional cases, invalid and endlessly looping
rpc_tasksmay be generated. Therpc_call_rpcerrorinrpc_check_timeoutcan timely terminate suchrpc_tasks. Removingrpc_call_rpcerrormay cause therpc_taskto fall into an infinite loop.For example, in the following situation:
nfs4_close_done
// get err from server
nfs4_async_handle_exception
// gotoout_restart
// umount -f
nfs_umount_beginrpc_killall_tasksrpc_signal_taskrpc_task_set_rpc_statustask->tk_rpc_status=-ERESTARTSYSset_bit
// setRPC_TASK_SIGNALLEDtotk_runstaterpc_restart_call_prepare
__rpc_restart_call
task->tk_rpc_status= 0
// cleartk_rpc_status
...
rpc_prepare_task
nfs4_close_prepare
nfs4_setup_sequence
rpc_call_start
task->tk_action=call_startAt this point, an
rpc_taskwithRPC_TASK_SIGNALLEDset buttk_rpc_statusas 0 will be generated. Thisrpc_taskwill fall into the following loop:call_encode-->call_transmit-->call_transmit_status-->call_status-->call_encode.Since
RPC_TASK_SIGNALLEDis set, no request will be sent incall_transmit. Similarly, sinceRPC_TASK_SIGNALLEDis set,rq_majortimeowill not be updated incall_status-->rpc_check_timeout, which will cause-ETIMEDOUT
to be directly set totk_statusincall_transmit_status-->xprt_request_wait_receive-->xprt_wait_for_reply_request_def-->rpc_sleep_on_timeout-->__rpc_sleep_on_priority_timeout.Here is the state and loop process of the
rpc_task:tk_runstate:RPC_TASK_RUNNINGRPC_TASK_ACTIVERPC_TASK_NEED_RECVRPC_TASK_SIGNALLEDtk_xprt->state:XPRT_CONNECTEDXPRT_BOUNDtk_flagsRPC_TASK_ASYNCRPC_TASK_MOVEABLERPC_TASK_DYNAMICRPC_TASK_SOFTRPC_TASK_NO_RETRANS_TIMEOUTRPC_TASK_CRED_NOREF
call_encode
xprt_request_enqueue_transmit
set_bit//RPC_TASK_NEED_XMIT
task->tk_action=call_transmit
call_transmit
task->tk_action=call_transmit_statusxprt_transmit
xprt_request_transmit
// checkRPC_TASK_SIGNALLEDand gotoout_dequeuexprt_request_dequeue_transmitxprt_request_dequeue_transmit_lockedtest_and_clear_bit//RPC_TASK_NEED_XMIT
call_transmit_status
task->tk_action=call_statusxprt_request_wait_receivexprt_wait_for_reply_request_defxprt_request_timeout// get timeoutreq->rq_majortimeo//rq_majortimeowill not be updatedrpc_sleep_on_timeout__rpc_sleep_on_priority_timeouttask->tk_status=-ETIMEDOUT// set ETIMEDOUT
call_status
task->tk_action=call_encode
rpc_check_timeout
// checkRPC_TASK_SIGNALLEDand skipxprt_reset_majortimeoFix it by adding
rpc_call_rpcerrorback.Fixes 39494194f93b ("SUNRPC: Fix races with rpc_killall_tasks()")Signed-off-by Li Lingfeng <[email protected]>---
net/sunrpc/clnt.c| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)net/sunrpc/clnt.c +3
-0@@ -2509,8 +2509,10 @@ rpc_check_timeout(struct rpc_task *task) { struct rpc_clnt *clnt = task->tk_client; - if (RPC_SIGNALLED(task)) + if (RPC_SIGNALLED(task)) { + rpc_call_rpcerror(task, -ERESTARTSYS); return; + } if (xprt_adjust_timeout(task->tk_rqstp) == 0) return;
Quoted 10 lines · yangerkun
Hi,
Thanks for the patch.
Before 39494194f93b("SUNRPC: Fix races with
rpc_killall_tasks()", every
time we setRPC_TASK_SIGNALLED, when we go through__rpc_execute, thisrpc_taskwill immediate break and exist.
Quoted 7 lines
However after that,
__rpc_executewon't judgeRPC_TASK_SIGNNALED, so for
the case like you point out below, even after your commitrpc_check_timeoutwill help break and exist eventually, but thisrpc_taskhas already do some work. I prefer reintroduce judgingRPC_TASK_SIGNNALEDin__rpc_executeto help exist immediatly.
Better yet... Let's get rid of the RPC_TASK_SIGNALLED flag altogether and just replace
#define RPC_TASK_SIGNALLED(task) (READ_ONCE(task->tk_rpc_status) == -ERESTARTSYS)
There is no good reason to try to maintain two completely separate sources of truth to describe the same task state.
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
Quoted 19 lines · Trond Myklebust
Quoted 10 lines · yangerkun
Hi,
Thanks for the patch.
Before 39494194f93b("SUNRPC: Fix races with
rpc_killall_tasks()", every
time we setRPC_TASK_SIGNALLED, when we go through__rpc_execute, thisrpc_taskwill immediate break and exist.Quoted 7 lines
However after that,
__rpc_executewon't judgeRPC_TASK_SIGNNALED, so for
the case like you point out below, even after your commitrpc_check_timeoutwill help break and exist eventually, but thisrpc_taskhas already do some work. I prefer reintroduce judgingRPC_TASK_SIGNNALEDin__rpc_executeto help exist immediatly.
Quoted 4 lines
Better yet... Let's get rid of the
RPC_TASK_SIGNALLEDflag altogether and just replace#define
RPC_TASK_SIGNALLED(task)(READ_ONCE(task->tk_rpc_status)==-ERESTARTSYS)
Hi,
Thanks for your reply! Yeah, if all the places where tk_rpc_status is
updated are by calling rpc_task_set_rpc_status, we can usetask->tk_rpc_status == -ERESTARTSYS to determine whether rpc_task isRPC_TASK_SIGNALLED. But for the case like Li has provided,__rpc_restart_call won't do this, and will overwrite tk_rpc_status unconditionally. This won't be a stable solution. Maybe it's better to change __rpc_restart_call calling rpc_task_set_rpc_status too? And__rpc_execute will be enough to help solve this case.
Quoted 4 lines
There is no good reason to try to maintain two completely separate sources of truth to describe the same task state.
Quoted 32 lines · yangerkun
Quoted 20 lines · Trond Myklebust
Quoted 10 lines · yangerkun
Hi,
Thanks for the patch.
Before 39494194f93b("SUNRPC: Fix races with
rpc_killall_tasks()", every
time we setRPC_TASK_SIGNALLED, when we go through__rpc_execute, thisrpc_taskwill immediate break and exist.Quoted 8 lines
However after that,
__rpc_executewon't judgeRPC_TASK_SIGNNALED, so
for
the case like you point out below, even after your commitrpc_check_timeoutwill help break and exist eventually, but thisrpc_taskhas already do some work. I prefer reintroduce judgingRPC_TASK_SIGNNALEDin__rpc_executeto help exist immediatly.Quoted 6 lines
Better yet... Let's get rid of the
RPC_TASK_SIGNALLEDflag altogether
and just replace#define
RPC_TASK_SIGNALLED(task)(READ_ONCE(task->tk_rpc_status)==-ERESTARTSYS)Hi,
Quoted 11 lines
Thanks for your reply! Yeah, if all the places where
tk_rpc_statusis updated are by callingrpc_task_set_rpc_status, we can usetask->tk_rpc_status==-ERESTARTSYSto determine whetherrpc_taskisRPC_TASK_SIGNALLED. But for the case like Li has provided,__rpc_restart_callwon't do this, and will overwritetk_rpc_statusunconditionally. This won't be a stable solution. Maybe it's better to
change__rpc_restart_callcallingrpc_task_set_rpc_statustoo? And__rpc_executewill be enough to help solve this case.
That would break __rpc_restart_call() to the point of rendering it completely useless.
The whole purpose of that call is to give the NFS layer a chance to handle errors in the exit callback, and then kick off a fresh call. Your suggestion would mean that any RPC level error sticks around, and causes the new call to immediately fail.
I see no point in doing anything more than fixing the looping behaviour. Eliminating the redundant flag will do that.
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
Quoted 45 lines · Trond Myklebust
Quoted 32 lines · yangerkun
Quoted 20 lines · Trond Myklebust
Quoted 10 lines · yangerkun
Hi,
Thanks for the patch.
Before 39494194f93b("SUNRPC: Fix races with
rpc_killall_tasks()", every
time we setRPC_TASK_SIGNALLED, when we go through__rpc_execute, thisrpc_taskwill immediate break and exist.Quoted 8 lines
However after that,
__rpc_executewon't judgeRPC_TASK_SIGNNALED, so
for
the case like you point out below, even after your commitrpc_check_timeoutwill help break and exist eventually, but thisrpc_taskhas already do some work. I prefer reintroduce judgingRPC_TASK_SIGNNALEDin__rpc_executeto help exist immediatly.Quoted 6 lines
Better yet... Let's get rid of the
RPC_TASK_SIGNALLEDflag altogether
and just replace#define
RPC_TASK_SIGNALLED(task)(READ_ONCE(task->tk_rpc_status)==-ERESTARTSYS)Hi,
Quoted 11 lines
Thanks for your reply! Yeah, if all the places where
tk_rpc_statusis updated are by callingrpc_task_set_rpc_status, we can usetask->tk_rpc_status==-ERESTARTSYSto determine whetherrpc_taskisRPC_TASK_SIGNALLED. But for the case like Li has provided,__rpc_restart_callwon't do this, and will overwritetk_rpc_statusunconditionally. This won't be a stable solution. Maybe it's better to
change__rpc_restart_callcallingrpc_task_set_rpc_statustoo? And__rpc_executewill be enough to help solve this case.
Quoted 2 lines
That would break
__rpc_restart_call()to the point of rendering it completely useless.
Aha, agree with you. There maybe case tk_rpc_status != 0 but rpc_restart_call can also rerun this rpc_task.
The only case we should consider is when we call rpc_signal_task, we should break this rpc_task unconditionally. Fixing it within __rpc_execute is enough.
Quoted 8 lines
The whole purpose of that call is to give the NFS layer a chance to handle errors in the exit callback, and then kick off a fresh call. Your suggestion would mean that any RPC level error sticks around, and causes the new call to immediately fail.
I see no point in doing anything more than fixing the looping behaviour. Eliminating the redundant flag will do that.
Quoted 22 lines · Trond Myklebust
Quoted 21 lines · yangerkun
Quoted 19 lines · Trond Myklebust
Quoted 18 lines · yangerkun
Hi,
Thanks for the patch.
Before 39494194f93b("SUNRPC: Fix races with
rpc_killall_tasks()", every
time we setRPC_TASK_SIGNALLED, when we go through__rpc_execute, thisrpc_taskwill immediate break and exist.However after that,
__rpc_executewon't judgeRPC_TASK_SIGNNALED, so
for
the case like you point out below, even after your commitrpc_check_timeoutwill help break and exist eventually, but thisrpc_taskhas already do some work. I prefer reintroduce judgingRPC_TASK_SIGNNALEDin__rpc_executeto help exist immediatly.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Better yet... Let's get rid of the
RPC_TASK_SIGNALLEDflag altogether
and just replace#define
RPC_TASK_SIGNALLED(task)(READ_ONCE(task->tk_rpc_status)==-ERESTARTSYS)
Hi,
I'm not quite clear on how this can resolve the issue.
If we remove the RPC_TASK_SIGNALLED flag and replace setting tk_runstate to RPC_TASK_SIGNALLED with setting tk_rpc_status to -ERESTARTSYS in rpc_signal_task, wouldn't setting tk_rpc_status back to 0 in __rpc_restart_call still lead to an infinite loop in the rpc_task? Could you please provide a more detailed explanation?
Thanks.
Quoted 23 lines
Quoted 13 lines
Hi,
Thanks for your reply! Yeah, if all the places where
tk_rpc_statusis updated are by callingrpc_task_set_rpc_status, we can usetask->tk_rpc_status==-ERESTARTSYSto determine whetherrpc_taskisRPC_TASK_SIGNALLED. But for the case like Li has provided,__rpc_restart_callwon't do this, and will overwritetk_rpc_statusunconditionally. This won't be a stable solution. Maybe it's better to
change__rpc_restart_callcallingrpc_task_set_rpc_statustoo? And__rpc_executewill be enough to help solve this case.That would break
__rpc_restart_call()to the point of rendering it completely useless.
The whole purpose of that call is to give the NFS layer a chance to handle errors in the exit callback, and then kick off a fresh call. Your suggestion would mean that any RPC level error sticks around, and causes the new call to immediately fail.I see no point in doing anything more than fixing the looping behaviour. Eliminating the redundant flag will do that.