All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 -mmotm 1/4] cgroups: Fix race between userspace and kernelspace
@ 2010-02-22 15:43 Kirill A. Shutemov
  0 siblings, 0 replies; 6+ messages in thread
From: Kirill A. Shutemov @ 2010-02-22 15:43 UTC (permalink / raw)
  To: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	linux-mm-Bw31MaZKKs3YtjvyW6yDsg
  Cc: Daisuke Nishimura, Dan Malek, Paul Menage, Balbir Singh,
	Andrew Morton, Pavel Emelyanov

eventfd are used to notify about two types of event:
 - control file-specific, like crossing memory threshold;
 - cgroup removing.

To understand what really happen, userspace can check if the cgroup
still exists. To avoid race beetween userspace and kernelspace we have
to notify userspace about cgroup removing only after rmdir of cgroup
directory.

Signed-off-by: Kirill A. Shutemov <kirill-oKw7cIdHH8eLwutG50LtGA@public.gmane.org>
Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
---
 kernel/cgroup.c |   32 +++++++++++++++++---------------
 1 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index ce9008f..46903cb 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -780,28 +780,15 @@ static struct inode *cgroup_new_inode(mode_t mode, struct super_block *sb)
 static int cgroup_call_pre_destroy(struct cgroup *cgrp)
 {
 	struct cgroup_subsys *ss;
-	struct cgroup_event *event, *tmp;
 	int ret = 0;
 
 	for_each_subsys(cgrp->root, ss)
 		if (ss->pre_destroy) {
 			ret = ss->pre_destroy(ss, cgrp);
 			if (ret)
-				goto out;
+				break;
 		}
 
-	/*
-	 * Unregister events and notify userspace.
-	 */
-	spin_lock(&cgrp->event_list_lock);
-	list_for_each_entry_safe(event, tmp, &cgrp->event_list, list) {
-		list_del(&event->list);
-		eventfd_signal(event->eventfd, 1);
-		schedule_work(&event->remove);
-	}
-	spin_unlock(&cgrp->event_list_lock);
-
-out:
 	return ret;
 }
 
@@ -2991,7 +2978,6 @@ static void cgroup_event_remove(struct work_struct *work)
 	event->cft->unregister_event(cgrp, event->cft, event->eventfd);
 
 	eventfd_ctx_put(event->eventfd);
-	remove_wait_queue(event->wqh, &event->wait);
 	kfree(event);
 }
 
@@ -3009,6 +2995,7 @@ static int cgroup_event_wake(wait_queue_t *wait, unsigned mode,
 	unsigned long flags = (unsigned long)key;
 
 	if (flags & POLLHUP) {
+		remove_wait_queue_locked(event->wqh, &event->wait);
 		spin_lock(&cgrp->event_list_lock);
 		list_del(&event->list);
 		spin_unlock(&cgrp->event_list_lock);
@@ -3457,6 +3444,7 @@ static int cgroup_rmdir(struct inode *unused_dir, struct dentry *dentry)
 	struct dentry *d;
 	struct cgroup *parent;
 	DEFINE_WAIT(wait);
+	struct cgroup_event *event, *tmp;
 	int ret;
 
 	/* the vfs holds both inode->i_mutex already */
@@ -3540,6 +3528,20 @@ again:
 	set_bit(CGRP_RELEASABLE, &parent->flags);
 	check_for_release(parent);
 
+	/*
+	 * Unregister events and notify userspace.
+	 * Notify userspace about cgroup removing only after rmdir of cgroup
+	 * directory to avoid race between userspace and kernelspace
+	 */
+	spin_lock(&cgrp->event_list_lock);
+	list_for_each_entry_safe(event, tmp, &cgrp->event_list, list) {
+		list_del(&event->list);
+		remove_wait_queue(event->wqh, &event->wait);
+		eventfd_signal(event->eventfd, 1);
+		schedule_work(&event->remove);
+	}
+	spin_unlock(&cgrp->event_list_lock);
+
 	mutex_unlock(&cgroup_mutex);
 	return 0;
 }
-- 
1.6.6.2

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 -mmotm 1/4] cgroups: Fix race between userspace and kernelspace
       [not found] ` <1f8bd63acb6485c88f8539e009459a28fb6ad55b.1266853233.git.kirill-oKw7cIdHH8eLwutG50LtGA@public.gmane.org>
  2010-02-23  3:17   ` Li Zefan
