Commit 0ab02ca
cgroup: protect modifications to cgroup_idr with cgroup_mutex
Setup cgroupfs like this:
# mount -t cgroup -o cpuacct xxx /cgroup
# mkdir /cgroup/sub1
# mkdir /cgroup/sub2
Then run these two commands:
# for ((; ;)) { mkdir /cgroup/sub1/tmp && rmdir /mnt/sub1/tmp; } &
# for ((; ;)) { mkdir /cgroup/sub2/tmp && rmdir /mnt/sub2/tmp; } &
After seconds you may see this warning:
------------[ cut here ]------------
WARNING: CPU: 1 PID: 25243 at lib/idr.c:527 sub_remove+0x87/0x1b0()
idr_remove called for id=6 which is not allocated.
...
Call Trace:
[<ffffffff8156063c>] dump_stack+0x7a/0x96
[<ffffffff810591ac>] warn_slowpath_common+0x8c/0xc0
[<ffffffff81059296>] warn_slowpath_fmt+0x46/0x50
[<ffffffff81300aa7>] sub_remove+0x87/0x1b0
[<ffffffff810f3f02>] ? css_killed_work_fn+0x32/0x1b0
[<ffffffff81300bf5>] idr_remove+0x25/0xd0
[<ffffffff810f2bab>] cgroup_destroy_css_killed+0x5b/0xc0
[<ffffffff810f4000>] css_killed_work_fn+0x130/0x1b0
[<ffffffff8107cdbc>] process_one_work+0x26c/0x550
[<ffffffff8107eefe>] worker_thread+0x12e/0x3b0
[<ffffffff81085f96>] kthread+0xe6/0xf0
[<ffffffff81570bac>] ret_from_fork+0x7c/0xb0
---[ end trace 2d1577ec10cf80d0 ]---
It's because allocating/removing cgroup ID is not properly synchronized.
The bug was introduced when we converted cgroup_ida to cgroup_idr.
While synchronization is already done inside ida_simple_{get,remove}(),
users are responsible for concurrent calls to idr_{alloc,remove}().
tj: Refreshed on top of b58c899 ("cgroup: fix error return from
cgroup_create()").
Fixes: 4e96ee8 ("cgroup: convert cgroup_ida to cgroup_idr")
Cc: <stable@vger.kernel.org> #3.12+
Reported-by: Michal Hocko <mhocko@suse.cz>
Signed-off-by: Li Zefan <lizefan@huawei.com>
Signed-off-by: Tejun Heo <tj@kernel.org>1 parent 48573a8 commit 0ab02ca
2 files changed
+20
-16
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
166 | 166 | | |
167 | 167 | | |
168 | 168 | | |
| 169 | + | |
| 170 | + | |
169 | 171 | | |
170 | 172 | | |
171 | 173 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
886 | 886 | | |
887 | 887 | | |
888 | 888 | | |
| 889 | + | |
889 | 890 | | |
| 891 | + | |
890 | 892 | | |
891 | 893 | | |
892 | 894 | | |
| |||
4167 | 4169 | | |
4168 | 4170 | | |
4169 | 4171 | | |
4170 | | - | |
4171 | | - | |
4172 | | - | |
4173 | | - | |
4174 | | - | |
4175 | | - | |
4176 | | - | |
4177 | | - | |
4178 | | - | |
4179 | | - | |
4180 | 4172 | | |
4181 | 4173 | | |
4182 | 4174 | | |
| |||
4186 | 4178 | | |
4187 | 4179 | | |
4188 | 4180 | | |
4189 | | - | |
| 4181 | + | |
| 4182 | + | |
| 4183 | + | |
| 4184 | + | |
| 4185 | + | |
| 4186 | + | |
| 4187 | + | |
| 4188 | + | |
| 4189 | + | |
| 4190 | + | |
| 4191 | + | |
4190 | 4192 | | |
4191 | 4193 | | |
4192 | 4194 | | |
| |||
4218 | 4220 | | |
4219 | 4221 | | |
4220 | 4222 | | |
4221 | | - | |
| 4223 | + | |
4222 | 4224 | | |
4223 | 4225 | | |
4224 | 4226 | | |
| |||
4254 | 4256 | | |
4255 | 4257 | | |
4256 | 4258 | | |
4257 | | - | |
4258 | | - | |
4259 | | - | |
4260 | | - | |
4261 | 4259 | | |
4262 | 4260 | | |
| 4261 | + | |
| 4262 | + | |
| 4263 | + | |
| 4264 | + | |
4263 | 4265 | | |
4264 | 4266 | | |
4265 | 4267 | | |
| |||
0 commit comments