All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH tip/core/urgent] rcu: protect fork-time cgroup access
@ 2010-03-29 21:15 Paul E. McKenney
  2010-03-29 21:19 ` Peter Zijlstra
  2010-03-29 22:43 ` Paul Menage
  0 siblings, 2 replies; 17+ messages in thread
From: Paul E. McKenney @ 2010-03-29 21:15 UTC (permalink / raw)
  To: linux-kernel
  Cc: mingo, laijs, dipankar, akpm, mathieu.desnoyers, josh, dvhltc,
	niv, tglx, peterz, rostedt, Valdis.Kletnieks, dhowells,
	eric.dumazet, abogani

Add an rcu_read_lock() / rcu_read_unlock() pair to protect a fork-time
cgroup access.  This seems likely to be a false positive.

Located by: Alessio Igor Bogani <abogani@texware.it>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---

 sched.c |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/sched.c b/kernel/sched.c
index 9ab3cd7..d4bb5e0 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -2621,7 +2621,9 @@ void sched_fork(struct task_struct *p, int clone_flags)
 	if (p->sched_class->task_fork)
 		p->sched_class->task_fork(p);
 
+	rcu_read_lock();
 	set_task_cpu(p, cpu);
+	rcu_read_unlock();
 
 #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
 	if (likely(sched_info_on()))

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH tip/core/urgent] rcu: protect fork-time cgroup access
  2010-03-29 21:15 [PATCH tip/core/urgent] rcu: protect fork-time cgroup access Paul E. McKenney
@ 2010-03-29 21:19 ` Peter Zijlstra
  2010-03-29 21:26   ` Peter Zijlstra
  2010-03-29 21:29   ` Paul E. McKenney
  2010-03-29 22:43 ` Paul Menage
  1 sibling, 2 replies; 17+ messages in thread
From: Peter Zijlstra @ 2010-03-29 21:19 UTC (permalink / raw)
  To: paulmck
  Cc: linux-kernel, mingo, laijs, dipankar, akpm, mathieu.desnoyers,
	josh, dvhltc, niv, tglx, rostedt, Valdis.Kletnieks, dhowells,
	eric.dumazet, abogani

On Mon, 2010-03-29 at 14:15 -0700, Paul E. McKenney wrote:
> Add an rcu_read_lock() / rcu_read_unlock() pair to protect a fork-time
> cgroup access.  This seems likely to be a false positive.
> 
> Located by: Alessio Igor Bogani <abogani@texware.it>
> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> ---
> 
>  sched.c |    2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/kernel/sched.c b/kernel/sched.c
> index 9ab3cd7..d4bb5e0 100644
> --- a/kernel/sched.c
> +++ b/kernel/sched.c
> @@ -2621,7 +2621,9 @@ void sched_fork(struct task_struct *p, int clone_flags)
>  	if (p->sched_class->task_fork)
>  		p->sched_class->task_fork(p);
>  
> +	rcu_read_lock();
>  	set_task_cpu(p, cpu);
> +	rcu_read_unlock();
>  
>  #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
>  	if (likely(sched_info_on()))

What got accessed? This patch just looks wrong.


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH tip/core/urgent] rcu: protect fork-time cgroup access
  2010-03-29 21:19 ` Peter Zijlstra
@ 2010-03-29 21:26   ` Peter Zijlstra
  2010-03-29 22:24     ` Paul E. McKenney
  2010-03-29 21:29   ` Paul E. McKenney
  1 sibling, 1 reply; 17+ messages in thread
From: Peter Zijlstra @ 2010-03-29 21:26 UTC (permalink / raw)
  To: paulmck
  Cc: linux-kernel, mingo, laijs, dipankar, akpm, mathieu.desnoyers,
	josh, dvhltc, niv, tglx, rostedt, Valdis.Kletnieks, dhowells,
	eric.dumazet, abogani

On Mon, 2010-03-29 at 23:19 +0200, Peter Zijlstra wrote:
> On Mon, 2010-03-29 at 14:15 -0700, Paul E. McKenney wrote:
> > Add an rcu_read_lock() / rcu_read_unlock() pair to protect a fork-time
> > cgroup access.  This seems likely to be a false positive.
> > 
> > Located by: Alessio Igor Bogani <abogani@texware.it>
> > Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> > ---
> > 
> >  sched.c |    2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/kernel/sched.c b/kernel/sched.c
> > index 9ab3cd7..d4bb5e0 100644
> > --- a/kernel/sched.c
> > +++ b/kernel/sched.c
> > @@ -2621,7 +2621,9 @@ void sched_fork(struct task_struct *p, int clone_flags)
> >  	if (p->sched_class->task_fork)
> >  		p->sched_class->task_fork(p);
> >  
> > +	rcu_read_lock();
> >  	set_task_cpu(p, cpu);
> > +	rcu_read_unlock();
> >  
> >  #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
> >  	if (likely(sched_info_on()))
> 
> What got accessed? This patch just looks wrong.

So the only cgroup thing I can find is set_task_rq()'s task_group()
usage, which does indeed look like it wants RCU, but then, why would
only the sched_fork() usage of set_task_cpu() need this.

If it's needed (possible) then set_task_rq() needs it unconditionally.

That said, the whole task_group stuff is tied to the cgroup muck, so it
shouldn't be possible for the task_group to disappear on us, but then, I
always sorta glaze over when I get near the cgroup core.


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH tip/core/urgent] rcu: protect fork-time cgroup access
  2010-03-29 21:19 ` Peter Zijlstra
  2010-03-29 21:26   ` Peter Zijlstra
@ 2010-03-29 21:29   ` Paul E. McKenney
  2010-03-29 21:34     ` Paul E. McKenney
  1 sibling, 1 reply; 17+ messages in thread
From: Paul E. McKenney @ 2010-03-29 21:29 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: linux-kernel, mingo, laijs, dipankar, akpm, mathieu.desnoyers,
	josh, dvhltc, niv, tglx, rostedt, Valdis.Kletnieks, dhowells,
	eric.dumazet, abogani

On Mon, Mar 29, 2010 at 11:19:23PM +0200, Peter Zijlstra wrote:
> On Mon, 2010-03-29 at 14:15 -0700, Paul E. McKenney wrote:
> > Add an rcu_read_lock() / rcu_read_unlock() pair to protect a fork-time
> > cgroup access.  This seems likely to be a false positive.
> > 
> > Located by: Alessio Igor Bogani <abogani@texware.it>
> > Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> > ---
> > 
> >  sched.c |    2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/kernel/sched.c b/kernel/sched.c
> > index 9ab3cd7..d4bb5e0 100644
> > --- a/kernel/sched.c
> > +++ b/kernel/sched.c
> > @@ -2621,7 +2621,9 @@ void sched_fork(struct task_struct *p, int clone_flags)
> >  	if (p->sched_class->task_fork)
> >  		p->sched_class->task_fork(p);
> >  
> > +	rcu_read_lock();
> >  	set_task_cpu(p, cpu);
> > +	rcu_read_unlock();
> >  
> >  #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
> >  	if (likely(sched_info_on()))
> 
> What got accessed? This patch just looks wrong.

It might well be wrong.  The lockdep RCU splat triggered in
task_subsys_state():

static inline struct cgroup_subsys_state *task_subsys_state(
	struct task_struct *task, int subsys_id)
{
	return rcu_dereference_check(task->cgroups->subsys[subsys_id],
				     rcu_read_lock_held() ||
				     cgroup_lock_is_held());
}

My thought was that this access was safe due to the fact that we were
in the middle of creating a task, so that no other CPU could access it.
But I am not certain of this, given the fact that this is digging through
cgroup state.

The lockdep splat is here: http://pastebin.ubuntu.com/406131/

Suggestions?

							Thanx, Paul

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH tip/core/urgent] rcu: protect fork-time cgroup access
  2010-03-29 21:29   ` Paul E. McKenney
@ 2010-03-29 21:34     ` Paul E. McKenney
  2010-03-29 21:42       ` Peter Zijlstra
  0 siblings, 1 reply; 17+ messages in thread
From: Paul E. McKenney @ 2010-03-29 21:34 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: linux-kernel, mingo, laijs, dipankar, akpm, mathieu.desnoyers,
	josh, dvhltc, niv, tglx, rostedt, Valdis.Kletnieks, dhowells,
	eric.dumazet, abogani

On Mon, Mar 29, 2010 at 02:29:32PM -0700, Paul E. McKenney wrote:
> On Mon, Mar 29, 2010 at 11:19:23PM +0200, Peter Zijlstra wrote:
> > On Mon, 2010-03-29 at 14:15 -0700, Paul E. McKenney wrote:
> > > Add an rcu_read_lock() / rcu_read_unlock() pair to protect a fork-time
> > > cgroup access.  This seems likely to be a false positive.
> > > 
> > > Located by: Alessio Igor Bogani <abogani@texware.it>
> > > Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> > > ---
> > > 
> > >  sched.c |    2 ++
> > >  1 file changed, 2 insertions(+)
> > > 
> > > diff --git a/kernel/sched.c b/kernel/sched.c
> > > index 9ab3cd7..d4bb5e0 100644
> > > --- a/kernel/sched.c
> > > +++ b/kernel/sched.c
> > > @@ -2621,7 +2621,9 @@ void sched_fork(struct task_struct *p, int clone_flags)
> > >  	if (p->sched_class->task_fork)
> > >  		p->sched_class->task_fork(p);
> > >  
> > > +	rcu_read_lock();
> > >  	set_task_cpu(p, cpu);
> > > +	rcu_read_unlock();
> > >  
> > >  #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
> > >  	if (likely(sched_info_on()))
> > 
> > What got accessed? This patch just looks wrong.
> 
> It might well be wrong.  The lockdep RCU splat triggered in
> task_subsys_state():
> 
> static inline struct cgroup_subsys_state *task_subsys_state(
> 	struct task_struct *task, int subsys_id)
> {
> 	return rcu_dereference_check(task->cgroups->subsys[subsys_id],
> 				     rcu_read_lock_held() ||
> 				     cgroup_lock_is_held());
> }
> 
> My thought was that this access was safe due to the fact that we were
> in the middle of creating a task, so that no other CPU could access it.
> But I am not certain of this, given the fact that this is digging through
> cgroup state.
> 
> The lockdep splat is here: http://pastebin.ubuntu.com/406131/
> 
> Suggestions?

And it appears that my patch is at best insufficient:
http://paste.ubuntu.com/406189/

Left to myself, I would wrap copy_process() with rcu_read_lock(),
but I would rather hear your thoughts before doing too much more
semi-random hacking.  ;-)

						Thanx, Paul

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH tip/core/urgent] rcu: protect fork-time cgroup access
  2010-03-29 21:34     ` Paul E. McKenney
