lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Sat, 16 Mar 2013 00:50:55 +0800
From:	Lai Jiangshan <laijs@...fujitsu.com>
To:	"Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>,
	Andrew Morton <akpm@...ux-foundation.org>,
	linux-kernel@...r.kernel.org
Cc:	Lai Jiangshan <laijs@...fujitsu.com>,
	Eric Paris <eparis@...isplace.org>,
	Eric Paris <eparis@...hat.com>,
	Lino Sanfilippo <LinoSanfilippo@....de>,
	Naohiro Aota <naota@...sp.net>,
	Al Viro <viro@...iv.linux.org.uk>
Subject: [PATCH 7/9] fsnotify: use existed call_srcu()

fsnotify implements its own call_srcu() by:
	dedicated thread + synchronize_srcu()

But srcu provides call_srcu() now, so we should convert them to use
existed call_srcu() and remove the thread.

Signed-off-by: Lai Jiangshan <laijs@...fujitsu.com>
Cc: Eric Paris <eparis@...isplace.org>
---
 fs/notify/mark.c                 |   59 ++++++-------------------------------
 include/linux/fsnotify_backend.h |    2 +-
 2 files changed, 11 insertions(+), 50 deletions(-)

diff --git a/fs/notify/mark.c b/fs/notify/mark.c
index aeededc..af5f0e1 100644
--- a/fs/notify/mark.c
+++ b/fs/notify/mark.c
@@ -98,9 +98,6 @@
 #include "fsnotify.h"
 
 DEFINE_SRCU(fsnotify_mark_srcu);
-static DEFINE_SPINLOCK(destroy_lock);
-static LIST_HEAD(destroy_list);
-static DECLARE_WAIT_QUEUE_HEAD(destroy_waitq);
 
 void fsnotify_get_mark(struct fsnotify_mark *mark)
 {
@@ -116,6 +113,14 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
 	}
 }
 
+static void fsnotify_destroy_mark_rcu(struct rcu_head *rcu)
+{
+	struct fsnotify_mark *mark;
+
+	mark = container_of(rcu, struct fsnotify_mark, rcu);
+	fsnotify_put_mark(mark);
+}
+
 /*
  * Any time a mark is getting freed we end up here.
  * The caller had better be holding a reference to this mark so we don't actually
@@ -155,10 +160,7 @@ void fsnotify_destroy_mark_locked(struct fsnotify_mark *mark,
 	/* release lock temporarily */
 	mutex_unlock(&group->mark_mutex);
 
-	spin_lock(&destroy_lock);
-	list_add(&mark->destroy_list, &destroy_list);
-	spin_unlock(&destroy_lock);
-	wake_up(&destroy_waitq);
+	call_srcu(&fsnotify_mark_srcu, &mark->rcu, fsnotify_destroy_mark_rcu);
 	/*
 	 * We don't necessarily have a ref on mark from caller so the above destroy
 	 * may have actually freed it, unless this group provides a 'freeing_mark'
@@ -273,11 +275,7 @@ err:
 	atomic_dec(&group->num_marks);
 
 	spin_unlock(&mark->lock);
-
-	spin_lock(&destroy_lock);
-	list_add(&mark->destroy_list, &destroy_list);
-	spin_unlock(&destroy_lock);
-	wake_up(&destroy_waitq);
+	call_srcu(&fsnotify_mark_srcu, &mark->rcu, fsnotify_destroy_mark_rcu);
 
 	return ret;
 }
@@ -342,40 +340,3 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
 	atomic_set(&mark->refcnt, 1);
 	mark->free_mark = free_mark;
 }
-
-static int fsnotify_mark_destroy(void *ignored)
-{
-	struct fsnotify_mark *mark, *next;
-	LIST_HEAD(private_destroy_list);
-
-	for (;;) {
-		spin_lock(&destroy_lock);
-		/* exchange the list head */
-		list_replace_init(&destroy_list, &private_destroy_list);
-		spin_unlock(&destroy_lock);
-
-		synchronize_srcu(&fsnotify_mark_srcu);
-
-		list_for_each_entry_safe(mark, next, &private_destroy_list, destroy_list) {
-			list_del_init(&mark->destroy_list);
-			fsnotify_put_mark(mark);
-		}
-
-		wait_event_interruptible(destroy_waitq, !list_empty(&destroy_list));
-	}
-
-	return 0;
-}
-
-static int __init fsnotify_mark_init(void)
-{
-	struct task_struct *thread;
-
-	thread = kthread_run(fsnotify_mark_destroy, NULL,
-			     "fsnotify_mark");
-	if (IS_ERR(thread))
-		panic("unable to start fsnotify mark destruction thread.");
-
-	return 0;
-}
-device_initcall(fsnotify_mark_init);
diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
index d5b0910..3d435eb 100644
--- a/include/linux/fsnotify_backend.h
+++ b/include/linux/fsnotify_backend.h
@@ -296,7 +296,7 @@ struct fsnotify_mark {
 #define FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY	0x08
 #define FSNOTIFY_MARK_FLAG_ALIVE		0x10
 	unsigned int flags;		/* vfsmount or inode mark? */
-	struct list_head destroy_list;
+	struct rcu_head rcu;
 	void (*free_mark)(struct fsnotify_mark *mark); /* called on final put+free */
 };
 
-- 
1.7.4.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