Skip to content

Commit b4046f0

Browse files
Li Zefantorvalds
authored andcommitted
devcgroup: avoid using cgroup_lock
There is nothing special that has to be protected by cgroup_lock, so introduce devcgroup_mtuex for it's own use. Signed-off-by: Li Zefan <lizf@cn.fujitsu.com> Cc: Paul Menage <menage@google.com> Acked-by: Serge Hallyn <serue@us.ibm.com> Cc: Balbir Singh <balbir@in.ibm.com> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent d969fbe commit b4046f0

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

security/device_cgroup.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/uaccess.h>
1212
#include <linux/seq_file.h>
1313
#include <linux/rcupdate.h>
14+
#include <linux/mutex.h>
1415

1516
#define ACC_MKNOD 1
1617
#define ACC_READ 2
@@ -21,9 +22,11 @@
2122
#define DEV_CHAR 2
2223
#define DEV_ALL 4 /* this represents all devices */
2324

25+
static DEFINE_MUTEX(devcgroup_mutex);
26+
2427
/*
2528
* whitelist locking rules:
26-
* hold cgroup_lock() for update/read.
29+
* hold devcgroup_mutex for update/read.
2730
* hold rcu_read_lock() for read.
2831
*/
2932

@@ -67,7 +70,7 @@ static int devcgroup_can_attach(struct cgroup_subsys *ss,
6770
}
6871

6972
/*
70-
* called under cgroup_lock()
73+
* called under devcgroup_mutex
7174
*/
7275
static int dev_whitelist_copy(struct list_head *dest, struct list_head *orig)
7376
{
@@ -92,7 +95,7 @@ static int dev_whitelist_copy(struct list_head *dest, struct list_head *orig)
9295

9396
/* Stupid prototype - don't bother combining existing entries */
9497
/*
95-
* called under cgroup_lock()
98+
* called under devcgroup_mutex
9699
*/
97100
static int dev_whitelist_add(struct dev_cgroup *dev_cgroup,
98101
struct dev_whitelist_item *wh)
@@ -130,7 +133,7 @@ static void whitelist_item_free(struct rcu_head *rcu)
130133
}
131134

132135
/*
133-
* called under cgroup_lock()
136+
* called under devcgroup_mutex
134137
*/
135138
static void dev_whitelist_rm(struct dev_cgroup *dev_cgroup,
136139
struct dev_whitelist_item *wh)
@@ -185,8 +188,10 @@ static struct cgroup_subsys_state *devcgroup_create(struct cgroup_subsys *ss,
185188
list_add(&wh->list, &dev_cgroup->whitelist);
186189
} else {
187190
parent_dev_cgroup = cgroup_to_devcgroup(parent_cgroup);
191+
mutex_lock(&devcgroup_mutex);
188192
ret = dev_whitelist_copy(&dev_cgroup->whitelist,
189193
&parent_dev_cgroup->whitelist);
194+
mutex_unlock(&devcgroup_mutex);
190195
if (ret) {
191196
kfree(dev_cgroup);
192197
return ERR_PTR(ret);
@@ -273,7 +278,7 @@ static int devcgroup_seq_read(struct cgroup *cgroup, struct cftype *cft,
273278
* does the access granted to dev_cgroup c contain the access
274279
* requested in whitelist item refwh.
275280
* return 1 if yes, 0 if no.
276-
* call with c->lock held
281+
* call with devcgroup_mutex held
277282
*/
278283
static int may_access_whitelist(struct dev_cgroup *c,
279284
struct dev_whitelist_item *refwh)
@@ -426,11 +431,11 @@ static int devcgroup_access_write(struct cgroup *cgrp, struct cftype *cft,
426431
const char *buffer)
427432
{
428433
int retval;
429-
if (!cgroup_lock_live_group(cgrp))
430-
return -ENODEV;
434+
435+
mutex_lock(&devcgroup_mutex);
431436
retval = devcgroup_update_access(cgroup_to_devcgroup(cgrp),
432437
cft->private, buffer);
433-
cgroup_unlock();
438+
mutex_unlock(&devcgroup_mutex);
434439
return retval;
435440
}
436441

0 commit comments

Comments
 (0)