@ 2010-03-29 21:42       ` Peter Zijlstra
  2010-03-29 21:51         ` Paul E. McKenney
  0 siblings, 1 reply; 17+ messages in thread
From: Peter Zijlstra @ 2010-03-29 21:42 UTC (permalink / raw)
  To: paulmck
  Cc: linux-kernel, mingo, laijs, dipankar, akpm, mathieu.desnoyers,
	josh, dvhltc, niv, tglx, rostedt, Valdis.Kletnieks, dhowells,
	eric.dumazet, abogani

On Mon, 2010-03-29 at 14:34 -0700, Paul E. McKenney wrote:

> And it appears that my patch is at best insufficient:
> http://paste.ubuntu.com/406189/
> 
> Left to myself, I would wrap copy_process() with rcu_read_lock(),
> but I would rather hear your thoughts before doing too much more
> semi-random hacking.  ;-)

Well, I don't think you can get away with that, copy_process() wants to
sleep on quite a few places ;-) Also, locks should be taken at the
smallest possible scope, unless we want to go back to BKL style
locking :-)

As to that freezer splat, you'd have to chase down the cgroup folks, I'm
fully ignorant on that.

For the set_task_rq() one, I'm afraid someone (which again I'm afraid
will be me) will have to look into how the task_group muck ties into the
cgroup muck as I think the original authors of that ran off :/




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH tip/core/urgent] rcu: protect fork-time cgroup access
  2010-03-29 21:42       ` Peter Zijlstra
@ 2010-03-29 21:51         ` Paul E. McKenney
  0 siblings, 0 replies; 17+ messages in thread
From: Paul E. McKenney @ 2010-03-29 21:51 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: linux-kernel, mingo, laijs, dipankar, akpm, mathieu.desnoyers,
	josh, dvhltc, niv, tglx, rostedt, Valdis.Kletnieks, dhowells,
	eric.dumazet, abogani, menage, lizf

On Mon, Mar 29, 2010 at 11:42:55PM +0200, Peter Zijlstra wrote:
> On Mon, 2010-03-29 at 14:34 -0700, Paul E. McKenney wrote:
> 
> > And it appears that my patch is at best insufficient:
> > http://paste.ubuntu.com/406189/
> > 
> > Left to myself, I would wrap copy_process() with rcu_read_lock(),
> > but I would rather hear your thoughts before doing too much more
> > semi-random hacking.  ;-)
> 
> Well, I don't think you can get away with that, copy_process() wants to
> sleep on quite a few places ;-) Also, locks should be taken at the
> smallest possible scope, unless we want to go back to BKL style
> locking :-)

No argument here!  ;-)

> As to that freezer splat, you'd have to chase down the cgroup folks, I'm
> fully ignorant on that.

K, adding them to CC.  The two splats are:

	http://pastebin.ubuntu.com/406131/
	http://paste.ubuntu.com/406189/

Some additional RCU protection is required, or perhaps some suppression
of false positives.  Thoughts?

> For the set_task_rq() one, I'm afraid someone (which again I'm afraid
> will be me) will have to look into how the task_group muck ties into the
> cgroup muck as I think the original authors of that ran off :/

Sigh!

							Thanx, Paul

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH tip/core/urgent] rcu: protect fork-time cgroup access
  2010-03-29 21:26   ` Peter Zijlstra
@ 2010-03-29 22:24     ` Paul E. McKenney
  0 siblings, 0 replies; 17+ messages in thread
