lkml.org 
[lkml]   [2019]   [Jul]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH v2 1/2] pidfd: add P_PIDFD to waitid()
On Sat, Jul 27, 2019 at 9:28 AM Linus Torvalds
<torvalds@linux-foundation.org> wrote:
>
> Something like
>
> struct pid *fd_to_pid(unsigned int fd)
> {
> struct fd f;
> struct pid *pid;
...

I forgot to put my usual disclaimer about TOTALLY UNTESTED GARBAGE in
that email. I want to make that part clear: that code snippet was
meant as a rough guide of direction, not as a "this works".

Hopefully that was clear.

Also note again that one of the reasons I would prefer that
"fd_to_pid()" interface is that you _can_ do it cleverly with RCU
lookup, but that requires a lot of care.

In particular, I think all of our _existing_
"proc_pid(file_inode(file))" users are done while you actually hold a
reference to "struct file *", so they don't have to worry about races
with another thread doing the final ->release(). So the "clever" thing
is possible, but might need a _lot_ of care to make sure the 'struct
pid *' associated with the file still exists.

The example code sequence was not doing the clever thing, obviously.
So it was untested _and_ simple-stupid. But it has the interface that
I'd prefer.

Linus

\
 
 \ /
  Last update: 2019-07-27 18:42    [W:0.041 / U:16.312 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site