diff options
author | Tejun Heo <tj@kernel.org> | 2014-02-08 10:36:58 -0500 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2014-02-08 10:36:58 -0500 |
commit | 69e943b7d3c2dcca1087e03e556ac6cb0d4433b4 (patch) | |
tree | 79bce2147f3eebb43e4300120a3a0d81b0a97e1c /kernel | |
parent | aec25020f5d4b69aea5317551d1cb7043f6b04fb (diff) |
cgroup: update locking in cgroup_show_options()
cgroup_show_options() grabs cgroup_root_mutex to protect the options
changing while printing; however, holding root_mutex or not doesn't
really make much difference for the function. subsys_mask can be
atomically tested and most of the options aren't allowed to change
anyway once mounted.
The only field which needs synchronization is ->release_agent_path.
This patch introduces a dedicated spinlock to synchronize accesses to
the field and drops cgroup_root_mutex locking from
cgroup_show_options(). The next patch will remove cgroup_root_mutex.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Li Zefan <lizefan@huawei.com>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/cgroup.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 5a77ca0784a6..b15058602120 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -92,6 +92,12 @@ static DEFINE_MUTEX(cgroup_mutex); | |||
92 | 92 | ||
93 | static DEFINE_MUTEX(cgroup_root_mutex); | 93 | static DEFINE_MUTEX(cgroup_root_mutex); |
94 | 94 | ||
95 | /* | ||
96 | * Protects cgroup_subsys->release_agent_path. Modifying it also requires | ||
97 | * cgroup_mutex. Reading requires either cgroup_mutex or this spinlock. | ||
98 | */ | ||
99 | static DEFINE_SPINLOCK(release_agent_path_lock); | ||
100 | |||
95 | #define cgroup_assert_mutex_or_rcu_locked() \ | 101 | #define cgroup_assert_mutex_or_rcu_locked() \ |
96 | rcu_lockdep_assert(rcu_read_lock_held() || \ | 102 | rcu_lockdep_assert(rcu_read_lock_held() || \ |
97 | lockdep_is_held(&cgroup_mutex), \ | 103 | lockdep_is_held(&cgroup_mutex), \ |
@@ -1034,7 +1040,6 @@ static int cgroup_show_options(struct seq_file *seq, struct dentry *dentry) | |||
1034 | struct cgroup_subsys *ss; | 1040 | struct cgroup_subsys *ss; |
1035 | int ssid; | 1041 | int ssid; |
1036 | 1042 | ||
1037 | mutex_lock(&cgroup_root_mutex); | ||
1038 | for_each_subsys(ss, ssid) | 1043 | for_each_subsys(ss, ssid) |
1039 | if (root->subsys_mask & (1 << ssid)) | 1044 | if (root->subsys_mask & (1 << ssid)) |
1040 | seq_printf(seq, ",%s", ss->name); | 1045 | seq_printf(seq, ",%s", ss->name); |
@@ -1044,13 +1049,16 @@ static int cgroup_show_options(struct seq_file *seq, struct dentry *dentry) | |||
1044 | seq_puts(seq, ",noprefix"); | 1049 | seq_puts(seq, ",noprefix"); |
1045 | if (root->flags & CGRP_ROOT_XATTR) | 1050 | if (root->flags & CGRP_ROOT_XATTR) |
1046 | seq_puts(seq, ",xattr"); | 1051 | seq_puts(seq, ",xattr"); |
1052 | |||
1053 | spin_lock(&release_agent_path_lock); | ||
1047 | if (strlen(root->release_agent_path)) | 1054 | if (strlen(root->release_agent_path)) |
1048 | seq_printf(seq, ",release_agent=%s", root->release_agent_path); | 1055 | seq_printf(seq, ",release_agent=%s", root->release_agent_path); |
1056 | spin_unlock(&release_agent_path_lock); | ||
1057 | |||
1049 | if (test_bit(CGRP_CPUSET_CLONE_CHILDREN, &root->top_cgroup.flags)) | 1058 | if (test_bit(CGRP_CPUSET_CLONE_CHILDREN, &root->top_cgroup.flags)) |
1050 | seq_puts(seq, ",clone_children"); | 1059 | seq_puts(seq, ",clone_children"); |
1051 | if (strlen(root->name)) | 1060 | if (strlen(root->name)) |
1052 | seq_printf(seq, ",name=%s", root->name); | 1061 | seq_printf(seq, ",name=%s", root->name); |
1053 | mutex_unlock(&cgroup_root_mutex); | ||
1054 | return 0; | 1062 | return 0; |
1055 | } | 1063 | } |
1056 | 1064 | ||
@@ -1272,8 +1280,11 @@ static int cgroup_remount(struct super_block *sb, int *flags, char *data) | |||
1272 | if (ret) | 1280 | if (ret) |
1273 | goto out_unlock; | 1281 | goto out_unlock; |
1274 | 1282 | ||
1275 | if (opts.release_agent) | 1283 | if (opts.release_agent) { |
1284 | spin_lock(&release_agent_path_lock); | ||
1276 | strcpy(root->release_agent_path, opts.release_agent); | 1285 | strcpy(root->release_agent_path, opts.release_agent); |
1286 | spin_unlock(&release_agent_path_lock); | ||
1287 | } | ||
1277 | out_unlock: | 1288 | out_unlock: |
1278 | kfree(opts.release_agent); | 1289 | kfree(opts.release_agent); |
1279 | kfree(opts.name); | 1290 | kfree(opts.name); |
@@ -2183,7 +2194,9 @@ static int cgroup_release_agent_write(struct cgroup_subsys_state *css, | |||
2183 | if (!cgroup_lock_live_group(css->cgroup)) | 2194 | if (!cgroup_lock_live_group(css->cgroup)) |
2184 | return -ENODEV; | 2195 | return -ENODEV; |
2185 | mutex_lock(&cgroup_root_mutex); | 2196 | mutex_lock(&cgroup_root_mutex); |
2197 | spin_lock(&release_agent_path_lock); | ||
2186 | strcpy(css->cgroup->root->release_agent_path, buffer); | 2198 | strcpy(css->cgroup->root->release_agent_path, buffer); |
2199 | spin_unlock(&release_agent_path_lock); | ||
2187 | mutex_unlock(&cgroup_root_mutex); | 2200 | mutex_unlock(&cgroup_root_mutex); |
2188 | mutex_unlock(&cgroup_mutex); | 2201 | mutex_unlock(&cgroup_mutex); |
2189 | return 0; | 2202 | return 0; |