Linux NFS development
 help / color / mirror / Atom feed
From: Chuck Lever <chuck.lever@oracle.com>
To: NeilBrown <neilb@suse.de>
Cc: Jeff Layton <jlayton@kernel.org>,
	linux-nfs@vger.kernel.org, Olga Kornievskaia <kolga@netapp.com>,
	Dai Ngo <Dai.Ngo@oracle.com>, Tom Talpey <tom@talpey.com>
Subject: Re: [PATCH 1/9] nfsd: hold ->cl_lock for hash_delegation_locked()
Date: Sun, 19 Nov 2023 18:38:48 -0500	[thread overview]
Message-ID: <ZVqciNeBnfAaHZ6a@tissot.1015granger.net> (raw)
In-Reply-To: <170042987584.19300.7721851585544522693@noble.neil.brown.name>

On Mon, Nov 20, 2023 at 08:37:55AM +1100, NeilBrown wrote:
> On Fri, 17 Nov 2023, Jeff Layton wrote:
> > On Fri, 2023-11-17 at 13:18 +1100, NeilBrown wrote:
> > > The protocol for creating a new state in nfsd is to allocated the state
> > > leaving it largely uninitialised, add that state to the ->cl_stateids
> > > idr so as to reserve a state id, then complete initialisation of the
> > > state and only set ->sc_type to non-zero once the state is fully
> > > initialised.
> > > 
> > > If a state is found in the idr with ->sc_type == 0, it is ignored.
> > > The ->cl_lock list is used to avoid races - it is held while checking
> > > sc_type during lookup, and held when a non-zero value is stored in
> > > ->sc_type.
> > > 
> > > ... except... hash_delegation_locked() finalises the initialisation of a
> > > delegation state, but does NOT hold ->cl_lock.
> > > 
> > > So this patch takes ->cl_lock at the appropriate time w.r.t other locks,
> > > and so ensures there are no races (which are extremely unlikely in any
> > > case).
> > > 
> > > Signed-off-by: NeilBrown <neilb@suse.de>
> > > ---
> > >  fs/nfsd/nfs4state.c | 3 +++
> > >  1 file changed, 3 insertions(+)
> > > 
> > > diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
> > > index 65fd5510323a..6368788a7d4e 100644
> > > --- a/fs/nfsd/nfs4state.c
> > > +++ b/fs/nfsd/nfs4state.c
> > > @@ -1317,6 +1317,7 @@ hash_delegation_locked(struct nfs4_delegation *dp, struct nfs4_file *fp)
> > >  
> > >  	lockdep_assert_held(&state_lock);
> > >  	lockdep_assert_held(&fp->fi_lock);
> > > +	lockdep_assert_held(&clp->cl_lock);
> > >  
> > >  	if (nfs4_delegation_exists(clp, fp))
> > >  		return -EAGAIN;
> > > @@ -5609,12 +5610,14 @@ nfs4_set_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp,
> > >  		goto out_unlock;
> > >  
> > >  	spin_lock(&state_lock);
> > > +	spin_lock(&clp->cl_lock);
> > >  	spin_lock(&fp->fi_lock);
> > >  	if (fp->fi_had_conflict)
> > >  		status = -EAGAIN;
> > >  	else
> > >  		status = hash_delegation_locked(dp, fp);
> > >  	spin_unlock(&fp->fi_lock);
> > > +	spin_unlock(&clp->cl_lock);
> > >  	spin_unlock(&state_lock);
> > >  
> > >  	if (status)
> > 
> > I know it's (supposedly) an unlikely race, but should we send this to
> > stable?
> 
> I don't know.  Once upon a time, "stable" meant something.  There was a
> clear list of rules.  Those seem to have been torn up.  Now it seems to
> be whatever some machine-learning tool chooses.
> If that tool chooses this patch (which I suspect it will), I won't
> object.  But I don't think it is worth encouraging it.

We've asked Sasha and GregKH not to use AUTOSEL on NFSD patches,
promising that we will explicitly mark anything that should be
back-ported.


-- 
Chuck Lever

  reply	other threads:[~2023-11-19 23:39 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-17  2:18 [PATCH 0/9 v3] support admin-revocation of v4 state NeilBrown
2023-11-17  2:18 ` [PATCH 1/9] nfsd: hold ->cl_lock for hash_delegation_locked() NeilBrown
2023-11-17 10:59   ` Jeff Layton
2023-11-19 21:37     ` NeilBrown
2023-11-19 23:38       ` Chuck Lever [this message]
2023-11-19 23:41         ` NeilBrown
2023-11-17 15:04   ` Chuck Lever
2023-11-19 22:07     ` NeilBrown
2023-11-17  2:18 ` [PATCH 2/9] nfsd: avoid race after unhash_delegation_locked() NeilBrown
2023-11-17 11:41   ` Jeff Layton
2023-11-17 19:43     ` Chuck Lever
2023-11-19 22:23       ` NeilBrown
2023-11-19 23:41         ` Chuck Lever
2023-11-17  2:18 ` [PATCH 3/9] nfsd: split sc_status out of sc_type NeilBrown
2023-11-17 19:52   ` Chuck Lever
2023-11-19 22:35     ` NeilBrown
2023-11-17  2:18 ` [PATCH 4/9] nfsd: prepare for supporting admin-revocation of state NeilBrown
2023-11-17  2:18 ` [PATCH 5/9] nfsd: allow admin-revoked state to appear in /proc/fs/nfsd/clients/*/states NeilBrown
2023-11-17 11:27   ` Jeff Layton
2023-11-19 22:36     ` NeilBrown
2023-11-17  2:18 ` [PATCH 6/9] nfsd: allow admin-revoked NFSv4.0 state to be freed NeilBrown
2023-11-17 11:34   ` Jeff Layton
2023-11-19 22:40     ` NeilBrown
2023-11-17 19:58   ` Chuck Lever
2023-11-19 22:47     ` NeilBrown
2023-11-19 23:44       ` Chuck Lever
2023-11-17  2:18 ` [PATCH 7/9] nfsd: allow lock state ids to be revoked and then freed NeilBrown
2023-11-17  2:18 ` [PATCH 8/9] nfsd: allow open " NeilBrown
2023-11-17  2:18 ` [PATCH 9/9] nfsd: allow delegation " NeilBrown
2023-11-17 12:25 ` [PATCH 0/9 v3] support admin-revocation of v4 state Jeff Layton
2023-11-19 23:21   ` NeilBrown

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=ZVqciNeBnfAaHZ6a@tissot.1015granger.net \
    --to=chuck.lever@oracle.com \
    --cc=Dai.Ngo@oracle.com \
    --cc=jlayton@kernel.org \
    --cc=kolga@netapp.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=neilb@suse.de \
    --cc=tom@talpey.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox