[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YMQMtwa/hv4Rmwba@zeniv-ca.linux.org.uk>
Date: Sat, 12 Jun 2021 01:24:07 +0000
From: Al Viro <viro@...iv.linux.org.uk>
To: Ian Kent <raven@...maw.net>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Tejun Heo <tj@...nel.org>, Eric Sandeen <sandeen@...deen.net>,
Fox Chen <foxhlchen@...il.com>,
Brice Goglin <brice.goglin@...il.com>,
Rick Lindsley <ricklind@...ux.vnet.ibm.com>,
David Howells <dhowells@...hat.com>,
Miklos Szeredi <miklos@...redi.hu>,
Marcelo Tosatti <mtosatti@...hat.com>,
"Eric W. Biederman" <ebiederm@...ssion.com>,
Carlos Maiolino <cmaiolino@...hat.com>,
linux-fsdevel <linux-fsdevel@...r.kernel.org>,
Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v6 4/7] kernfs: switch kernfs to use an rwsem
On Wed, Jun 09, 2021 at 04:50:52PM +0800, Ian Kent wrote:
> The kernfs global lock restricts the ability to perform kernfs node
> lookup operations in parallel during path walks.
>
> Change the kernfs mutex to an rwsem so that, when opportunity arises,
> node searches can be done in parallel with path walk lookups.
> diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
> index 5432883d819f2..c8f8e41b84110 100644
> --- a/fs/kernfs/symlink.c
> +++ b/fs/kernfs/symlink.c
> @@ -116,9 +116,9 @@ static int kernfs_getlink(struct inode *inode, char *path)
> struct kernfs_node *target = kn->symlink.target_kn;
> int error;
>
> - mutex_lock(&kernfs_mutex);
> + down_read(&kernfs_rwsem);
> error = kernfs_get_target_path(parent, target, path);
> - mutex_unlock(&kernfs_mutex);
> + up_read(&kernfs_rwsem);
Unrelated to this patchset, two notes from reading through that area:
1) parent is fetched outside of rwsem. Unstable, IOW.
2) kernfs_get_target_path() is an atrocity. On *any* symlink you
get an arseload of ../ (up to kernfs root), followed by into whatever
directory we want. Even if the target is in the same directory.
Think what happens if you mount --bind a subtree that contains both the
symlink and its destination. And try to follow that symlink.
It really ought to generate the minimal relative pathname.
And it's not hard to do:
calculate the depth of source
calculate the depth of destination
walk up from the deeper one until we get to the depth of the
shallower one.
walk up from both in tandem until two paths converge.
Now we have the LCA of those nodes and can use the to generate the relative
pathname.
Powered by blists - more mailing lists