From: Oleg Nesterov <oleg@tv-sign.ru>
To: Kirill Korotaev <dev@sw.ru>
Cc: Andrew Morton <akpm@osdl.org>, Dave Hansen <haveblue@us.ibm.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] sys_getppid oopses on debug kernel (v2)
Date: Wed, 9 Aug 2006 20:54:41 +0400 [thread overview]
Message-ID: <20060809165441.GA187@oleg> (raw)
In-Reply-To: <44D9D03B.6060907@sw.ru>
On 08/09, Kirill Korotaev wrote:
>
> >Why do we need to use ->group_leader? All threads should have the same
> >->real_parent.
> I'm not sure this is true for old LinuxThreads...
Yes, from the user-space pov it may be not true, but ->group_leader->real_parent
should be equal ->real_parent anyway.
> >Why do we need tasklist_lock? I think rcu_read_lock() is enough.
> >
> >In other words, do you see any problems with this code
> >
> > smlinkage long sys_getppid(void)
> > {
> > int pid;
> >
> > rcu_read_lock();
> > pid = rcu_dereference(current->real_parent)->tgid;
> > rcu_read_unlock();
> >
> > return pid;
> > }
> >
> >? Yes, we may read a stale value for ->real_parent, but the memory
> >can't be freed while we are under rcu_read_lock(). And in this case
> >the returned value is ok because the task could be reparented just
> >after return anyway.
> Your patch doesn't cure the problem.
> rcu_read_lock just disables preemtion and rcu_dereference
> introduces memory barrier. _None_ of this _prevents_
> another CPU from freeing old real_parent in parallel with your dereference.
How so? Note that release_task() doesn't call put_task_struct(), it does
call_rcu(&p->rcu, delayed_put_task_struct) instead. When delayed_put_task_struct()
is called, all CPUs must see the new value of ->real_parent (otherwise
RCU is just broken). If CPU sees the old value of ->real_parent, rcu_read_lock()
protects us from delayed_put_task_struct() on another CPU.
Ok, I think this is the same "classic" pattern as:
old = global_ptr;
global_ptr = new;
call_rcu(..free_old...);
vs
rcu_read_lock();
use(global_ptr);
rcu_read_unlock();
Do you agree?
Oleg.
next prev parent reply other threads:[~2006-08-09 12:31 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-08-09 14:38 [PATCH] sys_getppid oopses on debug kernel (v2) Oleg Nesterov
2006-08-09 12:08 ` Kirill Korotaev
2006-08-09 16:54 ` Oleg Nesterov [this message]
2006-08-09 13:02 ` Kirill Korotaev
2006-08-09 18:24 ` [PATCH] sys_getppid-oopses-on-debug-kernel-v2-simplify Oleg Nesterov
-- strict thread matches above, loose matches on Subject: below --
2006-08-08 15:50 [PATCH] sys_getppid oopses on debug kernel (v2) Kirill Korotaev
2006-08-08 16:09 ` Dave Hansen
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=20060809165441.GA187@oleg \
--to=oleg@tv-sign.ru \
--cc=akpm@osdl.org \
--cc=dev@sw.ru \
--cc=haveblue@us.ibm.com \
--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.