From: Paul E. McKenney @ 2010-03-29 22:24 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: linux-kernel, mingo, laijs, dipankar, akpm, mathieu.desnoyers,
	josh, dvhltc, niv, tglx, rostedt, Valdis.Kletnieks, dhowells,
	eric.dumazet, abogani

On Mon, Mar 29, 2010 at 11:26:04PM +0200, Peter Zijlstra wrote:
> On Mon, 2010-03-29 at 23:19 +0200, Peter Zijlstra wrote:
> > On Mon, 2010-03-29 at 14:15 -0700, Paul E. McKenney wrote:
> > > Add an rcu_read_lock() / rcu_read_unlock() pair to protect a fork-time
> > > cgroup access.  This seems likely to be a false positive.
> > > 
> > > Located by: Alessio Igor Bogani <abogani@texware.it>
> > > Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> > > ---
> > > 
> > >  sched.c |    2 ++
> > >  1 file changed, 2 insertions(+)
> > > 
> > > diff --git a/kernel/sched.c b/kernel/sched.c
> > > index 9ab3cd7..d4bb5e0 100644
> > > --- a/kernel/sched.c
> > > +++ b/kernel/sched.c
> > > @@ -2621,7 +2621,9 @@ void sched_fork(struct task_struct *p, int clone_flags)
> > >  	if (p->sched_class->task_fork)
> > >  		p->sched_class->task_fork(p);
> > >  
> > > +	rcu_read_lock();
> > >  	set_task_cpu(p, cpu);
> > > +	rcu_read_unlock();
> > >  
> > >  #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
> > >  	if (likely(sched_info_on()))
> > 
> > What got accessed? This patch just looks wrong.
> 
> So the only cgroup thing I can find is set_task_rq()'s task_group()
> usage, which does indeed look like it wants RCU, but then, why would
> only the sched_fork() usage of set_task_cpu() need this.
> 
> If it's needed (possible) then set_task_rq() needs it unconditionally.

Easy patch, if appropriate!

> That said, the whole task_group stuff is tied to the cgroup muck, so it
> shouldn't be possible for the task_group to disappear on us, but then, I
> always sorta glaze over when I get near the cgroup core.

Hey, if it was easy, I might have gotten it right on the first try!  ;-)

							Thanx, Paul

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH tip/core/urgent] rcu: protect fork-time cgroup access
  2010-03-29 21:15 [PATCH tip/core/urgent] rcu: protect fork-time cgroup access Paul E. McKenney
  2010-03-29 21:19 ` Peter Zijlstra
@ 2010-03-29 22:43 ` Paul Menage
  2010-03-29 23:05   ` Paul E. McKenney
  2010-03-30  8:50   ` Peter Zijlstra
  1 sibling, 2 replies; 17+ messages in thread
From: Paul Menage @ 2010-03-29 22:43 UTC (permalink / raw)
  To: paulmck
  Cc: linux-kernel, mingo, laijs, dipankar, akpm, mathieu.desnoyers,
	josh, dvhltc, niv, tglx, peterz, rostedt, Valdis.Kletnieks,
	dhowells, eric.dumazet, abogani

On Mon, Mar 29, 2010 at 2:15 PM, Paul E. McKenney
<paulmck@linux.vnet.ibm.com> wrote:
> Add an rcu_read_lock() / rcu_read_unlock() pair to protect a fork-time
> cgroup access.  This seems likely to be a false positive.
>
> Located by: Alessio Igor Bogani <abogani@texware.it>
> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> ---
>
>  sched.c |    2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/kernel/sched.c b/kernel/sched.c
> index 9ab3cd7..d4bb5e0 100644
> --- a/kernel/sched.c
> +++ b/kernel/sched.c
> @@ -2621,7 +2621,9 @@ void sched_fork(struct task_struct *p, int clone_flags)
>        if (p->sched_class->task_fork)
>                p->sched_class->task_fork(p);
>
> +       rcu_read_lock();
>        set_task_cpu(p, cpu);
> +       rcu_read_unlock();

I think you're right that this is a false positive - it would only be
a problem if it were possible for the task to be moved to a different
cgroup, and I think that shouldn't be the case at this point in the
fork path since the new process isn't visible on the tasklist yet,
right?

Paul

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH tip/core/urgent] rcu: protect fork-time cgroup access
  2010-03-29 22:43 ` Paul Menage
@ 2010-03-29 23:05   ` Paul E. McKenney
  2010-03-30 18:57     ` Paul Menage
  2010-03-30  8:50   ` Peter Zijlstra
  1 sibling, 1 reply; 17+ messages in thread
From: Paul E. McKenney @ 2010-03-29 23:05 UTC (permalink / raw)
  To: Paul Menage
  Cc: linux-kernel, mingo, laijs, dipankar, akpm, mathieu.desnoyers,
	josh, dvhltc, niv, tglx, peterz, rostedt, Valdis.Kletnieks,
	dhowells, eric.dumazet, abogani

