Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp3069948ybd; Fri, 28 Jun 2019 02:17:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqw3xKn6IXThBC41q5cIfdY6La5ZnRNR1ZqQmfdClBco/OaiUrFDoo7yDUC3hJ4bRJRTcBXZ X-Received: by 2002:a17:902:4aa3:: with SMTP id x32mr9826748pld.119.1561713478706; Fri, 28 Jun 2019 02:17:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561713478; cv=none; d=google.com; s=arc-20160816; b=t1LqtlVgF66FYxYi00JpjqSwNTNEX7uinf0GAPWXLpb99wpPllj5xB9PGGSG92ZzkF iIvwxnpzuxesNNAmsxZvMGN2WYDeY4wJdDzrT7Igx3C+GVWgowbHJzhH53zCN/33Zsda QC4NN/kCmoBQvmepJ/vBKFn4k9xEdFLwniJJImrIjxkmtbIpHDQ8qfKyGFQIjsQ2ohAP 7u3tgNkiEVQ4jAaRJRpEw9rNikGKLnQsDB5A8Gxmlr3si+dBRu6kJnP4FwSZrQ/C1kcR m3PU00zzyRoFboW7Fjs35z25ciXPqaul5Sp5mjG1TMe7WbAs3DTl3qPl1jp8FFhWIQAv 4HBQ== 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=qDxcVFqFgNNkV3TIcGqu0JHYgpA2EGWmwa8AL4oBEUs=; b=U5ABMdWg0WXB/Z4vWyxiglTUmYgOqJ617hWaNut2EUrQC6c46Yed/JTzXsDytMQrEC oGfdOoTNb00paNY2kCXPuWwMNi0Vm/o17CwC1cVA8vbSiLRc01LJdajubLY07iJKvv8Y +x0qubbyX+75LDYsNIp1Di02TuFrhKZzEKuP/ZrN34Zdw1PN9O9Oi8E3HcAIvObVqLm9 KD85DUhWtu/m7wr0ynrBAE7mYXn6lS74jhqZkNUub1m+FjipvOWkR1cS1wRjWqfXqKlq 35bU69UGrd4HvrGJm+DoGI+9egr5mSS7uP5bQejpd4+rlFqjnnRoF28RgxcNuArPhFoz HMYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hBzUoTfd; 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 x29si1762304pgk.528.2019.06.28.02.17.42; Fri, 28 Jun 2019 02:17: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=hBzUoTfd; 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 S1727026AbfF1JRB (ORCPT + 99 others); Fri, 28 Jun 2019 05:17:01 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:42638 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726837AbfF1JRA (ORCPT ); Fri, 28 Jun 2019 05:17:00 -0400 Received: by mail-pg1-f196.google.com with SMTP id k13so2310123pgq.9 for ; Fri, 28 Jun 2019 02:17:00 -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=qDxcVFqFgNNkV3TIcGqu0JHYgpA2EGWmwa8AL4oBEUs=; b=hBzUoTfd1DMRkBLiGUpfNnEjGd+L/NQxbeKO9MsEQK0fKkLsvMNLYAywU0IBNG3Ij+ 0V0wanIf3XZE+y7LDNAOJPWztRkUTvUQk8XWh191ie5PoXSF5IkBsWd6vc/DGQrdYsMn JUV9ToR23J6OBNb5Y0VKmcpjTyfS9JRZvsCFmnOmmdCSUfv8esvFk56FNtFKyfLiA79p GMGEkP63+Pwy74sZ6g89gbQo9AjnrSDOoJEQrqdr2aIh/+7h+6IoDwAq0jSwl+gasgS3 VlBFh6ENW0TXjVP5bnUaogWa4iaZ5iMejp2tyu/WnNDbJKF+3o+66dL1aLdLKxAs5E4m ELgw== 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=qDxcVFqFgNNkV3TIcGqu0JHYgpA2EGWmwa8AL4oBEUs=; b=fjk9GnUYaHFpF87aybF40vVgKriqI57mcFGfdNigt91HssR6wjP/b3VuhfmtejvML1 VZGtfoMJTMgh2KmpHFfJMoN9CYviDN2xzsa6caRfSGvS5efMW5a9Tz0PIrWS3i3J8H8y WRA+fK4NbfreAk/FpYKJq9kdECjPKpKJ6phJ8qgp1pCiJ6zNaMtHiq/E6xHQYhsmV4Hx E9Ge5ttGew/SsWmAGa52eJnzIbm0iR7qDu8nvcJrBUignnz5nhwTeAPnG9ofDl5yXcBE bhCKuJcGXGf2h52FRcXSgm6eAwAQbOqNI5j/BZBCREEpcGF+znu4k3Jm/q8ujIO1yffb Se2w== X-Gm-Message-State: APjAAAWDzuVKWynOkkRoJuOENa2Ul9oSeSpRqq6ObThI4awWjDxdM4en hqvyXfLfXme/rkRikc6ErPM= X-Received: by 2002:a17:90a:cb01:: with SMTP id z1mr11727842pjt.93.1561713419987; Fri, 28 Jun 2019 02:16:59 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id x65sm1754521pfd.139.2019.06.28.02.16.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Jun 2019 02:16:59 -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, longman@redhat.com, paulmck@linux.vnet.ibm.com, boqun.feng@gmail.com, Yuyang Du Subject: [PATCH v3 17/30] locking/lockdep: Add read-write type for a lock dependency Date: Fri, 28 Jun 2019 17:15:15 +0800 Message-Id: <20190628091528.17059-18-duyuyang@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: <20190628091528.17059-1-duyuyang@gmail.com> References: <20190628091528.17059-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 Direct dependencies need to keep track of their read-write lock types. Two bit fields, which share the distance field, are added to lock_list struct so the types are stored there. With a dependecy lock1 -> lock2, lock_type1 has the type for lock1 and lock_type2 has the type for lock2, where the values are one of the lock_type enums. Signed-off-by: Yuyang Du --- include/linux/lockdep.h | 15 ++++++++++++++- kernel/locking/lockdep.c | 25 +++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h index eb26e93..fd619ac 100644 --- a/include/linux/lockdep.h +++ b/include/linux/lockdep.h @@ -185,6 +185,8 @@ static inline void lockdep_copy_map(struct lockdep_map *to, to->class_cache[i] = NULL; } +#define LOCK_TYPE_BITS 2 + /* * Every lock has a list of other locks that were taken after or before * it as lock dependencies. These dependencies constitute a graph, which @@ -207,7 +209,17 @@ struct lock_list { struct list_head chains; struct lock_class *class[2]; struct lock_trace trace; - int distance; + + /* + * The lock_type fields keep track of the lock type of this + * dependency. + * + * With L1 -> L2, lock_type1 stores the lock type of L1, and + * lock_type2 stores that of L2. + */ + unsigned int lock_type1 : LOCK_TYPE_BITS, + lock_type2 : LOCK_TYPE_BITS, + distance : 32 - 2*LOCK_TYPE_BITS; /* * The parent field is used to implement breadth-first search. @@ -362,6 +374,7 @@ enum lock_type { LOCK_TYPE_WRITE = 0, LOCK_TYPE_READ, LOCK_TYPE_RECURSIVE, + NR_LOCK_TYPE, }; /* diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 3c97d71..1805017 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -1307,9 +1307,17 @@ static struct lock_list *alloc_list_entry(void) */ static int add_lock_to_list(struct lock_class *lock1, struct lock_class *lock2, unsigned long ip, int distance, - struct lock_trace *trace, struct lock_chain *chain) + struct lock_trace *trace, struct lock_chain *chain, + int lock_type1, int lock_type2) { struct lock_list *entry; + + /* + * The distance bit field in struct lock_list must be large + * enough to hold the maximum lock depth. + */ + BUILD_BUG_ON((1 << (32 - 2*LOCK_TYPE_BITS)) < MAX_LOCK_DEPTH); + /* * Lock not present yet - get a new dependency struct and * add it to the list: @@ -1322,6 +1330,8 @@ static int add_lock_to_list(struct lock_class *lock1, struct lock_class *lock2, entry->class[1] = lock2; entry->distance = distance; entry->trace = *trace; + entry->lock_type1 = lock_type1; + entry->lock_type2 = lock_type2; /* * Both allocation and removal are done under the graph lock; but @@ -1465,6 +1475,16 @@ static inline struct list_head *get_dep_list(struct lock_list *lock, int forward return &class->dep_list[forward]; } +static inline int get_lock_type1(struct lock_list *lock) +{ + return lock->lock_type1; +} + +static inline int get_lock_type2(struct lock_list *lock) +{ + return lock->lock_type2; +} + /* * Forward- or backward-dependency search, used for both circular dependency * checking and hardirq-unsafe/softirq-unsafe checking. @@ -2503,7 +2523,8 @@ static inline void inc_chains(void) * dependency list of the previous lock : */ ret = add_lock_to_list(hlock_class(prev), hlock_class(next), - next->acquire_ip, distance, trace, chain); + next->acquire_ip, distance, trace, chain, + prev->read, next->read); if (!ret) return 0; -- 1.8.3.1