From: Yong Zhang <yong.zhang0@gmail.com>
To: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: linux-kernel@vger.kernel.org, mingo@elte.hu,
laijs@cn.fujitsu.com, dipankar@in.ibm.com,
akpm@linux-foundation.org, mathieu.desnoyers@polymtl.ca,
josh@joshtriplett.org, niv@us.ibm.com, tglx@linutronix.de,
peterz@infradead.org, rostedt@goodmis.org,
Valdis.Kletnieks@vt.edu, dhowells@redhat.com,
eric.dumazet@gmail.com, darren@dvhart.com, patches@linaro.org
Subject: [PATCH 1/3] kernel.h: sched: introduce might_sleep_disabled()
Date: Tue, 6 Dec 2011 11:27:54 +0800 [thread overview]
Message-ID: <20111206032754.GA17091@zhy> (raw)
In-Reply-To: <20111206021227.GO2326@linux.vnet.ibm.com>
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@gmail.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
next prev parent reply other threads:[~2011-12-06 3:28 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-03 18:34 [PATCH tip/core/rcu 0/7] Preview of fourth set of RCU changes for 3.3 Paul E. McKenney
2011-12-03 18:34 ` [PATCH RFC tip/core/rcu 1/7] rcu: Don't check irq nesting from rcu idle entry/exit Paul E. McKenney
2011-12-03 18:34 ` [PATCH RFC tip/core/rcu 2/7] rcu: Irq nesting is always 0 on rcu_enter_idle_common Paul E. McKenney
2011-12-03 18:34 ` [PATCH RFC tip/core/rcu 3/7] rcu: Keep invoking callbacks if CPU otherwise idle Paul E. McKenney
2011-12-03 18:34 ` [PATCH RFC tip/core/rcu 4/7] rcu: Adaptive dyntick-idle preparation Paul E. McKenney
2011-12-03 18:34 ` [PATCH RFC tip/core/rcu 5/7] rcu: remove redundant rcu_cpu_stall_suppress declaration Paul E. McKenney
2011-12-03 18:34 ` [PATCH RFC tip/core/rcu 6/7] driver-core/cpu: Add cpu_is_hotpluggable() for rcutorture error analysis Paul E. McKenney
2011-12-03 21:06 ` Josh Triplett
2011-12-03 23:14 ` Paul E. McKenney
2011-12-03 18:34 ` [PATCH RFC tip/core/rcu 7/7] rcu: Quiet RCU-lockdep warnings involving interrupt disabling Paul E. McKenney
2011-12-05 9:19 ` Yong Zhang
2011-12-05 16:45 ` Paul E. McKenney
2011-12-06 1:26 ` Yong Zhang
2011-12-06 2:12 ` Paul E. McKenney
2011-12-06 3:27 ` Yong Zhang [this message]
2011-12-06 3:28 ` [PATCH 2/3] rtmutex: introduce rt_mutex_lock_irqdisabled() Yong Zhang
2011-12-06 3:29 ` [PATCH 3/3] rcu: use rt_mutex_lock_irqdisabled() in rcu_boost() Yong Zhang
2011-12-06 9:52 ` [PATCH RFC tip/core/rcu 7/7] rcu: Quiet RCU-lockdep warnings involving interrupt disabling Peter Zijlstra
2011-12-06 10:05 ` Yong Zhang
2011-12-06 10:32 ` Peter Zijlstra
2011-12-06 12:26 ` Steven Rostedt
2011-12-06 16:04 ` Paul E. McKenney
2011-12-06 16:33 ` Paul E. McKenney
2011-12-06 16:56 ` Steven Rostedt
2011-12-06 17:16 ` Paul E. McKenney
2011-12-06 10:27 ` Peter Zijlstra
2011-12-06 16:11 ` Paul E. McKenney
2011-12-06 16:14 ` Peter Zijlstra
2011-12-06 16:01 ` Paul E. McKenney
2011-12-05 9:41 ` Peter Zijlstra
2011-12-05 10:03 ` Yong Zhang
2011-12-05 16:48 ` Paul E. McKenney
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=20111206032754.GA17091@zhy \
--to=yong.zhang0@gmail.com \
--cc=Valdis.Kletnieks@vt.edu \
--cc=akpm@linux-foundation.org \
--cc=darren@dvhart.com \
--cc=dhowells@redhat.com \
--cc=dipankar@in.ibm.com \
--cc=eric.dumazet@gmail.com \
--cc=josh@joshtriplett.org \
--cc=laijs@cn.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@polymtl.ca \
--cc=mingo@elte.hu \
--cc=niv@us.ibm.com \
--cc=patches@linaro.org \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
/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