All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cpuset: rcu_read_lock() to protect task_cs()
@ 2008-11-21  8:49 Lai Jiangshan
  2008-11-21 18:36 ` Paul Menage
       [not found] ` <49267621.2070706-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
  0 siblings, 2 replies; 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().

it's correct that top_cpuset is never freed, but cgroup_subsys_state()
accesses css_set, this css_set maybe freed when task_cs() called.

we use use rcu_read_lock() to protect it.

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
@@ -363,14 +363,9 @@ void cpuset_update_task_memory_state(void)
 	struct task_struct *tsk = current;
 	struct cpuset *cs;
 
-	if (task_cs(tsk) == &top_cpuset) {
-		/* Don't need rcu for top_cpuset.  It's never freed. */
-		my_cpusets_mem_gen = top_cpuset.mems_generation;
-	} else {
-		rcu_read_lock();
-		my_cpusets_mem_gen = task_cs(tsk)->mems_generation;
-		rcu_read_unlock();
-	}
+	rcu_read_lock();
+	my_cpusets_mem_gen = task_cs(tsk)->mems_generation;
+	rcu_read_unlock();
 
 	if (my_cpusets_mem_gen != tsk->cpuset_mems_generation) {
 		mutex_lock(&callback_mutex);


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

* [PATCH] cpuset: rcu_read_lock() to protect task_cs()
@ 2008-11-21  8:49 Lai Jiangshan
  0 siblings, 0 replies; 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().

it's correct that top_cpuset is never freed, but cgroup_subsys_state()
accesses css_set, this css_set maybe freed when task_cs() called.

we use use rcu_read_lock() to protect it.

Signed-off-by: Lai Jiangshan <laijs-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
---
diff --git a/kernel/cpuset.c b/kernel/cpuset.c
index 3e00526..e0e087e 100644
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -363,14 +363,9 @@ void cpuset_update_task_memory_state(void)
 	struct task_struct *tsk = current;
 	struct cpuset *cs;
 
-	if (task_cs(tsk) == &top_cpuset) {
-		/* Don't need rcu for top_cpuset.  It's never freed. */
-		my_cpusets_mem_gen = top_cpuset.mems_generation;
-	} else {
-		rcu_read_lock();
-		my_cpusets_mem_gen = task_cs(tsk)->mems_generation;
-		rcu_read_unlock();
-	}
+	rcu_read_lock();
+	my_cpusets_mem_gen = task_cs(tsk)->mems_generation;
+	rcu_read_unlock();
 
 	if (my_cpusets_mem_gen != tsk->cpuset_mems_generation) {
 		mutex_lock(&callback_mutex);

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

* Re: [PATCH] cpuset: rcu_read_lock() to protect task_cs()
       [not found] ` <49267621.2070706-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
@ 2008-11-21 18:36   ` Paul Menage
  0 siblings, 0 replies; 4+ messages in thread
From: Paul Menage @ 2008-11-21 18:36 UTC (permalink / raw)
  To: Lai Jiangshan; +Cc: Linux Containers, Andrew Morton, Linux Kernel Mailing List

On Fri, Nov 21, 2008 at 12:49 AM, Lai Jiangshan <laijs-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org> wrote:
>
> task_cs() calls cgroup_subsys_state().

You mean it calls task_subsys_state().

>
> we must use rcu_read_lock() to protect cgroup_subsys_state().
>
> it's correct that top_cpuset is never freed, but cgroup_subsys_state()
> accesses css_set, this css_set maybe freed when task_cs() called.

It would be nice to have an RCU debug mode where rcu_dereference()
does a WARN() if it's invoked not under rcu_read_lock().

>
> we use use rcu_read_lock() to protect it.
>
> Signed-off-by: Lai Jiangshan <laijs-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
> ---
> diff --git a/kernel/cpuset.c b/kernel/cpuset.c
> index 3e00526..e0e087e 100644
> --- a/kernel/cpuset.c
> +++ b/kernel/cpuset.c
> @@ -363,14 +363,9 @@ void cpuset_update_task_memory_state(void)
>        struct task_struct *tsk = current;
>        struct cpuset *cs;
>
> -       if (task_cs(tsk) == &top_cpuset) {
> -               /* Don't need rcu for top_cpuset.  It's never freed. */
> -               my_cpusets_mem_gen = top_cpuset.mems_generation;
> -       } else {
> -               rcu_read_lock();
> -               my_cpusets_mem_gen = task_cs(tsk)->mems_generation;
> -               rcu_read_unlock();
> -       }
> +       rcu_read_lock();
> +       my_cpusets_mem_gen = task_cs(tsk)->mems_generation;
> +       rcu_read_unlock();

Yes, I guess this old cpusets assumption is no longer valid in cgroups.

Acked-by: Paul Menage <menage-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>

Thanks

Paul

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

* Re: [PATCH] cpuset: rcu_read_lock() to protect task_cs()
  2008-11-21  8:49 [PATCH] cpuset: rcu_read_lock() to protect task_cs() Lai Jiangshan
@ 2008-11-21 18:36 ` Paul Menage
       [not found] ` <49267621.2070706-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
  1 sibling, 0 replies; 4+ messages in thread
From: Paul Menage @ 2008-11-21 18:36 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 mean it calls task_subsys_state().

>
> we must use rcu_read_lock() to protect cgroup_subsys_state().
>
> it's correct that top_cpuset is never freed, but cgroup_subsys_state()
> accesses css_set, this css_set maybe freed when task_cs() called.

It would be nice to have an RCU debug mode where rcu_dereference()
does a WARN() if it's invoked not under rcu_read_lock().

>
> we use use rcu_read_lock() to protect it.
>
> 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
> @@ -363,14 +363,9 @@ void cpuset_update_task_memory_state(void)
>        struct task_struct *tsk = current;
>        struct cpuset *cs;
>
> -       if (task_cs(tsk) == &top_cpuset) {
> -               /* Don't need rcu for top_cpuset.  It's never freed. */
> -               my_cpusets_mem_gen = top_cpuset.mems_generation;
> -       } else {
> -               rcu_read_lock();
> -               my_cpusets_mem_gen = task_cs(tsk)->mems_generation;
> -               rcu_read_unlock();
> -       }
> +       rcu_read_lock();
> +       my_cpusets_mem_gen = task_cs(tsk)->mems_generation;
> +       rcu_read_unlock();

Yes, I guess this old cpusets assumption is no longer valid in cgroups.

Acked-by: Paul Menage <menage@google.com>

Thanks

Paul

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

end of thread, other threads:[~2008-11-21 18:36 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() Lai Jiangshan
2008-11-21 18:36 ` Paul Menage
     [not found] ` <49267621.2070706-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2008-11-21 18:36   ` Paul Menage
  -- strict thread matches above, loose matches on Subject: below --
2008-11-21  8:49 Lai Jiangshan

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.