From: Oleg Nesterov <oleg@redhat.com>
To: Jim Newsome <jnewsome@torproject.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
"Eric W . Biederman" <ebiederm@xmission.com>,
Christian Brauner <christian@brauner.io>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4] do_wait: make PIDTYPE_PID case O(1) instead of O(n)
Date: Fri, 12 Mar 2021 17:41:20 +0100 [thread overview]
Message-ID: <20210312164119.GC27820@redhat.com> (raw)
In-Reply-To: <20210311233823.20325-1-jnewsome@torproject.org>
On 03/11, Jim Newsome wrote:
>
> +static bool is_effectively_child(struct wait_opts *wo, bool ptrace,
> + struct task_struct *target)
> +{
> + struct task_struct *parent =
> + !ptrace ? target->real_parent : target->parent;
> +
> + return current == parent || (!(wo->wo_flags & __WNOTHREAD) &&
> + same_thread_group(current, parent));
> +}
> +
> +/*
> + * Optimization for waiting on PIDTYPE_PID. No need to iterate through child
> + * and tracee lists to find the target task.
> + */
> +static int do_wait_pid(struct wait_opts *wo)
> +{
> + bool ptrace;
> + struct task_struct *target;
> + int retval;
> +
> + ptrace = false;
> +
> + /* A non-ptrace wait can only be performed on a thread group leader. */
> + target = pid_task(wo->wo_pid, PIDTYPE_TGID);
> +
> + if (target && is_effectively_child(wo, ptrace, target)) {
> + retval = wait_consider_task(wo, ptrace, target);
> + if (retval)
> + return retval;
> + }
> +
> + ptrace = true;
> +
> + /* A ptrace wait can be done on non-thread-group-leaders. */
> + if (!target)
> + target = pid_task(wo->wo_pid, PIDTYPE_PID);
> +
> + if (target && is_effectively_child(wo, ptrace, target)) {
> + retval = wait_consider_task(wo, ptrace, target);
No, this is not right... You need to check target->ptrace != 0.
I know that Eric suggests to not use thread_group_leader() and I won't argue
even if I don't really agree.
Up to you, but to me something like
do_wait_pid()
{
target = pid_task(wo->wo_pid, PIDTYPE_PID);
if (!target)
return 0;
if (thread_group_leader(target) &&
is_effectively_child(wo, 0, target) {
...
}
if (target->ptrace &&
is_effectively_child(wo, 1, target) {
...
}
return 0;
}
looks more simple/clean.
Oleg.
next prev parent reply other threads:[~2021-03-12 16:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-11 23:38 [PATCH v4] do_wait: make PIDTYPE_PID case O(1) instead of O(n) Jim Newsome
2021-03-12 16:41 ` Oleg Nesterov [this message]
2021-03-12 16:51 ` Jim Newsome
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=20210312164119.GC27820@redhat.com \
--to=oleg@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=christian@brauner.io \
--cc=ebiederm@xmission.com \
--cc=jnewsome@torproject.org \
--cc=linux-kernel@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.