Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4155810ybi; Mon, 3 Jun 2019 06:35:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqz2sZDNRp/BQiR9K36d+q8KK5El0lB683YkTIVlOwHU7kc4FCCuOCdSs2NtIbmCOGCgk9hu X-Received: by 2002:a63:5462:: with SMTP id e34mr22510568pgm.400.1559568946794; Mon, 03 Jun 2019 06:35:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559568946; cv=none; d=google.com; s=arc-20160816; b=YFGUhIFhpgfKyoKNbHHAacLkutffvAHmgBg348qMNsrXgc3edsnIGbRfPGSivN49mh BS3xmmhXV5O/Gx1poLr8UxlOeazGp+8JSqJhO5NOhhji+G8bFJepqHMv11aNi7q6Y1me RS/eI6VBV/vD+j8Bl7ib0hQvmsCO/OmVyYbBf+RiLO9QiFZx52Z1LKnJsO5gfEhNM4SR 27U90zLJszggw+WGgKicAFrAZqboQB2h60VL/5PtAi2gfPsQOWo0dWjtQHIuMprQ6vKZ jVOI1uURKCvrxqGSDg69Q9KEud/j3nmJ9+FUKWNAuIHUPylCaIyBE4JGooutAB6k6UkN xhDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:dkim-signature:dkim-filter; bh=ID8SlhOGBycPVkbfjZfaePx7z0JmaA3ySYrLVCv5h2Q=; b=qjsMsnECRnG+ylvHJ+L7GFpRcY9/afYAN1iZWMf+uppLlsh2uFgfo0j+8Pus104mU+ 93Nin2UiKjRkIz3Z85aifY/PuW5lHubdML6ahCHxRSYbCZvDI1aLTLMT2Qy1pM3pGqKB +7PvCqOHe0no5j9seuhd2rHEgh+0zmvnP3c0+mTiAz31INqn7P35hOWvHGunc99GJbFN LFNvP8YzKrYGFcU3tstk9fJj3O+v/lM0m72fQ9EYcs2IOLMWuCx00XOmVANgUqKP24t+ Fhnj8qpvIxHdLD2UGtI/J8w6uDyGp52TYnplJgrYxFoMgplr1mZkO7hNYxmLdEaJ7y6E Z0JA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zytor.com header.s=2019051801 header.b=fkH2NLuw; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b92si15665749pjc.41.2019.06.03.06.35.29; Mon, 03 Jun 2019 06:35:46 -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=@zytor.com header.s=2019051801 header.b=fkH2NLuw; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728675AbfFCNd6 (ORCPT + 99 others); Mon, 3 Jun 2019 09:33:58 -0400 Received: from terminus.zytor.com ([198.137.202.136]:52187 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727387AbfFCNdz (ORCPT ); Mon, 3 Jun 2019 09:33:55 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x53DWePk610284 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 3 Jun 2019 06:32:40 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 terminus.zytor.com x53DWePk610284 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2019051801; t=1559568760; bh=ID8SlhOGBycPVkbfjZfaePx7z0JmaA3ySYrLVCv5h2Q=; h=Date:From:Cc:Reply-To:In-Reply-To:References:To:Subject:From; b=fkH2NLuwU01jM0tcIBcioloY5DcwROmwbK2vvygTb38iInQhaOI+g/rexV5IbTDKV nV9hXeJ3SE/vfPcfBuTtx6RwUsSPK4y9w4PSYKDn1KdVC3/L/+P95nG0IfSlrrCKu5 +3b0qtlGxjM4NOxT58Kz3PgJPfwWP+gvGiEJKUJtEJ0hxqnyGewoUCXpgbUNbynav0 WZSqHwpbnS78fVFWgqltt3oB3DMW8pWWePTpCAxg5zrYX4LDUUCkyAXVF7pVHzGF90 1J/DDsvLqKEmh6wR+Hcut1+o5XcagCA8+mb3R0ur7YAbXyFMAdeU6EK/21SjtNrOh2 tIYLhBxFzyIzQ== Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x53DWdYY610281; Mon, 3 Jun 2019 06:32:39 -0700 Date: Mon, 3 Jun 2019 06:32:39 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Imre Deak Message-ID: Cc: tglx@linutronix.de, torvalds@linux-foundation.org, will.deacon@arm.com, ville.syrjala@linux.intel.com, mingo@kernel.org, hpa@zytor.com, imre.deak@intel.com, linux-kernel@vger.kernel.org, peterz@infradead.org Reply-To: torvalds@linux-foundation.org, tglx@linutronix.de, will.deacon@arm.com, mingo@kernel.org, ville.syrjala@linux.intel.com, linux-kernel@vger.kernel.org, imre.deak@intel.com, hpa@zytor.com, peterz@infradead.org In-Reply-To: <20190524201509.9199-2-imre.deak@intel.com> References: <20190524201509.9199-2-imre.deak@intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:locking/core] locking/lockdep: Fix merging of hlocks with non-zero references Git-Commit-ID: d9349850e188b8b59e5322fda17ff389a1c0cd7d 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 X-Spam-Status: No, score=-2.4 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_96_Q,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: d9349850e188b8b59e5322fda17ff389a1c0cd7d Gitweb: https://git.kernel.org/tip/d9349850e188b8b59e5322fda17ff389a1c0cd7d Author: Imre Deak AuthorDate: Fri, 24 May 2019 23:15:09 +0300 Committer: Ingo Molnar CommitDate: Mon, 3 Jun 2019 12:32:56 +0200 locking/lockdep: Fix merging of hlocks with non-zero references 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 --- 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 6c97f67ec321..48a840adb281 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -3796,17 +3796,17 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, if (depth) { 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 2; }