From patchwork Thu Jul 31 13:56:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 4656571 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3EE289F2B8 for ; Thu, 31 Jul 2014 13:56:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8AB0320120 for ; Thu, 31 Jul 2014 13:56:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DF96A20115 for ; Thu, 31 Jul 2014 13:56:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751352AbaGaN4a (ORCPT ); Thu, 31 Jul 2014 09:56:30 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:49298 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751003AbaGaN4a (ORCPT ); Thu, 31 Jul 2014 09:56:30 -0400 Received: from dhcp-077-248-225-117.chello.nl ([77.248.225.117] helo=twins) by bombadil.infradead.org with esmtpsa (Exim 4.80.1 #2 (Red Hat Linux)) id 1XCqqJ-0003bN-18; Thu, 31 Jul 2014 13:56:27 +0000 Received: by twins (Postfix, from userid 1000) id 614EE800D019; Thu, 31 Jul 2014 15:56:16 +0200 (CEST) Date: Thu, 31 Jul 2014 15:56:16 +0200 From: Peter Zijlstra To: Ingo Molnar Cc: Ilya Dryomov , Linux Kernel Mailing List , Ceph Development , davidlohr@hp.com, jason.low2@hp.com Subject: Re: [PATCH] locking/mutexes: Revert "locking/mutexes: Add extra reschedule point" Message-ID: <20140731135616.GU19379@twins.programming.kicks-ass.net> References: <1406801797-20139-1-git-send-email-ilya.dryomov@inktank.com> <20140731115759.GS19379@twins.programming.kicks-ass.net> <20140731131331.GT19379@twins.programming.kicks-ass.net> <20140731134411.GA12050@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20140731134411.GA12050@gmail.com> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_TVD_MIME_EPI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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);