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]
Message-ID: <20111206032754.GA17091@zhy>
Date:	Tue, 6 Dec 2011 11:27:54 +0800
From:	Yong Zhang <yong.zhang0@...il.com>
To:	"Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>
Cc:	linux-kernel@...r.kernel.org, mingo@...e.hu, laijs@...fujitsu.com,
	dipankar@...ibm.com, akpm@...ux-foundation.org,
	mathieu.desnoyers@...ymtl.ca, josh@...htriplett.org,
	niv@...ibm.com, tglx@...utronix.de, peterz@...radead.org,
	rostedt@...dmis.org, Valdis.Kletnieks@...edu, dhowells@...hat.com,
	eric.dumazet@...il.com, darren@...art.com, patches@...aro.org
Subject: [PATCH 1/3] kernel.h: sched: introduce might_sleep_disabled()

Since commit [5342e269: rcu: Permit rt_mutex_unlock() with
irqs disabled], rt_mutex_lock() could be called with irqs
disabled and it will call might_sleep() unconditionally.
To prevent this kind of false positive, introduce
might_sleep_disabled() which will be used in later patch.

Signed-off-by: Yong Zhang <yong.zhang0@...il.com>
---
 include/linux/kernel.h |   25 +++++++++++++++++++++----
 include/linux/sched.h  |   14 +++++++-------
 kernel/sched.c         |    6 ++++--
 3 files changed, 32 insertions(+), 13 deletions(-)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index e8b1597..deaba68 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -130,7 +130,8 @@ extern int _cond_resched(void);
 #endif
 
 #ifdef CONFIG_DEBUG_ATOMIC_SLEEP
-  void __might_sleep(const char *file, int line, int preempt_offset);
+  void __might_sleep(const char *file, int line, int preempt_offset,
+					bool warn_irqs);
 /**
  * might_sleep - annotation for functions that can sleep
  *
@@ -141,12 +142,28 @@ extern int _cond_resched(void);
  * be bitten later when the calling function happens to sleep when it is not
  * supposed to.
  */
-# define might_sleep() \
-	do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0)
+# define might_sleep()						\
+	do {							\
+		__might_sleep(__FILE__, __LINE__, 0, true);	\
+		might_resched(); }				\
+	while (0)
+
+/*
+ * Special version of might_sleep() which don't warn when called
+ * with irq disabled. Will be used in rt_mutex_lock() which
+ * could be called with irq disabled.
+ */
+# define might_sleep_irqdisabled()						\
+	do {							\
+		__might_sleep(__FILE__, __LINE__, 0, false);	\
+		might_resched(); }				\
+	while (0)
+
 #else
   static inline void __might_sleep(const char *file, int line,
-				   int preempt_offset) { }
+		int preempt_offset, bool warn_irqs) { }
 # define might_sleep() do { might_resched(); } while (0)
+# define might_sleep_irqdisabled() do { might_resched(); } while (0)
 #endif
 
 #define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 4a7e4d3..d077c62 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -2534,9 +2534,9 @@ static inline int need_resched(void)
  */
 extern int _cond_resched(void);
 
-#define cond_resched() ({			\
-	__might_sleep(__FILE__, __LINE__, 0);	\
-	_cond_resched();			\
+#define cond_resched() ({				\
+	__might_sleep(__FILE__, __LINE__, 0, true);	\
+	_cond_resched();				\
 })
 
 extern int __cond_resched_lock(spinlock_t *lock);
@@ -2547,15 +2547,15 @@ extern int __cond_resched_lock(spinlock_t *lock);
 #define PREEMPT_LOCK_OFFSET	0
 #endif
 
-#define cond_resched_lock(lock) ({				\
-	__might_sleep(__FILE__, __LINE__, PREEMPT_LOCK_OFFSET);	\
-	__cond_resched_lock(lock);				\
+#define cond_resched_lock(lock) ({					\
+	__might_sleep(__FILE__, __LINE__, PREEMPT_LOCK_OFFSET, true);	\
+	__cond_resched_lock(lock);					\
 })
 
 extern int __cond_resched_softirq(void);
 
 #define cond_resched_softirq() ({					\
-	__might_sleep(__FILE__, __LINE__, SOFTIRQ_DISABLE_OFFSET);	\
+	__might_sleep(__FILE__, __LINE__, SOFTIRQ_DISABLE_OFFSET, true);\
 	__cond_resched_softirq();					\
 })
 
diff --git a/kernel/sched.c b/kernel/sched.c
index 0e9344a..ce24450 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -8363,12 +8363,14 @@ static inline int preempt_count_equals(int preempt_offset)
 	return (nested == preempt_offset);
 }
 
-void __might_sleep(const char *file, int line, int preempt_offset)
+void __might_sleep(const char *file, int line, int preempt_offset,
+		   bool warn_irqs)
 {
 	static unsigned long prev_jiffy;	/* ratelimiting */
 
 	rcu_sleep_check(); /* WARN_ON_ONCE() by default, no rate limit reqd. */
-	if ((preempt_count_equals(preempt_offset) && !irqs_disabled()) ||
+	if ((preempt_count_equals(preempt_offset) &&
+	    (warn_irqs ? !irqs_disabled() : 1)) ||
 	    system_state != SYSTEM_RUNNING || oops_in_progress)
 		return;
 	if (time_before(jiffies, prev_jiffy + HZ) && prev_jiffy)
-- 
1.7.5.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