Commit e5ced8e
committed
cgroup_freezer: replace freezer->lock with freezer_mutex
After 96d365e ("cgroup: make css_set_lock a rwsem and rename it
to css_set_rwsem"), css task iterators requires sleepable context as
it may block on css_set_rwsem. I missed that cgroup_freezer was
iterating tasks under IRQ-safe spinlock freezer->lock. This leads to
errors like the following on freezer state reads and transitions.
BUG: sleeping function called from invalid context at /work
/os/work/kernel/locking/rwsem.c:20
in_atomic(): 0, irqs_disabled(): 0, pid: 462, name: bash
5 locks held by bash/462:
#0: (sb_writers#7){.+.+.+}, at: [<ffffffff811f0843>] vfs_write+0x1a3/0x1c0
#1: (&of->mutex){+.+.+.}, at: [<ffffffff8126d78b>] kernfs_fop_write+0xbb/0x170
#2: (s_active#70){.+.+.+}, at: [<ffffffff8126d793>] kernfs_fop_write+0xc3/0x170
#3: (freezer_mutex){+.+...}, at: [<ffffffff81135981>] freezer_write+0x61/0x1e0
#4: (rcu_read_lock){......}, at: [<ffffffff81135973>] freezer_write+0x53/0x1e0
Preemption disabled at:[<ffffffff81104404>] console_unlock+0x1e4/0x460
CPU: 3 PID: 462 Comm: bash Not tainted 3.15.0-rc1-work+ torvalds#10
Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
ffff88000916a6d0 ffff88000e0a3da0 ffffffff81cf8c96 0000000000000000
ffff88000e0a3dc8 ffffffff810cf4f2 ffffffff82388040 ffff880013aaf740
0000000000000002 ffff88000e0a3de8 ffffffff81d05974 0000000000000246
Call Trace:
[<ffffffff81cf8c96>] dump_stack+0x4e/0x7a
[<ffffffff810cf4f2>] __might_sleep+0x162/0x260
[<ffffffff81d05974>] down_read+0x24/0x60
[<ffffffff81133e87>] css_task_iter_start+0x27/0x70
[<ffffffff8113584d>] freezer_apply_state+0x5d/0x130
[<ffffffff81135a16>] freezer_write+0xf6/0x1e0
[<ffffffff8112eb88>] cgroup_file_write+0xd8/0x230
[<ffffffff8126d7b7>] kernfs_fop_write+0xe7/0x170
[<ffffffff811f0756>] vfs_write+0xb6/0x1c0
[<ffffffff811f121d>] SyS_write+0x4d/0xc0
[<ffffffff81d08292>] system_call_fastpath+0x16/0x1b
freezer->lock used to be used in hot paths but that time is long gone
and there's no reason for the lock to be IRQ-safe spinlock or even
per-cgroup. In fact, given the fact that a cgroup may contain large
number of tasks, it's not a good idea to iterate over them while
holding IRQ-safe spinlock.
Let's simplify locking by replacing per-cgroup freezer->lock with
global freezer_mutex. This also makes the comments explaining the
intricacies of policy inheritance and the locking around it as the
states are protected by a common mutex.
The conversion is mostly straight-forward. The followings are worth
mentioning.
* freezer_css_online() no longer needs double locking.
* freezer_attach() now performs propagation simply while holding
freezer_mutex. update_if_frozen() race no longer exists and the
comment is removed.
* freezer_fork() now tests whether the task is in root cgroup using
the new task_css_is_root() without doing rcu_read_lock/unlock(). If
not, it grabs freezer_mutex and performs the operation.
* freezer_read() and freezer_change_state() grab freezer_mutex across
the whole operation and pin the css while iterating so that each
descendant processing happens in sleepable context.
Fixes: 96d365e ("cgroup: make css_set_lock a rwsem and rename it to css_set_rwsem")
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Li Zefan <lizefan@huawei.com>1 parent 5024ae2 commit e5ced8e
1 file changed
+46
-66
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
45 | | - | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
| |||
93 | 95 | | |
94 | 96 | | |
95 | 97 | | |
96 | | - | |
97 | 98 | | |
98 | 99 | | |
99 | 100 | | |
| |||
110 | 111 | | |
111 | 112 | | |
112 | 113 | | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
| 114 | + | |
121 | 115 | | |
122 | 116 | | |
123 | 117 | | |
| |||
126 | 120 | | |
127 | 121 | | |
128 | 122 | | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
| 123 | + | |
133 | 124 | | |
134 | 125 | | |
135 | 126 | | |
| |||
144 | 135 | | |
145 | 136 | | |
146 | 137 | | |
147 | | - | |
| 138 | + | |
148 | 139 | | |
149 | 140 | | |
150 | 141 | | |
151 | 142 | | |
152 | 143 | | |
153 | 144 | | |
154 | | - | |
| 145 | + | |
155 | 146 | | |
156 | 147 | | |
157 | 148 | | |
| |||
175 | 166 | | |
176 | 167 | | |
177 | 168 | | |
178 | | - | |
| 169 | + | |
179 | 170 | | |
180 | 171 | | |
181 | 172 | | |
| |||
197 | 188 | | |
198 | 189 | | |
199 | 190 | | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
| 191 | + | |
209 | 192 | | |
210 | | - | |
211 | 193 | | |
212 | 194 | | |
213 | | - | |
214 | 195 | | |
| 196 | + | |
| 197 | + | |
215 | 198 | | |
216 | 199 | | |
217 | 200 | | |
| |||
228 | 211 | | |
229 | 212 | | |
230 | 213 | | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | 214 | | |
235 | 215 | | |
236 | 216 | | |
237 | 217 | | |
238 | 218 | | |
239 | 219 | | |
240 | 220 | | |
241 | | - | |
242 | | - | |
| 221 | + | |
| 222 | + | |
243 | 223 | | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
255 | 229 | | |
256 | | - | |
257 | | - | |
| 230 | + | |
258 | 231 | | |
| 232 | + | |
259 | 233 | | |
260 | 234 | | |
261 | 235 | | |
| |||
281 | 255 | | |
282 | 256 | | |
283 | 257 | | |
284 | | - | |
285 | | - | |
286 | | - | |
| 258 | + | |
287 | 259 | | |
288 | 260 | | |
289 | 261 | | |
290 | | - | |
| 262 | + | |
291 | 263 | | |
292 | 264 | | |
| 265 | + | |
293 | 266 | | |
294 | 267 | | |
295 | 268 | | |
296 | 269 | | |
297 | 270 | | |
298 | | - | |
| 271 | + | |
299 | 272 | | |
| 273 | + | |
300 | 274 | | |
301 | 275 | | |
302 | 276 | | |
| |||
317 | 291 | | |
318 | 292 | | |
319 | 293 | | |
320 | | - | |
321 | | - | |
322 | 294 | | |
323 | 295 | | |
324 | 296 | | |
325 | 297 | | |
326 | 298 | | |
327 | 299 | | |
| 300 | + | |
328 | 301 | | |
329 | 302 | | |
330 | 303 | | |
331 | | - | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
332 | 309 | | |
333 | 310 | | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
334 | 315 | | |
| 316 | + | |
335 | 317 | | |
336 | 318 | | |
337 | 319 | | |
| |||
373 | 355 | | |
374 | 356 | | |
375 | 357 | | |
376 | | - | |
| 358 | + | |
377 | 359 | | |
378 | 360 | | |
379 | 361 | | |
| |||
414 | 396 | | |
415 | 397 | | |
416 | 398 | | |
| 399 | + | |
417 | 400 | | |
418 | 401 | | |
419 | 402 | | |
420 | 403 | | |
421 | 404 | | |
422 | | - | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
423 | 408 | | |
424 | | - | |
| 409 | + | |
425 | 410 | | |
426 | 411 | | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
| 412 | + | |
434 | 413 | | |
435 | 414 | | |
436 | 415 | | |
437 | | - | |
438 | 416 | | |
439 | | - | |
| 417 | + | |
| 418 | + | |
440 | 419 | | |
441 | 420 | | |
| 421 | + | |
442 | 422 | | |
443 | 423 | | |
444 | 424 | | |
| |||
0 commit comments