On Mon, Mar 29, 2010 at 03:43:43PM -0700, Paul Menage wrote:
> On Mon, Mar 29, 2010 at 2:15 PM, Paul E. McKenney
> <paulmck@linux.vnet.ibm.com> wrote:
> > Add an rcu_read_lock() / rcu_read_unlock() pair to protect a fork-time
> > cgroup access.  This seems likely to be a false positive.
> >
> > Located by: Alessio Igor Bogani <abogani@texware.it>
> > Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> > ---
> >
> >  sched.c |    2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/kernel/sched.c b/kernel/sched.c
> > index 9ab3cd7..d4bb5e0 100644
> > --- a/kernel/sched.c
> > +++ b/kernel/sched.c
> > @@ -2621,7 +2621,9 @@ void sched_fork(struct task_struct *p, int clone_flags)
> >        if (p->sched_class->task_fork)
> >                p->sched_class->task_fork(p);
> >
> > +       rcu_read_lock();
> >        set_task_cpu(p, cpu);
> > +       rcu_read_unlock();
> 
> I think you're right that this is a false positive - it would only be
> a problem if it were possible for the task to be moved to a different
> cgroup, and I think that shouldn't be the case at this point in the
> fork path since the new process isn't visible on the tasklist yet,
> right?

You are correct, it is not yet on the tasklist.

So I have to ask...  What happens if the underlying cgroup is removed
between the time sched_fork() calls set_task_cpu() and the time that
copy_process() puts the new task on the tasklist?  Or is the initial
cgroup guaranteed to be immortal?

							Thanx, Paul

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH tip/core/urgent] rcu: protect fork-time cgroup access
  2010-03-29 22:43 ` Paul Menage
  2010-03-29 23:05   ` Paul E. McKenney
@ 2010-03-30  8:50   ` Peter Zijlstra
  2010-03-30 17:28     ` Paul E. McKenney
  1 sibling, 1 reply; 17+ messages in thread
From: Peter Zijlstra @ 2010-03-30  8:50 UTC (permalink / raw)
  To: Paul Menage
  Cc: paulmck, linux-kernel, mingo, laijs, dipankar, akpm,
	mathieu.desnoyers, josh, dvhltc, niv, tglx, rostedt,
	Valdis.Kletnieks, dhowells, eric.dumazet, abogani

On Mon, 2010-03-29 at 15:43 -0700, Paul Menage wrote:
> On Mon, Mar 29, 2010 at 2:15 PM, Paul E. McKenney
> <paulmck@linux.vnet.ibm.com> wrote:
> > Add an rcu_read_lock() / rcu_read_unlock() pair to protect a fork-time
> > cgroup access.  This seems likely to be a false positive.
> >
> > Located by: Alessio Igor Bogani <abogani@texware.it>
> > Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> > ---
> >
> >  sched.c |    2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/kernel/sched.c b/kernel/sched.c
> > index 9ab3cd7..d4bb5e0 100644
> > --- a/kernel/sched.c
> > +++ b/kernel/sched.c
> > @@ -2621,7 +2621,9 @@ void sched_fork(struct task_struct *p, int clone_flags)
> >        if (p->sched_class->task_fork)
> >                p->sched_class->task_fork(p);
> >
> > +       rcu_read_lock();
> >        set_task_cpu(p, cpu);
> > +       rcu_read_unlock();
> 
> I think you're right that this is a false positive - it would only be
> a problem if it were possible for the task to be moved to a different
> cgroup, and I think that shouldn't be the case at this point in the
> fork path since the new process isn't visible on the tasklist yet,
> right?

Well the thing is, this fork time invocation of
set_task_cpu()->set_task_rq() is in no way special, there's multiple
places like that.



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH tip/core/urgent] rcu: protect fork-time cgroup access
  2010-03-30  8:50   ` Peter Zijlstra
@ 2010-03-30 17:28     ` Paul E. McKenney
  0 siblings, 0 replies; 17+ messages in thread
From: Paul E. McKenney @ 2010-03-30 17:28 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Paul Menage, linux-kernel, mingo, laijs, dipankar, akpm,
	mathieu.desnoyers, josh, dvhltc, niv, tglx, rostedt,
	Valdis.Kletnieks, dhowells, eric.dumazet, abogani

