public inbox for linux-nfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Li Lingfeng <lilingfeng3@huawei.com>
To: yangerkun <yangerkun@huawei.com>, <trondmy@kernel.org>,
	<anna@kernel.org>, <chuck.lever@oracle.com>, <jlayton@kernel.org>,
	<neilb@suse.de>, <okorniev@redhat.com>, <Dai.Ngo@oracle.com>,
	<tom@talpey.com>, <davem@davemloft.net>, <edumazet@google.com>,
	<kuba@kernel.org>, <pabeni@redhat.com>, <horms@kernel.org>
Cc: <linux-nfs@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<netdev@vger.kernel.org>, <yukuai1@huaweicloud.com>,
	<houtao1@huawei.com>, <yi.zhang@huawei.com>,
	<lilingfeng@huaweicloud.com>
Subject: Re: [PATCH] SUNRPC: Set tk_rpc_status when RPC_TASK_SIGNALLED is detected
Date: Thu, 16 Jan 2025 22:32:09 +0800	[thread overview]
Message-ID: <751d31cc-640f-47fc-bb5e-1f9fbdd6316b@huawei.com> (raw)
In-Reply-To: <fed3cd85-0a15-ae30-b167-84881d6a5efd@huawei.com>

在 2025/1/16 19:43, yangerkun 写道:
> 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.
Thanks for your advice, I will send v2 soon.
>
> 在 2025/1/14 22:41, Li Lingfeng 写道:
>> 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_start
>>
>> At 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_BOUND
>> tk_flags
>> RPC_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 ETIMEDOUT
>>
>> call_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.
>>
>> Fixes: 39494194f93b ("SUNRPC: Fix races with rpc_killall_tasks()")
>> Signed-off-by: Li Lingfeng <lilingfeng3@huawei.com>
>> ---
>>   net/sunrpc/clnt.c | 4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
>> index 0090162ee8c3..0acdff19a37c 100644
>> --- a/net/sunrpc/clnt.c
>> +++ b/net/sunrpc/clnt.c
>> @@ -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;

  reply	other threads:[~2025-01-16 14:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-14 14:41 [PATCH] SUNRPC: Set tk_rpc_status when RPC_TASK_SIGNALLED is detected Li Lingfeng
2025-01-16 11:43 ` yangerkun
2025-01-16 14:32   ` Li Lingfeng [this message]
2025-01-16 20:52   ` Trond Myklebust
2025-01-17  2:29     ` yangerkun
2025-01-17  3:15       ` Trond Myklebust
2025-01-17 12:16         ` yangerkun
2025-01-26  2:20         ` Li Lingfeng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=751d31cc-640f-47fc-bb5e-1f9fbdd6316b@huawei.com \
    --to=lilingfeng3@huawei.com \
    --cc=Dai.Ngo@oracle.com \
    --cc=anna@kernel.org \
    --cc=chuck.lever@oracle.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=houtao1@huawei.com \
    --cc=jlayton@kernel.org \
    --cc=kuba@kernel.org \
    --cc=lilingfeng@huaweicloud.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=neilb@suse.de \
    --cc=netdev@vger.kernel.org \
    --cc=okorniev@redhat.com \
    --cc=pabeni@redhat.com \
    --cc=tom@talpey.com \
    --cc=trondmy@kernel.org \
    --cc=yangerkun@huawei.com \
    --cc=yi.zhang@huawei.com \
    --cc=yukuai1@huaweicloud.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox