Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2834364pxv; Mon, 12 Jul 2021 03:06:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzoNoUFlMU4X4xouYN2YzImGQ2d6d+oouZq0FHBhh6gKDfvQFrrr5S+qlqN/EvTjqOUQNY X-Received: by 2002:a5e:8406:: with SMTP id h6mr21673263ioj.193.1626084377137; Mon, 12 Jul 2021 03:06:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626084377; cv=none; d=google.com; s=arc-20160816; b=jk5jx2PRF6vxhO9y7EhJR7rQvMZsJ9LFQ2bGb29J7fGdJx30wPARsw2MoY4G/mnwnn W/CBNET/Ol2T0KHe8vhnnFs0DQh7WRVNnWBljhHhxHR4IhwH4MliCZcne88X25RUvw3A N+giPxI1fglOh0JjEDNwcD6Jlm45e/F22AEzVjh+NWEvU9DPzKMq51QjeW2bxOvU/nd6 IJQr2/hHhsuROoZzJFlYqNaR36/oBQolyyaXRtVpIz2+5BdW4OmjXCGVxBSIHcMOll6y pMrlk+Pfdqj1mYdHA4dQzYhwAnbuEgq+dTnWKe2qqdY9bO11JXdR0uyD4AsyGRfFzdbz 9lqg== 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=WEFMBtTdjM/OMocE1qfHZ8inW4E1rc2usZourWLcWdM=; b=N6/fBFy286Ks5gqTNgn+rHcqh/KknfPfyO2xQSiV5mC2gmrdDO3A/MVnnh+vGPAfJY 6sE9vYxl9iwquEHhMrh5M1miBw82jNN+yhZIILKmc8zP8D9A9ezEyPYvASjfPDapQqQd +K5EFDNWGH4Vsp7RUK7qevkvax38qlV6owoQNxmeiqApVUR9TFnRW4/lVQyfjT5Gojwo vH7UvLMrgL4GSFMMrHpm2zBwtTYmiirFqeEAnAlqZIkqWS1Fv0l6wlCBEE1Ysepa3RRQ 8LYjkwEe2QIUH5bOpXSYDbmUcqGZUREJR+M76BSRCn4u9l37/zMGtFxPGNV4txBUWUy1 hENg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2uC0L5ny; 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 y1si2869629jao.99.2021.07.12.03.06.05; Mon, 12 Jul 2021 03:06:17 -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=2uC0L5ny; 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 S1346922AbhGLHbP (ORCPT + 99 others); Mon, 12 Jul 2021 03:31:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:39618 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242936AbhGLHEP (ORCPT ); Mon, 12 Jul 2021 03:04:15 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4F4B461107; Mon, 12 Jul 2021 07:01:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626073287; bh=Oy5be5t/1nI8ffgcw3IWyLLcAjSX2IFQuUsBDWkUY+E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2uC0L5nyYioiWHragYkCEaA+uTVnGnhMqFNeqEU9hQQNPdEmWJ0qPS789hIAsffmh NSsrns99OyWgvVQzAhYLUtfitFrzV7/QTYrDav6dtYnBgi3TJFGy7lO+HzRggy3EOB iqD63iwRAeaoBhRTL7p0ZN1pa4q+n58gehg9N88g= 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.12 190/700] lockding/lockdep: Avoid to find wrong lock dep path in check_irq_usage() Date: Mon, 12 Jul 2021 08:04:33 +0200 Message-Id: <20210712060953.672063206@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060924.797321836@linuxfoundation.org> References: <20210712060924.797321836@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 03a9d9b96045..b56c3855756e 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -2772,8 +2772,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