On Tue, Mar 30, 2010 at 10:50:34AM +0200, Peter Zijlstra wrote:
> On Mon, 2010-03-29 at 15:43 -0700, Paul Menage wrote:
> > On Mon, Mar 29, 2010 at 2:15 PM, Paul E. McKenney
> > <paulmck@linux.vnet.ibm.com> wrote:
> > > Add an rcu_read_lock() / rcu_read_unlock() pair to protect a fork-time
> > > cgroup access.  This seems likely to be a false positive.
> > >
> > > Located by: Alessio Igor Bogani <abogani@texware.it>
> > > Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> > > ---
> > >
> > >  sched.c |    2 ++
> > >  1 file changed, 2 insertions(+)
> > >
> > > diff --git a/kernel/sched.c b/kernel/sched.c
> > > index 9ab3cd7..d4bb5e0 100644
> > > --- a/kernel/sched.c
> > > +++ b/kernel/sched.c
> > > @@ -2621,7 +2621,9 @@ void sched_fork(struct task_struct *p, int clone_flags)
> > >        if (p->sched_class->task_fork)
> > >                p->sched_class->task_fork(p);
> > >
> > > +       rcu_read_lock();
> > >        set_task_cpu(p, cpu);
> > > +       rcu_read_unlock();
> > 
> > I think you're right that this is a false positive - it would only be
> > a problem if it were possible for the task to be moved to a different
> > cgroup, and I think that shouldn't be the case at this point in the
> > fork path since the new process isn't visible on the tasklist yet,
> > right?
> 
> Well the thing is, this fork time invocation of
> set_task_cpu()->set_task_rq() is in no way special, there's multiple
> places like that.

Certainly the lack of clarity about why this access is safe indicates
that recording some of the locking design in rcu_dereferenceI() would
be quite helpful.  ;-)

							Thanx, Paul

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH tip/core/urgent] rcu: protect fork-time cgroup access
  2010-03-29 23:05   ` Paul E. McKenney
@ 2010-03-30 18:57     ` Paul Menage
  0 siblings, 0 replies; 17+ messages in thread
From: Paul Menage @ 2010-03-30 18:57 UTC (permalink / raw)
  To: paulmck
  Cc: linux-kernel, mingo, laijs, dipankar, akpm, mathieu.desnoyers,
	josh, dvhltc, niv, tglx, peterz, rostedt, Valdis.Kletnieks,
	dhowells, eric.dumazet, abogani

On Mon, Mar 29, 2010 at 4:05 PM, Paul E. McKenney
<paulmck@linux.vnet.ibm.com> wrote:
>
> So I have to ask...  What happens if the underlying cgroup is removed
> between the time sched_fork() calls set_task_cpu() and the time that
> copy_process() puts the new task on the tasklist?  Or is the initial
> cgroup guaranteed to be immortal?
>

As long as your code is running after cgroup_fork() - which
sched_fork() is - then it should be OK. cgroup_fork() takes a
reference count on the parent's cgroups set, which implicitly keeps
all of those cgroups alive until the task either exits or is moved.
But it can't be moved until it's visible on the task list.

Possibly dup_task_struct should do tsk->cgroups = NULL so that
(currently) unsafe references to the un-refcounted tsk->cgroups before
cgroup_fork() get caught.

Paul

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH tip/core/urgent] rcu: protect fork-time cgroup access
       [not found] ` <20100330093204.GP3345-52DBMbEzqgQ/wnmkkaCWp/UQ3DHhIser@public.gmane.org>
@ 2010-03-30 17:26   ` Paul E. McKenney
  0 siblings, 0 replies; 17+ messages in thread
From: Paul E. McKenney @ 2010-03-30 17:26 UTC (permalink / raw)
  To: Matt Helsley
  Cc: menage-hpIqsD4AKlfQT0dZR+AlfA, dvhltc-r/Jw6+rmf7HQT0dZR+AlfA,
	mathieu.desnoyers-scC8bbJcJLCw5LPnMra/2Q,
	eric.dumazet-Re5JQEeQqe8AvxtiuMwx3w,
	containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	rostedt-nx8X9YLhiw1AfugRpC6u6w, josh-iaAMLnmF4UmaiuxdJuQwMA,
	dhowells-H+wXaHxf7aLQT0dZR+AlfA, niv-r/Jw6+rmf7HQT0dZR+AlfA,
	tglx-hfZtesqFncYOwBW4kG4KsQ, dipankar-xthvdsQ13ZrQT0dZR+AlfA,
	Valdis.Kletnieks-PjAqaU27lzQ, mingo-X9Un+BFzKDI,
	akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b,
	abogani-c2gU+FDvWfqonA0d6jMUrA

