Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9929056ybi; Wed, 24 Jul 2019 12:30:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqz6iE7cEX9SWmaPbu+l1ugMsYxSDUyx8BbLIjUI9oBXpIj+DY4bmykCr1M2Qoj0FHul/l/b X-Received: by 2002:a63:6d8d:: with SMTP id i135mr82101000pgc.303.1563996636019; Wed, 24 Jul 2019 12:30:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563996636; cv=none; d=google.com; s=arc-20160816; b=dSxCqUE1SJ5PwSR8P3XCzTowW3A73wtdjhig1abcIVPTD0ITOogg7J9rKOzxrySRV9 J6TnM92UiayOmQOg+jaKSzjESDX/aZYHohWl3JhP/7Lh3ahZH7Ak4FTjPYI8AF7ELv9l U7HslaK9iB2MAOpfboBozrHK4WVxa88WHX+Gpt78IsZsSXteDKV2fcUsBDoNFGYdjV9z ZkDtY1UZIZvwxTr/hvliWwxaoB/IgQ+r/rXgLWjU9ZHF9XaXoeeFdjvTO4wMRPvb3ZuX uXe//PjY3uFe/KCQJ94KNLzT/laZx7YlFPqqru8x0+DwaTh0ZVqPW3PQHMzCn8fbBV52 a+mA== 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=q88jvSgrBCaQWNT4k5ongVKGylZCoujLTE9or2Sfxk4=; b=TitTWW/YH2eTBC3QY3RlNEiV6NAvVkOsL9ALGUvp0c07Ey1Btik5oH6295URj4vd1Y ncIsGK9hOSl3I5Bl2sdOUCtOl6MCMHZPG4WBzdDUyXK/U+GeYyNYSC5qiKhrKnrCuB2j HG2YYYt+SI1wCurH8JKKMmdJf5imwAQaTMPPh89yDkEY+mD/zI+txlb0Ij54/MjXFdwm 2yXr6IEKtzDPKnN2/ZSaeHdETs/c3tVZF6I5TRXvBH+V2y8hoInlXLwOZlFhlStwu4OE bDXuRh+DZ+tNBW5q+2eAGP0kh3tQMBpoo+oYx+J29AC9B3fnf7txiIAwMNSid+dWBQt/ oi8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="E4B68V/0"; 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 c64si14776850pje.9.2019.07.24.12.30.20; Wed, 24 Jul 2019 12:30:36 -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="E4B68V/0"; 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 S2388045AbfGXTZg (ORCPT + 99 others); Wed, 24 Jul 2019 15:25:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:42276 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727866AbfGXTZ2 (ORCPT ); Wed, 24 Jul 2019 15:25:28 -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 6A4612238C; Wed, 24 Jul 2019 19:25:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563996327; bh=2NOu5slPchyYzV3NlPXkyp2WHWzu1QJQ8C9Nnbpd33Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E4B68V/0QrXzc65s3WSKPv7BUI+4bkDmxRijSFTeT+PHSppjAodU/WjV5KwBhforz WZVQxFlsWSvqCDVABikx3OMjZW4BGEL5VkP1PmA+H5C+KSeV+VBn4YcwPbR/em83u1 wTwejOK8UAS+HThGmWooHiCL7VYoV/9G5LVhfg04= 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 5.2 058/413] locking/lockdep: Fix merging of hlocks with non-zero references Date: Wed, 24 Jul 2019 21:15:49 +0200 Message-Id: <20190724191739.482210861@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191735.096702571@linuxfoundation.org> References: <20190724191735.096702571@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 82361e1bce0f..dbc936ccf149 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -3703,17 +3703,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; } -- 2.20.1