@ 2010-02-24  7:12   ` Balbir Singh
  1 sibling, 0 replies; 6+ messages in thread
From: Balbir Singh @ 2010-02-24  7:12 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: Daisuke Nishimura,
	containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	linux-mm-Bw31MaZKKs3YtjvyW6yDsg, Dan Malek, Paul Menage,
	Andrew Morton, Pavel Emelyanov

* Kirill A. Shutemov <kirill-oKw7cIdHH8eLwutG50LtGA@public.gmane.org> [2010-02-22 17:43:39]:

> eventfd are used to notify about two types of event:
>  - control file-specific, like crossing memory threshold;
>  - cgroup removing.
> 
> To understand what really happen, userspace can check if the cgroup
> still exists. To avoid race beetween userspace and kernelspace we have
> to notify userspace about cgroup removing only after rmdir of cgroup
> directory.
> 
> Signed-off-by: Kirill A. Shutemov <kirill-oKw7cIdHH8eLwutG50LtGA@public.gmane.org>
> Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>

That does make sense, looks good to me. You've already got the
necessary acks.

-- 
	Three Cheers,
	Balbir

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 -mmotm 1/4] cgroups: Fix race between userspace and kernelspace
  2010-02-22 15:43 Kirill A. Shutemov
  2010-02-23  3:17 ` Li Zefan
       [not found] ` <1f8bd63acb6485c88f8539e009459a28fb6ad55b.1266853233.git.kirill-oKw7cIdHH8eLwutG50LtGA@public.gmane.org>
@ 2010-02-24  7:12 ` Balbir Singh
  2 siblings, 0 replies; 6+ messages in thread
From: Balbir Singh @ 2010-02-24  7:12 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: containers, linux-mm, Paul Menage, Li Zefan, Andrew Morton,
	KAMEZAWA Hiroyuki, Pavel Emelyanov, Dan Malek, Daisuke Nishimura

* Kirill A. Shutemov <kirill@shutemov.name> [2010-02-22 17:43:39]:

> eventfd are used to notify about two types of event:
>  - control file-specific, like crossing memory threshold;
>  - cgroup removing.
> 
> To understand what really happen, userspace can check if the cgroup
> still exists. To avoid race beetween userspace and kernelspace we have
> to notify userspace about cgroup removing only after rmdir of cgroup
> directory.
> 
> Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
> Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>

That does make sense, looks good to me. You've already got the
necessary acks.

-- 
	Three Cheers,
	Balbir

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 -mmotm 1/4] cgroups: Fix race between userspace and kernelspace
       [not found] ` <1f8bd63acb6485c88f8539e009459a28fb6ad55b.1266853233.git.kirill-oKw7cIdHH8eLwutG50LtGA@public.gmane.org>
@ 2010-02-23  3:17   ` Li Zefan
  2010-02-24  7:12   ` Balbir Singh
  1 sibling, 0 replies; 6+ messages in thread
From: Li Zefan @ 2010-02-23  3:17 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	Daisuke Nishimura, linux-mm-Bw31MaZKKs3YtjvyW6yDsg, Dan Malek,
	Paul Menage, Pavel Emelyanov, Andrew Morton, Balbir Singh

(Late reply for I just came back from a long vacation)

Kirill A. Shutemov wrote:
> eventfd are used to notify about two types of event:
>  - control file-specific, like crossing memory threshold;
>  - cgroup removing.
> 
> To understand what really happen, userspace can check if the cgroup
> still exists. To avoid race beetween userspace and kernelspace we have
> to notify userspace about cgroup removing only after rmdir of cgroup
> directory.
> 
> Signed-off-by: Kirill A. Shutemov <kirill-oKw7cIdHH8eLwutG50LtGA@public.gmane.org>
> Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>

Acked-by: Li Zefan <lizf-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 -mmotm 1/4] cgroups: Fix race between userspace and kernelspace
  2010-02-22 15:43 Kirill A. Shutemov
@ 2010-02-23  3:17 ` Li Zefan
       [not found] ` <1f8bd63acb6485c88f8539e009459a28fb6ad55b.1266853233.git.kirill-oKw7cIdHH8eLwutG50LtGA@public.gmane.org>
  2010-02-24  7:12 ` Balbir Singh
  2 siblings, 0 replies; 6+ messages in thread
From: Li Zefan @ 2010-02-23  3:17 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: containers, linux-mm, Paul Menage, Andrew Morton,
	KAMEZAWA Hiroyuki, Balbir Singh, Pavel Emelyanov, Dan Malek,
	Daisuke Nishimura

(Late reply for I just came back from a long vacation)

Kirill A. Shutemov wrote:
> eventfd are used to notify about two types of event:
>  - control file-specific, like crossing memory threshold;
>  - cgroup removing.
> 
> To understand what really happen, userspace can check if the cgroup
> still exists. To avoid race beetween userspace and kernelspace we have
> to notify userspace about cgroup removing only after rmdir of cgroup
> directory.
> 
> Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
> Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>

