Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3345457pxv; Sun, 4 Jul 2021 16:09:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOhfqfdQ92Z2rEPKFkjPItv9uobbl02NWbVoLvAfm61xjCFntGpFpo6MgIhQyNAMXjByv+ X-Received: by 2002:a02:7348:: with SMTP id a8mr9584129jae.116.1625440149334; Sun, 04 Jul 2021 16:09:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625440149; cv=none; d=google.com; s=arc-20160816; b=rIFH5lWsNAWaYIca/6OZIEH4DHhyTzzZrlxBkVb96LZ5EfA+jlHyP7tdzpNQ8c7ANA drdu0Wh7DFW5TYI7Cg57KRH3pU3LSlm+dAGqMb4U3kHXGOeee1rbb83CucLr0MsA+fio DOQBt8fpRwh3lRDYISiyfPxb+h1O2kxyGuhNuOgD5g7rhOWJxybjuqM+1jID904EZH6i Ona+oEtjvGgwDsh+eMY4RDo3x3G5WgymBm8gl1/vCZMZsIPCLL8rNhI4EQsJJEcg6s8J aBaHdx2rPSYqY4a1vRdGe4SECZB9UAho5DpUuITWc3Q019qupdt+IxY2nO/9EqQx9kmd uo7w== 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=JGJpTptigjH5hRjVxkKlbHge1ODeevsQAFgaBx7oAfs=; b=c/3y6ffUJmGjJd6C48NAm4gAcSFjsKa/Y4TiwnJUpbvWAAvFig3iSHbXo/9EvJR0Wr 1PvExO5QgVaXvbpHLM1kTXQk9qLSPojvPGP0gbumuuJjAnCm4OuCQoqBMpVSchZ0842D QXQ0mXjcweneJ8SmuWCQyFlYobrTUmPoPbWriwv9/O/VADVoR6P3vuz9+xyNgK69omII ZfAwuBwWm+8bLuPgQP/2Ys7pYg5hGkOBq9ejtZkRW1i4QZ0Q8jRbluZGf7r/UF0hi/XD dMN9noTrbaBKKWb3KNxx2PDPqhW1E6u3LbNyNor1faeQUh2V+Hd9CsUIRDk+BFCUHezr uRzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sudvLUAC; 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 o192si12650810jao.55.2021.07.04.16.08.57; Sun, 04 Jul 2021 16:09:09 -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=sudvLUAC; 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 S232149AbhGDXKD (ORCPT + 99 others); Sun, 4 Jul 2021 19:10:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:48138 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231401AbhGDXIo (ORCPT ); Sun, 4 Jul 2021 19:08:44 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 99F96613FB; Sun, 4 Jul 2021 23:06:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625439968; bh=q6vmNX2IUIhLdwUmkhoKLOs2c5YhP2jmDvOfWVKlIaw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sudvLUAC+/ktb7V8M2TbIGf0TI+6YT4ziXD8RpHCvvVDt/agGR61XP/3D9805EzD2 gPzG7elTjJqawaS5Pvo5SCTAUhgK3xL+X1tGKf2/5d3fcrn6gSBeEVCzvjhIC0WSlb TkE99dvwjrvpKKtMLhnHK6Fr3RFa9ABogPzeY765sU7Ajolg75/zATcrx+Nw2kgudv oDRjMO+6gmGSpUx3nlQQL4+viQzV3dl6L/Gy94zscNLU+kKYcnm+4aJrfcxVUufB/i uKv4QqJJ+YGEZoX1RUCHMDdrcyTgQNt/RAubfzcSbC67CPzyB10TFoKjc3uDSwOEHg 5EF2PbzgJCr8A== 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.13 80/85] lockding/lockdep: Avoid to find wrong lock dep path in check_irq_usage() Date: Sun, 4 Jul 2021 19:04:15 -0400 Message-Id: <20210704230420.1488358-80-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210704230420.1488358-1-sashal@kernel.org> References: <20210704230420.1488358-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 e51fa6575c39..39b6392b4826 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -2773,8 +2773,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