Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2825801pxv; Mon, 12 Jul 2021 02:53:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3hn1c499zLkoXmnOhrDa+cgxQ3XU4mL4+ALvOYTdXlfZc2KDPM/xDFptGwGz50nkxEf8o X-Received: by 2002:a6b:6016:: with SMTP id r22mr34725340iog.12.1626083617244; Mon, 12 Jul 2021 02:53:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626083617; cv=none; d=google.com; s=arc-20160816; b=Sb4JW+pYjPnQR20LhNL9sqcztKoRJEh7l88bxSLwaB1G0dTiYaXn0xXr5hI8L8c7ab MOMgpNNSlMm9JG/pf/0/IkDjUQUCtqW/2XhSAYQmiJGKpV0mG8YRXCCbP77S+70z9ibF CNdZEReFOdL8vJg7b0udmJHB55Xro9p1CvTry3Pu0WV81cJc/kHvHW7q7uSMGMdRDn9O DY0aIMfMvKR5TXRCXMETdCIdF/RgdCssnrKGr3PbHab3zEthQ8f5c+G0NPKzZPEdDhM+ /JHrnPW27n8kpTKDQc9JPiG9JN/rW4eEFXW3L2Ex+azBAz7kBjzV9jCfKSJsnnFX2uZJ Oegg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Xy/ZoF/yqIt1vaLWTfEfXYwlNnwhLQUP3VVyCJtE1TY=; b=Hb3IrGzIMU855NAcqPqwA+Qk/DxNiBxOvM3d6DIg+hj8BsdvVtW9PhOdVPb+nCRvKL E2BjYTPZ3o2PPHS0tzv2pZ+c0HWvMqw46ArgVW08GBYNClJKQMlGsixqrVUiMNYWT4+b fVwShxdUzSADv6GSLWzPUiiFLpMKbjsq8eyJEmc0KPBCHEhQp51PHA/7p6hFpsBqKYPI XmIp4xrnVm4F8LTEkaWe3zZxAIeysrgzwzgo/fJK756uzVDk55TgvMnA+90SKzMzgjSd hSFgFTPZBR6Sro8ffTzcv1iGppZLRNQ1ZWhsQ5NKzZttdx7iVjrcswJtmAUq+Do1OBud HIAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sK3wCGFx; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h26si17523853jav.114.2021.07.12.02.53.25; Mon, 12 Jul 2021 02:53:37 -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=@linuxfoundation.org header.s=korg header.b=sK3wCGFx; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239401AbhGLGtn (ORCPT + 99 others); Mon, 12 Jul 2021 02:49:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:33546 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237969AbhGLGjs (ORCPT ); Mon, 12 Jul 2021 02:39:48 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 903BD611AF; Mon, 12 Jul 2021 06:35:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626071754; bh=AaVeBHJ+hq/UItHnqJAyBABInzgok6huWFHNOds8KoI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sK3wCGFx0Rb6uyINBEPYRcrEmR2fdCTi61wbB4wWTrnW0n564p/N0Z5I3EpE1PoT8 Ba3lsLJ/gHdzjOugE+AyGDf0qF00DbXilNEbuzf2XFcw6uq+uhLf4CHp0047TH8AB1 EWdz5EFxRRbVowoSZPnPxjhybB9TZsxW8VBc4x7k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johannes Berg , Boqun Feng , "Peter Zijlstra (Intel)" , Sasha Levin Subject: [PATCH 5.10 162/593] lockding/lockdep: Avoid to find wrong lock dep path in check_irq_usage() Date: Mon, 12 Jul 2021 08:05:22 +0200 Message-Id: <20210712060900.878110304@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060843.180606720@linuxfoundation.org> References: <20210712060843.180606720@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 78b51b8ad4f6..788629c06ce9 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -2764,8 +2764,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