Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1976783ybl; Thu, 29 Aug 2019 01:35:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqzzYoKLnTdXhf1wIEa2Xk5jqJYqOcEWXy206Bu6Q32c0KXVeoWzxAy9Bjj2CwunKQhUTBgB X-Received: by 2002:a17:90a:33ed:: with SMTP id n100mr8642731pjb.19.1567067759206; Thu, 29 Aug 2019 01:35:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567067759; cv=none; d=google.com; s=arc-20160816; b=J9FY9kvoH5rfOjP2TyE8ZFixeecs+imcS8J7BZl6j2pFAgYM2l3ca22ERymwwSUaDK greAvQ70w6yAMpl96nJGfSC+uh6rfLEX+6op3Xhe8JAY7UDfMoD7AekKBTNdsoBUVm/D mid5khOqwWPC3L364DJz8Oolj+0pXk2ItAgPxqhWNvHVsI326whaYieSVc7W+mc5xjes ZbSfsHcu+Cns2blHovf5KLWcy8Y6QbBsul7zGHDCIicGSEa4x3ozy5s95o7YGvLvAYkV swEJXjPQ0e5wL/awXY6WMmfCvmmO/XuUTCmBvz/cwNLtwSTPLF1OVElWUEw2H2RmiGRl uMFw== 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=ZmSNSHjFH64m7mQTqiUGyFNSFmpZt3lLAAG/sBWU8k0=; b=FYdKs5OjIuXDqALd7XBFZQjGrbtycfZRijJQ/yvJdlmZH/5CdM+u1O6JRCcTOVirNF sSOuBDJO49GlmCNsEHoWNSx1zF807llxaFc2+CJFe7VRDTzXYO6LpPxMJi7CRDWoBFTR sSN+kGBQu+xo+r5PFEA/tHeeB9XIK3x8++jLH2tGUYgRJo3MddhkUoXEGYfuByxxYvdq ZaxUFxKW+pMaaC+dSBnhMq6WBug0g5YRSbzHoPnKCQl7BwEyp0g3gZjzhJG38xOtw69h zum+EXR71KN73qMWQXv5CD0DWHJJvz5Y/F0K+CTXojhBWeDwf1ncbrn268nbFNyFyYS4 nlXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="fyiB/Oxg"; 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 f29si1947849pfq.100.2019.08.29.01.35.44; Thu, 29 Aug 2019 01:35:59 -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="fyiB/Oxg"; 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 S1727961AbfH2IdI (ORCPT + 99 others); Thu, 29 Aug 2019 04:33:08 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:46304 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727933AbfH2IdD (ORCPT ); Thu, 29 Aug 2019 04:33:03 -0400 Received: by mail-pf1-f193.google.com with SMTP id q139so1549685pfc.13 for ; Thu, 29 Aug 2019 01:33:03 -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=ZmSNSHjFH64m7mQTqiUGyFNSFmpZt3lLAAG/sBWU8k0=; b=fyiB/Oxg8WQgWvGKS91BB4dDCchEVhcC5tCtywOGuZ+CWEUtP6gp6CNS7/OupmuFdr d55sYdvHOI+DQXpbCnWg41y/HPTtHawQuzH9cpdv4i1fGOtRFl6HMZ1PjC6mO9eU30oz VInCzmiGVW3xjNrRYSlk1PvHkI6BTQnpZnqa6iM9UYvK/8ptBzF8RK2vVIqGNeD+d/d9 dd9JNN7mk8yvvSQj4nyltKv15rCtQNVNrYDugdA3NxqhppxCD8dktUod9PpmCZiIB0np 13JwhZwrXAx8VrPDqxHAsK3ltpQmE4Ia8maL2PkJnXsyrNsSYEpdSF3mgPHZxcG8jsd+ 7nsQ== 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=ZmSNSHjFH64m7mQTqiUGyFNSFmpZt3lLAAG/sBWU8k0=; b=ZTuBh6KYdVQU0li3CzShAdAmWM08x5fz4VltRIUNeA9UGEYWmfAUg5WGy++9ZVu/Yj pwB3RZgdAJUyIrSUmC1f26Oc2tvidcCWSBuXudTPDuKT+iL91Oz7zq+6pxRlxC+i+QN3 RNf8jPE3geWvJa/DHMHinD3r4bq8fx5FsW9cJ3loZ3mRRHFlxLOhmu1LEhuVD9ZV3sbm w2odEwrOiZBgOxF0mG25e36Azzl7OC9Mgaz762iC/xXzaE+UB1utFj3JLoo8OPJgV5Nh gKKAe1NHYCX+RuM1/zzP6782KTKdikoemcgpe3EuxgrWIiBMwz1gPavZFjZ8NeRmmwE4 HTkw== X-Gm-Message-State: APjAAAWB+8blZarmOTOqaloljtRSI6uUXlj42HErDMMiGztCRItBhyPC lBmraA5kZLDBoEEscTnTS5U= X-Received: by 2002:a62:4ed1:: with SMTP id c200mr9767191pfb.218.1567067583230; Thu, 29 Aug 2019 01:33:03 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id v22sm1260155pgk.69.2019.08.29.01.32.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Aug 2019 01:33:02 -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 v4 20/30] locking/lockdep: Update direct dependency's read-write type if it exists Date: Thu, 29 Aug 2019 16:31:22 +0800 Message-Id: <20190829083132.22394-21-duyuyang@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: <20190829083132.22394-1-duyuyang@gmail.com> References: <20190829083132.22394-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 When adding a dependency, if the dependency exists the dependency's read-write type will be "upgraded" if the new dependency has more exclusive lock types. The order toward more exclusiveness is: recursive read -> read -> write. Signed-off-by: Yuyang Du --- kernel/locking/lockdep.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 41cb735..eb88314 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -1588,6 +1588,21 @@ static inline int get_lock_type2(struct lock_list *lock) return lock->lock_type2; } +static inline int hlock_type(struct held_lock *hlock) +{ + return hlock->read; +} + +static inline void set_lock_type1(struct lock_list *lock, int read) +{ + lock->lock_type1 = read; +} + +static inline void set_lock_type2(struct lock_list *lock, int read) +{ + lock->lock_type2 = read; +} + /* * Forward- or backward-dependency search, used for both circular dependency * checking and hardirq-unsafe/softirq-unsafe checking. @@ -2585,6 +2600,17 @@ static inline void inc_chains(void) list_add_tail_rcu(&chain->chain_entry, &entry->chains); __set_bit(chain - lock_chains, lock_chains_in_dep); + /* + * For a direct dependency, smaller type value + * generally means more lock exlusiveness; we + * keep the more exlusive one, in other words, + * we "upgrade" the dependency if we can. + */ + if (prev->read < get_lock_type1(entry)) + set_lock_type1(entry, prev->read); + if (next->read < get_lock_type2(entry)) + set_lock_type2(entry, next->read); + if (distance == 1) entry->distance = 1; -- 1.8.3.1