From: Oleg Nesterov <oleg@redhat.com>
To: Kees Cook <keescook@chromium.org>
Cc: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>,
Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Andrew Morton <akpm@linux-foundation.org>,
Cyrill Gorcunov <gorcunov@openvz.org>,
John Stultz <john.stultz@linaro.org>,
Thomas Gleixner <tglx@linutronix.de>,
Nicolas Pitre <nicolas.pitre@linaro.org>,
Michal Hocko <mhocko@suse.com>,
Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>,
Mateusz Guzik <mguzik@redhat.com>,
LKML <linux-kernel@vger.kernel.org>,
Pavel Emelyanov <xemul@virtuozzo.com>,
Konstantin Khorenko <khorenko@virtuozzo.com>
Subject: Re: task_is_descendant() cleanup
Date: Mon, 30 Jan 2017 14:49:48 +0100 [thread overview]
Message-ID: <20170130134947.GA24718@redhat.com> (raw)
In-Reply-To: <CAGXu5jKb3+pBgF9Cd-+Ay8iJZovckJBYQrUPq-7iTRT-BpanxQ@mail.gmail.com>
On 01/25, Kees Cook wrote:
>
> On Mon, Jan 23, 2017 at 4:52 AM, Oleg Nesterov <oleg@redhat.com> wrote:
> > On 01/23, Oleg Nesterov wrote:
> >>
> >> Btw task_is_descendant() looks wrong at first glance.
> >
> > No, I missed the 2nd ->group_leader dereference. Still this function looks
> > overcomplicated and the usage of thread_group_leader/group_leader just add
> > the unnecessary confusion. It can be simplified a little bit:
> >
> > static int task_is_descendant(struct task_struct *parent,
> > struct task_struct *child)
> > {
> > int rc = 0;
> > struct task_struct *walker;
> >
> > if (!parent || !child)
> > return 0;
> >
> > rcu_read_lock();
> > for (walker = child; walker->pid; walker = rcu_dereference(walker->real_parent))
> > if (same_thread_group(parent, walker)) {
> > rc = 1;
> > break;
> > }
> > rcu_read_unlock();
> >
> > return rc;
> > }
> >
> > Kees, I can send a patch if you think this very minor cleanup makes any sense.
>
> Err, isn't checking same_thread_group() at every level more expensive
> than what I currently have?
Well, same_thread_group(p1,p2) is just
p1->signal == p2->signal
yes this is a bit more expensive than
walker == parent
we currently have, yes. But this eliminates
if (!thread_group_leader(walker))
walker = rcu_dereference(walker->group_leader);
we currently do at every level. And note that "parent" can exec and change its
->group_leader at any time, we probably do not care but this looks confusing.
But please forget, this is really minor.
Oleg.
next prev parent reply other threads:[~2017-01-30 13:58 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-19 16:43 [PATCH] prctl: propagate has_child_subreaper flag to every descendant Pavel Tikhomirov
2017-01-20 18:14 ` Oleg Nesterov
2017-01-22 10:00 ` Pavel Tikhomirov
2017-01-22 10:11 ` Pavel Tikhomirov
2017-01-23 11:55 ` Oleg Nesterov
2017-01-23 12:52 ` task_is_descendant() cleanup Oleg Nesterov
2017-01-25 21:59 ` Kees Cook
2017-01-30 13:49 ` Oleg Nesterov [this message]
2017-01-23 14:30 ` [PATCH] prctl: propagate has_child_subreaper flag to every descendant Pavel Tikhomirov
2017-01-23 16:06 ` Oleg Nesterov
2017-01-23 11:57 ` [PATCH] introduce the walk_process_tree() helper Oleg Nesterov
2017-01-23 12:07 ` Oleg Nesterov
2017-01-24 15:01 ` Pavel Tikhomirov
2017-01-23 16:44 ` setns() && PR_SET_CHILD_SUBREAPER Oleg Nesterov
2017-01-23 18:21 ` Eric W. Biederman
2017-01-24 14:07 ` Oleg Nesterov
2017-01-24 15:24 ` Eric W. Biederman
2017-01-30 18:16 ` Oleg Nesterov
2017-01-30 18:17 ` [PATCH] exit: fix the setns() && PR_SET_CHILD_SUBREAPER interaction Oleg Nesterov
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=20170130134947.GA24718@redhat.com \
--to=oleg@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=gorcunov@openvz.org \
--cc=john.stultz@linaro.org \
--cc=keescook@chromium.org \
--cc=khorenko@virtuozzo.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mguzik@redhat.com \
--cc=mhocko@suse.com \
--cc=mingo@redhat.com \
--cc=nicolas.pitre@linaro.org \
--cc=peterz@infradead.org \
--cc=ptikhomirov@virtuozzo.com \
--cc=skinsbursky@virtuozzo.com \
--cc=tglx@linutronix.de \
--cc=xemul@virtuozzo.com \
/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.