Skip to content

Commit 40c6143

Browse files
committed
nfsd: don't take fi_lock in nfsd_break_deleg_cb()
jira LE-1907 Rebuild_History Non-Buildable kernel-5.14.0-427.35.1.el9_4 commit-author NeilBrown <neilb@suse.de> commit 5ea9a7c A recent change to check_for_locks() changed it to take ->flc_lock while holding ->fi_lock. This creates a lock inversion (reported by lockdep) because there is a case where ->fi_lock is taken while holding ->flc_lock. ->flc_lock is held across ->fl_lmops callbacks, and nfsd_break_deleg_cb() is one of those and does take ->fi_lock. However it doesn't need to. Prior to v4.17-rc1~110^2~22 ("nfsd: create a separate lease for each delegation") nfsd_break_deleg_cb() would walk the ->fi_delegations list and so needed the lock. Since then it doesn't walk the list and doesn't need the lock. Two actions are performed under the lock. One is to call nfsd_break_one_deleg which calls nfsd4_run_cb(). These doesn't act on the nfs4_file at all, so don't need the lock. The other is to set ->fi_had_conflict which is in the nfs4_file. This field is only ever set here (except when initialised to false) so there is no possible problem will multiple threads racing when setting it. The field is tested twice in nfs4_set_delegation(). The first test does not hold a lock and is documented as an opportunistic optimisation, so it doesn't impose any need to hold ->fi_lock while setting ->fi_had_conflict. The second test in nfs4_set_delegation() *is* make under ->fi_lock, so removing the locking when ->fi_had_conflict is set could make a change. The change could only be interesting if ->fi_had_conflict tested as false even though nfsd_break_one_deleg() ran before ->fi_lock was unlocked. i.e. while hash_delegation_locked() was running. As hash_delegation_lock() doesn't interact in any way with nfs4_run_cb() there can be no importance to this interaction. So this patch removes the locking from nfsd_break_one_deleg() and moves the final test on ->fi_had_conflict out of the locked region to make it clear that locking isn't important to the test. It is still tested *after* vfs_setlease() has succeeded. This might be significant and as vfs_setlease() takes ->flc_lock, and nfsd_break_one_deleg() is called under ->flc_lock this "after" is a true ordering provided by a spinlock. Fixes: edcf972 ("nfsd: fix RELEASE_LOCKOWNER") Signed-off-by: NeilBrown <neilb@suse.de> Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Chuck Lever <chuck.lever@oracle.com> (cherry picked from commit 5ea9a7c) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent 2293826 commit 40c6143

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

fs/nfsd/nfs4state.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4967,10 +4967,8 @@ nfsd_break_deleg_cb(struct file_lock *fl)
49674967
*/
49684968
fl->fl_break_time = 0;
49694969

4970-
spin_lock(&fp->fi_lock);
49714970
fp->fi_had_conflict = true;
49724971
nfsd_break_one_deleg(dp);
4973-
spin_unlock(&fp->fi_lock);
49744972
return false;
49754973
}
49764974

@@ -5579,12 +5577,13 @@ nfs4_set_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp,
55795577
if (status)
55805578
goto out_unlock;
55815579

5580+
status = -EAGAIN;
5581+
if (fp->fi_had_conflict)
5582+
goto out_unlock;
5583+
55825584
spin_lock(&state_lock);
55835585
spin_lock(&fp->fi_lock);
5584-
if (fp->fi_had_conflict)
5585-
status = -EAGAIN;
5586-
else
5587-
status = hash_delegation_locked(dp, fp);
5586+
status = hash_delegation_locked(dp, fp);
55885587
spin_unlock(&fp->fi_lock);
55895588
spin_unlock(&state_lock);
55905589

0 commit comments

Comments
 (0)