Commit af84d28
Ian Kent
kernfs: Separate kernfs_pr_cont_buf and rename_lock
JIRA: https://issues.redhat.com/browse/RHEL-52956
Upstream status: Linus
commit 1a702dc
Author: Hao Luo <haoluo@google.com>
Date: Mon May 16 12:09:51 2022 -0700
kernfs: Separate kernfs_pr_cont_buf and rename_lock.
Previously the protection of kernfs_pr_cont_buf was piggy backed by
rename_lock, which means that pr_cont() needs to be protected under
rename_lock. This can cause potential circular lock dependencies.
If there is an OOM, we have the following call hierarchy:
-> cpuset_print_current_mems_allowed()
-> pr_cont_cgroup_name()
-> pr_cont_kernfs_name()
pr_cont_kernfs_name() will grab rename_lock and call printk. So we have
the following lock dependencies:
kernfs_rename_lock -> console_sem
Sometimes, printk does a wakeup before releasing console_sem, which has
the dependence chain:
console_sem -> p->pi_lock -> rq->lock
Now, imagine one wants to read cgroup_name under rq->lock, for example,
printing cgroup_name in a tracepoint in the scheduler code. They will
be holding rq->lock and take rename_lock:
rq->lock -> kernfs_rename_lock
Now they will deadlock.
A prevention to this circular lock dependency is to separate the
protection of pr_cont_buf from rename_lock. In principle, rename_lock
is to protect the integrity of cgroup name when copying to buf. Once
pr_cont_buf has got its content, rename_lock can be dropped. So it's
safe to drop rename_lock after kernfs_name_locked (and
kernfs_path_from_node_locked) and rely on a dedicated pr_cont_lock
to protect pr_cont_buf.
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Hao Luo <haoluo@google.com>
Link: https://lore.kernel.org/r/20220516190951.3144144-1-haoluo@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Ian Kent <ikent@redhat.com>1 parent e203ef1 commit af84d28
1 file changed
+19
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
22 | 30 | | |
23 | 31 | | |
24 | 32 | | |
| |||
234 | 242 | | |
235 | 243 | | |
236 | 244 | | |
237 | | - | |
| 245 | + | |
238 | 246 | | |
239 | | - | |
| 247 | + | |
240 | 248 | | |
241 | 249 | | |
242 | | - | |
| 250 | + | |
243 | 251 | | |
244 | 252 | | |
245 | 253 | | |
| |||
253 | 261 | | |
254 | 262 | | |
255 | 263 | | |
256 | | - | |
| 264 | + | |
257 | 265 | | |
258 | | - | |
259 | | - | |
| 266 | + | |
| 267 | + | |
260 | 268 | | |
261 | 269 | | |
262 | 270 | | |
| |||
270 | 278 | | |
271 | 279 | | |
272 | 280 | | |
273 | | - | |
| 281 | + | |
274 | 282 | | |
275 | 283 | | |
276 | 284 | | |
| |||
841 | 849 | | |
842 | 850 | | |
843 | 851 | | |
844 | | - | |
845 | | - | |
| 852 | + | |
846 | 853 | | |
847 | 854 | | |
848 | 855 | | |
849 | 856 | | |
850 | | - | |
| 857 | + | |
851 | 858 | | |
852 | 859 | | |
853 | 860 | | |
| |||
859 | 866 | | |
860 | 867 | | |
861 | 868 | | |
862 | | - | |
| 869 | + | |
863 | 870 | | |
864 | 871 | | |
865 | 872 | | |
| |||
0 commit comments