Commit 0bd89676 authored by Hou Tao's avatar Hou Tao Committed by Darrick J. Wong

xfs: check kthread_should_stop() after the setting of task state

A umount hang is possible when a race occurs between the umount
process and the xfsaild kthread. The following sequences outline
the race:

    xfsaild: kthread_should_stop()
	     => return false, so xfsaild continue

    umount: set_bit(KTHREAD_SHOULD_STOP, &kthread->flags)
	    => by kthread_stop()
    umount: wake_up_process()
	    => because xfsaild is still running, so 0 is returned

    xfsaild: __set_current_state(TASK_INTERRUPTIBLE)
    xfsaild: schedule()
	    => now, xfsaild will wait indefinitely

    umount: wait_for_completion()
	    => and umount will hang

To fix that, we need to check kthread_should_stop() after we set
the task state, so the xfsaild will either see the stop bit and
exit or the task state is reset to runnable by wake_up_process()
such that it isn't scheduled out indefinitely and detects the stop
bit at the next iteration.
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarBrian Foster <bfoster@redhat.com>
Signed-off-by: default avatarHou Tao <houtao1@huawei.com>
Reviewed-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
parent f0387501
...@@ -514,11 +514,26 @@ xfsaild( ...@@ -514,11 +514,26 @@ xfsaild(
current->flags |= PF_MEMALLOC; current->flags |= PF_MEMALLOC;
set_freezable(); set_freezable();
while (!kthread_should_stop()) { while (1) {
if (tout && tout <= 20) if (tout && tout <= 20)
__set_current_state(TASK_KILLABLE); set_current_state(TASK_KILLABLE);
else else
__set_current_state(TASK_INTERRUPTIBLE); set_current_state(TASK_INTERRUPTIBLE);
/*
* Check kthread_should_stop() after we set the task state
* to guarantee that we either see the stop bit and exit or
* the task state is reset to runnable such that it's not
* scheduled out indefinitely and detects the stop bit at
* next iteration.
*
* A memory barrier is included in above task state set to
* serialize again kthread_stop().
*/
if (kthread_should_stop()) {
__set_current_state(TASK_RUNNING);
break;
}
spin_lock(&ailp->xa_lock); spin_lock(&ailp->xa_lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment