Commit 928293cc authored by Benjamin Coddington's avatar Benjamin Coddington Committed by Liu Jian
Browse files

SUNRPC: Fix a race to wake a sync task

stable inclusion
from stable-v4.19.320
commit 06d281f0ad7504e9f250c6a9ef78d9e48cea5717
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IAYZ0U

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=06d281f0ad7504e9f250c6a9ef78d9e48cea5717



-------------------------------------------------

[ Upstream commit ed0172af5d6fc07d1b40ca82f5ca3979300369f7 ]

We've observed NFS clients with sync tasks sleeping in __rpc_execute
waiting on RPC_TASK_QUEUED that have not responded to a wake-up from
rpc_make_runnable().  I suspect this problem usually goes unnoticed,
because on a busy client the task will eventually be re-awoken by another
task completion or xprt event.  However, if the state manager is draining
the slot table, a sync task missing a wake-up can result in a hung client.

We've been able to prove that the waker in rpc_make_runnable() successfully
calls wake_up_bit() (ie- there's no race to tk_runstate), but the
wake_up_bit() call fails to wake the waiter.  I suspect the waker is
missing the load of the bit's wait_queue_head, so waitqueue_active() is
false.  There are some very helpful comments about this problem above
wake_up_bit(), prepare_to_wait(), and waitqueue_active().

Fix this by inserting smp_mb__after_atomic() before the wake_up_bit(),
which pairs with prepare_to_wait() calling set_current_state().

Signed-off-by: default avatarBenjamin Coddington <bcodding@redhat.com>
Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
Signed-off-by: default avatarAnna Schumaker <Anna.Schumaker@Netapp.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarLiu Jian <liujian56@huawei.com>
parent 01be597e
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -349,9 +349,11 @@ static void rpc_make_runnable(struct workqueue_struct *wq,
	if (RPC_IS_ASYNC(task)) {
		INIT_WORK(&task->u.tk_work, rpc_async_schedule);
		queue_work(wq, &task->u.tk_work);
	} else
	} else {
		smp_mb__after_atomic();
		wake_up_bit(&task->tk_runstate, RPC_TASK_QUEUED);
	}
}

/*
 * Prepare for sleeping on a wait queue.