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:	Thu,  7 Mar 2013 20:37:13 -0800
From:	Michel Lespinasse <walken@...gle.com>
To:	Oleg Nesterov <oleg@...hat.com>,
	David Howells <dhowells@...hat.com>,
	Thomas Gleixner <tglx@...utronix.de>
Cc:	torvalds@...ux-foundation.org, akpm@...ux-foundation.org,
	linux-kernel@...r.kernel.org
Subject: [RFC PATCH 1/5] kernel: add tasklist_{read,write}_lock{,_any} helper functions

Add tasklist_{read,write}_lock{,_any} functions to acquire/release the
tasklist_lock.

The _any variants may be called from any context, while the others must
be called from process context only.

One of the objectives here is to add explicit annotations for this.
If the call sites for the _any variants could be eliminated somehow,
all remaining tasklist_lock acquisitions would be in process context
so we wouldn't have to use an unfair rwlock_t implementation anymore.

Signed-off-by: Michel Lespinasse <walken@...gle.com>

---
 include/linux/sched.h | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index ac8dbca5ea15..4eb58b796261 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -218,6 +218,7 @@ extern char ___assert_task_state[1 - 2*!!(
 #define TASK_COMM_LEN 16
 
 #include <linux/spinlock.h>
+#include <linux/hardirq.h>
 
 /*
  * This serializes "schedule()" and also protects
@@ -228,6 +229,43 @@ extern char ___assert_task_state[1 - 2*!!(
 extern rwlock_t tasklist_lock;
 extern spinlock_t mmlist_lock;
 
+static inline void tasklist_write_lock(void)
+{
+	WARN_ON_ONCE(in_serving_softirq() || in_irq() || in_nmi());
+	write_lock_irq(&tasklist_lock);
+}
+
+static inline void tasklist_write_unlock(void)
+{
+	write_unlock_irq(&tasklist_lock);
+}
+
+static inline void tasklist_read_lock(void)
+{
+	WARN_ON_ONCE(in_serving_softirq() || in_irq() || in_nmi());
+	read_lock(&tasklist_lock);
+}
+
+static inline void tasklist_read_unlock(void)
+{
+	read_unlock(&tasklist_lock);
+}
+
+static inline void tasklist_read_lock_any(void)
+{
+	read_lock(&tasklist_lock);
+}
+
+static inline int tasklist_read_trylock_any(void)
+{
+	return read_trylock(&tasklist_lock);
+}
+
+static inline void tasklist_read_unlock_any(void)
+{
+	read_unlock(&tasklist_lock);
+}
+
 struct task_struct;
 
 #ifdef CONFIG_PROVE_RCU
-- 
1.8.1.3
--
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