Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp655734ybb; Fri, 20 Mar 2020 05:59:32 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvnDUwTlNoKZRZfLC05ClTaGRc2XfcIFXt2l36noyiF43QuQqOhawgpdd9u48tBhSQuncx8 X-Received: by 2002:aca:dec6:: with SMTP id v189mr6320188oig.156.1584709172101; Fri, 20 Mar 2020 05:59:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584709172; cv=none; d=google.com; s=arc-20160816; b=Vl685dZalB2en95qt+e22EA2CKIcMZjViY3X0MFiG2jeTmb/aagbebCZg33WbM+Kyr vGUwARndPrcKYYB7AVQFCfUp9OMyEtYPRPB0wnfGNzGJ1v9SenGdUtodthOuiHjSKpR4 yfEaWbvElmXVW6C972Q+w+kz4pncX00vQs76AN204yeixAl2J5G/Iyl1O7EINHaAJ7YH 9ssXphysg84/sd9DvmfwXk3LLNs3iK9ZCowrIEdu1wc/MHlNTEuZubRrWMRNNQXoNYi9 zgmtkJ/yCtYsjGUvEa+TPNg/Rbw2AI2LVlSRILbd6i6MV9ZTgdn9K4jv0dGlgt8coFba iUpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=X+NNOpMP86SgmA+cqzxqtESj2sovN55o1MDliJnWnNI=; b=Cq6SeILU4ET1uxLD/XnkXgDdqmZrR+eEN0MJ9udZk2v81ZaZoxosTZMTTeVEKz5zJp FdeoIo8PcRJFP/ri4cHaFZRoMrXTU4yTUuJvNaUL34I/ECRkAexE18XKZ/6LSqbuSOXW aB3Z6UAB4h7+2dsUm6LkXy6hWODSmVxRG0nEMpuQbsYpbQEakqAERgZUC4YGsbmnxEtR 8HxTDmyNaPUF964ierF/zEwBElFLd+b5n1q8hXZKAebWuw0VKyTHqF6KJz3FsB79HRIB bHfwvPnB1wuw4Ma1WJVbZRIJNeB/1bjRHTdQj/5npgbaPIGUrgnWnOWrcV2GLmzMAE/F kgLQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u10si2644553oib.91.2020.03.20.05.59.20; Fri, 20 Mar 2020 05:59:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727486AbgCTM6p (ORCPT + 99 others); Fri, 20 Mar 2020 08:58:45 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:35682 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727426AbgCTM6j (ORCPT ); Fri, 20 Mar 2020 08:58:39 -0400 Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1jFHEQ-0003qv-0M; Fri, 20 Mar 2020 13:58:34 +0100 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 944B51C22C0; Fri, 20 Mar 2020 13:58:33 +0100 (CET) Date: Fri, 20 Mar 2020 12:58:33 -0000 From: "tip-bot2 for Boqun Feng" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/core] locking/lockdep: Avoid recursion in lockdep_count_{for,back}ward_deps() Cc: Qian Cai , Boqun Feng , "Peter Zijlstra (Intel)" , x86 , LKML In-Reply-To: <20200312151258.128036-1-boqun.feng@gmail.com> References: <20200312151258.128036-1-boqun.feng@gmail.com> MIME-Version: 1.0 Message-ID: <158470911332.28353.7259360463548170185.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the locking/core branch of tip: Commit-ID: 25016bd7f4caf5fc983bbab7403d08e64cba3004 Gitweb: https://git.kernel.org/tip/25016bd7f4caf5fc983bbab7403d08e64cba3004 Author: Boqun Feng AuthorDate: Thu, 12 Mar 2020 23:12:55 +08:00 Committer: Peter Zijlstra CommitterDate: Fri, 20 Mar 2020 13:06:25 +01:00 locking/lockdep: Avoid recursion in lockdep_count_{for,back}ward_deps() Qian Cai reported a bug when PROVE_RCU_LIST=y, and read on /proc/lockdep triggered a warning: [ ] DEBUG_LOCKS_WARN_ON(current->hardirqs_enabled) ... [ ] Call Trace: [ ] lock_is_held_type+0x5d/0x150 [ ] ? rcu_lockdep_current_cpu_online+0x64/0x80 [ ] rcu_read_lock_any_held+0xac/0x100 [ ] ? rcu_read_lock_held+0xc0/0xc0 [ ] ? __slab_free+0x421/0x540 [ ] ? kasan_kmalloc+0x9/0x10 [ ] ? __kmalloc_node+0x1d7/0x320 [ ] ? kvmalloc_node+0x6f/0x80 [ ] __bfs+0x28a/0x3c0 [ ] ? class_equal+0x30/0x30 [ ] lockdep_count_forward_deps+0x11a/0x1a0 The warning got triggered because lockdep_count_forward_deps() call __bfs() without current->lockdep_recursion being set, as a result a lockdep internal function (__bfs()) is checked by lockdep, which is unexpected, and the inconsistency between the irq-off state and the state traced by lockdep caused the warning. Apart from this warning, lockdep internal functions like __bfs() should always be protected by current->lockdep_recursion to avoid potential deadlocks and data inconsistency, therefore add the current->lockdep_recursion on-and-off section to protect __bfs() in both lockdep_count_forward_deps() and lockdep_count_backward_deps() Reported-by: Qian Cai Signed-off-by: Boqun Feng Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20200312151258.128036-1-boqun.feng@gmail.com --- kernel/locking/lockdep.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index e55c4ee..2564950 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -1723,9 +1723,11 @@ unsigned long lockdep_count_forward_deps(struct lock_class *class) this.class = class; raw_local_irq_save(flags); + current->lockdep_recursion = 1; arch_spin_lock(&lockdep_lock); ret = __lockdep_count_forward_deps(&this); arch_spin_unlock(&lockdep_lock); + current->lockdep_recursion = 0; raw_local_irq_restore(flags); return ret; @@ -1750,9 +1752,11 @@ unsigned long lockdep_count_backward_deps(struct lock_class *class) this.class = class; raw_local_irq_save(flags); + current->lockdep_recursion = 1; arch_spin_lock(&lockdep_lock); ret = __lockdep_count_backward_deps(&this); arch_spin_unlock(&lockdep_lock); + current->lockdep_recursion = 0; raw_local_irq_restore(flags); return ret;