Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp409591yba; Wed, 24 Apr 2019 03:28:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqx3fkZLUbonp23bTB5dc/ozAnsmG5lDZvEHdrPSjWPpNOFMkkw+52okaBvnzHfSwIH2f9Pp X-Received: by 2002:a17:902:e490:: with SMTP id cj16mr31908660plb.156.1556101738118; Wed, 24 Apr 2019 03:28:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556101738; cv=none; d=google.com; s=arc-20160816; b=H3UBnSUKTtJ4i6KIykKq1z7GQE8JlrH32UapADSZcYQ5vacJ5GHoDGiItRe4jRHiv2 V1agSKKkPxcfjkaS1CJdZYWRWfJhPrmBszFS+gpd19l/JvG5YS/84EBAC+1ZZ3dK/EcP Ba1VyLqyXFyn2R7Uux2NmgT7zBx1NE2UFJ4VV7Y0GqBA3zZ8Y9ASI4VnuW0KNCl0mK8g pP1EgX9cecvKHibzRfEfAaBD8DUZScqFoqqTvNsrksmBKTEBmvTji6xlcIi46f+0hcdE uuw0jJs0z4peKBJMUjVWNqTDpySNNTP45Ita3PjluQMqb2i7hE0vhscImXvP66Lp4kZK OzUA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jdQQqD+D5SVNRXrIoNn1Xj9jq/lMLPa5FtY9TZa9L2k=; b=RWXg6K0QUGBjtJszE5na5D6kw5SVbwtXH9cM3GREtCEJJae/5St/muFhrYZNRiEs1h A/QWUqNr9qs+eEsYBD7jZVVvIPCRPGLTUAkHwJYFh79hbnZXENjUKWAIaxAgAjOsADlH J8wPfBHQ/87fbujc6PTrSgUgyp9N4d90c9cB3NLcS47smbwbre1qAtx7gq/ZmFSHK4Ar VbOAaZLC4SfOMlLUpV5k4OSJyjD5hwRfDWumtlHQ7FjX1hw3W1FuYJXFAMM+gkIgpNhC ZJqgfmxBk/nGSABrgRCvTh2LBZ25rMZZsNMWDfaJ4t+xk9lxEhWFZmU9ebTXFyhM1+xS 4ExQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ETNqxi47; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c10si18883704pfg.172.2019.04.24.03.28.42; Wed, 24 Apr 2019 03:28:58 -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=@gmail.com header.s=20161025 header.b=ETNqxi47; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729199AbfDXKVX (ORCPT + 99 others); Wed, 24 Apr 2019 06:21:23 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:40104 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728530AbfDXKVR (ORCPT ); Wed, 24 Apr 2019 06:21:17 -0400 Received: by mail-pg1-f194.google.com with SMTP id d31so9165473pgl.7 for ; Wed, 24 Apr 2019 03:21:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jdQQqD+D5SVNRXrIoNn1Xj9jq/lMLPa5FtY9TZa9L2k=; b=ETNqxi47ZUZmJRnKK9t6vb+3QWKME4t1iuVeal4DrxOcREiT6dcFbs0+2XtHF0Kik3 Y+diHWzsUuHsk5407qHFFhbsQWiHGAJsr/k8aY0ZG5CgLamOmCpk9+U9BDvKUs1trHqK f74RXqf4z6Hmr9Kd9K+U4StyL9eejJZ5iwR/tMzwaU6qbwHjZeozggexUwnujeo6QLAY 3A1TbB1pHPV3q+2+w8gfEIDmbojmPSpDHMTFvgrAUxZYBN/jOubXExp8DDFCE30j3Oux XgdOMK9Q9coYjU/zBoaGvxZRVtb05x0Anuz53/vmCaXJ4WKFzZUWabV2oi18X9Q9YljB nq+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jdQQqD+D5SVNRXrIoNn1Xj9jq/lMLPa5FtY9TZa9L2k=; b=GtusQZRZMHm6ankBB7xvBtrXKzXCriG4bEVtUjgIhgvl3NBU5275GLLTipiMB8KGCq IJvA9HGQCdEahslaFY+QZGF8ii9PieXZ6hWvl+FAK1J5kaGaelIvPn3/QaVVuE4/hVij pFL1YzyLMrt4X43mbF1XPL6zU1Tb9JSBgzR2MiZgKIHdLS99PaGd0lR1l1YLBn8+ZKDR ErVrkK8lRt6jmzHsCeKftSU42WZXzlAxkiGNXqrXi9Aj24RZyBC5CmoUb6122Lg94nKX QgHc7hEQ/gp1/Pxr76jkV3OjVRjk3WdxAb4Fwfu2JQERkBjvNLz0FGKOv2vfndF9plDk abLQ== X-Gm-Message-State: APjAAAV11q1ISxx/r9N6dNdTHw7PJ2tSGWcl2IQSHqh+x3m3+zCZ2pqh Kx2wSzM41G/6oBE3QoQZqghyAh/fdhc6gg== X-Received: by 2002:a65:6546:: with SMTP id a6mr6049907pgw.5.1556101276860; Wed, 24 Apr 2019 03:21:16 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id v19sm25051604pfn.62.2019.04.24.03.21.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Apr 2019 03:21:16 -0700 (PDT) From: Yuyang Du To: peterz@infradead.org, will.deacon@arm.com, mingo@kernel.org Cc: bvanassche@acm.org, ming.lei@redhat.com, frederic@kernel.org, tglx@linutronix.de, linux-kernel@vger.kernel.org, Yuyang Du Subject: [PATCH 16/28] locking/lockdep: Add explanation to lock usage rules in lockdep design doc Date: Wed, 24 Apr 2019 18:19:22 +0800 Message-Id: <20190424101934.51535-17-duyuyang@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: <20190424101934.51535-1-duyuyang@gmail.com> References: <20190424101934.51535-1-duyuyang@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The irq usage and lock dependency rules that if violated a deacklock may happen are explained in more detail. Signed-off-by: Yuyang Du --- 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 d5062fc..e1187d8 100644 --- a/Documentation/locking/lockdep-design.txt +++ b/Documentation/locking/lockdep-design.txt @@ -103,14 +103,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: @@ -119,15 +129,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: -- 1.8.3.1