Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp255597pxa; Thu, 27 Aug 2020 01:03:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy53xp0kV+vQ5tyeN/mRnEBu9BvIK780vlbO4Z2mRw95Ndnhl/1AhCAJX9yjx9o3NncPGPs X-Received: by 2002:aa7:cb0e:: with SMTP id s14mr5550501edt.225.1598515403995; Thu, 27 Aug 2020 01:03:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598515403; cv=none; d=google.com; s=arc-20160816; b=Uth49UPU/fRlebcRuEbvowx42hEAQxT6Z/ldoDA6DYi3MtWdCDqu3rUuiCsrk3+Mez V/gfVQX0M5TT9FpODPWX/+2bUXZX5N+/XoMbWvm/G6sLXW0r56JsXCdI3NlYU/8fYl3D nxrkrVkUv8PaLSPyliO/cHXyILCelnvMNPd8YKXV/43RFFUycKiiOtBDqLvRZTVYDoPZ HMX90eZu3Xm+3dVpG7d5srZQUL2+vNpA2khvOS2rSBv5hEZ3GZ0Sc16MXw+qbmLWjY53 /0iLiqjtL8SZvABu8WAV+Fhh8x1AhM5xlf9VFtg3rE5zI3orexNhef9VWSjRmjHrTh9T S8Pg== 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 :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:dkim-signature :dkim-signature:date; bh=m8Ciqs3YM2g+c8NPG6PBkKuWuAFXhMXbrMXHn1msgxo=; b=QdQ8DlGZrY7Dm6HISz6gZdvs7Dd82FmS1RPYSTm+XKYRXj0K9BlHFX20EXwwQrE7kK 9ZGeZvN8AhTPIU0vyK1i3JnNi51W58KY5g9Kb0uy5g6UK1bWHXI8jwFmb5I0Ppqx5c1Z YbxrspVXO5/Z2nZ4cGiJ5xaSZfQsVmo14bUN4OXCnB1RHbkp7H0xFiVgZV78uwA9hPhY 282ei3FLLJm8y8uHVamzXjNYkhot2zDjDHG1wyH7+J5vBGy8fNAiXjczvqU1ZdhykAgS 0agVek1Iu9VG3jSNXka7sCETeXgEgNZdchRs+tZCoNyArwK4U0aUSGN7yBXSC+q9d7Ve 2BSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linutronix.de header.s=2020 header.b="02K9v/Ea"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e4si808533ejx.444.2020.08.27.01.02.59; Thu, 27 Aug 2020 01:03:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@linutronix.de header.s=2020 header.b="02K9v/Ea"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728646AbgH0H7n (ORCPT + 99 others); Thu, 27 Aug 2020 03:59:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728375AbgH0HyV (ORCPT ); Thu, 27 Aug 2020 03:54:21 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24669C061264; Thu, 27 Aug 2020 00:54:21 -0700 (PDT) Date: Thu, 27 Aug 2020 07:54:18 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1598514859; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m8Ciqs3YM2g+c8NPG6PBkKuWuAFXhMXbrMXHn1msgxo=; b=02K9v/Ea0CLcbCRE4mWjcI7bXOjJMyoe/R6z8vE4WnBsiVd3qJBCXdqrmT3eGXhj/CtQxj Q5Wvdpu2Jk+eOa3iRZIiCSNwPR7QvljTQ0DaFcLuNSdmVnSLZn7NhP0YpC95/wHHl6/An3 X2g18xbokxMhRfl6pBb8mkI+q5hMDRbvB+KOmW278+BIa39FuJh1HFQFIkOyI9g9whecW+ 1Svv9YpuUkcGadvMrJhKYiVxoRuRDS2TcCGrTt8Hle28HkNukESCasouPeXiDQvMo7j+kH lkkamJPlz0MpidDnyFLipfqfsTmUwqnhKQIGwpiJWU9ZtN/Wx8J1Jt9klveZPQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1598514859; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m8Ciqs3YM2g+c8NPG6PBkKuWuAFXhMXbrMXHn1msgxo=; b=psnWegaYfW/gT3mykIbuwKdBqLhTojfkg28tgrgGXNGDrtKz6IUvICqeGt83IQTXoDp3vC eOr4Z6z415esaGCw== From: "tip-bot2 for Boqun Feng" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/core] lockdep: Support deadlock detection for recursive read locks in check_noncircular() Cc: Boqun Feng , "Peter Zijlstra (Intel)" , x86 , LKML In-Reply-To: <20200807074238.1632519-10-boqun.feng@gmail.com> References: <20200807074238.1632519-10-boqun.feng@gmail.com> MIME-Version: 1.0 Message-ID: <159851485875.20229.3863601787426044121.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the locking/core branch of tip: Commit-ID: 9de0c9bbcedf752e762c67f105bff342e30f9105 Gitweb: https://git.kernel.org/tip/9de0c9bbcedf752e762c67f105bff342e30f9105 Author: Boqun Feng AuthorDate: Fri, 07 Aug 2020 15:42:28 +08:00 Committer: Peter Zijlstra CommitterDate: Wed, 26 Aug 2020 12:42:05 +02:00 lockdep: Support deadlock detection for recursive read locks in check_noncircular() Currently, lockdep only has limit support for deadlock detection for recursive read locks. This patch support deadlock detection for recursive read locks. The basic idea is: We are about to add dependency B -> A in to the dependency graph, we use check_noncircular() to find whether we have a strong dependency path A -> .. -> B so that we have a strong dependency circle (a closed strong dependency path): A -> .. -> B -> A , which doesn't have two adjacent dependencies as -(*R)-> L -(S*)->. Since A -> .. -> B is already a strong dependency path, so if either B -> A is -(E*)-> or A -> .. -> B is -(*N)->, the circle A -> .. -> B -> A is strong, otherwise not. So we introduce a new match function hlock_conflict() to replace the class_equal() for the deadlock check in check_noncircular(). Signed-off-by: Boqun Feng Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20200807074238.1632519-10-boqun.feng@gmail.com --- kernel/locking/lockdep.c | 43 +++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 78cd74d..9160f1d 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -1838,10 +1838,37 @@ static inline bool class_equal(struct lock_list *entry, void *data) return entry->class == data; } +/* + * We are about to add B -> A into the dependency graph, and in __bfs() a + * strong dependency path A -> .. -> B is found: hlock_class equals + * entry->class. + * + * We will have a deadlock case (conflict) if A -> .. -> B -> A is a strong + * dependency cycle, that means: + * + * Either + * + * a) B -> A is -(E*)-> + * + * or + * + * b) A -> .. -> B is -(*N)-> (i.e. A -> .. -(*N)-> B) + * + * as then we don't have -(*R)-> -(S*)-> in the cycle. + */ +static inline bool hlock_conflict(struct lock_list *entry, void *data) +{ + struct held_lock *hlock = (struct held_lock *)data; + + return hlock_class(hlock) == entry->class && /* Found A -> .. -> B */ + (hlock->read == 0 || /* B -> A is -(E*)-> */ + !entry->only_xr); /* A -> .. -> B is -(*N)-> */ +} + static noinline void print_circular_bug(struct lock_list *this, - struct lock_list *target, - struct held_lock *check_src, - struct held_lock *check_tgt) + struct lock_list *target, + struct held_lock *check_src, + struct held_lock *check_tgt) { struct task_struct *curr = current; struct lock_list *parent; @@ -1950,13 +1977,13 @@ unsigned long lockdep_count_backward_deps(struct lock_class *class) * or not. */ static noinline enum bfs_result -check_path(struct lock_class *target, struct lock_list *src_entry, +check_path(struct held_lock *target, struct lock_list *src_entry, + bool (*match)(struct lock_list *entry, void *data), struct lock_list **target_entry) { enum bfs_result ret; - ret = __bfs_forwards(src_entry, (void *)target, class_equal, - target_entry); + ret = __bfs_forwards(src_entry, target, match, target_entry); if (unlikely(bfs_error(ret))) print_bfs_bug(ret); @@ -1983,7 +2010,7 @@ check_noncircular(struct held_lock *src, struct held_lock *target, debug_atomic_inc(nr_cyclic_checks); - ret = check_path(hlock_class(target), &src_entry, &target_entry); + ret = check_path(target, &src_entry, hlock_conflict, &target_entry); if (unlikely(ret == BFS_RMATCH)) { if (!*trace) { @@ -2021,7 +2048,7 @@ check_redundant(struct held_lock *src, struct held_lock *target) debug_atomic_inc(nr_redundant_checks); - ret = check_path(hlock_class(target), &src_entry, &target_entry); + ret = check_path(target, &src_entry, class_equal, &target_entry); if (ret == BFS_RMATCH) debug_atomic_inc(nr_redundant);