On Tue, Mar 30, 2010 at 02:32:04AM -0700, Matt Helsley wrote:
> > On Mon, Mar 29, 2010 at 11:42:55PM +0200, Peter Zijlstra wrote:
> > > On Mon, 2010-03-29 at 14:34 -0700, Paul E. McKenney wrote:
> > >
> > > > And it appears that my patch is at best insufficient:
> > > > http://paste.ubuntu.com/406189/
> > > >
> > > > Left to myself, I would wrap copy_process() with rcu_read_lock(),
> > > > but I would rather hear your thoughts before doing too much more
> > > > semi-random hacking.  ;-)
> > >
> > > Well, I don't think you can get away with that, copy_process() wants to
> > > sleep on quite a few places ;-) Also, locks should be taken at the
> > > smallest possible scope, unless we want to go back to BKL style
> > > locking :-)
> > 
> > No argument here!  ;-)
> > 
> > > As to that freezer splat, you'd have to chase down the cgroup folks, I'm
> > > fully ignorant on that.
> > 
> > K, adding them to CC.  The two splats are:
> > 
> >        http://pastebin.ubuntu.com/406131/
> >         http://paste.ubuntu.com/406189/
> 
> Please feel free to Cc me on cgroup freezer stuff.
> 
> There's a comment in the code explaining why it's not used in freezer_fork():
> 
>        /*
>         * No lock is needed, since the task isn't on tasklist yet,
>         * so it can't be moved to another cgroup, which means the
>         * freezer won't be removed and will be valid during this
>         * function call.
>         */
> 	freezer = task_freezer(task);

Good to know, thank you!

So the cgroup that this task is associated with cannot be deleted in
the meantime?

							Thanx, Paul

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH tip/core/urgent] rcu: protect fork-time cgroup access
  2010-03-30  9:32 Matt Helsley
@ 2010-03-30 17:26 ` Paul E. McKenney
       [not found] ` <20100330093204.GP3345-52DBMbEzqgQ/wnmkkaCWp/UQ3DHhIser@public.gmane.org>
  1 sibling, 0 replies; 17+ messages in thread
From: Paul E. McKenney @ 2010-03-30 17:26 UTC (permalink / raw)
  To: Matt Helsley
  Cc: Peter Zijlstra, linux-kernel, mingo, laijs, dipankar, akpm,
	mathieu.desnoyers, josh, dvhltc, niv, tglx, rostedt,
	Valdis.Kletnieks, dhowells, eric.dumazet, abogani, menage, lizf,
	containers

On Tue, Mar 30, 2010 at 02:32:04AM -0700, Matt Helsley wrote:
> > On Mon, Mar 29, 2010 at 11:42:55PM +0200, Peter Zijlstra wrote:
> > > On Mon, 2010-03-29 at 14:34 -0700, Paul E. McKenney wrote:
> > >
> > > > And it appears that my patch is at best insufficient:
> > > > http://paste.ubuntu.com/406189/
> > > >
> > > > Left to myself, I would wrap copy_process() with rcu_read_lock(),
> > > > but I would rather hear your thoughts before doing too much more
> > > > semi-random hacking.  ;-)
> > >
> > > Well, I don't think you can get away with that, copy_process() wants to
> > > sleep on quite a few places ;-) Also, locks should be taken at the
> > > smallest possible scope, unless we want to go back to BKL style
> > > locking :-)
> > 
> > No argument here!  ;-)
> > 
> > > As to that freezer splat, you'd have to chase down the cgroup folks, I'm
> > > fully ignorant on that.
> > 
> > K, adding them to CC.  The two splats are:
> > 
> >        http://pastebin.ubuntu.com/406131/
> >         http://paste.ubuntu.com/406189/
> 
> Please feel free to Cc me on cgroup freezer stuff.
> 
> There's a comment in the code explaining why it's not used in freezer_fork():
> 
>        /*
>         * No lock is needed, since the task isn't on tasklist yet,
>         * so it can't be moved to another cgroup, which means the
>         * freezer won't be removed and will be valid during this
>         * function call.
>         */
> 	freezer = task_freezer(task);

Good to know, thank you!

So the cgroup that this task is associated with cannot be deleted in
the meantime?

							Thanx, Paul

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH tip/core/urgent] rcu: protect fork-time cgroup access
@ 2010-03-30  9:32 Matt Helsley
  0 siblings, 0 replies; 17+ messages in thread
From: Matt Helsley @ 2010-03-30  9:32 UTC (permalink / raw)
  To: Paul E. McKenney
  Cc: menage-hpIqsD4AKlfQT0dZR+AlfA, dvhltc-r/Jw6+rmf7HQT0dZR+AlfA,
	mathieu.desnoyers-scC8bbJcJLCw5LPnMra/2Q,
	eric.dumazet-Re5JQEeQqe8AvxtiuMwx3w,
	containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	rostedt-nx8X9YLhiw1AfugRpC6u6w, josh-iaAMLnmF4UmaiuxdJuQwMA,
	dhowells-H+wXaHxf7aLQT0dZR+AlfA, niv-r/Jw6+rmf7HQT0dZR+AlfA,
	tglx-hfZtesqFncYOwBW4kG4KsQ, dipankar-xthvdsQ13ZrQT0dZR+AlfA,
	Valdis.Kletnieks-PjAqaU27lzQ, mingo-X9Un+BFzKDI,
	akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b,
	abogani-c2gU+FDvWfqonA0d6jMUrA

