From: ebiederm@xmission.com (Eric W. Biederman)
To: Oleg Nesterov <oleg@tv-sign.ru>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Pavel Emelyanov <xemul@openvz.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] proc-remove-races-from-proc_id_readdir-factor-out-tgid-increment
Date: Tue, 20 Nov 2007 13:45:08 -0700 [thread overview]
Message-ID: <m1d4u4sl2j.fsf@ebiederm.dsl.xmission.com> (raw)
In-Reply-To: <20071120163457.GA13021@tv-sign.ru> (Oleg Nesterov's message of "Tue, 20 Nov 2007 19:34:57 +0300")
Oleg Nesterov <oleg@tv-sign.ru> writes:
> On 11/19, Eric W. Biederman wrote:
>>
>> So to fix the problem this patch modifies next_tgid() to return
>> both a tgid and the task struct in question.
>>
>> A structure is introduced to return these values because it is
>> slightly cleaner and easier to optimize, and the resulting code
>> is a little shorter.
>
> Nice. Perhaps we can also factor out the incrementing of iter.tgid? Lessens
> the generated code, and (imho) cleanups the source a little bit.
Well the name doesn't imply what the exact sematic is and we
only have one caller, so we might as well. Looking at the
code I don't see any problems.
Acked-by: "Eric W. Biederman" <ebiederm@xmission.com>
> (untested, 2.6.24-rc2-mm1 doesn't boot on my machine)
>
> Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
>
> --- PT/fs/proc/base.c~ 2007-11-20 19:00:05.000000000 +0300
> +++ PT/fs/proc/base.c 2007-11-20 19:06:28.000000000 +0300
> @@ -2378,6 +2378,7 @@ static struct tgid_iter next_tgid(struct
> rcu_read_lock();
> retry:
> iter.task = NULL;
> + iter.tgid++;
> pid = find_ge_pid(iter.tgid, ns);
> if (pid) {
> iter.tgid = pid_nr_ns(pid, ns);
> @@ -2394,10 +2395,8 @@ retry:
> * found doesn't happen to be a thread group leader.
> * As we don't care in the case of readdir.
> */
> - if (!iter.task || !has_group_leader_pid(iter.task)) {
> - iter.tgid += 1;
> + if (!iter.task || !has_group_leader_pid(iter.task))
> goto retry;
> - }
> get_task_struct(iter.task);
> }
> rcu_read_unlock();
> @@ -2434,10 +2433,8 @@ int proc_pid_readdir(struct file * filp,
>
> ns = filp->f_dentry->d_sb->s_fs_info;
> iter.task = NULL;
> - iter.tgid = filp->f_pos - TGID_OFFSET;
> - for (iter = next_tgid(ns, iter);
> - iter.task;
> - iter.tgid += 1, iter = next_tgid(ns, iter)) {
> + iter.tgid = filp->f_pos - TGID_OFFSET - 1;
> + while ((iter = next_tgid(ns, iter)).task) {
> filp->f_pos = iter.tgid + TGID_OFFSET;
> if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
> put_task_struct(iter.task);
prev parent reply other threads:[~2007-11-20 20:46 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-17 18:15 [PATCH] task_pid_nr_ns() breaks proc_pid_readdir() Oleg Nesterov
2007-11-17 20:35 ` Eric W. Biederman
2007-11-18 14:20 ` Oleg Nesterov
2007-11-19 18:15 ` Eric W. Biederman
2007-11-19 18:29 ` Oleg Nesterov
2007-11-19 18:50 ` Eric W. Biederman
2007-11-19 21:44 ` [PATCH] proc: Remove races from proc_id_readdir() Eric W. Biederman
2007-11-20 16:34 ` [PATCH] proc-remove-races-from-proc_id_readdir-factor-out-tgid-increment Oleg Nesterov
2007-11-20 20:45 ` Eric W. Biederman [this message]
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=m1d4u4sl2j.fsf@ebiederm.dsl.xmission.com \
--to=ebiederm@xmission.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=oleg@tv-sign.ru \
--cc=xemul@openvz.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®