From: Mike Snitzer <snitzer@kernel.org>
To: NeilBrown <neilb@suse.de>
Cc: Jeff Layton <jlayton@kernel.org>,
linux-nfs@vger.kernel.org, Chuck Lever <chuck.lever@oracle.com>,
Trond Myklebust <trondmy@hammerspace.com>,
snitzer@hammerspace.com
Subject: Re: [PATCH v7 17/20] nfsd: use SRCU to dereference nn->nfsd_serv
Date: Wed, 26 Jun 2024 12:49:23 -0400 [thread overview]
Message-ID: <ZnxGk4N5WRhAUXdL@kernel.org> (raw)
In-Reply-To: <171935815356.14261.943840832291192923@noble.neil.brown.name>
On Wed, Jun 26, 2024 at 09:29:13AM +1000, NeilBrown wrote:
> On Tue, 25 Jun 2024, Jeff Layton wrote:
> > On Mon, 2024-06-24 at 12:27 -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 | 14 ++++++++++--
> > > fs/nfsd/nfs4state.c | 25 ++++++++++++++-------
> > > fs/nfsd/nfsctl.c | 7 ++++--
> > > fs/nfsd/nfssvc.c | 54 ++++++++++++++++++++++++++++++++++++---------
> > > 5 files changed, 88 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..92d0d0883f17 100644
> > > --- a/fs/nfsd/netns.h
> > > +++ b/fs/nfsd/netns.h
> > > @@ -139,8 +139,14 @@ 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. Using 'void' rather than
> > > + * 'struct svc_serv' to guard against new code dereferencing nfsd_serv
> > > + * without using proper synchronization.
> > > + * Use nfsd_serv_get() or take nfsd_mutex to dereference.
> > > + */
> > > + void __rcu *nfsd_serv;
> > > + struct srcu_struct nfsd_serv_srcu;
> >
> > I'm still not sold on the use of a void pointer here. It might protect
> > you from using nn->nfsd_serv directly, but if you do:
> >
> > struct svc_serv *serv = nn->nfsd_serv;
> >
> > ...that will still work. If you really want to guard against direct
> > dereferencing, maybe it should be an unsigned long? Then you really
> > will have to cast to use it.
>
> I agree. The point of the "__rcu" attribute is that sparse will
> complain if you use the pointer without using srcu_dereference().
> And CONFIG_PROVE_RCU gives you run-time splats.
> We should use the tools we already have.
Good news, I've switched from using SRCU to a percpu-refcount. So v8
will be considerably cleaner (less shotgun blast due to dropping the
excessive churn from SRCU prep and implementation).
SRCU would've enabled us to drop the client notifier spinlock, and
maybe more but certianly best to avoid all the SRCU changes.
Mike
next prev parent reply other threads:[~2024-06-26 16:49 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-24 16:27 [PATCH v7 00/20] nfs/nfsd: add support for localio Mike Snitzer
2024-06-24 16:27 ` [PATCH v7 01/20] nfs: pass nfs_client to nfs_initiate_pgio Mike Snitzer
2024-06-24 16:27 ` [PATCH v7 02/20] nfs: pass descriptor thru nfs_initiate_pgio path Mike Snitzer
2024-06-24 16:27 ` [PATCH v7 03/20] nfs: pass struct file to nfs_init_pgio and nfs_init_commit Mike Snitzer
2024-06-24 16:27 ` [PATCH v7 04/20] sunrpc: add rpcauth_map_to_svc_cred_local Mike Snitzer
2024-06-24 16:27 ` [PATCH v7 05/20] nfs_common: add NFS LOCALIO auxiliary protocol enablement Mike Snitzer
2024-06-25 23:33 ` NeilBrown
2024-06-26 16:50 ` Mike Snitzer
2024-06-24 16:27 ` [PATCH v7 06/20] nfs/nfsd: add "localio" support Mike Snitzer
2024-06-24 18:26 ` Chuck Lever
2024-06-25 4:57 ` Mike Snitzer
2024-06-25 13:59 ` Chuck Lever
2024-06-24 16:27 ` [PATCH v7 07/20] nfsd/localio: manage netns reference in nfsd_open_local_fh Mike Snitzer
2024-06-24 16:27 ` [PATCH v7 08/20] NFS: Enable localio for non-pNFS I/O Mike Snitzer
2024-06-24 16:27 ` [PATCH v7 09/20] pnfs/flexfiles: Enable localio for flexfiles I/O Mike Snitzer
2024-06-24 16:27 ` [PATCH v7 10/20] nfs/localio: use dedicated workqueues for filesystem read and write Mike Snitzer
2024-06-25 23:15 ` NeilBrown
2024-06-24 16:27 ` [PATCH v7 11/20] nfs/nfsd: factor out {encode,decode}_opaque_fixed to nfs_xdr.h Mike Snitzer
2024-06-24 18:28 ` Chuck Lever
2024-06-24 16:27 ` [PATCH v7 12/20] SUNRPC: remove call_allocate() BUG_ON if p_arglen=0 to allow RPC with void arg Mike Snitzer
2024-06-25 23:19 ` NeilBrown
2024-06-26 16:53 ` Mike Snitzer
2024-06-24 16:27 ` [PATCH v7 13/20] nfs: implement client support for NFS_LOCALIO_PROGRAM Mike Snitzer
2024-06-25 23:21 ` NeilBrown
2024-06-26 16:45 ` Mike Snitzer
2024-06-24 16:27 ` [PATCH v7 14/20] nfsd: implement server " Mike Snitzer
2024-06-24 18:45 ` Chuck Lever
2024-06-25 23:23 ` NeilBrown
2024-06-26 16:27 ` Mike Snitzer
2024-06-24 16:27 ` [PATCH v7 15/20] SUNRPC: replace program list with program array Mike Snitzer
2024-06-24 16:27 ` [PATCH v7 16/20] nfsd: prepare to use SRCU to dereference nn->nfsd_serv Mike Snitzer
2024-06-24 16:27 ` [PATCH v7 17/20] nfsd: " Mike Snitzer
2024-06-25 12:43 ` Jeff Layton
2024-06-25 23:29 ` NeilBrown
2024-06-26 16:49 ` Mike Snitzer [this message]
2024-06-24 16:27 ` [PATCH v7 18/20] nfsd/localio: use SRCU to dereference nn->nfsd_serv in nfsd_open_local_fh Mike Snitzer
2024-06-24 16:27 ` [PATCH v7 19/20] nfs: add Documentation/filesystems/nfs/localio.rst Mike Snitzer
2024-06-25 11:59 ` Jeff Layton
2024-06-24 16:27 ` [PATCH v7 20/20] nfs/nfsd: add Kconfig options to allow localio to be enabled Mike Snitzer
2024-06-25 12:49 ` [PATCH v7 00/20] nfs/nfsd: add support for localio Jeff Layton
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=ZnxGk4N5WRhAUXdL@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox