[Devel] [PATCH RHEL7 COMMIT] sunrpc: fix race between "kill_tasks" set and actual task killing

Konstantin Khorenko khorenko at virtuozzo.com
Tue Jul 11 18:33:59 MSK 2017


The commit is pushed to "branch-rh7-3.10.0-514.26.1.vz7.33.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-514.26.1.vz7.33.3
------>
commit ade78a36090d4fe2dedcd593e823dddf0a2511d5
Author: Stanislav Kinsburskiy <skinsbursky at virtuozzo.com>
Date:   Tue Jul 11 19:33:59 2017 +0400

    sunrpc: fix race between "kill_tasks" set and actual task killing
    
    Patchset description:
    
    SUNRPC: fix races in tasks killing
    
    This series fix two races with SUNRPC tasks killing on fast stop and also fix
    the kill itself (*all* the tasks are killed now, but not only those in
    "pending" wait queue).
    
    https://jira.sw.ru/browse/PSBM-68214
    
    Stanislav Kinsburskiy (3):
          sunrpc: fix race between "kill_tasks" set and actual task killing
          sunrpc: use rpc_killall_tasks helper when "kill_tasks" toggle is raised
          sunrpc: do not place task to sleep if has to be killed
    
    ============================================================
    This patch description:
    
    There could be a situation, when RPC task is not yet sleeping, but already
    passed the check for "kill_tasks" in __rpc_execute().
    There is a race in such a case, because task will fall into sleep anyway.
    This patch makes this probability a little bit less.
    
    Signed-off-by: Stanislav Kinsburskiy <skinsbursky at virtuozzo.com>
---
 net/sunrpc/clnt.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
index 8543de4..94b0187 100644
--- a/net/sunrpc/clnt.c
+++ b/net/sunrpc/clnt.c
@@ -2556,6 +2556,7 @@ static ssize_t write_kill_tasks(struct file *file, const char __user *buf,
 {
 	struct net *net = PDE_DATA(file->f_path.dentry->d_inode);
 	struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
+	bool prev_kill_tasks = sn->kill_tasks;
 	char tbuf[20];
 	unsigned long kill_tasks;
 	int res;
@@ -2570,11 +2571,12 @@ static ssize_t write_kill_tasks(struct file *file, const char __user *buf,
 	if (res)
 		return res;
 
+	sn->kill_tasks = !!kill_tasks;
+
 	/* Kill pending tasks */
-	if (kill_tasks && !sn->kill_tasks)
+	if (sn->kill_tasks && !prev_kill_tasks)
 		rpc_kill_tasks(net);
 
-	sn->kill_tasks = !!kill_tasks;
 	return count;
 }
 


More information about the Devel mailing list