lkml.org 
[lkml]   [2018]   [Nov]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 01/12] kernfs: add function to find kernfs_node without increasing ref counter
On Tue, Nov 13, 2018 at 06:53:59PM +0100, Paolo Valente wrote:
>
>
> > Il giorno 12 nov 2018, alle ore 13:28, Greg Kroah-Hartman <gregkh@linuxfoundation.org> ha scritto:
> >
> > On Mon, Nov 12, 2018 at 10:56:21AM +0100, Paolo Valente wrote:
> >> From: Angelo Ruocco <angeloruocco90@gmail.com>
> >>
> >> The kernfs pseudo file system doesn't export any function to only find
> >> a node by name, without also getting a reference on it.
> >> But in some cases it is useful to just locate a kernfs node, while
> >> using it or not depends on some other condition.
> >>
> >> This commit adds a function to just look for a node, without getting
> >> a reference on it.
> >
> > Eeek, that sounds really bad. So you save off a pointer to something,
> > and have no idea if that pointer now really is valid or not? It can
> > instantly disappear right afterwards.
> >
>
> Hi Greg,
> that function is invoked only in functions executed with cgroup_mutex
> held. This guarantees that nothing disappears or becomes
> inconsistent. That's why we decided to go for this optimization,
> instead of doing useless gets&puts pairs. Still, I'm not expert
> enough to state whether it is impossible that, once we have defined
> that function, it may then get used in some unsafe way.

I can guarantee once you define that function, it will be used in an
unsafe way :(

So just don't create it, use the put calls, it's fast and should never
be a performance issue.

> So, I seem to see two options:
> 1) Add a comment on the function, saying that cgroup_mutex must be
> held while invoking it (I guess you won't like this one).

Nope, do not create it.

> 2) Do not define such a new function, and, in the other patches, use
> the already-available find_and_get.

Yes, please do that.

thanks,

greg k-h

\
 
 \ /
  Last update: 2018-11-13 20:36    [W:0.060 / U:2.064 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site