Commit 4b1c7840 authored by Tejun Heo's avatar Tejun Heo

device_cgroup: add lockdep asserts

device_cgroup uses RCU safe ->exceptions list which is write-protected
by devcgroup_mutex and has had some issues using locking correctly.
Add lockdep asserts to utility functions so that future errors can be
easily detected.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Acked-by: default avatarSerge E. Hallyn <serge.hallyn@ubuntu.com>
Cc: Aristeu Rozanski <aris@redhat.com>
Cc: Li Zefan <lizefan@huawei.com>
parent 5b805f2a
...@@ -82,6 +82,8 @@ static int dev_exceptions_copy(struct list_head *dest, struct list_head *orig) ...@@ -82,6 +82,8 @@ static int dev_exceptions_copy(struct list_head *dest, struct list_head *orig)
{ {
struct dev_exception_item *ex, *tmp, *new; struct dev_exception_item *ex, *tmp, *new;
lockdep_assert_held(&devcgroup_mutex);
list_for_each_entry(ex, orig, list) { list_for_each_entry(ex, orig, list) {
new = kmemdup(ex, sizeof(*ex), GFP_KERNEL); new = kmemdup(ex, sizeof(*ex), GFP_KERNEL);
if (!new) if (!new)
...@@ -107,6 +109,8 @@ static int dev_exception_add(struct dev_cgroup *dev_cgroup, ...@@ -107,6 +109,8 @@ static int dev_exception_add(struct dev_cgroup *dev_cgroup,
{ {
struct dev_exception_item *excopy, *walk; struct dev_exception_item *excopy, *walk;
lockdep_assert_held(&devcgroup_mutex);
excopy = kmemdup(ex, sizeof(*ex), GFP_KERNEL); excopy = kmemdup(ex, sizeof(*ex), GFP_KERNEL);
if (!excopy) if (!excopy)
return -ENOMEM; return -ENOMEM;
...@@ -137,6 +141,8 @@ static void dev_exception_rm(struct dev_cgroup *dev_cgroup, ...@@ -137,6 +141,8 @@ static void dev_exception_rm(struct dev_cgroup *dev_cgroup,
{ {
struct dev_exception_item *walk, *tmp; struct dev_exception_item *walk, *tmp;
lockdep_assert_held(&devcgroup_mutex);
list_for_each_entry_safe(walk, tmp, &dev_cgroup->exceptions, list) { list_for_each_entry_safe(walk, tmp, &dev_cgroup->exceptions, list) {
if (walk->type != ex->type) if (walk->type != ex->type)
continue; continue;
...@@ -163,6 +169,8 @@ static void dev_exception_clean(struct dev_cgroup *dev_cgroup) ...@@ -163,6 +169,8 @@ static void dev_exception_clean(struct dev_cgroup *dev_cgroup)
{ {
struct dev_exception_item *ex, *tmp; struct dev_exception_item *ex, *tmp;
lockdep_assert_held(&devcgroup_mutex);
list_for_each_entry_safe(ex, tmp, &dev_cgroup->exceptions, list) { list_for_each_entry_safe(ex, tmp, &dev_cgroup->exceptions, list) {
list_del_rcu(&ex->list); list_del_rcu(&ex->list);
kfree_rcu(ex, rcu); kfree_rcu(ex, rcu);
...@@ -298,6 +306,10 @@ static int may_access(struct dev_cgroup *dev_cgroup, ...@@ -298,6 +306,10 @@ static int may_access(struct dev_cgroup *dev_cgroup,
struct dev_exception_item *ex; struct dev_exception_item *ex;
bool match = false; bool match = false;
rcu_lockdep_assert(rcu_read_lock_held() ||
lockdep_is_held(&devcgroup_mutex),
"device_cgroup::may_access() called without proper synchronization");
list_for_each_entry_rcu(ex, &dev_cgroup->exceptions, list) { list_for_each_entry_rcu(ex, &dev_cgroup->exceptions, list) {
if ((refex->type & DEV_BLOCK) && !(ex->type & DEV_BLOCK)) if ((refex->type & DEV_BLOCK) && !(ex->type & DEV_BLOCK))
continue; continue;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment