Skip to content

Commit 56c35f4

Browse files
neilbrownchucklever
authored andcommitted
nfsd: drop st_mutex before calling move_to_close_lru()
move_to_close_lru() is currently called with ->st_mutex held. This can lead to a deadlock as move_to_close_lru() waits for sc_count to drop to 2, and some threads holding a reference might be waiting for the mutex. These references will never be dropped so sc_count will never reach 2. There can be no harm in dropping ->st_mutex before move_to_close_lru() because the only place that takes the mutex is nfsd4_lock_ol_stateid(), and it quickly aborts if sc_type is NFS4_CLOSED_STID, which it will be before move_to_close_lru() is called. See also https://lore.kernel.org/lkml/[email protected]/T/ where this problem was raised but not successfully resolved. Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: NeilBrown <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent eec7620 commit 56c35f4

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

fs/nfsd/nfs4state.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7357,7 +7357,7 @@ nfsd4_open_downgrade(struct svc_rqst *rqstp,
73577357
return status;
73587358
}
73597359

7360-
static void nfsd4_close_open_stateid(struct nfs4_ol_stateid *s)
7360+
static bool nfsd4_close_open_stateid(struct nfs4_ol_stateid *s)
73617361
{
73627362
struct nfs4_client *clp = s->st_stid.sc_client;
73637363
bool unhashed;
@@ -7374,11 +7374,11 @@ static void nfsd4_close_open_stateid(struct nfs4_ol_stateid *s)
73747374
list_for_each_entry(stp, &reaplist, st_locks)
73757375
nfs4_free_cpntf_statelist(clp->net, &stp->st_stid);
73767376
free_ol_stateid_reaplist(&reaplist);
7377+
return false;
73777378
} else {
73787379
spin_unlock(&clp->cl_lock);
73797380
free_ol_stateid_reaplist(&reaplist);
7380-
if (unhashed)
7381-
move_to_close_lru(s, clp->net);
7381+
return unhashed;
73827382
}
73837383
}
73847384

@@ -7394,6 +7394,7 @@ nfsd4_close(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
73947394
struct nfs4_ol_stateid *stp;
73957395
struct net *net = SVC_NET(rqstp);
73967396
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
7397+
bool need_move_to_close_list;
73977398

73987399
dprintk("NFSD: nfsd4_close on file %pd\n",
73997400
cstate->current_fh.fh_dentry);
@@ -7418,8 +7419,10 @@ nfsd4_close(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
74187419
*/
74197420
nfs4_inc_and_copy_stateid(&close->cl_stateid, &stp->st_stid);
74207421

7421-
nfsd4_close_open_stateid(stp);
7422+
need_move_to_close_list = nfsd4_close_open_stateid(stp);
74227423
mutex_unlock(&stp->st_mutex);
7424+
if (need_move_to_close_list)
7425+
move_to_close_lru(stp, net);
74237426

74247427
/* v4.1+ suggests that we send a special stateid in here, since the
74257428
* clients should just ignore this anyway. Since this is not useful

0 commit comments

Comments
 (0)