From: Oleg Nesterov <oleg@redhat.com>
To: Tycho Andersen <tycho@tycho.pizza>
Cc: Christian Brauner <brauner@kernel.org>,
linux-kernel@vger.kernel.org, linux-api@vger.kernel.org,
Tycho Andersen <tandersen@netflix.com>,
"Eric W. Biederman" <ebiederm@xmission.com>
Subject: Re: [PATCH v3 1/3] pidfd: allow pidfd_open() on non-thread-group leaders
Date: Sat, 27 Jan 2024 11:54:32 +0100 [thread overview]
Message-ID: <20240127105410.GA13787@redhat.com> (raw)
In-Reply-To: <ZbQpPknTTCyiyxrP@tycho.pizza>
Hi Tycho,
On 01/26, Tycho Andersen wrote:
>
> On Thu, Jan 25, 2024 at 03:08:31PM +0100, Oleg Nesterov wrote:
> > What do you think?
>
> Thank you, it passes all my tests.
Great, thanks!
OK, I'll make v2 on top of the recent
"pidfd: cleanup the usage of __pidfd_prepare's flags"
but we need to finish our discussion with Christian about the
usage of O_EXCL.
As for clone(CLONE_PIDFD | CLONE_THREAD), this is trivial but
I think this needs another discussion too, lets do this later.
> > + /* unnecessary if do_notify_parent() was already called,
> > + we can do better */
> > + do_notify_pidfd(tsk);
>
> "do better" here could be something like,
>
> [...snip...]
No, no, please see below.
For the moment, please forget about PIDFD_THREAD, lets discuss
the current behaviour.
> but even with that, there's other calls in the tree to
> do_notify_parent() that might double notify.
Yes, and we can't avoid this. Well, perhaps do_notify_parent()
can do something like
if (ptrace_reparented())
do_notify_pidfd();
so that only the "final" do_notify_parent() does do_notify_pidfd()
but this needs another discussion and in fact I don't think this
would be right or make much sense. Lets forget this for now.
Now. Even without PIDFD_THREAD, I think it makes sense to change
do_notify_parent() to do
if (thread_group_empty(tsk))
do_notify_pidfd(tsk);
thread_group_empty(tsk) can only be true if tsk is a group leader
and it is the last thread. And this is exactly what pidfd_poll()
currently needs.
In fact I'd even prefer to do this in a separate patch for the
documentation purposes.
Now, PIDFD_THREAD can just add
if (!thread_group_empty(tsk))
do_notify_pidfd(tsk);
right after "tsk->exit_state = EXIT_ZOMBIE", that is all.
This also preserves the do_notify_pidfd/__wake_up_parent ordering.
Not that I think this is important, just for consistency.
> This brings up another interesting behavior that I noticed while
> testing this, if you do a poll() on pidfd, followed quickly by a
> pidfd_getfd() on the same thread you just got an event on, you can
> sometimes get an EBADF from __pidfd_fget() instead of the more
> expected ESRCH higher up the stack.
exit_notify() is called after exit_files(). pidfd_getfd() returns
ESRCH if the exiting thread completes release_task(), otherwise it
returns EBADF because ->files == NULL. This too doesn't really
depend on PIDFD_THREAD.
> I wonder if it makes sense to abuse ->f_flags to add a PIDFD_NOTIFIED?
> Then we can refuse further pidfd syscall operations in a sane way, and
But how? We only have "struct pid *", how can we find all files
"attached" to this pid?
> also "do better" above by checking this flag from do_pidfd_notify()
> before doing it again?
and even it was possible, I don't think it makes a lot of sense, see
also above.
but perhaps I understood you...
Oleg.
next prev parent reply other threads:[~2024-01-27 10:55 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-23 15:34 [PATCH v3 0/3] pidfds for non thread group leaders Tycho Andersen
2024-01-23 15:34 ` [PATCH v3 1/3] pidfd: allow pidfd_open() on non-thread-group leaders Tycho Andersen
2024-01-23 19:56 ` Oleg Nesterov
2024-01-23 21:10 ` Tycho Andersen
2024-01-23 22:22 ` Oleg Nesterov
2024-01-24 1:25 ` Oleg Nesterov
2024-01-25 14:08 ` Oleg Nesterov
2024-01-25 17:17 ` Christian Brauner
2024-01-25 17:51 ` Oleg Nesterov
2024-01-25 18:03 ` Tycho Andersen
2024-01-25 18:25 ` Oleg Nesterov
2024-01-25 18:30 ` Oleg Nesterov
2024-01-25 18:36 ` Tycho Andersen
2024-01-26 9:49 ` Christian Brauner
2024-01-26 9:42 ` Christian Brauner
2024-01-26 14:33 ` Oleg Nesterov
2024-01-26 9:47 ` Christian Brauner
2024-01-26 14:33 ` Oleg Nesterov
2024-01-27 14:26 ` Christian Brauner
2024-01-26 21:50 ` Tycho Andersen
2024-01-27 10:54 ` Oleg Nesterov [this message]
2024-01-27 14:33 ` Christian Brauner
2024-01-27 15:55 ` Tycho Andersen
2024-01-27 16:31 ` Oleg Nesterov
2024-01-27 17:20 ` Tycho Andersen
2024-01-27 19:31 ` Oleg Nesterov
2024-01-27 20:44 ` Tycho Andersen
2024-01-27 21:10 ` Oleg Nesterov
2024-01-29 11:23 ` [RFC PATCH] pidfd: implement PIDFD_THREAD flag for pidfd_open() Oleg Nesterov
2024-01-29 13:41 ` Christian Brauner
2024-01-29 14:31 ` Tycho Andersen
2024-01-29 15:14 ` Christian Brauner
2024-01-30 11:21 ` Oleg Nesterov
2024-01-31 18:11 ` Andy Lutomirski
2024-01-31 18:48 ` Oleg Nesterov
2024-01-31 19:14 ` Oleg Nesterov
2024-01-31 19:24 ` Andy Lutomirski
2024-01-31 19:46 ` Christian Brauner
2024-01-31 19:50 ` Andy Lutomirski
2024-02-01 13:30 ` Christian Brauner
2024-02-01 13:39 ` Christian Brauner
2024-02-01 19:33 ` Andy Lutomirski
2024-01-23 15:34 ` [PATCH v3 2/3] selftests/pidfd: add non-thread-group leader tests Tycho Andersen
2024-01-23 15:34 ` [PATCH v3 3/3] clone: allow CLONE_THREAD | CLONE_PIDFD together Tycho Andersen
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=20240127105410.GA13787@redhat.com \
--to=oleg@redhat.com \
--cc=brauner@kernel.org \
--cc=ebiederm@xmission.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tandersen@netflix.com \
--cc=tycho@tycho.pizza \
/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;
as well as URLs for NNTP newsgroup(s).