From patchwork Tue Dec 6 03:27:54 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong Zhang X-Patchwork-Id: 5500 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id D30F223E16 for ; Tue, 6 Dec 2011 03:28:09 +0000 (UTC) Received: from mail-lpp01m010-f52.google.com (mail-lpp01m010-f52.google.com [209.85.215.52]) by fiordland.canonical.com (Postfix) with ESMTP id 903D9A1833C for ; Tue, 6 Dec 2011 03:28:09 +0000 (UTC) Received: by lagm6 with SMTP id m6so709786lag.11 for ; Mon, 05 Dec 2011 19:28:09 -0800 (PST) Received: by 10.152.145.233 with SMTP id sx9mr7773584lab.6.1323142089135; Mon, 05 Dec 2011 19:28:09 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.152.41.198 with SMTP id h6cs294809lal; Mon, 5 Dec 2011 19:28:08 -0800 (PST) Received: by 10.50.171.3 with SMTP id aq3mr13040535igc.49.1323142086866; Mon, 05 Dec 2011 19:28:06 -0800 (PST) Received: from mail-iy0-f178.google.com (mail-iy0-f178.google.com [209.85.210.178]) by mx.google.com with ESMTPS id o5si1774727icu.76.2011.12.05.19.28.06 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 05 Dec 2011 19:28:06 -0800 (PST) Received-SPF: pass (google.com: domain of yong.zhang0@gmail.com designates 209.85.210.178 as permitted sender) client-ip=209.85.210.178; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yong.zhang0@gmail.com designates 209.85.210.178 as permitted sender) smtp.mail=yong.zhang0@gmail.com; dkim=pass (test mode) header.i=@gmail.com Received: by iabn5 with SMTP id n5so698787iab.37 for ; Mon, 05 Dec 2011 19:28:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:reply-to:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=1oCmDHK3ilEUOTre1wP0OEabcqTG0P97HjfnZ40pVXQ=; b=PkVAJaHxeNF9JoC1RdZSoEDzJZcUIlHmlJ4ZEorbVdWMYZFAAiVoAFmCwxHwpkBGjp S6p+FVsUq46G471mrTJNpcLz5k61X+OmVtU0Pw1tvTSEe8D578Cp+So+cS5kfVZ3PT0g flK3gVQPl9sv8lOXmRd2ZWSCW2S0ASpnqiONE= Received: by 10.50.135.71 with SMTP id pq7mr3782914igb.26.1323142086242; Mon, 05 Dec 2011 19:28:06 -0800 (PST) Received: from localhost ([61.148.56.138]) by mx.google.com with ESMTPS id dd36sm84141895ibb.7.2011.12.05.19.28.02 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 05 Dec 2011 19:28:05 -0800 (PST) Date: Tue, 6 Dec 2011 11:27:54 +0800 From: Yong Zhang To: "Paul E. McKenney" 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() Message-ID: <20111206032754.GA17091@zhy> Reply-To: Yong Zhang References: <20111203183417.GA18914@linux.vnet.ibm.com> <1322937282-19846-7-git-send-email-paulmck@linux.vnet.ibm.com> <20111205091924.GA28117@zhy> <20111205164505.GB2326@linux.vnet.ibm.com> <20111206012635.GA32498@zhy> <20111206021227.GO2326@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20111206021227.GO2326@linux.vnet.ibm.com> User-Agent: Mutt/1.5.21 (2010-09-15) 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 --- 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)