All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chuck Lever <chuck.lever@oracle.com>
To: linux-nfs@vger.kernel.org
Subject: [PATCH v2 2/6] NFSD: Fix possible sleep during nfsd4_release_lockowner()
Date: Tue, 24 May 2022 14:57:04 -0400	[thread overview]
Message-ID: <165341862441.3187.2513226782679879324.stgit@bazille.1015granger.net> (raw)
In-Reply-To: <165341832236.3187.8388683641228729897.stgit@bazille.1015granger.net>

nfsd4_release_lockowner() holds clp->cl_lock when it calls
check_for_locks(). However, check_for_locks() calls nfsd_file_get()
/ nfsd_file_put() to access the backing inode's flc_posix list, and
nfsd_file_put() can sleep if the inode was recently removed.

Instead, use the recently introduced counter field in struct
nfs4_lockowner that keeps track of how many locks are associated
with that lock owner.

Reported-by: Dai Ngo <dai.ngo@oracle.com>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Cc: stable@vger.kernel.org
---
 fs/nfsd/nfs4state.c |   11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index d2d9748eaca6..7cedb0da888d 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -7563,16 +7563,11 @@ nfsd4_release_lockowner(struct svc_rqst *rqstp,
 		if (sop->so_is_open_owner || !same_owner_str(sop, owner))
 			continue;
 
-		/* see if there are still any locks associated with it */
 		lo = lockowner(sop);
-		list_for_each_entry(stp, &sop->so_stateids, st_perstateowner) {
-			if (check_for_locks(stp->st_stid.sc_file, lo)) {
-				status = nfserr_locks_held;
-				spin_unlock(&clp->cl_lock);
-				return status;
-			}
+		if (atomic_read(&lo->lo_lockcnt) != 0) {
+			spin_unlock(&clp->cl_lock);
+			return nfserr_locks_held;
 		}
-
 		nfs4_get_stateowner(sop);
 		break;
 	}



  parent reply	other threads:[~2022-05-24 18:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-24 18:56 [PATCH v2 0/6] RELEASE_LOCKOWNER discussion, cont Chuck Lever
2022-05-24 18:56 ` [PATCH v2 1/6] fs/locks.c: Count held file locks Chuck Lever
2022-05-24 18:57 ` Chuck Lever [this message]
2022-05-24 18:57 ` [PATCH v2 3/6] blargh Chuck Lever
2022-05-24 18:57 ` [PATCH v2 4/6] NFSD: Modernize nfsd4_release_lockowner() Chuck Lever
2022-05-24 18:57 ` [PATCH v2 5/6] NFSD: Add documenting comment for nfsd4_release_lockowner() Chuck Lever
2022-05-24 18:57 ` [PATCH v2 6/6] NFSD: nfsd_file_put() can sleep Chuck Lever

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=165341862441.3187.2513226782679879324.stgit@bazille.1015granger.net \
    --to=chuck.lever@oracle.com \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.