Skip to contentSkip to conversation

cpuset: rcu_read_lock() to protect task_cs() even we don't dereference to task_cs()'s return value

PATCH In review Lai Jiangshan 4 participants 7 messages Nov 21, 2008 – Nov 22, 2008 3 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpuset: rcu_read_lock() to protect task_cs() even we don't dereference to task_cs()'s return value

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.

---

kernel/cpuset.c +5 -1
index 3e00526..e0e087e 100644
@@ -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)

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 2 lines · Lai Jiangshan

task_cs() calls cgroup_subsys_state().

You man "calls task_subsys_state()"

Quoted 6 lines

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

Quoted 22 lines

---

kernel/cpuset.c +5 -1
index 3e00526..e0e087e 100644
@@ -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)
#3 lore raw
In reply to Lai Jiangshan
Quoted 2 lines · Lai Jiangshan

task_cs() calls cgroup_subsys_state().

You man "calls task_subsys_state()"

Quoted 6 lines

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

Quoted 22 lines

---

kernel/cpuset.c +5 -1
index 3e00526..e0e087e 100644
@@ -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)

A message that is not in the archive (sent off-list or not yet received): 6599ad830811211105p711aebc3v85ffffbc399bdd6e-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#5 lore raw
Quoted 4 lines · Paul Menage

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

#6 lore raw
In reply to Paul Menage
Quoted 4 lines · Paul Menage

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

A message that is not in the archive (sent off-list or not yet received): 6599ad830811211107n141e6cb5n2abf14e59110d764-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#8 lore raw
Quoted 8 lines · Paul Menage
Quoted 3 lines · Paul Menage

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.

#9 lore raw
In reply to Paul Menage
Quoted 8 lines · Paul Menage
Quoted 3 lines · Paul Menage

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.