Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1677680pxj; Fri, 18 Jun 2021 12:24:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw94yKCuENwrkp6Bro82xz5fjgTdfgTf4WevCYv6R1fE5Wpg8pOgeP3myyRg8sLLuy1f1/A X-Received: by 2002:a05:6402:204:: with SMTP id t4mr7115792edv.34.1624044267986; Fri, 18 Jun 2021 12:24:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624044267; cv=none; d=google.com; s=arc-20160816; b=ibLFqvMNV8th1hirGR7Z4ZP2/zFKzXnrM5z9KOIpKJSUrcY3O0kWUrBUX7Vrhk7tXn CnZYG6HZaibQOuxkDONesmrnK3CRN+8qFf9KmnMoTyhhAXN9ltxWCGEiVRI2h9WUnIbP UIR4BITDfrMzB6nUOxkGr13AQP7oybvQL/EaImJvd1P8P1W99oY7s61N0rNKtHcx1T3P HlqJs2pHbgPwehU9Up5X2BZ1cC2KzRur8+GrFVNfMsrgaIeWSVeRGVkUKDdpMoMSMFBl TM7N5f5K2yOAOC22Opy8/LOgfbw6dhEYBEJdqsFL7D+HtSzmqQ15XKmM3LyGAYiTrOor 3Qew== 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=Iw5bM1oWSVgU2E0qpCpapukI6tZeaIAQEfdVoRxxe+U=; b=Gv6eCF0AUMwp8n38IFTgXAxm+BAwDI3Wj9PwPKSKtTTpB7XoPWBOa0sTOaxRXmc0pH SfUZ0S38GE3B6YHpEHaDD8J8zbL6YUnIHv73rIS/+cXZO1r7HoKgsxJujnxep2s7COKT /ZUefHhAaDBhBNvvr48I1OMM4ZgItIZtkpQI45HXaKOWDTTEo1s/vZnlgY/5vftoga2T Ut5eVw5aL55UaxpvaRlChjArBMpxa5SGPG67O7GynTgo5sLZi3w2Gteep1R1ltGf+VGp nsn0VcwipC8i2FZ26Y2FttKVLz89dKY/6B+4ggpTQZUtDVwlJsw5NJBERSXYg7dbl49A S9Pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HSvqD37V; 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=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 29si3423540ejf.125.2021.06.18.12.24.05; Fri, 18 Jun 2021 12:24:27 -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=@gmail.com header.s=20161025 header.b=HSvqD37V; 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=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233957AbhFRREF (ORCPT + 99 others); Fri, 18 Jun 2021 13:04:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233366AbhFRREA (ORCPT ); Fri, 18 Jun 2021 13:04:00 -0400 Received: from mail-il1-x132.google.com (mail-il1-x132.google.com [IPv6:2607:f8b0:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEE7CC061574 for ; Fri, 18 Jun 2021 10:01:49 -0700 (PDT) Received: by mail-il1-x132.google.com with SMTP id b14so8993087ilq.7 for ; Fri, 18 Jun 2021 10:01:49 -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=Iw5bM1oWSVgU2E0qpCpapukI6tZeaIAQEfdVoRxxe+U=; b=HSvqD37VA3IlhlWhCnUah6hPnJedzYXIzunNPYQLx8TPc/ZKLlzCew98F3FfX7aGgh kD9VkbEyp3QDSlHp7qhLVUcYnHS+4F9BhxDwJsBVwbX/+OxiI1SASVv7NM5Oa+vz6w6S 4+ToGV4QQJCMYrGB4q29bY5ESXRPJDbJI030jTK4gGHCWEXrlwrEIUGNrFyiO3wcX8yk EoWAMJ56QSlX+xqhavoTv0bSHE0YNaA0DSDKie5F0E0NyFBcAwwRLlqGV9NSXiqIY9uM rBPG3KKuM8ZjUJPo+WB9mKBPpfRKEjTa5DKawHuLmAK341jYWLFewdNRGDf6NeV6zrMl bTow== 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=Iw5bM1oWSVgU2E0qpCpapukI6tZeaIAQEfdVoRxxe+U=; b=jDWaZzcXs97M0fOH4JUxuJ6LANpXwXnTYZk9wsrifuSpKvnBecKbzGhhOD2AQEhjL4 8GieD7JZFPCFfdD/6Rfs3gARIGALO0f17gC/Pc29wOjSoHLKHTsV+ltSl7QR6YYSfdnR qeTSFksCBR79OsHbsCLh5QV4dxrKKxyIdnZ4ReZPCdHZukh7vpvgZ5z6JQwyaUoW8Dx5 3yWUY6o0w2sV0oc2xvM1PFug5PAlcVmt7axEW1qHAL0dfNCpB22OdckgvHKlbQesVHXq osa4yKKMPtb1RfgbKsgGLOBjAfoe0KTUZnhqwPAdxL3SO2O/hV6V+5Tgr9Q0vxtCcX3T DJ4Q== X-Gm-Message-State: AOAM530AlftqDUHK5Xyji1Y2jBMJUHKxllV6gSy2TaRWWYkMInY1DxeQ eWuRv3xJMErsQnEuH+/doQI= X-Received: by 2002:a05:6e02:612:: with SMTP id t18mr8375035ils.261.1624035709187; Fri, 18 Jun 2021 10:01:49 -0700 (PDT) Received: from auth1-smtp.messagingengine.com (auth1-smtp.messagingengine.com. [66.111.4.227]) by smtp.gmail.com with ESMTPSA id y4sm416122iop.54.2021.06.18.10.01.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jun 2021 10:01:45 -0700 (PDT) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailauth.nyi.internal (Postfix) with ESMTP id 9D27827C0054; Fri, 18 Jun 2021 13:01:44 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Fri, 18 Jun 2021 13:01:44 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfeeffedguddtgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepuehoqhhu nhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrg htthgvrhhnpeehvdevteefgfeiudettdefvedvvdelkeejueffffelgeeuhffhjeetkeei ueeuleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe gsohhquhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeiledvgeehtdei gedqudejjeekheehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgtohhmsehfih igmhgvrdhnrghmvg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 18 Jun 2021 13:01:44 -0400 (EDT) From: Boqun Feng To: Peter Zijlstra Cc: Ingo Molnar , Will Deacon , Waiman Long , Boqun Feng , linux-kernel@vger.kernel.org, Johannes Berg Subject: [PATCH 3/4] lockding/lockdep: Avoid to find wrong lock dep path in check_irq_usage() Date: Sat, 19 Jun 2021 01:01:09 +0800 Message-Id: <20210618170110.3699115-4-boqun.feng@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210618170110.3699115-1-boqun.feng@gmail.com> References: <20210618170110.3699115-1-boqun.feng@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 74d084a398be..6ff1e8405a83 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)) { -- 2.30.2