Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1322802ybz; Thu, 16 Apr 2020 07:12:33 -0700 (PDT) X-Google-Smtp-Source: APiQypL/vfEiEzuFp8nc+vVWn2L02I4qKKmQmWvkJE0uRKaNG9l5JhcthHj2W4F3Sa6LJAuGVH+J X-Received: by 2002:a50:a2e5:: with SMTP id 92mr30825814edm.139.1587046353245; Thu, 16 Apr 2020 07:12:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587046353; cv=none; d=google.com; s=arc-20160816; b=zzT9QgTEmmRIuQSSGR5RLLRHtHgHBNWqucT8yNyGceGK4lbu4NXY5oKIzZ9uNClRFr NIoGVJ88CsnN8swlznXboL4z9tyEOHbJN9FCdCKKGaFRwCXZ82+bAkOUkutUQO3AAtCt YQvyb2omWbPmKAcC69YBwlbxT2UmWxiFqVKYXfqqmjCUfYTCZsR3WA37yeUzzjsI/cXV M2oMWr6LNezBl3Kx8uRHu4LBH6NBFcvNZyb6iqmMzNGFE1K/vxMMXL5NWhoVXY8D0tnD FUCitTsAZlCWDEX9Y9J6AqxyMs16PCI8D4IYUtQNuB1z/fblVeCV6+alRucmKBNfTyWS jd6g== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2uCQmBfOLHvBeGzAghFTc6Lu5fKLdbrqzIyF0lzus6o=; b=PvNundNLDjnQYM774tp0jybfNPzQQ56aGZafeI+32WEyCsZeKq2Xv6Vsn988gUbglB ahMEgq00V2/tC79qDK/JMqlWP2ked+Izj719Pu47mdtugjEnjuJUPhJZS6KdckXEiy5+ FJ3+ijbNIfF3dMMV+JDaoj7wu4M25Bk9OZCcS3HIFix7bOmJr4vJPN9/CB9N9LJWuxet Erld70jHn37c8f/kYQuqzjktRF2hvzxdwySELBNpeEN9HtI3nUXOO6JhHIRBaaJO27Th R0DhGeIogsX8FaxV00r9pqdzgE1LVy1IDPGX0Tl2w7eQUswyO3ldJnfjKMN+GjZJJTXx ZnQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hxehtmeH; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cc1si13808937edb.68.2020.04.16.07.12.04; Thu, 16 Apr 2020 07:12:33 -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=default header.b=hxehtmeH; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2409737AbgDPOHS (ORCPT + 99 others); Thu, 16 Apr 2020 10:07:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:58212 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2896924AbgDPNoz (ORCPT ); Thu, 16 Apr 2020 09:44:55 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5984A2076D; Thu, 16 Apr 2020 13:44:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587044693; bh=r82tKIi8mDH0MV9ri2qt6LEF7mgjBkWhy3KjXEKilYc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hxehtmeHMIuUSEeffCPTGeOX23pro1zASACd5ITzrf2M4VNjMb24hJTaCx6WDtGLV DViqitGpHS0yb4vRJIqq2Vbd7PlgT94s+sRFqkhYiz08ZKVrIANK3ins/vcl3PEntn WgUNL9zxpqln1JyZbNxJ+ANbMYwPWO2njrlYmhHo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qian Cai , Boqun Feng , "Peter Zijlstra (Intel)" , Sasha Levin Subject: [PATCH 5.4 063/232] locking/lockdep: Avoid recursion in lockdep_count_{for,back}ward_deps() Date: Thu, 16 Apr 2020 15:22:37 +0200 Message-Id: <20200416131323.295885799@linuxfoundation.org> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200416131316.640996080@linuxfoundation.org> References: <20200416131316.640996080@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Boqun Feng [ Upstream commit 25016bd7f4caf5fc983bbab7403d08e64cba3004 ] 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 Signed-off-by: Sasha Levin --- kernel/locking/lockdep.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 35d3b6925b1ee..9ab1a965c3b92 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -1719,9 +1719,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; @@ -1746,9 +1748,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; -- 2.20.1