Skip to content

Commit 05eda6e

Browse files
neilbrownchucklever
authored andcommitted
nfsd: don't call locks_release_private() twice concurrently
It is possible for free_blocked_lock() to be called twice concurrently, once from nfsd4_lock() and once from nfsd4_release_lockowner() calling remove_blocked_locks(). This is why a kref was added. It is perfectly safe for locks_delete_block() and kref_put() to be called in parallel as they use locking or atomicity respectively as protection. However locks_release_private() has no locking. It is safe for it to be called twice sequentially, but not concurrently. This patch moves that call from free_blocked_lock() where it could race with itself, to free_nbl() where it cannot. This will slightly delay the freeing of private info or release of the owner - but not by much. It is arguably more natural for this freeing to happen in free_nbl() where the structure itself is freed. This bug was found by code inspection - it has not been seen in practice. Fixes: 47446d7 ("nfsd4: add refcount for nfsd4_blocked_lock") Signed-off-by: NeilBrown <neilb@suse.de> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent 1e33e14 commit 05eda6e

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

fs/nfsd/nfs4state.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,14 @@ free_nbl(struct kref *kref)
318318
struct nfsd4_blocked_lock *nbl;
319319

320320
nbl = container_of(kref, struct nfsd4_blocked_lock, nbl_kref);
321+
locks_release_private(&nbl->nbl_lock);
321322
kfree(nbl);
322323
}
323324

324325
static void
325326
free_blocked_lock(struct nfsd4_blocked_lock *nbl)
326327
{
327328
locks_delete_block(&nbl->nbl_lock);
328-
locks_release_private(&nbl->nbl_lock);
329329
kref_put(&nbl->nbl_kref, free_nbl);
330330
}
331331

0 commit comments

Comments
 (0)