> On Mon, Mar 29, 2010 at 11:42:55PM +0200, Peter Zijlstra wrote:
> > On Mon, 2010-03-29 at 14:34 -0700, Paul E. McKenney wrote:
> >
> > > And it appears that my patch is at best insufficient:
> > > http://paste.ubuntu.com/406189/
> > >
> > > Left to myself, I would wrap copy_process() with rcu_read_lock(),
> > > but I would rather hear your thoughts before doing too much more
> > > semi-random hacking.  ;-)
> >
> > Well, I don't think you can get away with that, copy_process() wants to
> > sleep on quite a few places ;-) Also, locks should be taken at the
> > smallest possible scope, unless we want to go back to BKL style
> > locking :-)
> 
> No argument here!  ;-)
> 
> > As to that freezer splat, you'd have to chase down the cgroup folks, I'm
> > fully ignorant on that.
> 
> K, adding them to CC.  The two splats are:
> 
>        http://pastebin.ubuntu.com/406131/
>         http://paste.ubuntu.com/406189/

Please feel free to Cc me on cgroup freezer stuff.

There's a comment in the code explaining why it's not used in freezer_fork():

       /*
        * No lock is needed, since the task isn't on tasklist yet,
        * so it can't be moved to another cgroup, which means the
        * freezer won't be removed and will be valid during this
        * function call.
        */
	freezer = task_freezer(task);

Cheers,
	-Matt Helsley

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH tip/core/urgent] rcu: protect fork-time cgroup access
@ 2010-03-30  9:32 Matt Helsley
  2010-03-30 17:26 ` Paul E. McKenney
       [not found] ` <20100330093204.GP3345-52DBMbEzqgQ/wnmkkaCWp/UQ3DHhIser@public.gmane.org>
  0 siblings, 2 replies; 17+ messages in thread
From: Matt Helsley @ 2010-03-30  9:32 UTC (permalink / raw)
  To: Paul E. McKenney
  Cc: Peter Zijlstra, linux-kernel, mingo, laijs, dipankar, akpm,
	mathieu.desnoyers, josh, dvhltc, niv, tglx, rostedt,
	Valdis.Kletnieks, dhowells, eric.dumazet, abogani, menage, lizf,
	containers

> On Mon, Mar 29, 2010 at 11:42:55PM +0200, Peter Zijlstra wrote:
> > On Mon, 2010-03-29 at 14:34 -0700, Paul E. McKenney wrote:
> >
> > > And it appears that my patch is at best insufficient:
> > > http://paste.ubuntu.com/406189/
> > >
> > > Left to myself, I would wrap copy_process() with rcu_read_lock(),
> > > but I would rather hear your thoughts before doing too much more
> > > semi-random hacking.  ;-)
> >
> > Well, I don't think you can get away with that, copy_process() wants to
> > sleep on quite a few places ;-) Also, locks should be taken at the
> > smallest possible scope, unless we want to go back to BKL style
> > locking :-)
> 
> No argument here!  ;-)
> 
> > As to that freezer splat, you'd have to chase down the cgroup folks, I'm
> > fully ignorant on that.
> 
> K, adding them to CC.  The two splats are:
> 
>        http://pastebin.ubuntu.com/406131/
>         http://paste.ubuntu.com/406189/

Please feel free to Cc me on cgroup freezer stuff.

There's a comment in the code explaining why it's not used in freezer_fork():

       /*
        * No lock is needed, since the task isn't on tasklist yet,
        * so it can't be moved to another cgroup, which means the
        * freezer won't be removed and will be valid during this
        * function call.
        */
	freezer = task_freezer(task);

Cheers,
	-Matt Helsley

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2010-03-30 18:57 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-29 21:15 [PATCH tip/core/urgent] rcu: protect fork-time cgroup access Paul E. McKenney
2010-03-29 21:19 ` Peter Zijlstra
2010-03-29 21:26   ` Peter Zijlstra
2010-03-29 22:24     ` Paul E. McKenney
2010-03-29 21:29   ` Paul E. McKenney
2010-03-29 21:34     ` Paul E. McKenney
2010-03-29 21:42       ` Peter Zijlstra
2010-03-29 21:51         ` Paul E. McKenney
2010-03-29 22:43 ` Paul Menage
2010-03-29 23:05   ` Paul E. McKenney
2010-03-30 18:57     ` Paul Menage
2010-03-30  8:50   ` Peter Zijlstra
2010-03-30 17:28     ` Paul E. McKenney
2010-03-30  9:32 Matt Helsley
2010-03-30 17:26 ` Paul E. McKenney
     [not found] ` <20100330093204.GP3345-52DBMbEzqgQ/wnmkkaCWp/UQ3DHhIser@public.gmane.org>
2010-03-30 17:26   ` Paul E. McKenney
2010-03-30  9:32 Matt Helsley

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.