Commit d1d8b49a authored by Yihao Wu's avatar Yihao Wu Committed by Greg Kroah-Hartman

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

commit 52b042ab upstream.

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: default avatarYihao Wu <wuyihao@linux.alibaba.com>
Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
Signed-off-by: default avatarAnna Schumaker <Anna.Schumaker@Netapp.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 42b761f6
...@@ -6867,7 +6867,6 @@ struct nfs4_lock_waiter { ...@@ -6867,7 +6867,6 @@ struct nfs4_lock_waiter {
struct task_struct *task; struct task_struct *task;
struct inode *inode; struct inode *inode;
struct nfs_lowner *owner; struct nfs_lowner *owner;
bool notified;
}; };
static int static int
...@@ -6889,13 +6888,13 @@ nfs4_wake_lock_waiter(wait_queue_entry_t *wait, unsigned int mode, int flags, vo ...@@ -6889,13 +6888,13 @@ nfs4_wake_lock_waiter(wait_queue_entry_t *wait, unsigned int mode, int flags, vo
/* Make sure it's for the right inode */ /* Make sure it's for the right inode */
if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh))
return 0; return 0;
waiter->notified = true;
} }
/* override "private" so we can use default_wake_function */ /* override "private" so we can use default_wake_function */
wait->private = waiter->task; 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; wait->private = waiter;
return ret; return ret;
} }
...@@ -6904,7 +6903,6 @@ static int ...@@ -6904,7 +6903,6 @@ static int
nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
{ {
int status = -ERESTARTSYS; int status = -ERESTARTSYS;
unsigned long flags;
struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner;
struct nfs_server *server = NFS_SERVER(state->inode); struct nfs_server *server = NFS_SERVER(state->inode);
struct nfs_client *clp = server->nfs_client; struct nfs_client *clp = server->nfs_client;
...@@ -6914,8 +6912,7 @@ nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) ...@@ -6914,8 +6912,7 @@ nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
.s_dev = server->s_dev }; .s_dev = server->s_dev };
struct nfs4_lock_waiter waiter = { .task = current, struct nfs4_lock_waiter waiter = { .task = current,
.inode = state->inode, .inode = state->inode,
.owner = &owner, .owner = &owner};
.notified = false };
wait_queue_entry_t wait; wait_queue_entry_t wait;
/* Don't bother with waitqueue if we don't expect a callback */ /* Don't bother with waitqueue if we don't expect a callback */
...@@ -6928,21 +6925,14 @@ nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) ...@@ -6928,21 +6925,14 @@ nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
add_wait_queue(q, &wait); add_wait_queue(q, &wait);
while(!signalled()) { while(!signalled()) {
waiter.notified = false;
status = nfs4_proc_setlk(state, cmd, request); status = nfs4_proc_setlk(state, cmd, request);
if ((status != -EAGAIN) || IS_SETLK(cmd)) if ((status != -EAGAIN) || IS_SETLK(cmd))
break; break;
status = -ERESTARTSYS; status = -ERESTARTSYS;
spin_lock_irqsave(&q->lock, flags); freezer_do_not_count();
if (waiter.notified) { wait_woken(&wait, TASK_INTERRUPTIBLE, NFS4_LOCK_MAXTIMEOUT);
spin_unlock_irqrestore(&q->lock, flags); freezer_count();
continue;
}
set_current_state(TASK_INTERRUPTIBLE);
spin_unlock_irqrestore(&q->lock, flags);
freezable_schedule_timeout(NFS4_LOCK_MAXTIMEOUT);
} }
finish_wait(q, &wait); finish_wait(q, &wait);
......
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