Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3782760ybi; Mon, 29 Jul 2019 12:32:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqzgZDWlPCTHrqOrbpfYWrcKg79fh/zQQCVc9wLL5SMnb/lWezEqmpEuXH8EXvijjC3lbBHr X-Received: by 2002:a63:c118:: with SMTP id w24mr103984624pgf.347.1564428722417; Mon, 29 Jul 2019 12:32:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564428722; cv=none; d=google.com; s=arc-20160816; b=otQMnYttQYHey5B2Rs3VLjASqgA0130vxQddfja6YFvpPrYDp6M6/cYaSghtpEMeT2 cKk6XlnKKFfcVsrgEkU+OBlA3I7wLm5PsEur8IcAloQVufOM1DTqIvdpaye6xjasj6Tx /iXBFFT6DvfYVGaLYzvNLfzl2iRe4SFvMqsnESNd6hMzsLsoBwb/lvzbSRhmnXhX849U jQWvp8Vg69oKHGEH94ICXuq8k/pmdSbinKaAuHK93k1JGM+ojKbTMVfJjTLUVsx5Uw0U PbxzAyAjfSJt0GuPrcnvQvudFm5hK0tN5d+HbbTnDk1s+H2yq6oumQAoexjXkP4zx1nh 5QCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=RegRqoaTBAobQRSo6P3sML797uiXVaNJCnUTrVkrDqQ=; b=HIbbB2TY9wmNDuTzvHXzLNCv+2ii1S+RwM+nYCl/PYrd8SqCdStLmvojb9ByeFlkqS 6Sc+eCAW8IZeAiwbi0KYek2ms0T0PSKCSU2Sy5mVWiApLeZxVGJMqH8P80cvAtqC2Fre pGaIvowH1DQS4gVdqzbARAac9Z7X8lZZ/TGuZ03RwjlB7h7O8aSJAFyznjuZzDGZBTTT U0EaoOcp54AeLGzbZn4ouNPoY5Ac4K20+8/svTJH1zANMpPQ9C98evN8c1Bot3/UeWWw j2zjsd0gpU40EL5dND0qUth6uqUrgeZqHEmqpkNQ8vaKkolGuO096ax78GQTmCjVn5Vz CFsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XEMXrB9x; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cp2si27451902plb.437.2019.07.29.12.31.47; Mon, 29 Jul 2019 12:32:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XEMXrB9x; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728749AbfG2TY7 (ORCPT + 99 others); Mon, 29 Jul 2019 15:24:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:37226 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725818AbfG2TYz (ORCPT ); Mon, 29 Jul 2019 15:24:55 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 799952070B; Mon, 29 Jul 2019 19:24:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564428295; bh=7WNEyGJ2ikqqjSTeU1QkTbXK3/MsiQHU9I9QZ+4RW98=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XEMXrB9xkuFaiZNv/nwJBgQLI7jGJnd/iA8ydOPcLMnquWtdYcpZQQ6JRZ4W0t+7t 0VRKtWF5YhT5pUILcJWLtQ2OPgN50rGWmtdrn+imIt+nxrPaDg359hC3U31ZmmXZjG Kt+127+Do9U/1jJHeJMLv+BzutJK4ZFK3vCQRN0Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Imre Deak , "Peter Zijlstra (Intel)" , =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= , Linus Torvalds , Thomas Gleixner , Will Deacon , Ingo Molnar , Sasha Levin Subject: [PATCH 4.14 031/293] locking/lockdep: Fix merging of hlocks with non-zero references Date: Mon, 29 Jul 2019 21:18:42 +0200 Message-Id: <20190729190824.223012577@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190820.321094988@linuxfoundation.org> References: <20190729190820.321094988@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit d9349850e188b8b59e5322fda17ff389a1c0cd7d ] The sequence static DEFINE_WW_CLASS(test_ww_class); struct ww_acquire_ctx ww_ctx; struct ww_mutex ww_lock_a; struct ww_mutex ww_lock_b; struct ww_mutex ww_lock_c; struct mutex lock_c; ww_acquire_init(&ww_ctx, &test_ww_class); ww_mutex_init(&ww_lock_a, &test_ww_class); ww_mutex_init(&ww_lock_b, &test_ww_class); ww_mutex_init(&ww_lock_c, &test_ww_class); mutex_init(&lock_c); ww_mutex_lock(&ww_lock_a, &ww_ctx); mutex_lock(&lock_c); ww_mutex_lock(&ww_lock_b, &ww_ctx); ww_mutex_lock(&ww_lock_c, &ww_ctx); mutex_unlock(&lock_c); (*) ww_mutex_unlock(&ww_lock_c); ww_mutex_unlock(&ww_lock_b); ww_mutex_unlock(&ww_lock_a); ww_acquire_fini(&ww_ctx); (**) will trigger the following error in __lock_release() when calling mutex_release() at **: DEBUG_LOCKS_WARN_ON(depth <= 0) The problem is that the hlock merging happening at * updates the references for test_ww_class incorrectly to 3 whereas it should've updated it to 4 (representing all the instances for ww_ctx and ww_lock_[abc]). Fix this by updating the references during merging correctly taking into account that we can have non-zero references (both for the hlock that we merge into another hlock or for the hlock we are merging into). Signed-off-by: Imre Deak Signed-off-by: Peter Zijlstra (Intel) Cc: =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Will Deacon Link: https://lkml.kernel.org/r/20190524201509.9199-2-imre.deak@intel.com Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin --- kernel/locking/lockdep.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index bf694c709b96..565005a3b8f0 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -3402,17 +3402,17 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, if (depth && !cross_lock(lock)) { hlock = curr->held_locks + depth - 1; if (hlock->class_idx == class_idx && nest_lock) { - if (hlock->references) { - /* - * Check: unsigned int references:12, overflow. - */ - if (DEBUG_LOCKS_WARN_ON(hlock->references == (1 << 12)-1)) - return 0; + if (!references) + references++; + if (!hlock->references) hlock->references++; - } else { - hlock->references = 2; - } + + hlock->references += references; + + /* Overflow */ + if (DEBUG_LOCKS_WARN_ON(hlock->references < references)) + return 0; return 1; } -- 2.20.1