From: Li Zefan <lizf@cn.fujitsu.com>
To: Bharata B Rao <bharata.rao@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Paul Menage <menage@google.com>,
Andrew Morton <akpm@linux-foundation.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] sched: fix another race when reading /proc/sched_debug
Date: Sat, 13 Dec 2008 16:22:24 +0800 [thread overview]
Message-ID: <494370C0.4050005@cn.fujitsu.com> (raw)
In-Reply-To: <344eb09a0812120338h29e1088pac7f9a22e37bf609@mail.gmail.com>
Bharata B Rao wrote:
> On Fri, Dec 12, 2008 at 3:23 PM, Li Zefan <lizf@cn.fujitsu.com> wrote:
>> kernel/sched_debug.c | 10 ++++++++--
>> 1 files changed, 8 insertions(+), 2 deletions(-)
>>
>> diff --git a/kernel/sched_debug.c b/kernel/sched_debug.c
>> index 26ed8e3..01abf5b 100644
>> --- a/kernel/sched_debug.c
>> +++ b/kernel/sched_debug.c
>> @@ -127,8 +127,11 @@ void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
>> if (tg)
>> cgroup = tg->css.cgroup;
>>
>> - if (cgroup)
>> + if (cgroup) {
>> + cgroup_lock();
>> cgroup_path(cgroup, path, sizeof(path));
>> + cgroup_unlock();
>> + }
>>
>> SEQ_printf(m, "\ncfs_rq[%d]:%s\n", cpu, path);
>> #else
>> @@ -181,8 +184,11 @@ void print_rt_rq(struct seq_file *m, int cpu, struct rt_rq *rt_rq)
>> if (tg)
>> cgroup = tg->css.cgroup;
>>
>> - if (cgroup)
>> + if (cgroup) {
>> + cgroup_lock();
>> cgroup_path(cgroup, path, sizeof(path));
>> + cgroup_unlock();
>> + }
>>
>> SEQ_printf(m, "\nrt_rq[%d]:%s\n", cpu, path);
>> #else
>
> The comment in cgroup_path() routine says that it needs to be called
> with cgroup_mutex held. With the above fix, print_task() in
> sched_debug.c remains the last caller of cgroup_path() which calls it
> without holding cgroup_mutex. Does this also need a fix ?
>
You mean:
print_task(struct seq_file *m, struct rq *rq, struct task_struct *p)
{
...
cgroup_path(task_group(p)->css.cgroup, path, sizeof(path));
...
}
Hmm...Normally we have to take task_lock() or rcu_read_lock() to retrieve
the cgroup from the task, and as long as we hold either lock, we don't need
to take cgroup_lock().
I noticed neither task_lock() nor rcu is held before calling cgroup_path,
so I wrote a test program to see if I can trigger a but here, but it didn't
happen. I'll dig more.
prev parent reply other threads:[~2008-12-13 8:23 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-12 9:53 [PATCH] sched: fix another race when reading /proc/sched_debug Li Zefan
2008-12-12 10:00 ` Ingo Molnar
2008-12-14 2:54 ` Li Zefan
2008-12-14 12:48 ` Peter Zijlstra
2008-12-15 1:25 ` Li Zefan
2008-12-15 8:13 ` Peter Zijlstra
2008-12-15 9:51 ` Li Zefan
2008-12-15 10:43 ` Peter Zijlstra
2008-12-15 11:08 ` KAMEZAWA Hiroyuki
2008-12-16 5:48 ` Li Zefan
2008-12-16 6:59 ` Li Zefan
2008-12-16 9:41 ` Paul Menage
2008-12-16 12:42 ` Paul Menage
2008-12-16 12:55 ` Li Zefan
2008-12-16 18:35 ` Paul Menage
[not found] ` <6599ad830812141347k5d7e7e08vfc17855ea0ac981c@mail.gmail.com>
2008-12-15 1:39 ` Li Zefan
2008-12-15 1:50 ` KAMEZAWA Hiroyuki
2008-12-15 2:11 ` Li Zefan
2008-12-16 9:23 ` Paul Menage
2008-12-16 9:39 ` Li Zefan
2008-12-19 4:37 ` Balbir Singh
2008-12-19 14:06 ` Paul Menage
2008-12-16 8:01 ` Li Zefan
2008-12-16 12:23 ` Ingo Molnar
2008-12-12 11:38 ` Bharata B Rao
2008-12-13 8:22 ` Li Zefan [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=494370C0.4050005@cn.fujitsu.com \
--to=lizf@cn.fujitsu.com \
--cc=a.p.zijlstra@chello.nl \
--cc=akpm@linux-foundation.org \
--cc=bharata.rao@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=menage@google.com \
--cc=mingo@elte.hu \
/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