From: Tejun Heo <tj@kernel.org> To: Christian Borntraeger <borntraeger@de.ibm.com> Cc: linux-kernel@vger.kernel.org, linux-s390 <linux-s390@vger.kernel.org>, KVM list <kvm@vger.kernel.org>, Oleg Nesterov <oleg@redhat.com>, Peter Zijlstra <peterz@infradead.org>, "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>, Li Zefan <lizefan@huawei.com>, Johannes Weiner <hannes@cmpxchg.org>, cgroups@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v2 2/2] cgroup: make sure a parent css isn't freed before its children Date: Fri, 22 Jan 2016 10:45:52 -0500 [thread overview] Message-ID: <20160122154552.GE32380@htj.duckdns.org> (raw) In-Reply-To: <20160121203215.GG5157@mtj.duckdns.org> >From 8bb5ef79bc0f4016ecf79e8dce6096a3c63603e4 Mon Sep 17 00:00:00 2001 From: Tejun Heo <tj@kernel.org> Date: Thu, 21 Jan 2016 15:32:15 -0500 There are three subsystem callbacks in css shutdown path - css_offline(), css_released() and css_free(). Except for css_released(), cgroup core didn't guarantee the order of invocation. css_offline() or css_free() could be called on a parent css before its children. This behavior is unexpected and led to bugs in cpu and memory controller. The previous patch updated ordering for css_offline() which fixes the cpu controller issue. While there currently isn't a known bug caused by misordering of css_free() invocations, let's fix it too for consistency. css_free() ordering can be trivially fixed by moving putting of the parent css below css_free() invocation. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> --- Hello, Applied to cgroup/for-4.5-fixes w/ description updated. Will push out to Linus early next week. Thanks. kernel/cgroup.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kernel/cgroup.c b/kernel/cgroup.c index d015877..d27904c 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c @@ -4657,14 +4657,15 @@ static void css_free_work_fn(struct work_struct *work) if (ss) { /* css free path */ + struct cgroup_subsys_state *parent = css->parent; int id = css->id; - if (css->parent) - css_put(css->parent); - ss->css_free(css); cgroup_idr_remove(&ss->css_idr, id); cgroup_put(cgrp); + + if (parent) + css_put(parent); } else { /* cgroup free path */ atomic_dec(&cgrp->root->nr_cgrps); -- 2.5.0
WARNING: multiple messages have this Message-ID (diff)
From: Tejun Heo <tj@kernel.org> To: Christian Borntraeger <borntraeger@de.ibm.com> Cc: linux-kernel@vger.kernel.org, linux-s390 <linux-s390@vger.kernel.org>, KVM list <kvm@vger.kernel.org>, Oleg Nesterov <oleg@redhat.com>, Peter Zijlstra <peterz@infradead.org>, "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>, Li Zefan <lizefan@huawei.com>, Johannes Weiner <hannes@cmpxchg.org>, cgroups@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v2 2/2] cgroup: make sure a parent css isn't freed before its children Date: Fri, 22 Jan 2016 10:45:52 -0500 [thread overview] Message-ID: <20160122154552.GE32380@htj.duckdns.org> (raw) In-Reply-To: <20160121203215.GG5157@mtj.duckdns.org> From 8bb5ef79bc0f4016ecf79e8dce6096a3c63603e4 Mon Sep 17 00:00:00 2001 From: Tejun Heo <tj@kernel.org> Date: Thu, 21 Jan 2016 15:32:15 -0500 There are three subsystem callbacks in css shutdown path - css_offline(), css_released() and css_free(). Except for css_released(), cgroup core didn't guarantee the order of invocation. css_offline() or css_free() could be called on a parent css before its children. This behavior is unexpected and led to bugs in cpu and memory controller. The previous patch updated ordering for css_offline() which fixes the cpu controller issue. While there currently isn't a known bug caused by misordering of css_free() invocations, let's fix it too for consistency. css_free() ordering can be trivially fixed by moving putting of the parent css below css_free() invocation. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> --- Hello, Applied to cgroup/for-4.5-fixes w/ description updated. Will push out to Linus early next week. Thanks. kernel/cgroup.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kernel/cgroup.c b/kernel/cgroup.c index d015877..d27904c 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c @@ -4657,14 +4657,15 @@ static void css_free_work_fn(struct work_struct *work) if (ss) { /* css free path */ + struct cgroup_subsys_state *parent = css->parent; int id = css->id; - if (css->parent) - css_put(css->parent); - ss->css_free(css); cgroup_idr_remove(&ss->css_idr, id); cgroup_put(cgrp); + + if (parent) + css_put(parent); } else { /* cgroup free path */ atomic_dec(&cgrp->root->nr_cgrps); -- 2.5.0
next prev parent reply other threads:[~2016-01-22 15:45 UTC|newest] Thread overview: 87+ messages / expand[flat|nested] mbox.gz Atom feed top 2016-01-14 11:19 regression 4.4: deadlock in with cgroup percpu_rwsem Christian Borntraeger 2016-01-14 11:19 ` Christian Borntraeger 2016-01-14 13:38 ` Christian Borntraeger 2016-01-14 13:38 ` Christian Borntraeger 2016-01-14 14:04 ` Nikolay Borisov 2016-01-14 14:04 ` Nikolay Borisov 2016-01-14 14:08 ` Christian Borntraeger 2016-01-14 14:08 ` Christian Borntraeger 2016-01-14 14:27 ` Nikolay Borisov 2016-01-14 14:27 ` Nikolay Borisov 2016-01-14 17:15 ` Christian Borntraeger 2016-01-14 17:15 ` Christian Borntraeger 2016-01-14 19:56 ` Tejun Heo 2016-01-14 19:56 ` Tejun Heo 2016-01-15 7:30 ` Christian Borntraeger 2016-01-15 7:30 ` Christian Borntraeger 2016-01-15 15:13 ` Christian Borntraeger 2016-01-15 15:13 ` Christian Borntraeger 2016-01-18 18:32 ` Peter Zijlstra 2016-01-18 18:32 ` Peter Zijlstra 2016-01-18 18:48 ` Christian Borntraeger 2016-01-18 18:48 ` Christian Borntraeger 2016-01-19 9:55 ` Heiko Carstens 2016-01-19 9:55 ` Heiko Carstens 2016-01-19 19:36 ` Christian Borntraeger 2016-01-19 19:36 ` Christian Borntraeger 2016-01-19 19:38 ` Tejun Heo 2016-01-19 19:38 ` Tejun Heo 2016-01-20 7:07 ` Heiko Carstens 2016-01-20 7:07 ` Heiko Carstens 2016-01-20 10:15 ` Christian Borntraeger 2016-01-20 10:15 ` Christian Borntraeger 2016-01-20 10:30 ` Peter Zijlstra 2016-01-20 10:30 ` Peter Zijlstra 2016-01-20 10:47 ` Peter Zijlstra 2016-01-20 10:47 ` Peter Zijlstra 2016-01-20 15:30 ` Tejun Heo 2016-01-20 15:30 ` Tejun Heo 2016-01-20 16:04 ` Tejun Heo 2016-01-20 16:04 ` Tejun Heo 2016-01-20 16:49 ` Peter Zijlstra 2016-01-20 16:49 ` Peter Zijlstra 2016-01-20 16:56 ` Tejun Heo 2016-01-20 16:56 ` Tejun Heo 2016-01-23 2:03 ` Paul E. McKenney 2016-01-23 2:03 ` Paul E. McKenney 2016-01-25 8:49 ` Christoph Hellwig 2016-01-25 8:49 ` Christoph Hellwig 2016-01-25 19:38 ` Tejun Heo 2016-01-25 19:38 ` Tejun Heo 2016-01-26 14:51 ` Christoph Hellwig 2016-01-26 14:51 ` Christoph Hellwig 2016-01-26 15:28 ` Tejun Heo 2016-01-26 15:28 ` Tejun Heo 2016-01-26 16:41 ` Christoph Hellwig 2016-01-26 16:41 ` Christoph Hellwig 2016-01-20 10:53 ` Peter Zijlstra 2016-01-20 10:53 ` Peter Zijlstra 2016-01-21 8:23 ` Christian Borntraeger 2016-01-21 8:23 ` Christian Borntraeger 2016-01-21 9:27 ` Peter Zijlstra 2016-01-21 9:27 ` Peter Zijlstra 2016-01-15 16:40 ` Tejun Heo 2016-01-15 16:40 ` Tejun Heo 2016-01-19 17:18 ` [PATCH cgroup/for-4.5-fixes] cpuset: make mm migration asynchronous Tejun Heo 2016-01-19 17:18 ` Tejun Heo 2016-01-22 14:24 ` Christian Borntraeger 2016-01-22 15:22 ` Tejun Heo 2016-01-22 15:45 ` Christian Borntraeger 2016-01-22 15:45 ` Christian Borntraeger 2016-01-22 15:47 ` Tejun Heo 2016-01-22 15:23 ` Tejun Heo 2016-01-22 15:23 ` Tejun Heo 2016-01-21 20:31 ` [PATCH 1/2] cgroup: make sure a parent css isn't offlined before its children Tejun Heo 2016-01-21 20:31 ` Tejun Heo 2016-01-21 20:32 ` [PATCH 2/2] cgroup: make sure a parent css isn't freed " Tejun Heo 2016-01-22 15:45 ` Tejun Heo [this message] 2016-01-22 15:45 ` [PATCH v2 " Tejun Heo 2016-01-21 21:24 ` [PATCH 1/2] cgroup: make sure a parent css isn't offlined " Peter Zijlstra 2016-01-21 21:24 ` Peter Zijlstra 2016-01-21 21:28 ` Tejun Heo 2016-01-21 21:28 ` Tejun Heo 2016-01-22 8:18 ` Christian Borntraeger 2016-02-29 11:13 ` [tip:sched/core] sched/cgroup: Fix cgroup entity load tracking tear-down tip-bot for Peter Zijlstra 2016-01-22 15:45 ` [PATCH v2 1/2] cgroup: make sure a parent css isn't offlined before its children Tejun Heo 2016-01-22 15:45 ` Tejun Heo 2016-01-22 15:45 ` Tejun Heo
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20160122154552.GE32380@htj.duckdns.org \ --to=tj@kernel.org \ --cc=borntraeger@de.ibm.com \ --cc=cgroups@vger.kernel.org \ --cc=hannes@cmpxchg.org \ --cc=kernel-team@fb.com \ --cc=kvm@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-s390@vger.kernel.org \ --cc=lizefan@huawei.com \ --cc=oleg@redhat.com \ --cc=paulmck@linux.vnet.ibm.com \ --cc=peterz@infradead.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.