From: "J. Bruce Fields" <bfields@fieldses.org>
To: Jeff Layton <jlayton@kernel.org>
Cc: linux-nfs@vger.kernel.org, chuck.lever@oracle.com,
Vasily Averin <vvs@virtuozzo.com>
Subject: Re: [PATCH] nfsd: don't put blocked locks on LRU until after vfs_lock_file returns
Date: Tue, 23 Nov 2021 11:41:41 -0500 [thread overview]
Message-ID: <20211123164141.GD8978@fieldses.org> (raw)
In-Reply-To: <ed633e0aaa64847d159e1db1087b4a3da9143ec4.camel@kernel.org>
On Tue, Nov 23, 2021 at 11:31:01AM -0500, Jeff Layton wrote:
> On Tue, 2021-11-23 at 10:59 -0500, J. Bruce Fields wrote:
> > On Tue, Nov 23, 2021 at 07:22:23AM -0500, Jeff Layton wrote:
> > > Vasily reported a case where vfs_lock_file took a very long time to
> > > return (longer than a lease period). The laundromat eventually ran and
> > > reaped the thing and when the vfs_lock_file returned, it ended up
> > > accessing freed memory.
> >
> > By the way, once we've called vfs_lock_file(), is there anything
> > preventing nfsd4_cb_notify_lock_release() from freeing nbl before we get
> > here?
> >
>
> No, I don't think there is. Good catch.
It may be a rare race (an rpc's not normally going to reply in that
time), but I wouldn't be surprised if there's some error condition where
it's possible.
> Hmm...the only way I can see to fix that would be to add a refcount to
> these things, in which case we probably don't need this patch since it
> would prevent the original issue as well...
Depending on how long that might take, I'd be OK with applying this as a
stopgap.
--b.
>
> > >
> > > Don't put entries onto the LRU until vfs_lock_file returns.
> > >
> > > Reported-by: Vasily Averin <vvs@virtuozzo.com>
> > > Signed-off-by: Jeff Layton <jlayton@kernel.org>
> > > ---
> > > fs/nfsd/nfs4state.c | 6 ++++--
> > > 1 file changed, 4 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
> > > index bfad94c70b84..8cfef84b9355 100644
> > > --- a/fs/nfsd/nfs4state.c
> > > +++ b/fs/nfsd/nfs4state.c
> > > @@ -6966,10 +6966,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
> > > }
> > >
> > > if (fl_flags & FL_SLEEP) {
> > > - nbl->nbl_time = ktime_get_boottime_seconds();
> > > spin_lock(&nn->blocked_locks_lock);
> > > list_add_tail(&nbl->nbl_list, &lock_sop->lo_blocked);
> > > - list_add_tail(&nbl->nbl_lru, &nn->blocked_locks_lru);
> > > spin_unlock(&nn->blocked_locks_lock);
> > > }
> > >
> > > @@ -6982,6 +6980,10 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
> > > nn->somebody_reclaimed = true;
> > > break;
> > > case FILE_LOCK_DEFERRED:
> > > + nbl->nbl_time = ktime_get_boottime_seconds();
> > > + spin_lock(&nn->blocked_locks_lock);
> > > + list_add_tail(&nbl->nbl_lru, &nn->blocked_locks_lru);
> > > + spin_unlock(&nn->blocked_locks_lock);
> > > nbl = NULL;
> > > fallthrough;
> > > case -EAGAIN: /* conflock holds conflicting lock */
> > > --
> > > 2.33.1
>
> --
> Jeff Layton <jlayton@kernel.org>
next prev parent reply other threads:[~2021-11-23 16:42 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-23 12:22 [PATCH] nfsd: don't put blocked locks on LRU until after vfs_lock_file returns Jeff Layton
2021-11-23 15:20 ` Vasily Averin
2021-11-23 15:21 ` Chuck Lever III
2021-11-23 15:59 ` J. Bruce Fields
2021-11-23 16:31 ` Jeff Layton
2021-11-23 16:41 ` J. Bruce Fields [this message]
2021-11-23 17:02 ` 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=20211123164141.GD8978@fieldses.org \
--to=bfields@fieldses.org \
--cc=chuck.lever@oracle.com \
--cc=jlayton@kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=vvs@virtuozzo.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.