Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5453073pxj; Wed, 23 Jun 2021 01:20:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtOAyA4b2I1cvVHr61PbIUqgAo6kvlb/P1ZiEvsCkDZqB+KFEvN/EEyAEyxZnfnsyKcjJy X-Received: by 2002:a17:907:10c3:: with SMTP id rv3mr8612600ejb.420.1624436457460; Wed, 23 Jun 2021 01:20:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624436457; cv=none; d=google.com; s=arc-20160816; b=afuXzgZFaZNxbc05H4ZCUlIO/yR0/xZZzTUOpN08F1F/k/Mm9+u/bKFzuAILoqIXAY 5i6iHl+GBIRZIWQs4R1OuxVpPKny+FOPxcoyKaNNXDqEaKDxNsXuVsGGyRH6rHUzr/9D ObjGp6jlTAIfbs5CUIfQEiGCKsYi8kvRwmE9BIq9rsFViM0go0/dVMplfs8LMjDeW4dW cz/oSPQh06kLCc13W+a7LVQ/yxlS1I000FsLx/syZZvDVaAjJZljxcj7La8HyEgc4qrn hmpFZLPecUu2f0kpVtNyT6wQNLnkwYH1l4RafRD5MF2ysds1Yxd7fNtRnta6tIbFZA/C y21A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=bnHpRyORp2w7j2xFo8ba3YWQSR/vu9cDVYBZOXkxCYc=; b=gUoJwLYhvLp2RaDHftRBF2Kuq76SKLxUSbTDwJS14RhlZN7I/k8+lf54RhDwtK4Tzh 1lDDbYQgV3NYnoG1A2ONYqW1WZRWt8EZ2kMJtFj/ZR/g4oVTkVoWSTdW7BRPIZ6hrN0q 3owqRltFWhbjhIxy9PWBnu9rAkeHAemfzVvsxnC/k+KW9pdh+3XK7xFX4bMz8Ftr01sA WCp3Z+M8txu3YibyuC5V/Ya/1LnmRkeTl4m5+W0NSpXCF8j1roMnoU2n+UwEJUM/QZLD vwCi/eUGKIZiA0dHW7xmZjxFIxtoZHb86UsgH7uizChTo7m7A7YDHWA3wlZPinvfF2Ao 1uNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=kh7X0kvF; dkim=neutral (no key) header.i=@linutronix.de; 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=pass (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 bx15si12828322edb.510.2021.06.23.01.20.34; Wed, 23 Jun 2021 01:20:57 -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=pass header.i=@linutronix.de header.s=2020 header.b=kh7X0kvF; dkim=neutral (no key) header.i=@linutronix.de; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230300AbhFWIVk (ORCPT + 99 others); Wed, 23 Jun 2021 04:21:40 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:35124 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229950AbhFWIV3 (ORCPT ); Wed, 23 Jun 2021 04:21:29 -0400 Date: Wed, 23 Jun 2021 08:19:09 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1624436350; 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=bnHpRyORp2w7j2xFo8ba3YWQSR/vu9cDVYBZOXkxCYc=; b=kh7X0kvFk8ZY1w49P54BntYPV2bmCbfjexYuCdsHp7rWKY6mfws5fZRtMAlenlYLZ5rq9V cFN4aO1Vmc4n/imTPrZXS3//AXc/L2TohSPhUojuW6Or4kUZWHeGa4j9bjqmZm8/J2hMZa psM/eoOs+t0rn4Q/P8SJRkSwDTQdmIZnL14i6l7GlzXkv++MEU+jV9gaPSGBAU6wNNY6s8 W0y+vP5xlGjvzky5TJyXsESzTH9CAxRiPam5buxPYU8Yk54NXrBTkUCGstP9Be1dbT2WJc PVToJf71tdtP0whqR2ekpdreyy6g7kZnr9ALP8v5lBI+/MnJRYeC5JeiyXPxMw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1624436350; 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=bnHpRyORp2w7j2xFo8ba3YWQSR/vu9cDVYBZOXkxCYc=; b=rKALescxL2M5u2r0f2KmIm3QsbB14XtKMP822K7gFq29wVDCrWoCbDJJwA4Kld9tKYdX1e y9DARDWI1EaigsDw== From: "tip-bot2 for Boqun Feng" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/core] lockding/lockdep: Avoid to find wrong lock dep path in check_irq_usage() Cc: Johannes Berg , Boqun Feng , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20210618170110.3699115-4-boqun.feng@gmail.com> References: <20210618170110.3699115-4-boqun.feng@gmail.com> MIME-Version: 1.0 Message-ID: <162443634961.395.10623514533302474947.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 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: 7b1f8c6179769af6ffa055e1169610b51d71edd5 Gitweb: https://git.kernel.org/tip/7b1f8c6179769af6ffa055e1169610b51d71edd5 Author: Boqun Feng AuthorDate: Sat, 19 Jun 2021 01:01:09 +08:00 Committer: Peter Zijlstra CommitterDate: Tue, 22 Jun 2021 16:42:07 +02:00 lockding/lockdep: Avoid to find wrong lock dep path in check_irq_usage() In the step #3 of check_irq_usage(), we seach backwards to find a lock whose usage conflicts the usage of @target_entry1 on safe/unsafe. However, we should only keep the irq-unsafe usage of @target_entry1 into consideration, because it could be a case where a lock is hardirq-unsafe but soft-safe, and in check_irq_usage() we find it because its hardirq-unsafe could result into a hardirq-safe-unsafe deadlock, but currently since we don't filter out the other usage bits, so we may find a lock dependency path softirq-unsafe -> softirq-safe, which in fact doesn't cause a deadlock. And this may cause misleading lockdep splats. Fix this by only keeping LOCKF_ENABLED_IRQ_ALL bits when we try the backwards search. Reported-by: Johannes Berg Signed-off-by: Boqun Feng Signed-off-by: Peter Zijlstra (Intel) Link: https://lore.kernel.org/r/20210618170110.3699115-4-boqun.feng@gmail.com --- kernel/locking/lockdep.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 74d084a..6ff1e84 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -2768,8 +2768,18 @@ static int check_irq_usage(struct task_struct *curr, struct held_lock *prev, * Step 3: we found a bad match! Now retrieve a lock from the backward * list whose usage mask matches the exclusive usage mask from the * lock found on the forward list. + * + * Note, we should only keep the LOCKF_ENABLED_IRQ_ALL bits, considering + * the follow case: + * + * When trying to add A -> B to the graph, we find that there is a + * hardirq-safe L, that L -> ... -> A, and another hardirq-unsafe M, + * that B -> ... -> M. However M is **softirq-safe**, if we use exact + * invert bits of M's usage_mask, we will find another lock N that is + * **softirq-unsafe** and N -> ... -> A, however N -> .. -> M will not + * cause a inversion deadlock. */ - backward_mask = original_mask(target_entry1->class->usage_mask); + backward_mask = original_mask(target_entry1->class->usage_mask & LOCKF_ENABLED_IRQ_ALL); ret = find_usage_backwards(&this, backward_mask, &target_entry); if (bfs_error(ret)) {