*** BLURB HERE ***
Chen Ridong (2): cgroup_writeback: Revert "fix deadlock in cgroup1_writeback" cgroup_writeback: fix deadlock in cgroup1_writeback
mm/backing-dev.c | 7 +++++-- mm/memcontrol.c | 24 +++++++++--------------- 2 files changed, 14 insertions(+), 17 deletions(-)
hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I99KM6
--------------------------------
"fix deadlock in cgroup1_writeback" will lead to softlockup for deleting cgroup_mutex lead to blkcg->memcg_list unprotected. so revert "cgroup_writeback: fix deadlock in cgroup1_writeback".
Signed-off-by: Chen Ridong chenridong@huawei.com --- mm/backing-dev.c | 2 ++ mm/memcontrol.c | 21 ++++++--------------- 2 files changed, 8 insertions(+), 15 deletions(-)
diff --git a/mm/backing-dev.c b/mm/backing-dev.c index bfb2c50b0354..d70f8420c805 100644 --- a/mm/backing-dev.c +++ b/mm/backing-dev.c @@ -1221,6 +1221,8 @@ void wb_attach_memcg_to_blkcg(struct cgroup_subsys_state *memcg_css, if (!cgroup1_writeback) return;
+ lockdep_assert_held(&cgroup_mutex); + css_get(blkcg_css); memcg->wb_blk_css = blkcg_css; if (pre_blkcss == NULL) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 5613bf6c1d7d..0f1813deb527 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6042,22 +6042,15 @@ static int wb_blkio_show(struct seq_file *m, void *v) if (!path) return -ENOMEM;
- rcu_read_lock(); + mutex_lock(&cgroup_mutex); blkcg_css = memcg->wb_blk_css; - if (!css_tryget_online(blkcg_css)) { - kfree(path); - rcu_read_unlock(); - - return -EINVAL; - } blkcg_cgroup = blkcg_css->cgroup; blkcg_id = cgroup_ino(blkcg_cgroup); cgroup_path(blkcg_cgroup, path, PATH_MAX); + mutex_unlock(&cgroup_mutex); seq_printf(m, "wb_blkio_path:%s\n", path); seq_printf(m, "wb_blkio_ino:%lu\n", blkcg_id); kfree(path); - css_put(blkcg_css); - rcu_read_unlock();
return 0; } @@ -6080,24 +6073,22 @@ static ssize_t wb_blkio_write(struct kernfs_open_file *of, char *buf, if (ret) return ret;
- rcu_read_lock(); + mutex_lock(&cgroup_mutex); root = blkcg_root_css->cgroup->root; blk_cgroup = __cgroup_get_from_id(root, cgrp_id); if (IS_ERR(blk_cgroup)) { - rcu_read_unlock(); + mutex_unlock(&cgroup_mutex); return -EINVAL; } blkcg_css = cgroup_tryget_css(blk_cgroup, &io_cgrp_subsys); - if (!blkcg_css) { - ret = -EINVAL; + if (!blkcg_css) goto out_unlock; - } wb_attach_memcg_to_blkcg(memcg_css, blkcg_css); css_put(blkcg_css);
out_unlock: cgroup_put(blk_cgroup); - rcu_read_unlock(); + mutex_unlock(&cgroup_mutex);
return ret < 0 ? ret : nbytes; }
hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I99KM6
--------------------------------
When read/write memory.wb_blkio_ino of a memcg, and delete the memcg at the same time, it could cause deadlock as below: CPU0 CPU1 rlock(kn->active#4); lock(cgroup_mutex); lock(kn->active#4); lock(cgroup_mutex);
Therefore, use cgroup_kn_lock_live to replace cgroup_mutex in reading/writing memory.wb_blkio_ino. cgroup_kn_lock_live is locking helper for cgroup kernfs methods.
Fixes: cf4973d8f67c ("cgroup: support cgroup writeback on cgroupv1") Signed-off-by: Chen Ridong chenridong@huawei.com --- mm/backing-dev.c | 5 +++-- mm/memcontrol.c | 13 ++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/mm/backing-dev.c b/mm/backing-dev.c index d70f8420c805..a62efda13ee8 100644 --- a/mm/backing-dev.c +++ b/mm/backing-dev.c @@ -579,8 +579,8 @@ static struct cgroup_subsys_state *cgwbv1_get_blkcss(struct mem_cgroup *memcg) struct cgroup_subsys_state *blkcg_css;
rcu_read_lock(); - blkcg_css = memcg->wb_blk_css; - if (!css_tryget_online(blkcg_css)) { + blkcg_css = READ_ONCE(memcg->wb_blk_css); + if (!blkcg_css || !css_tryget_online(blkcg_css)) { blkcg_css = blkcg_root_css; css_get(blkcg_css); } @@ -1180,6 +1180,7 @@ static void wb_kill_memcg(struct cgroup_subsys_state *memcg_css)
list_del_init(&memcg->memcg_node); css_put(memcg->wb_blk_css); + memcg->wb_blk_css = NULL; }
static void wb_kill_blkcg(struct cgroup_subsys_state *blkcg_css) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 0f1813deb527..df2d73ad85cf 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6029,6 +6029,7 @@ static ssize_t memcg_high_async_ratio_write(struct kernfs_open_file *of,
static int wb_blkio_show(struct seq_file *m, void *v) { + struct kernfs_open_file *of = m->private; char *path; ino_t blkcg_id; struct cgroup *blkcg_cgroup; @@ -6042,12 +6043,13 @@ static int wb_blkio_show(struct seq_file *m, void *v) if (!path) return -ENOMEM;
- mutex_lock(&cgroup_mutex); + if (!cgroup_kn_lock_live(of->kn, false)) + return -ENODEV; blkcg_css = memcg->wb_blk_css; blkcg_cgroup = blkcg_css->cgroup; blkcg_id = cgroup_ino(blkcg_cgroup); cgroup_path(blkcg_cgroup, path, PATH_MAX); - mutex_unlock(&cgroup_mutex); + cgroup_kn_unlock(of->kn); seq_printf(m, "wb_blkio_path:%s\n", path); seq_printf(m, "wb_blkio_ino:%lu\n", blkcg_id); kfree(path); @@ -6073,11 +6075,12 @@ static ssize_t wb_blkio_write(struct kernfs_open_file *of, char *buf, if (ret) return ret;
- mutex_lock(&cgroup_mutex); + if (!cgroup_kn_lock_live(of->kn, false)) + return -ENODEV; root = blkcg_root_css->cgroup->root; blk_cgroup = __cgroup_get_from_id(root, cgrp_id); if (IS_ERR(blk_cgroup)) { - mutex_unlock(&cgroup_mutex); + cgroup_kn_unlock(of->kn); return -EINVAL; } blkcg_css = cgroup_tryget_css(blk_cgroup, &io_cgrp_subsys); @@ -6088,7 +6091,7 @@ static ssize_t wb_blkio_write(struct kernfs_open_file *of, char *buf,
out_unlock: cgroup_put(blk_cgroup); - mutex_unlock(&cgroup_mutex); + cgroup_kn_unlock(of->kn);
return ret < 0 ? ret : nbytes; }
反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://gitee.com/openeuler/kernel/pulls/6282 邮件列表地址:https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/R...
FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://gitee.com/openeuler/kernel/pulls/6282 Mailing list address: https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/R...