From: Oleg Nesterov <oleg@redhat.com>
To: Kirill Kolyshkin <kolyshkin@gmail.com>
Cc: Alejandro Colomar <alx@kernel.org>,
linux-man@vger.kernel.org, Christian Brauner <brauner@kernel.org>
Subject: Re: [PATCH 2/3] pidfd_open.2: add PIDFD_THREAD and poll nuances
Date: Wed, 10 Jul 2024 00:25:41 +0200 [thread overview]
Message-ID: <20240709222541.GB6162@redhat.com> (raw)
In-Reply-To: <CAGmPdrxFk5Z62BkVaQwhNsuvbb8C=uHsdFMfA3iJwPCu8bZuMw@mail.gmail.com>
On 07/09, Kirill Kolyshkin wrote:
>
> On Tue, Jul 9, 2024 at 2:43 AM Oleg Nesterov <oleg@redhat.com> wrote:
> >
> > Hi Kir,
> >
> > On 07/08, Kir Kolyshkin wrote:
> > >
> > > [1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=64bef697d33b
> >
> > The changelog says:
> >
> > pidfd: implement PIDFD_THREAD flag for pidfd_open()
> >
> > With this flag:
> >
> > - pidfd_open() doesn't require that the target task must be
> > a thread-group leader
> >
> > - pidfd_poll() succeeds when the task exits and becomes a
> > zombie (iow, passes exit_notify()), even if it is a leader
> > and thread-group is not empty.
> >
> > This means that the behaviour of pidfd_poll(PIDFD_THREAD,
> > pid-of-group-leader) is not well defined if it races with
> > exec() from its sub-thread; pidfd_poll() can succeed or not
> > depending on whether pidfd_task_exited() is called before
> > or after exchange_tids().
> >
> > > +The behavior depends on whether the file descriptor refers
> > > +to a process (thread-group leader) or a thread (see
> > > +.B PIDFD_THREAD
> > > +above):
> > > +.RS
> > > +.IP \[bu] 3
> > > +For a thread-group leader, the polling task is woken if the
> > > +thread-group is empty. In other words, if the thread-group
> > > +leader task exits when there are still threads alive in its
> > > +thread-group, the polling task will not be woken when the
> > > +thread-group leader exits, but rather when the last thread in the
> > > +thread-group exits.
> >
> > so this part is not accurate.
>
> I copied the above text almost verbatim from the merge commit
> description (commit b5683a37c881).
And b5683a37c881 says
For thread-group leader pidfds ...
...
For thread-specific pidfds the polling task is woken if the
thread exits.
I think that "thread-specific pidfds" means pidfd created with the
PIDFD_THREAD flag.
> Until it's clarified, let's remove this text, adding a TODO instead.
OK. but you can also look at the (trivial) code:
static __poll_t pidfd_poll(struct file *file, struct poll_table_struct *pts)
{
struct pid *pid = pidfd_pid(file);
bool thread = file->f_flags & PIDFD_THREAD;
struct task_struct *task;
__poll_t poll_flags = 0;
poll_wait(file, &pid->wait_pidfd, pts);
/*
* Depending on PIDFD_THREAD, inform pollers when the thread
* or the whole thread-group exits.
*/
guard(rcu)();
task = pid_task(pid, PIDTYPE_PID);
if (!task)
poll_flags = EPOLLIN | EPOLLRDNORM | EPOLLHUP;
else if (task->exit_state && (thread || thread_group_empty(task)))
poll_flags = EPOLLIN | EPOLLRDNORM;
return poll_flags;
}
please note that the thread_group_empty() check has no effect if
bool thread == f_flags & PIDFD_THREAD is true.
In this case pidfd_poll() succeeds if the the target task has already
exited (passed exit_notify, so ->exit_state is not zero), no matter if
it is a leader or not.
Oleg.
next prev parent reply other threads:[~2024-07-09 22:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-09 2:13 [PATCH 0/3] man2: document Linux v6.9 pidfd-related changes Kir Kolyshkin
2024-07-09 2:13 ` [PATCH 1/3] clone.2: document CLONE_PIDFD | CLONE_THREAD Kir Kolyshkin
2024-07-09 2:13 ` [PATCH 2/3] pidfd_open.2: add PIDFD_THREAD and poll nuances Kir Kolyshkin
2024-07-09 9:42 ` Oleg Nesterov
2024-07-09 22:06 ` Kirill Kolyshkin
2024-07-09 22:25 ` Oleg Nesterov [this message]
2024-07-09 2:13 ` [PATCH 3/3] pidfd_send_signal.2: describe flags Kir Kolyshkin
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=20240709222541.GB6162@redhat.com \
--to=oleg@redhat.com \
--cc=alx@kernel.org \
--cc=brauner@kernel.org \
--cc=kolyshkin@gmail.com \
--cc=linux-man@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.