Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3346248pxv; Sun, 4 Jul 2021 16:10:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwutLsnpniCAMTUjZiV6XThCyQjDINYM+YKmV/eLwpOTDnP0BMC1WM+p3FeBDBappFzE20Z X-Received: by 2002:a92:d4c9:: with SMTP id o9mr8158388ilm.263.1625440241622; Sun, 04 Jul 2021 16:10:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625440241; cv=none; d=google.com; s=arc-20160816; b=T4w9VvXYwXmsrmGcBvOanvIA6WKCHVFK38XvB1BUtcMo6AqvumAu1KCQ1NJcGgnquy YzGTSUhWqyl/DJlKfNrt6VZYuqUS/bz6eeG2PjUigisiRXg3HDrFZFErM7rxtGBzQv90 lYsdsjgVoVmP5OnErL/jMh6uk2WlNvOwULDuDkKM7PVOV4FppxUXani2tEfzYLytC6m9 zXcsyKxB7Yqo+ef9adQ4u47tL9K9e7SZVXIkikWHgFjKmVtf6XGQUYtZfTMzn6uRRFcT vLuJ1gbQ3nT5V1pl1+aBzB4YdsMNsXUaVHLBl9WhBetr9mT+464sRRgxqWUl8esmjuMz CVLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VNgyi+UD/kwJ1HYfY98spoLF6AbE+TP4wdIzicC9tls=; b=HjtaugwXApxo9pniFWv9E5Iz4gGDGgufxnr+LRw8jKHKEhS0tCUFbLQ50A6vBacnBc PJt0fqriYuvGDlxb3i2x7mZfxHrVvB/gnVBTnr2Q9rnAbf7iVjUoUyHSYSohJFdzozp8 sKg/DrJUGqj5Coq8ObUnUZ0vXL4vmEBNn3eFYkyvXPYri561E5QEMcmFCSne6ux3v15T k4yOimtOX2RRBo66RGuPhNjH/cyWIlJEWzzTihzs/6O3/7x7IJ++nYc2E/uc/QSXLnLx rpIzqj+EDfKL91CMsD2XgplR2mwTL6HVQpkSrJZAz/yoFSb6PzD5iWg+xG51O+/K1/iS XV7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=E48C09KS; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h10si11742430ile.35.2021.07.04.16.10.29; Sun, 04 Jul 2021 16:10:41 -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=@kernel.org header.s=k20201202 header.b=E48C09KS; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232770AbhGDXMh (ORCPT + 99 others); Sun, 4 Jul 2021 19:12:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:50502 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232524AbhGDXKp (ORCPT ); Sun, 4 Jul 2021 19:10:45 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D6BB761953; Sun, 4 Jul 2021 23:07:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625440077; bh=bruSXXDteeN2HgWIUromQ4eJfYJCa7dWPkMfX+Rmlfg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E48C09KS3K8dHjlTyPT4EGo5BtzqPAGbxQ+jExmkqR3aPU/MGr+Wr3bWvxMSqpOfe /GM+03wTdyJHVhIjUZuRJJ8pJHn9tSApjo/69JnyyBxgGrviK2aNyFJh/yJ1z76LhJ 1A26Xjw/iMBhpps4M/jy8WIW/0i+czRd1mkB3Itg3To+5G/t673ngxuPFKYYShRJU/ 1UJKfoBBn1V5oJeJlVJ702kw66V97dMloSKXbBDgWKdWx3BAfALSPaT2GjCcfcPmgn wU9NF8HKrWVVd0LO3rQqGEKfkqDH4AuIARkx44HFubRN9Hru6feZH4F9Ng/Wgr+Wx/ GjLVWDhYxRoPg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Boqun Feng , Johannes Berg , Peter Zijlstra , Sasha Levin Subject: [PATCH AUTOSEL 5.12 76/80] lockding/lockdep: Avoid to find wrong lock dep path in check_irq_usage() Date: Sun, 4 Jul 2021 19:06:12 -0400 Message-Id: <20210704230616.1489200-76-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210704230616.1489200-1-sashal@kernel.org> References: <20210704230616.1489200-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Boqun Feng [ Upstream commit 7b1f8c6179769af6ffa055e1169610b51d71edd5 ] 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 Signed-off-by: Sasha Levin --- 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 7bd1d9ba6dc0..0d575e9e1e37 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -2770,8 +2770,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)) { -- 2.30.2