From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754162AbcE3Hn5 (ORCPT ); Mon, 30 May 2016 03:43:57 -0400 Received: from mga01.intel.com ([192.55.52.88]:48767 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751137AbcE3Hn4 (ORCPT ); Mon, 30 May 2016 03:43:56 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,388,1459839600"; d="scan'208";a="977106344" Subject: Re: [PATCH] mutex: Report recursive ww_mutex locking early To: Chris Wilson , Peter Zijlstra , Ingo Molnar References: <1464251487-23778-1-git-send-email-chris@chris-wilson.co.uk> <1464293297-19777-1-git-send-email-chris@chris-wilson.co.uk> Cc: intel-gfx@lists.freedesktop.org, =?UTF-8?Q?Christian_K=c3=b6nig?= , linux-kernel@vger.kernel.org From: Maarten Lankhorst Message-ID: <4271f89a-ab98-2d97-fccb-3527931597ec@linux.intel.com> Date: Mon, 30 May 2016 09:43:53 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.0 MIME-Version: 1.0 In-Reply-To: <1464293297-19777-1-git-send-email-chris@chris-wilson.co.uk> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Op 26-05-16 om 22:08 schreef Chris Wilson: > 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. > > Testcase: igt/kms_cursor_legacy > Suggested-by: Maarten Lankhorst > Signed-off-by: Chris Wilson > Cc: Peter Zijlstra > Cc: Ingo Molnar > Cc: Christian König > Cc: Maarten Lankhorst > Cc: linux-kernel@vger.kernel.org > --- > > Maarten suggested this as a simpler fix to the immediate problem. Imo, > we still want to perform deadlock detection within the spin in order to > catch more complicated deadlocks without osq_lock() forcing fairness! Reviewed-by: Maarten Lankhorst Should this be Cc: stable@vger.kernel.org ? I think in the normal case things would move forward even with osq_lock, but you can make a separate patch to add it to mutex_can_spin_on_owner, with the same comment as in mutex_optimistic_spin. > --- > 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 d60f1ba3e64f..1659398dc8f8 100644 > --- a/kernel/locking/mutex.c > +++ b/kernel/locking/mutex.c > @@ -502,9 +502,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 > @@ -530,6 +527,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); >