Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp408199yba; Wed, 24 Apr 2019 03:27:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqz2E3zwO6WAYZ20MNWWdMerJPAtXgDdexy9oW0pXJw9JuJ4m1tOlImw09FQNRJyKJ1w1P9j X-Received: by 2002:a17:902:4643:: with SMTP id o61mr8268352pld.249.1556101638270; Wed, 24 Apr 2019 03:27:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556101638; cv=none; d=google.com; s=arc-20160816; b=dCLPFtQejed2DbWya6MfWccCSTS8zJw06Q9ntTLvZA2PIfMCAC9vztctJGv4zg7cha m6jG0QOzJFAioN6gAAmfBYt/So/tsmRMaWxmjFe6SLONHvGEIhdN+MQeIsyzYpPPQrDs riJzaF6+SjZh5FdN5cbnWZXf/ikvIvJM2aOEWhgPSWkDaUqTNwixXkQgmjV3rAUyXlKC qP9YKzshpn0XAuCxdr5t+4ZPcxBMk3gcGs1gw8djaHhlx+vLY4E0cpgA5G4AnSFiAvas MHDwqZl5Jrsu3bxOPYpFZv1S064H9K3/lDU9XKzlXpL8ADX8HgGh2xTR/1MaDMZeVrXs GyGw== 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=D0Pab/AtTPxB5RWhI2RP6rmxChFSTkmf53xKekTBC6E=; b=WeRecDX5ZDHE73nLXwf3cDOnZVIDPS6PBcNbt1Ps6hpCwy8M0AWC19hZtinjGyrNmN KdbI4gOQwi9viR/2Bd4zs8tGZvbDJpGgEDdEApfmpCYlxfS9qN1w0R/pbQJcmeUjgWbW oh5DXT8HA6y6ILbgYQF1fY5s3O36JyCxZJqp23Dg6G2F1VtDuGKU70MSt3m/SwAQwIlC uKsMOUUjw3Meq76EnPSDHsgPZN7JEBQzbphH0iHbeSNFzrloENW6XamIDRnFTii7krNA brbztoWsc5VEMkzU/KLI0RbIS/wdzAHnSof7tSXgDvbmc9j2AKLYkv2TQkUSWSryDhZC uL0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fS0w0TCX; 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 m6si7584883pgd.78.2019.04.24.03.27.02; Wed, 24 Apr 2019 03:27:18 -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=fS0w0TCX; 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 S1729760AbfDXKVd (ORCPT + 99 others); Wed, 24 Apr 2019 06:21:33 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:45676 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729181AbfDXKVa (ORCPT ); Wed, 24 Apr 2019 06:21:30 -0400 Received: by mail-pf1-f196.google.com with SMTP id e24so9059090pfi.12 for ; Wed, 24 Apr 2019 03:21:29 -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=D0Pab/AtTPxB5RWhI2RP6rmxChFSTkmf53xKekTBC6E=; b=fS0w0TCXXl/T2/KdYF6vTF8H+PwTGgkOEZQbojayQKs5xg48MCEr67Bgl0n8xhGEWW kZAauMuQ/jVUVxMAmpB4EIr6iPKiT8dO2TEmPr8TZvitNvPOBmvbaTfK037cl881UE01 7M0tPOZdtXKfQeSNX4gA1sFdbuBrUvatEwi1JSR+Whhqdtl0hUTcXN17uC2ND2Uso+UO IvCbg5sdsjefdnvkYTgMviSHzC/lHT50biNqwWgqQ5cqnQzgslCMmH07N+xKNgKFO1Q7 rerMt6GD40xu1tynHSXmd6SMcL7F0zzbUp69dKYnd/6NfLM/ymScdLFWpjOvkwirlByA JU9Q== 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=D0Pab/AtTPxB5RWhI2RP6rmxChFSTkmf53xKekTBC6E=; b=ObhEWb3xRcoEToyCvWLK7rbLJPw6A3RNkAeYDzC+uuogw1HyfIU4Td5+TNbKji4oZA qFunQm5dBs9Ot/fz9ROE8J4vuopWTYv4xStIA7mTyAWnkeM6oE8Y/yvLeHD0hWZcm3Qu TXm+sGy87txqUeLSWIq8ER0Y1CNQReovPHcmTHvVTa3nh4PrqJVcsuOZ5p8f4vhrny0a zBpCZnPx1uqP0CPYQ0T+Kob3ATGWBjazPSKbI6cy2Floatcrh2vK2dHqVMf7ZIKbKdTd Y/3FZzl11e4MZWzvScNxIe2WfMoUS5jE1D47hxMq6imwud4ddiv2crCsElc43PWqHX81 sDGw== X-Gm-Message-State: APjAAAVTIw1Qto0KFMgm+0O6Rl5vZowZ2Hf5x9CHGJ2ofOUF8yyJOfip 8/lB0c3SRET6j17rYsUjDGM= X-Received: by 2002:a63:df50:: with SMTP id h16mr17239035pgj.208.1556101289447; Wed, 24 Apr 2019 03:21:29 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id v19sm25051604pfn.62.2019.04.24.03.21.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Apr 2019 03:21:28 -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 20/28] locking/lockdep: Refactorize check_noncircular and check_redundant Date: Wed, 24 Apr 2019 18:19:26 +0800 Message-Id: <20190424101934.51535-21-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 These two functions now handle different check results themselves. A new check_path function is added to check whether there is a path in the dependency graph. No functional change. Signed-off-by: Yuyang Du --- kernel/locking/lockdep.c | 98 +++++++++++++++++++++++++++++++----------------- 1 file changed, 63 insertions(+), 35 deletions(-) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index a3138c9..4d42124 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -1681,33 +1681,79 @@ unsigned long lockdep_count_backward_deps(struct lock_class *class) } /* - * Prove that the dependency graph starting at can not - * lead to . Print an error and return 0 if it does. + * Check that the dependency graph starting at can lead to + * or not. Print an error and return 0 if it does. */ static noinline int -check_noncircular(struct lock_list *root, struct lock_class *target, - struct lock_list **target_entry) +check_path(struct lock_class *target, struct lock_list *src_entry, + struct lock_list **target_entry) { - int result; + int ret; + + ret = __bfs_forwards(src_entry, (void *)target, class_equal, + target_entry); + + if (unlikely(ret < 0)) + print_bfs_bug(ret); + + return ret; +} + +/* + * Prove that the dependency graph starting at can not + * lead to . If it can, there is a circle when adding + * -> dependency. + * + * Print an error and return 0 if it does. + */ +static noinline int +check_noncircular(struct held_lock *src, struct held_lock *target) +{ + int ret; + struct lock_list *uninitialized_var(target_entry); + struct lock_list src_entry = { + .class = hlock_class(src), + .parent = NULL, + }; debug_atomic_inc(nr_cyclic_checks); - result = __bfs_forwards(root, target, class_equal, target_entry); + ret = check_path(hlock_class(target), &src_entry, &target_entry); - return result; + if (unlikely(!ret)) + print_circular_bug(&src_entry, target_entry, src, target); + + return ret; } +/* + * Check that the dependency graph starting at can lead to + * or not. If it can, -> dependency is already + * in the graph. + * + * Print an error and return 2 if it does or 1 if it does not. + */ static noinline int -check_redundant(struct lock_list *root, struct lock_class *target, - struct lock_list **target_entry) +check_redundant(struct held_lock *src, struct held_lock *target) { - int result; + int ret; + struct lock_list *uninitialized_var(target_entry); + struct lock_list src_entry = { + .class = hlock_class(src), + .parent = NULL, + }; debug_atomic_inc(nr_redundant_checks); - result = __bfs_forwards(root, target, class_equal, target_entry); + ret = check_path(hlock_class(target), &src_entry, &target_entry); - return result; + if (!ret) { + debug_atomic_inc(nr_redundant); + ret = 2; + } else if (ret < 0) + ret = 0; + + return ret; } #if defined(CONFIG_TRACE_IRQFLAGS) @@ -2208,9 +2254,7 @@ static inline void inc_chains(void) check_prev_add(struct task_struct *curr, struct held_lock *prev, struct held_lock *next, int distance) { - struct lock_list *uninitialized_var(target_entry); struct lock_list *entry; - struct lock_list this; struct lock_trace trace; int ret; @@ -2242,17 +2286,9 @@ static inline void inc_chains(void) * MAX_CIRCULAR_QUEUE_SIZE) which keeps track of a breadth of nodes * in the graph whose neighbours are to be checked. */ - this.class = hlock_class(next); - this.parent = NULL; - ret = check_noncircular(&this, hlock_class(prev), &target_entry); - if (unlikely(!ret)) { - print_circular_bug(&this, target_entry, next, prev); - return 0; - } - else if (unlikely(ret < 0)) { - print_bfs_bug(ret); + ret = check_noncircular(next, prev); + if (unlikely(ret <= 0)) return 0; - } if (!check_prev_add_irq(curr, prev, next)) return 0; @@ -2286,17 +2322,9 @@ static inline void inc_chains(void) /* * Is the -> link redundant? */ - this.class = hlock_class(prev); - this.parent = NULL; - ret = check_redundant(&this, hlock_class(next), &target_entry); - if (!ret) { - debug_atomic_inc(nr_redundant); - return 2; - } - if (ret < 0) { - print_bfs_bug(ret); - return 0; - } + ret = check_redundant(prev, next); + if (ret != 1) + return ret; if (!save_trace(&trace)) return 0; -- 1.8.3.1