The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] cpuset: rcu_read_lock() to protect task_cs() even we don't dereference to task_cs()'s return value
@ 2008-11-21  8:49 Lai Jiangshan
  2008-11-21 19:05 ` Paul Menage
  0 siblings, 1 reply; 4+ messages in thread
From: Lai Jiangshan @ 2008-11-21  8:49 UTC (permalink / raw)
  To: Andrew Morton, Paul Menage, Linux Kernel Mailing List,
	Linux Containers


task_cs() calls cgroup_subsys_state().

we must use rcu_read_lock() to protect cgroup_subsys_state().

in current_cpuset_is_being_rebound(), we don't dereference to task_cs()'s
return value, but task_cs() accesses css_set, this css_set maybe freed
when task_cs() called.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
diff --git a/kernel/cpuset.c b/kernel/cpuset.c
index 3e00526..e0e087e 100644
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -1141,7 +1136,11 @@ done:
 
 int current_cpuset_is_being_rebound(void)
 {
-	return task_cs(current) == cpuset_being_rebound;
+	struct cpuset *cs;
+	rcu_read_lock();
+	cs = task_cs(current);
+	rcu_read_unlock();
+	return cs == cpuset_being_rebound;
 }
 
 static int update_relax_domain_level(struct cpuset *cs, s64 val)


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

* Re: [PATCH] cpuset: rcu_read_lock() to protect task_cs() even we  don't dereference to task_cs()'s return value
  2008-11-21  8:49 [PATCH] cpuset: rcu_read_lock() to protect task_cs() even we don't dereference to task_cs()'s return value Lai Jiangshan
@ 2008-11-21 19:05 ` Paul Menage
  2008-11-21 19:07   ` Paul Menage
  0 siblings, 1 reply; 4+ messages in thread
From: Paul Menage @ 2008-11-21 19:05 UTC (permalink / raw)
  To: Lai Jiangshan; +Cc: Andrew Morton, Linux Kernel Mailing List, Linux Containers

On Fri, Nov 21, 2008 at 12:49 AM, Lai Jiangshan <laijs@cn.fujitsu.com> wrote:
>
> task_cs() calls cgroup_subsys_state().

You man "calls task_subsys_state()"

>
> we must use rcu_read_lock() to protect cgroup_subsys_state().
>
> in current_cpuset_is_being_rebound(), we don't dereference to task_cs()'s
> return value, but task_cs() accesses css_set, this css_set maybe freed
> when task_cs() called.

Wouldn't this be fixed by your patch that adds an rcu_read_lock() to
task_subsys_state() ?

Paul

>
> Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
> ---
> diff --git a/kernel/cpuset.c b/kernel/cpuset.c
> index 3e00526..e0e087e 100644
> --- a/kernel/cpuset.c
> +++ b/kernel/cpuset.c
> @@ -1141,7 +1136,11 @@ done:
>
>  int current_cpuset_is_being_rebound(void)
>  {
> -       return task_cs(current) == cpuset_being_rebound;
> +       struct cpuset *cs;
> +       rcu_read_lock();
> +       cs = task_cs(current);
> +       rcu_read_unlock();
> +       return cs == cpuset_being_rebound;
>  }
>
>  static int update_relax_domain_level(struct cpuset *cs, s64 val)
>
>

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

* Re: [PATCH] cpuset: rcu_read_lock() to protect task_cs() even we  don't dereference to task_cs()'s return value
  2008-11-21 19:05 ` Paul Menage
@ 2008-11-21 19:07   ` Paul Menage
  2008-11-22  3:01     ` Lai Jiangshan
  0 siblings, 1 reply; 4+ messages in thread
From: Paul Menage @ 2008-11-21 19:07 UTC (permalink / raw)
  To: Lai Jiangshan; +Cc: Andrew Morton, Linux Kernel Mailing List, Linux Containers

On Fri, Nov 21, 2008 at 11:05 AM, Paul Menage <menage@google.com> wrote:
>
> Wouldn't this be fixed by your patch that adds an rcu_read_lock() to
> task_subsys_state() ?
>

Sorry, your other patch actually adds the rcu_read_lock() to
task_cgroup(). But adding an rcu_read_lock() to task_subsys_state()
would also help here.

Paul

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

* Re: [PATCH] cpuset: rcu_read_lock() to protect task_cs() even we don't dereference to task_cs()'s return value
  2008-11-21 19:07   ` Paul Menage
@ 2008-11-22  3:01     ` Lai Jiangshan
  0 siblings, 0 replies; 4+ messages in thread
From: Lai Jiangshan @ 2008-11-22  3:01 UTC (permalink / raw)
  To: Paul Menage; +Cc: Andrew Morton, Linux Kernel Mailing List, Linux Containers

Paul Menage wrote:
> On Fri, Nov 21, 2008 at 11:05 AM, Paul Menage <menage@google.com> wrote:
>> Wouldn't this be fixed by your patch that adds an rcu_read_lock() to
>> task_subsys_state() ?
>>
> 
> Sorry, your other patch actually adds the rcu_read_lock() to
> task_cgroup(). But adding an rcu_read_lock() to task_subsys_state()
> would also help here.

Adding an rcu_read_lock() to task_subsys_state() also help here.
But task_subsys_state() is used in fast path.

If we add an implicit rcu_read_lock() in task_subsys_state(),
we still need rcu_read_lock()/task_lock() for using it,
so it's redundant rcu_read_lock(), and slower the fast path a little.

Lai.


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

end of thread, other threads:[~2008-11-22  3:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-21  8:49 [PATCH] cpuset: rcu_read_lock() to protect task_cs() even we don't dereference to task_cs()'s return value Lai Jiangshan
2008-11-21 19:05 ` Paul Menage
2008-11-21 19:07   ` Paul Menage
2008-11-22  3:01     ` Lai Jiangshan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox