提交 327136ff 编写于 作者: Y Yihao Wu 提交者: Joseph Qi

NFSv4.1: Again fix a race where CB_NOTIFY_LOCK fails to wake a waiter

Commit b7dbcc0e "NFSv4.1: Fix a race where CB_NOTIFY_LOCK fails to wake a waiter"
found this bug. However it didn't fix it.

This commit replaces schedule_timeout() with wait_woken() and
default_wake_function() with woken_wake_function() in function
nfs4_retry_setlk() and nfs4_wake_lock_waiter(). wait_woken() uses
memory barriers in its implementation to avoid potential race condition
when putting a process into sleeping state and then waking it up.

Fixes: a1d617d8 ("nfs: allow blocking locks to be awoken by lock callbacks")
Cc: stable@vger.kernel.org #4.9+
Signed-off-by: NYihao Wu <wuyihao@linux.alibaba.com>
Reviewed-by: NJeff Layton <jlayton@kernel.org>
Acked-by: NJoseph Qi <joseph.qi@linux.alibaba.com>
上级 37ab1da1
......@@ -6850,7 +6850,6 @@ struct nfs4_lock_waiter {
struct task_struct *task;
struct inode *inode;
struct nfs_lowner *owner;
bool notified;
};
static int
......@@ -6872,13 +6871,13 @@ nfs4_wake_lock_waiter(wait_queue_entry_t *wait, unsigned int mode, int flags, vo
/* Make sure it's for the right inode */
if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh))
return 0;
waiter->notified = true;
}
/* override "private" so we can use default_wake_function */
wait->private = waiter->task;
ret = autoremove_wake_function(wait, mode, flags, key);
ret = woken_wake_function(wait, mode, flags, key);
if (ret)
list_del_init(&wait->entry);
wait->private = waiter;
return ret;
}
......@@ -6897,8 +6896,7 @@ nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
.s_dev = server->s_dev };
struct nfs4_lock_waiter waiter = { .task = current,
.inode = state->inode,
.owner = &owner,
.notified = false };
.owner = &owner};
wait_queue_entry_t wait;
/* Don't bother with waitqueue if we don't expect a callback */
......@@ -6911,21 +6909,14 @@ nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
add_wait_queue(q, &wait);
while(!signalled()) {
waiter.notified = false;
status = nfs4_proc_setlk(state, cmd, request);
if ((status != -EAGAIN) || IS_SETLK(cmd))
break;
status = -ERESTARTSYS;
spin_lock_irqsave(&q->lock, flags);
if (waiter.notified) {
spin_unlock_irqrestore(&q->lock, flags);
continue;
}
set_current_state(TASK_INTERRUPTIBLE);
spin_unlock_irqrestore(&q->lock, flags);
freezable_schedule_timeout(NFS4_LOCK_MAXTIMEOUT);
freezer_do_not_count();
wait_woken(&wait, TASK_INTERRUPTIBLE, NFS4_LOCK_MAXTIMEOUT);
freezer_count();
}
finish_wait(q, &wait);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册