Acked-by: Li Zefan <lizf@cn.fujitsu.com>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 -mmotm 1/4] cgroups: Fix race between userspace and kernelspace
@ 2010-02-22 15:43 Kirill A. Shutemov
  2010-02-23  3:17 ` Li Zefan
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Kirill A. Shutemov @ 2010-02-22 15:43 UTC (permalink / raw)
  To: containers, linux-mm
  Cc: Paul Menage, Li Zefan, Andrew Morton, KAMEZAWA Hiroyuki,
	Balbir Singh, Pavel Emelyanov, Dan Malek, Daisuke Nishimura,
	Kirill A. Shutemov

eventfd are used to notify about two types of event:
 - control file-specific, like crossing memory threshold;
 - cgroup removing.

To understand what really happen, userspace can check if the cgroup
still exists. To avoid race beetween userspace and kernelspace we have
to notify userspace about cgroup removing only after rmdir of cgroup
directory.

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
---
 kernel/cgroup.c |   32 +++++++++++++++++---------------
 1 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index ce9008f..46903cb 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -780,28 +780,15 @@ static struct inode *cgroup_new_inode(mode_t mode, struct super_block *sb)
 static int cgroup_call_pre_destroy(struct cgroup *cgrp)
 {
 	struct cgroup_subsys *ss;
-	struct cgroup_event *event, *tmp;
 	int ret = 0;
 
 	for_each_subsys(cgrp->root, ss)
 		if (ss->pre_destroy) {
 			ret = ss->pre_destroy(ss, cgrp);
 			if (ret)
-				goto out;
+				break;
 		}
 
-	/*
-	 * Unregister events and notify userspace.
-	 */
-	spin_lock(&cgrp->event_list_lock);
-	list_for_each_entry_safe(event, tmp, &cgrp->event_list, list) {
-		list_del(&event->list);
-		eventfd_signal(event->eventfd, 1);
-		schedule_work(&event->remove);
-	}
-	spin_unlock(&cgrp->event_list_lock);
-
-out:
 	return ret;
 }
 
@@ -2991,7 +2978,6 @@ static void cgroup_event_remove(struct work_struct *work)
 	event->cft->unregister_event(cgrp, event->cft, event->eventfd);
 
 	eventfd_ctx_put(event->eventfd);
-	remove_wait_queue(event->wqh, &event->wait);
 	kfree(event);
 }
 
@@ -3009,6 +2995,7 @@ static int cgroup_event_wake(wait_queue_t *wait, unsigned mode,
 	unsigned long flags = (unsigned long)key;
 
 	if (flags & POLLHUP) {
+		remove_wait_queue_locked(event->wqh, &event->wait);
 		spin_lock(&cgrp->event_list_lock);
 		list_del(&event->list);
 		spin_unlock(&cgrp->event_list_lock);
@@ -3457,6 +3444,7 @@ static int cgroup_rmdir(struct inode *unused_dir, struct dentry *dentry)
 	struct dentry *d;
 	struct cgroup *parent;
 	DEFINE_WAIT(wait);
+	struct cgroup_event *event, *tmp;
 	int ret;
 
 	/* the vfs holds both inode->i_mutex already */
@@ -3540,6 +3528,20 @@ again:
 	set_bit(CGRP_RELEASABLE, &parent->flags);
 	check_for_release(parent);
 
+	/*
+	 * Unregister events and notify userspace.
+	 * Notify userspace about cgroup removing only after rmdir of cgroup
+	 * directory to avoid race between userspace and kernelspace
+	 */
+	spin_lock(&cgrp->event_list_lock);
+	list_for_each_entry_safe(event, tmp, &cgrp->event_list, list) {
+		list_del(&event->list);
+		remove_wait_queue(event->wqh, &event->wait);
+		eventfd_signal(event->eventfd, 1);
+		schedule_work(&event->remove);
+	}
+	spin_unlock(&cgrp->event_list_lock);
+
 	mutex_unlock(&cgroup_mutex);
 	return 0;
 }
-- 
1.6.6.2

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-02-24  7:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-22 15:43 [PATCH v2 -mmotm 1/4] cgroups: Fix race between userspace and kernelspace Kirill A. Shutemov
2010-02-22 15:43 Kirill A. Shutemov
2010-02-23  3:17 ` Li Zefan
     [not found] ` <1f8bd63acb6485c88f8539e009459a28fb6ad55b.1266853233.git.kirill-oKw7cIdHH8eLwutG50LtGA@public.gmane.org>
2010-02-23  3:17   ` Li Zefan
2010-02-24  7:12   ` Balbir Singh
2010-02-24  7:12 ` Balbir Singh

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.