From: Peter Zijlstra <peterz@infradead.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: Ilya Dryomov <ilya.dryomov@inktank.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Ceph Development <ceph-devel@vger.kernel.org>,
davidlohr@hp.com, jason.low2@hp.com
Subject: Re: [PATCH] locking/mutexes: Revert "locking/mutexes: Add extra reschedule point"
Date: Thu, 31 Jul 2014 15:56:16 +0200 [thread overview]
Message-ID: <20140731135616.GU19379@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <20140731134411.GA12050@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2010 bytes --]
On Thu, Jul 31, 2014 at 03:44:11PM +0200, Ingo Molnar wrote:
>
> > diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
> > index ae712b25e492..3d726fdaa764 100644
> > --- a/kernel/locking/mutex.c
> > +++ b/kernel/locking/mutex.c
> > @@ -473,8 +473,12 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
> > * reschedule now, before we try-lock the mutex. This avoids getting
> > * scheduled out right after we obtained the mutex.
> > */
> > - if (need_resched())
> > + if (need_resched()) {
> > + if (WARN_ON_ONCE(current->state != TASK_RUNNING))
> > + __set_current_state(TASK_RUNNING);
> > +
> > schedule_preempt_disabled();
> > + }
>
> Might make sense to add that debug check under mutex debugging or so,
> with a sensible kernel message printed.
Something like so? I suppose we should do a similar one for rwsem,
semaphores and possibly wait_event*() too.
---
Subject: locking/mutex: Add debug check for task state
Calling blocking locks with current->state != TASK_RUNNING is a bug.
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
---
kernel/locking/mutex.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
index ae712b25e492..d5daf8c38899 100644
--- a/kernel/locking/mutex.c
+++ b/kernel/locking/mutex.c
@@ -375,6 +375,17 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
unsigned long flags;
int ret;
+#ifdef CONFIG_DEBUG_MUTEXES
+ /*
+ * Blocking primitives (including this one) will set (and therefore
+ * destroy) current->state, since we will exit with TASK_RUNNING
+ * make sure we enter with it, otherwise we will destroy state.
+ */
+ if (WARN_ONCE(current->state != TASK_RUNNING,
+ "do not call blocking locks when !TASK_RUNNING\n"))
+ __set_current_state(TASK_RUNNING);
+#endif
+
preempt_disable();
mutex_acquire_nest(&lock->dep_map, subclass, 0, nest_lock, ip);
[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]
next prev parent reply other threads:[~2014-07-31 13:56 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-31 10:16 [PATCH] locking/mutexes: Revert "locking/mutexes: Add extra reschedule point" Ilya Dryomov
2014-07-31 11:57 ` Peter Zijlstra
2014-07-31 12:37 ` Ilya Dryomov
2014-07-31 13:13 ` Peter Zijlstra
2014-07-31 13:25 ` Ilya Dryomov
2014-07-31 13:44 ` Ingo Molnar
2014-07-31 13:56 ` Peter Zijlstra [this message]
2014-08-02 20:04 ` [RFC][PATCH] locking: Debug nested wait/locking primitives Peter Zijlstra
2014-07-31 14:30 ` [PATCH] locking/mutexes: Revert "locking/mutexes: Add extra reschedule point" Mike Galbraith
2014-07-31 14:37 ` Ilya Dryomov
2014-07-31 14:39 ` Peter Zijlstra
2014-08-01 12:56 ` Ilya Dryomov
2014-08-01 13:27 ` Peter Zijlstra
2014-08-01 13:50 ` Ilya Dryomov
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=20140731135616.GU19379@twins.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=ceph-devel@vger.kernel.org \
--cc=davidlohr@hp.com \
--cc=ilya.dryomov@inktank.com \
--cc=jason.low2@hp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
/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