Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4447669ybi; Mon, 3 Jun 2019 11:01:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqwwL9UL7V1YkLGhX87s8FBa2KvYe4wNrkYLezElsewn1NGq3SB6LJle9xju1cxIh0EN9VjK X-Received: by 2002:aa7:8ac9:: with SMTP id b9mr24027244pfd.260.1559584891555; Mon, 03 Jun 2019 11:01:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559584891; cv=none; d=google.com; s=arc-20160816; b=CQiqQMNfOfSOs4ppA+4pDNGLxXamx7TJ5NZLD9I5NfQiEJORBjhpcSh2ipdBP/7T/Y vhrz/j7mhaBp3sYzjDmMQZfpd/15MW2AUChYKZZcLVXqEUH3d3HKyN9STrS0Is2l9Ci6 Us2wILn9bt3J98uEKlE8S0Rsc4KNOEDF1R53JfbgeQWVaxQckVA4jbPsCwZVJvpwKm9A zHfoFONSlyIyUd9p571ZewZR4zneIEilhlYa1Z9PUWbXetfeVs1meCEd5Ex32fk9wuhI ec0bGl91z2RlhlM/1E1JrlOtmPX+hKDLgSr5AehrFNhAHLmUPX2hf8jOTu6mrFjkQxTY OGTg== 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=ZJgHSBpX0kT7fL9wXKGuCVJbtoQ4uP+I8TijZxt9U0w=; b=y75eybBHPFdc+onRsj7WNeOttA7/W/dGw0Uz4ggxtbirj/Axz6NXHGu5B7aoWW17CX VeoK5Q8Zqek1hFibelzn+wL/VRKvL6GR0WfeEXdkaUgadf6lumOsOaZx9wIV0wrg0z+3 tgxXX1fRIAjUGMQ248znPWulVkE+TBNsQIiNt2AoCyhTA0O1WWSGVXKhVVnhJeIxyUSV ZNJDB5YVM5dxakzyXWrS055xbBY+ryftRqx+RZKylIZh4xBCAah7eEZtDZ1mqkEXJXOk qxVEXf2opQN1e5/iG0s+xdUKPz6pmS993+Wkvgdt4lwGVVBw9k4qO2oP2JvwvdtnX9b7 9gag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zytor.com header.s=2019051801 header.b=Fy9pcCyN; 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 d25si16143110pfn.259.2019.06.03.11.01.15; Mon, 03 Jun 2019 11:01:31 -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=Fy9pcCyN; 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 S1728418AbfFCNRb (ORCPT + 99 others); Mon, 3 Jun 2019 09:17:31 -0400 Received: from terminus.zytor.com ([198.137.202.136]:35585 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726516AbfFCNRb (ORCPT ); Mon, 3 Jun 2019 09:17:31 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x53DHK5v606187 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 3 Jun 2019 06:17:21 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 terminus.zytor.com x53DHK5v606187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2019051801; t=1559567841; bh=ZJgHSBpX0kT7fL9wXKGuCVJbtoQ4uP+I8TijZxt9U0w=; h=Date:From:Cc:Reply-To:In-Reply-To:References:To:Subject:From; b=Fy9pcCyNPhpRl8DT3wsvKPNQ3EqS1RdbbPrLvH+liy9bjDopZdKoQ3nJTKg9VgTSH iuGhTEesjYMxQLu1A+h6lVx8yxY1YWxaMvZklhD6wUe8eqRQgHTllremYDBmkNvNER uvVSff5gwa4zJS65TlWlyU4bRKqNpBMDDqkkrKcDjHu9NjxCFCQ6dUhY0uO3SLeNmR dJw9Jg9yganM6FC4y5YfhHMeLrtKzcZvuP413jO/N8CHfhAOzux2JInKPFB/mPztSO lJrMevs5YipgBLjM5oc+Wud1T2XFIMgMeKnRNINhxQQUEv+PEBq8QNqNP/1lreoL+4 AvakixOcPs6dw== Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x53DHKSp606184; Mon, 3 Jun 2019 06:17:20 -0700 Date: Mon, 3 Jun 2019 06:17:20 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Yuyang Du Message-ID: Cc: tglx@linutronix.de, mingo@kernel.org, hpa@zytor.com, torvalds@linux-foundation.org, peterz@infradead.org, linux-kernel@vger.kernel.org, duyuyang@gmail.com Reply-To: peterz@infradead.org, tglx@linutronix.de, mingo@kernel.org, hpa@zytor.com, torvalds@linux-foundation.org, duyuyang@gmail.com, linux-kernel@vger.kernel.org In-Reply-To: <20190506081939.74287-17-duyuyang@gmail.com> References: <20190506081939.74287-17-duyuyang@gmail.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:locking/core] locking/lockdep: Add explanation to lock usage rules in lockdep design doc Git-Commit-ID: 1ac4ba5ed0114bcc146d5743d97df414af25c524 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=-0.3 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_96_Q,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, FREEMAIL_FORGED_REPLYTO 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: 1ac4ba5ed0114bcc146d5743d97df414af25c524 Gitweb: https://git.kernel.org/tip/1ac4ba5ed0114bcc146d5743d97df414af25c524 Author: Yuyang Du AuthorDate: Mon, 6 May 2019 16:19:32 +0800 Committer: Ingo Molnar CommitDate: Mon, 3 Jun 2019 11:55:48 +0200 locking/lockdep: Add explanation to lock usage rules in lockdep design doc The irq usage and lock dependency rules that if violated a deacklock may happen are explained in more detail. Signed-off-by: Yuyang Du Signed-off-by: Peter Zijlstra (Intel) Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: bvanassche@acm.org Cc: frederic@kernel.org Cc: ming.lei@redhat.com Cc: will.deacon@arm.com Link: https://lkml.kernel.org/r/20190506081939.74287-17-duyuyang@gmail.com Signed-off-by: Ingo Molnar --- Documentation/locking/lockdep-design.txt | 33 ++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/Documentation/locking/lockdep-design.txt b/Documentation/locking/lockdep-design.txt index ae65758383ea..f189d130e543 100644 --- a/Documentation/locking/lockdep-design.txt +++ b/Documentation/locking/lockdep-design.txt @@ -108,14 +108,24 @@ Unused locks (e.g., mutexes) cannot be part of the cause of an error. Single-lock state rules: ------------------------ +A lock is irq-safe means it was ever used in an irq context, while a lock +is irq-unsafe means it was ever acquired with irq enabled. + A softirq-unsafe lock-class is automatically hardirq-unsafe as well. The -following states are exclusive, and only one of them is allowed to be -set for any lock-class: +following states must be exclusive: only one of them is allowed to be set +for any lock-class based on its usage: + + or + or - and - and +This is because if a lock can be used in irq context (irq-safe) then it +cannot be ever acquired with irq enabled (irq-unsafe). Otherwise, a +deadlock may happen. For example, in the scenario that after this lock +was acquired but before released, if the context is interrupted this +lock will be attempted to acquire twice, which creates a deadlock, +referred to as lock recursion deadlock. -The validator detects and reports lock usage that violate these +The validator detects and reports lock usage that violates these single-lock state rules. Multi-lock dependency rules: @@ -124,15 +134,18 @@ Multi-lock dependency rules: The same lock-class must not be acquired twice, because this could lead to lock recursion deadlocks. -Furthermore, two locks may not be taken in different order: +Furthermore, two locks can not be taken in inverse order: -> -> -because this could lead to lock inversion deadlocks. (The validator -finds such dependencies in arbitrary complexity, i.e. there can be any -other locking sequence between the acquire-lock operations, the -validator will still track all dependencies between locks.) +because this could lead to a deadlock - referred to as lock inversion +deadlock - as attempts to acquire the two locks form a circle which +could lead to the two contexts waiting for each other permanently. The +validator will find such dependency circle in arbitrary complexity, +i.e., there can be any other locking sequence between the acquire-lock +operations; the validator will still find whether these locks can be +acquired in a circular fashion. Furthermore, the following usage based lock dependencies are not allowed between any two lock-classes: