Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp3071330ybd; Fri, 28 Jun 2019 02:19:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqxU+hNhWdkquW44qpsWp4knWW0t/QRj1OnoSnM98x1MoNhlPT3UQr+IQ5yI+uTSIp3jxH5j X-Received: by 2002:a17:902:a504:: with SMTP id s4mr10200070plq.117.1561713560191; Fri, 28 Jun 2019 02:19:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561713560; cv=none; d=google.com; s=arc-20160816; b=VnV5IQpANhxGUw8oqt2NjEUQN04z1iu9k63nUknirBmTZRq2EN8lYdKg1qPrHJsNRb hRmFCO5fOZzg7DqUambO29Cm3YOLOeZDJoch03jKxsMsb9vD7u7R8MkyNnWjk2LfqugO TNSG5J1k1qIFAlgQk36p3M41lGdfc0sY3OPRP5bcjIMz+F5k1Fn+DegD/i3ANkZa1vBx Hy6U5i7OiyhJIItR35z20BsVgBdi3azB/d0u8jgw0g2oPwKlxQEHyiLKS89IQU8O+eOk vNNRU2G5JyFrqgBWZHMqOvb3ec69H66j/KYPDWcxKO6f/ARjtywYvY/kI3PwOAWbtYfi xN4A== 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=HJUauKN/so7Khj/FpE4yerAjuRI4hWRsB8P/SwQ+7Do=; b=IQDxiHervtDddFRRxhXaYY/osmpJbjcOUGdPcDOvcTzqYjvIZqHsIsTaR2rBWD2jFd NUNB0bAmD+AKrJsLgdGhNMCbcyxz58mQxobewGFZmTHvGwE4ujNSpZKowxkASyg5J555 OPR2xfrN/yzjdPQqfUauYGFg68YEymrgliklw54UJq6UcM2XDWIQRma8/eV3id2ZHsUp vKQwPhuIsUg6zgd51zcUjcxJX3KC6mzke9iiTsrjjfvGFhU+4YA2N2urfbt5wMP7nPTY Fsma2j8o5IghiD81NuWDEjA0ENJfz8k4nAYlSjUvHrVM/cYP9XT1ARClXofEd4SZOB8O yXkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VTk4unz7; 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 z7si1517823pgu.224.2019.06.28.02.19.03; Fri, 28 Jun 2019 02:19:20 -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=VTk4unz7; 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 S1726524AbfF1JRM (ORCPT + 99 others); Fri, 28 Jun 2019 05:17:12 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:35522 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726601AbfF1JRJ (ORCPT ); Fri, 28 Jun 2019 05:17:09 -0400 Received: by mail-pl1-f195.google.com with SMTP id w24so2913834plp.2 for ; Fri, 28 Jun 2019 02:17:08 -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=HJUauKN/so7Khj/FpE4yerAjuRI4hWRsB8P/SwQ+7Do=; b=VTk4unz7sBDk/ccWUYysrD7fSgCff1if+nDX57Z1FQfmoBQ4OMM+P7ZbJMez4MMyN1 lOtsigCL6vlfHp/Ecz7RF6s3/7NpqHG92rC8oD59hVf3570+OsEbWUG0MHAYivcktqdl SdIeYC1/c2qKnBHWlk2llAMeSVkjSmDDPEOLnPEQjWrWBL6EFcuLYvvmM55BhYhO068z 9iyiEe3QPlThweTFVjm0yGT9EbftVVfsG2kHaMhgX8RBTCbS07lNrDu7QpDDf+bVnfU0 X8ntRPBagohy9ZCpcBHzgKlDaG2HEpgnOe7fJqjj0z2iEAUznIjvUcWKJUQUc2X93jMY 4n7A== 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=HJUauKN/so7Khj/FpE4yerAjuRI4hWRsB8P/SwQ+7Do=; b=nnDiycuQwooLDjUYKoNGs37ORzhv3caAgzPcQLvKTrYNI/3XR3PnSQ4ueK8SE0n6jA 4cRI1iyN0YPGCjaFU4yAdx73epBnEhbLefxIKZFKBHxbAI64bjDlnfXImv3cVuJe5kAh llld0Zw6swctlbVBMToH/hM3TynCnFJ6kFRAChtDDuG437Aupa+2m4QOLVk2D9L6NWCx ypUIPBKx8oLc5dwtkt7wA5wCYetIk5oJiYvywJMJ6tbSuI97+8DDIR0W8bS01EKkfW4e LWQZ0OSMPYEgSUE4AWec0cfwz0qDVwDh9taQqo/HHXI0sHeej7n/ytlLpFs0ypu4rsWj u4GA== X-Gm-Message-State: APjAAAUJdY8y5SVhKP8LLd9e2yINavpzYjXs+PbitrI2MsjIu1vQbOwP 88JLOWp76gsKwWfBhLxVjeI= X-Received: by 2002:a17:902:6b02:: with SMTP id o2mr9488821plk.99.1561713428498; Fri, 28 Jun 2019 02:17:08 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id x65sm1754521pfd.139.2019.06.28.02.17.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Jun 2019 02:17:08 -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 19/30] locking/lockdep: Update direct dependency's read-write type if it exists Date: Fri, 28 Jun 2019 17:15:17 +0800 Message-Id: <20190628091528.17059-20-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 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: 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 9fa38fb..2329add 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -1516,6 +1516,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. @@ -2511,6 +2526,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