cls_cgroup: Fix rcu lockdep warning
Subsystems (2)
PATCH 1/1 cls_cgroup: Fix rcu lockdep warning
Calling task_subsys_state() without holding rcu_read_lock or cgroup_mutex can cause lockdep warning.
--- include/net/cls_cgroup.h | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-)
include/net/cls_cgroup.h +8 -2
@@ -27,11 +27,17 @@ struct cgroup_cls_state#ifdef CONFIG_NET_CLS_CGROUP static inline u32 task_cls_classid (struct task_struct *p) { +int classid; +if (in_interrupt ())return 0 ; -return container_of (task_subsys_state (p, net_cls_subsys_id), - struct cgroup_cls_state, css)->classid; +rcu_read_lock (); + classid =container_of (task_subsys_state (p, net_cls_subsys_id), + struct cgroup_cls_state, css)->classid; +rcu_read_unlock (); + +return classid; }#else extern int net_cls_subsys_id;
Signature · 1 line
1.6.3
Quoted 3 lines · Li Zefan
Calling
task_subsys_state()without holdingrcu_read_lockorcgroup_mutexcan cause lockdep warning.
That is not a suitable changelog.
Was the warning correct? Is your patch correct? What does RCU protect here and why can we use classid after dropping it.
Simply frobbing code to make the warning go away is not good.
David Miller
maintainerFrom: Peter Zijlstra <[email protected]>
Date: Thu, 02 Sep 2010 12:38:36 +0200
Quoted 11 lines · Li Zefan
Quoted 3 lines
Calling
task_subsys_state()without holdingrcu_read_lockorcgroup_mutexcan cause lockdep warning.That is not a suitable changelog.
Was the warning correct? Is your patch correct? What does RCU protect here and why can we use classid after dropping it.
Simply frobbing code to make the warning go away is not good.
In fact shouldn't this be a rcu_dereference() or similar?
Quoted 8 lines · David Miller
From: Peter Zijlstra <[email protected]>
Date: Thu, 02 Sep 2010 12:38:36 +0200Quoted 5 lines · Li Zefan
Quoted 3 lines
Calling
task_subsys_state()without holdingrcu_read_lockorcgroup_mutexcan cause lockdep warning.
Quoted 8 lines
Quoted 6 lines
That is not a suitable changelog.
Was the warning correct? Is your patch correct? What does RCU protect here and why can we use classid after dropping it.
Simply frobbing code to make the warning go away is not good.
In fact shouldn't this be a
rcu_dereference()or similar?
The rcu_dereference() is there, just buried in task_subsys_state_check() which is called from task_subsys_state(). The code extracts the classid, which is an integer, so the RCU-protected pointer does not leak out of the RCU read-side critical section.
So this is OK, but the changelog should indeed say why it is OK.
Thanx, Paul
Quoted 5 lines · Peter Zijlstra
Quoted 3 lines · Li Zefan
Calling
task_subsys_state()without holdingrcu_read_lockorcgroup_mutexcan cause lockdep warning.
Quoted 8 lines
That is not a suitable changelog.
Was the warning correct? Is your patch correct? What does RCU protect here and why can we use classid after dropping it.
Simply frobbing code to make the warning go away is not good.
task->cgroups and task->cgroups->subsys[i] are protected by RCU. So we avoid accessing invalid pointers here. This can happen, for example, when you are deref those pointers while someone move @task from one cgroup to another.
otoh, there is no lock rule for ->classid.
Quoted 5 lines · Li Zefan
Calling
task_subsys_state()without holdingrcu_read_lockorcgroup_mutexcan cause lockdep warning.Reported-by Dave Jones <[email protected]>Signed-off-by Li Zefan <[email protected]>
Thanks for catching this.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt