From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752698AbcFCKrp (ORCPT ); Fri, 3 Jun 2016 06:47:45 -0400 Received: from terminus.zytor.com ([198.137.202.10]:55904 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752087AbcFCKro (ORCPT ); Fri, 3 Jun 2016 06:47:44 -0400 Date: Fri, 3 Jun 2016 03:46:40 -0700 From: tip-bot for Chris Wilson Message-ID: Cc: chris@chris-wilson.co.uk, tglx@linutronix.de, linux-kernel@vger.kernel.org, maarten.lankhorst@linux.intel.com, peterz@infradead.org, akpm@linux-foundation.org, hpa@zytor.com, torvalds@linux-foundation.org, paulmck@linux.vnet.ibm.com, mingo@kernel.org Reply-To: akpm@linux-foundation.org, mingo@kernel.org, paulmck@linux.vnet.ibm.com, hpa@zytor.com, torvalds@linux-foundation.org, tglx@linutronix.de, chris@chris-wilson.co.uk, peterz@infradead.org, maarten.lankhorst@linux.intel.com, linux-kernel@vger.kernel.org In-Reply-To: <1464293297-19777-1-git-send-email-chris@chris-wilson.co.uk> References: <1464293297-19777-1-git-send-email-chris@chris-wilson.co.uk> To: linux-tip-commits@vger.kernel.org Subject: [tip:locking/core] locking/ww_mutex: Report recursive ww_mutex locking early Git-Commit-ID: 0422e83d84ae24b933e4b0d4c1e0f0b4ae8a0a3b X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 0422e83d84ae24b933e4b0d4c1e0f0b4ae8a0a3b Gitweb: http://git.kernel.org/tip/0422e83d84ae24b933e4b0d4c1e0f0b4ae8a0a3b Author: Chris Wilson AuthorDate: Thu, 26 May 2016 21:08:17 +0100 Committer: Ingo Molnar CommitDate: Fri, 3 Jun 2016 08:37:26 +0200 locking/ww_mutex: Report recursive ww_mutex locking early Recursive locking for ww_mutexes was originally conceived as an exception. However, it is heavily used by the DRM atomic modesetting code. Currently, the recursive deadlock is checked after we have queued up for a busy-spin and as we never release the lock, we spin until kicked, whereupon the deadlock is discovered and reported. A simple solution for the now common problem is to move the recursive deadlock discovery to the first action when taking the ww_mutex. Suggested-by: Maarten Lankhorst Signed-off-by: Chris Wilson Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Maarten Lankhorst Cc: Andrew Morton Cc: Linus Torvalds Cc: Paul E. McKenney Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: stable@vger.kernel.org Link: http://lkml.kernel.org/r/1464293297-19777-1-git-send-email-chris@chris-wilson.co.uk Signed-off-by: Ingo Molnar --- kernel/locking/mutex.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c index e364b42..79d2d76 100644 --- a/kernel/locking/mutex.c +++ b/kernel/locking/mutex.c @@ -486,9 +486,6 @@ __ww_mutex_lock_check_stamp(struct mutex *lock, struct ww_acquire_ctx *ctx) if (!hold_ctx) return 0; - if (unlikely(ctx == hold_ctx)) - return -EALREADY; - if (ctx->stamp - hold_ctx->stamp <= LONG_MAX && (ctx->stamp != hold_ctx->stamp || ctx > hold_ctx)) { #ifdef CONFIG_DEBUG_MUTEXES @@ -514,6 +511,12 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, unsigned long flags; int ret; + if (use_ww_ctx) { + struct ww_mutex *ww = container_of(lock, struct ww_mutex, base); + if (unlikely(ww_ctx == READ_ONCE(ww->ctx))) + return -EALREADY; + } + preempt_disable(); mutex_acquire_nest(&lock->dep_map, subclass, 0, nest_lock, ip);