From: Li Zefan <lizefan@huawei.com>
To: "Kirill A. Shutemov" <kirill@shutemov.name>
Cc: Tejun Heo <tj@kernel.org>, Cgroups <cgroups@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] cgroup: fix cgroup_rmdir() vs close(eventfd) race
Date: Mon, 18 Feb 2013 18:39:14 +0800 [thread overview]
Message-ID: <512204D2.6020701@huawei.com> (raw)
In-Reply-To: <20130218103613.GB3394@shutemov.name>
On 2013/2/18 18:36, Kirill A. Shutemov wrote:
> On Mon, Feb 18, 2013 at 02:12:23PM +0800, Li Zefan wrote:
>> commit 205a872bd6f9a9a09ef035ef1e90185a8245cc58 ("cgroup: fix lockdep
>> warning for event_control") solved a deadlock by introducing a new
>> bug.
>>
>> Move cgrp->event_list to a temporary list doesn't mean you can traverse
>> this list locklessly, because at the same time cgroup_event_wake() can
>> be called and remove the event from the list. The result of this race
>> is disastrous.
>>
>> We adopt the way how kvm irqfd code implements race-free event removal,
>> which is now described in the comments in cgroup_event_wake().
>>
>> Signed-off-by: Li Zefan <lizefan@huawei.com>
>> ---
>> kernel/cgroup.c | 50 ++++++++++++++++++++++++++++++++++----------------
>> 1 file changed, 34 insertions(+), 16 deletions(-)
>>
>> diff --git a/kernel/cgroup.c b/kernel/cgroup.c
>> index 26c071c..65c8101 100644
>> --- a/kernel/cgroup.c
>> +++ b/kernel/cgroup.c
>> @@ -217,6 +217,10 @@ struct cgroup_event {
>> */
>> struct list_head list;
>> /*
>> + * Need to notify userspace when this event is removed?
>> + */
>> + bool signal_on_remove;
>> + /*
>> * All fields below needed to unregister event when
>> * userspace closes eventfd.
>> */
>> @@ -3833,8 +3837,17 @@ static void cgroup_event_remove(struct work_struct *work)
>> remove);
>> struct cgroup *cgrp = event->cgrp;
>>
>> + remove_wait_queue(event->wqh, &event->wait);
>> +
>> event->cft->unregister_event(cgrp, event->cft, event->eventfd);
>>
>> + /*
>> + * If this event is to be removed due to cgroup removal,
>> + * we notify userspace.
>> + */
>> + if (event->signal_on_remove)
>> + eventfd_signal(event->eventfd, 1);
>
> It's safe to notify anyway, isn't it? Let's just drop signal_on_remove.
>
should be. just tried to be conservative to make sure I fix the bug without changing
any behavior.
> Otherwise, look good.
>
> Acked-by: Kirill A. Shutemov <kirill@shutemov.name>
>
next prev parent reply other threads:[~2013-02-18 10:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-18 6:12 [PATCH v2] cgroup: fix cgroup_rmdir() vs close(eventfd) race Li Zefan
[not found] ` <5121C647.7030608-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2013-02-18 10:36 ` Kirill A. Shutemov
2013-02-18 10:39 ` Li Zefan [this message]
2013-02-18 17:16 ` Tejun Heo
[not found] ` <20130218171647.GD17414-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2013-02-18 17:18 ` 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=512204D2.6020701@huawei.com \
--to=lizefan@huawei.com \
--cc=cgroups@vger.kernel.org \
--cc=kirill@shutemov.name \
--cc=linux-kernel@vger.kernel.org \
--cc=tj@kernel.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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox