From: Jeff Layton <jlayton@kernel.org>
To: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>,
Chuck Lever III <chuck.lever@oracle.com>
Cc: Frank van der Linden <fllinden@amazon.com>,
Linux NFS Mailing List <linux-nfs@vger.kernel.org>,
Frank van der Linden <fllinden@amazon.com>,
linux-fsdevel <linux-fsdevel@vger.kernel.org>
Subject: Re: [PATCH] nfsd: don't use GFP_KERNEL from nfsd_getxattr()/nfsd_listxattr()
Date: Sun, 16 Apr 2023 07:51:41 -0400 [thread overview]
Message-ID: <7246a80ae33244a4553bbc0ca9e771ce8143d97b.camel@kernel.org> (raw)
In-Reply-To: <c310695e-4279-b1a7-5c2a-2771cc19aa66@I-love.SAKURA.ne.jp>
On Sun, 2023-04-16 at 08:21 +0900, Tetsuo Handa wrote:
> On 2023/04/16 3:40, Jeff Layton wrote:
> > On Sun, 2023-04-16 at 02:11 +0900, Tetsuo Handa wrote:
> > > On 2023/04/16 1:13, Chuck Lever III wrote:
> > > > > On Apr 15, 2023, at 7:07 AM, Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> wrote:
> > > > >
> > > > > Since GFP_KERNEL is GFP_NOFS | __GFP_FS, usage like GFP_KERNEL | GFP_NOFS
> > > > > does not make sense. Drop __GFP_FS flag in order to avoid deadlock.
> > > >
> > > > The server side threads run in process context. GFP_KERNEL
> > > > is safe to use here -- as Jeff said, this code is not in
> > > > the server's reclaim path. Plenty of other call sites in
> > > > the NFS server code use GFP_KERNEL.
> > >
> > > GFP_KERNEL memory allocation calls filesystem's shrinker functions
> > > because of __GFP_FS flag. My understanding is
> > >
> > > Whether this code is in memory reclaim path or not is irrelevant.
> > > Whether memory reclaim path might hold lock or not is relevant.
> > >
> > > . Therefore, question is, does nfsd hold i_rwsem during memory reclaim path?
> > >
> >
> > No. At the time of these allocations, the i_rwsem is not held.
>
> Excuse me? nfsd_getxattr()/nfsd_listxattr() _are_ holding i_rwsem
> via inode_lock_shared(inode) before kvmalloc(GFP_KERNEL | GFP_NOFS) allocation.
> That's why
>
> /*
> * We're holding i_rwsem - use GFP_NOFS.
> */
>
> is explicitly there in nfsd_listxattr() side.
>
> If memory reclaim path (directly or indirectly via locking dependency) involves
> inode_lock_shared(inode)/inode_lock(inode), it is not safe to use __GFP_FS flag.
>
(cc'ing Frank V. who wrote this code and -fsdevel)
I stand corrected! You're absolutely right that it's taking the i_rwsem
for read there. That seems pretty weird, actually. I don't believe we
need to hold the inode_lock to call vfs_getxattr or vfs_listxattr, and
certainly nothing else under there requires it.
Frank, was there some reason you decided you needed the inode_lock
there? It looks like under the hood, the xattr code requires you to take
it for write in setxattr and removexattr, but you don't need it at all
in getxattr or listxattr. Go figure.
If there's no reason to keep it there, then in addition to removing
GFP_NOFS there I think we probably ought to just remove the inode_lock
from nfsd_getxattr and nfsd_listxattr altogether.
Longer term, I wonder what the inode_lock is protecting in setxattr and
removexattr operations, given that get and list don't require them?
These are always delegated to the filesystem driver -- there is no
generic xattr implementation.
Maybe we ought to do a lock pushdown on those operations at some point?
I'd bet that most of the setxattr/removexattr operations do their own
locking and don't require the i_rwsem at all.
--
Jeff Layton <jlayton@kernel.org>
next parent reply other threads:[~2023-04-16 11:51 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <72bf692e-bb6b-c1f2-d1ba-3205ab649b43@I-love.SAKURA.ne.jp>
[not found] ` <4BC7955B-40E4-4A43-B2D1-2E9302E84337@oracle.com>
[not found] ` <b014047a-4a70-b38f-c5bb-01bc3c53d6f2@I-love.SAKURA.ne.jp>
[not found] ` <aee35d52ab19e7e95f69742be8329764db72cbf8.camel@kernel.org>
[not found] ` <c310695e-4279-b1a7-5c2a-2771cc19aa66@I-love.SAKURA.ne.jp>
2023-04-16 11:51 ` Jeff Layton [this message]
2023-04-16 16:20 ` [PATCH] nfsd: don't use GFP_KERNEL from nfsd_getxattr()/nfsd_listxattr() Chuck Lever III
2023-04-16 23:37 ` Dave Chinner
2023-04-17 22:25 ` Frank van der Linden
2023-04-17 23:07 ` Frank van der Linden
2023-04-19 13:51 ` Chuck Lever III
2023-04-19 23:32 ` Dave Chinner
2023-04-20 13:41 ` Chuck Lever III
2023-04-20 14:05 ` Tetsuo Handa
2023-04-20 14:41 ` Chuck Lever III
2023-04-20 15:20 ` 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=7246a80ae33244a4553bbc0ca9e771ce8143d97b.camel@kernel.org \
--to=jlayton@kernel.org \
--cc=chuck.lever@oracle.com \
--cc=fllinden@amazon.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=penguin-kernel@I-love.SAKURA.ne.jp \
/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