All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Snitzer <snitzer@kernel.org>
To: Jeff Layton <jlayton@kernel.org>
Cc: linux-nfs@vger.kernel.org, Chuck Lever <chuck.lever@oracle.com>,
	Trond Myklebust <trondmy@hammerspace.com>,
	NeilBrown <neilb@suse.de>,
	snitzer@hammerspace.com
Subject: Re: [PATCH v5 16/19] nfsd: use SRCU to dereference nn->nfsd_serv
Date: Wed, 19 Jun 2024 13:26:23 -0400	[thread overview]
Message-ID: <ZnMUv3NJ7w1cE5dU@kernel.org> (raw)
In-Reply-To: <808b8e465430e66b5b3c3bf048a3a165ba41231b.camel@kernel.org>

On Wed, Jun 19, 2024 at 08:39:46AM -0400, Jeff Layton wrote:
> On Tue, 2024-06-18 at 16:19 -0400, Mike Snitzer wrote:
> > Introduce nfsd_serv_get, nfsd_serv_put and nfsd_serv_sync and update
> > the nfsd code to prevent nfsd_destroy_serv from destroying
> > nn->nfsd_serv until all nfsd code is done with it (particularly the
> > localio code that doesn't run in the context of nfsd's svc threads,
> > nor does it take the nfsd_mutex).
> > 
> > Commit 83d5e5b0af90 ("dm: optimize use SRCU and RCU") provided a
> > familiar well-worn pattern for how implement.
> > 
> > Suggested-by: NeilBrown <neilb@suse.de>
> > Signed-off-by: Mike Snitzer <snitzer@kernel.org>
> > ---
> >  fs/nfsd/filecache.c | 13 ++++++++---
> >  fs/nfsd/netns.h     | 12 ++++++++--
> >  fs/nfsd/nfs4state.c | 25 ++++++++++++++-------
> >  fs/nfsd/nfsctl.c    |  7 ++++--
> >  fs/nfsd/nfssvc.c    | 55 ++++++++++++++++++++++++++++++++++++---------
> >  5 files changed, 87 insertions(+), 25 deletions(-)
> > 
> > diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c
> > index 99631fa56662..474b3a3af3fb 100644
> > --- a/fs/nfsd/filecache.c
> > +++ b/fs/nfsd/filecache.c
> > @@ -413,12 +413,15 @@ nfsd_file_dispose_list_delayed(struct list_head *dispose)
> >  		struct nfsd_file *nf = list_first_entry(dispose,
> >  						struct nfsd_file, nf_lru);
> >  		struct nfsd_net *nn = net_generic(nf->nf_net, nfsd_net_id);
> > +		int srcu_idx;
> > +		struct svc_serv *serv = nfsd_serv_get(nn, &srcu_idx);
> >  		struct nfsd_fcache_disposal *l = nn->fcache_disposal;
> >  
> >  		spin_lock(&l->lock);
> >  		list_move_tail(&nf->nf_lru, &l->freeme);
> >  		spin_unlock(&l->lock);
> > -		svc_wake_up(nn->nfsd_serv);
> > +		svc_wake_up(serv);
> > +		nfsd_serv_put(nn, srcu_idx);
> >  	}
> >  }
> >  
> > @@ -443,11 +446,15 @@ void nfsd_file_net_dispose(struct nfsd_net *nn)
> >  		for (i = 0; i < 8 && !list_empty(&l->freeme); i++)
> >  			list_move(l->freeme.next, &dispose);
> >  		spin_unlock(&l->lock);
> > -		if (!list_empty(&l->freeme))
> > +		if (!list_empty(&l->freeme)) {
> > +			int srcu_idx;
> > +			struct svc_serv *serv = nfsd_serv_get(nn, &srcu_idx);
> >  			/* Wake up another thread to share the work
> >  			 * *before* doing any actual disposing.
> >  			 */
> > -			svc_wake_up(nn->nfsd_serv);
> > +			svc_wake_up(serv);
> > +			nfsd_serv_put(nn, srcu_idx);
> > +		}
> >  		nfsd_file_dispose_list(&dispose);
> >  	}
> >  }
> > diff --git a/fs/nfsd/netns.h b/fs/nfsd/netns.h
> > index 0c5a1d97e4ac..0eebcc03bcd3 100644
> > --- a/fs/nfsd/netns.h
> > +++ b/fs/nfsd/netns.h
> > @@ -139,8 +139,12 @@ struct nfsd_net {
> >  	u32 clverifier_counter;
> >  
> >  	struct svc_info nfsd_info;
> > -#define nfsd_serv nfsd_info.serv
> > -
> > +	/*
> > +	 * The current 'nfsd_serv' at nfsd_info.serv
> > +	 * Use nfsd_serv_get() or take nfsd_mutex to dereference.
> > +	 */
> > +	void __rcu *nfsd_serv;
> 
> I don't understand why you need a void pointer here. This should only
> ever hold a pointer to the serv or NULL. It seems like this work just
> as well: 
> 
> 	struct svc_serv __rcu *nfsd_serv;
> 

It is defensive, future-proofs us from some new code being introduced
that dereferences nn->nfsd_serv without proper use of nfsd_serv_get().


> > @@ -589,9 +615,12 @@ void nfsd_destroy_serv(struct net *net)
> >  	struct nfsd_net *nn = net_generic(net, nfsd_net_id);
> >  	struct svc_serv *serv = nn->nfsd_serv;
> >  
> > +	lockdep_assert_held(&nfsd_mutex);
> > +
> >  	spin_lock(&nfsd_notifier_lock);
> > -	nn->nfsd_serv = NULL;
> > +	rcu_assign_pointer(nn->nfsd_serv, NULL);
> >  	spin_unlock(&nfsd_notifier_lock);
> > +	nfsd_serv_sync(nn);
> >  
> >  	/* check if the notifier still has clients */
> >  	if (atomic_dec_return(&nfsd_notifier_refcount) == 0) {
> > @@ -711,6 +740,10 @@ int nfsd_create_serv(struct net *net)
> >  	if (nn->nfsd_serv)
> >  		return 0;
> >  
> > +	error = init_srcu_struct(&nn->nfsd_serv_srcu);
> > +	if (error)
> > +		return error;
> > +
> >  	if (nfsd_max_blksize == 0)
> >  		nfsd_max_blksize = nfsd_get_default_max_blksize();
> >  	nfsd_reset_versions(nn);
> > @@ -727,8 +760,10 @@ int nfsd_create_serv(struct net *net)
> >  	}
> >  	spin_lock(&nfsd_notifier_lock);
> >  	nn->nfsd_info.mutex = &nfsd_mutex;
> > -	nn->nfsd_serv = serv;
> > +	nn->nfsd_info.serv = serv;
> > +	rcu_assign_pointer(nn->nfsd_serv, nn->nfsd_info.serv);
> >  	spin_unlock(&nfsd_notifier_lock);
> > +	nfsd_serv_sync(nn);
> 
> I get why you're doing the synchronize on destroy, but why on the
> create? You're not tearing anything down here, so I don't see the need
> to ensure synchronization.

Yeah, it isn't needed.  Fixed, thanks.

Mike

  reply	other threads:[~2024-06-19 17:26 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-18 20:19 [PATCH v5 00/19] nfs/nfsd: add support for localio Mike Snitzer
2024-06-18 20:19 ` [PATCH v5 01/19] nfs: pass nfs_client to nfs_initiate_pgio Mike Snitzer
2024-06-18 20:19 ` [PATCH v5 02/19] nfs: pass descriptor thru nfs_initiate_pgio path Mike Snitzer
2024-06-18 20:19 ` [PATCH v5 03/19] nfs: pass struct file to nfs_init_pgio and nfs_init_commit Mike Snitzer
2024-06-18 20:19 ` [PATCH v5 04/19] sunrpc: add rpcauth_map_to_svc_cred_local Mike Snitzer
2024-06-18 20:19 ` [PATCH v5 05/19] nfs_common: add NFS LOCALIO protocol extension enablement Mike Snitzer
2024-06-19  5:04   ` NeilBrown
2024-06-18 20:19 ` [PATCH v5 06/19] nfs/nfsd: add "localio" support Mike Snitzer
2024-06-18 21:28   ` Jeff Layton
2024-06-18 20:19 ` [PATCH v5 07/19] NFS: Enable localio for non-pNFS I/O Mike Snitzer
2024-06-18 20:19 ` [PATCH v5 08/19] pnfs/flexfiles: Enable localio for flexfiles I/O Mike Snitzer
2024-06-18 20:19 ` [PATCH v5 09/19] nfs: implement v3 and v4 client support for NFS_LOCALIO_PROGRAM Mike Snitzer
2024-06-19  5:30   ` NeilBrown
2024-06-19 13:18     ` Chuck Lever III
2024-06-18 20:19 ` [PATCH v5 10/19] nfsd: implement v3 and v4 server " Mike Snitzer
2024-06-18 20:19 ` [PATCH v5 11/19] nfs/nfsd: consolidate {encode,decode}_opaque_fixed in nfs_xdr.h Mike Snitzer
2024-06-18 20:19 ` [PATCH v5 12/19] nfs/localio: move managing nfsd_open_local_fh symbol to nfs_common Mike Snitzer
2024-06-18 21:32   ` Jeff Layton
2024-06-18 20:19 ` [PATCH v5 13/19] nfs/nfsd: ensure localio server always uses its network namespace Mike Snitzer
2024-06-18 21:36   ` Jeff Layton
2024-06-18 20:19 ` [PATCH v5 14/19] nfsd/localio: manage netns reference in nfsd_open_local_fh Mike Snitzer
2024-06-18 20:19 ` [PATCH v5 15/19] nfsd: prepare to use SRCU to dereference nn->nfsd_serv Mike Snitzer
2024-06-18 20:19 ` [PATCH v5 16/19] nfsd: " Mike Snitzer
2024-06-19 12:39   ` Jeff Layton
2024-06-19 17:26     ` Mike Snitzer [this message]
2024-06-18 20:19 ` [PATCH v5 17/19] nfsd/localio: use SRCU to dereference nn->nfsd_serv in nfsd_open_local_fh Mike Snitzer
2024-06-18 20:19 ` [PATCH v5 18/19] nfs/localio: use dedicated workqueues for filesystem read and write Mike Snitzer
2024-06-18 20:19 ` [PATCH v5 19/19] nfs: add Documentation/filesystems/nfs/localio.rst Mike Snitzer
2024-06-18 21:46   ` Chuck Lever
2024-06-19  5:47     ` NeilBrown
2024-06-19 18:27       ` Mike Snitzer
2024-06-19  5:49 ` [PATCH v5 00/19] nfs/nfsd: add support for localio Christoph Hellwig
2024-06-19  7:10   ` NeilBrown
2024-06-19  7:15     ` Christoph Hellwig
2024-06-19 10:09     ` Jeff Layton
2024-06-19 21:09       ` NeilBrown
2024-06-19 22:28         ` Jeff Layton
2024-06-19 22:46         ` Mike Snitzer
2024-06-20  5:16         ` Christoph Hellwig
2024-06-19 17:57     ` Mike Snitzer
2024-06-19 18:04       ` Chuck Lever III
2024-06-19 18:13         ` Mike Snitzer
2024-06-19 18:22           ` Chuck Lever III
2024-06-20  5:18       ` Christoph Hellwig
2024-06-19 14:02   ` Trond Myklebust

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=ZnMUv3NJ7w1cE5dU@kernel.org \
    --to=snitzer@kernel.org \
    --cc=chuck.lever@oracle.com \
    --cc=jlayton@kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=neilb@suse.de \
    --cc=snitzer@hammerspace.com \
    --cc=trondmy@hammerspace.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 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.