Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp629107ybh; Thu, 12 Mar 2020 08:14:28 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuAPSzfwbF/x58z/wN7Pw6pkGBFfSZgoTIio2yW23vhnlKqZNbUiFmX+YjWjZLt83tH3VUL X-Received: by 2002:a9d:694a:: with SMTP id p10mr7061412oto.151.1584026067884; Thu, 12 Mar 2020 08:14:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584026067; cv=none; d=google.com; s=arc-20160816; b=Eug0x1ZwVT15/qBNaj+9XtsY8uULk7CmSxjxDBldyVdw3ODJYfWyO4CPNxjjJnwOOk CRk+pUCpdOYufiWJ2V7UMlIXamDmZqf3WsYBfDIRWDWCVEYg2RUM2wn1W7hMnntcY2hM TV1vBKuRpZYIJbClC/6q+SKFHA0+PiQbgC8nihpMGBc2vHIbqwxDM8KLTQkEz34NTKOl 0LGsyKeYy/MzuWq4vMVV1sJ5Ps2SJvq/Tu9y9sh1zizeykJisUK47kiypox5alyodv75 Hd4e9LkPn/4h1Yb22jLtEvXQXdHu1kPPLut1m9qES7scvNceSZHg1x1ZXMBus4W+JYZG Sv0g== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=TLdhe5zz/3gMVJTRHKdPZxN/mknp2/3uH9yjLxovQmo=; b=gw0112/0zYm9ESrJ90Fq4BbGpWDe6npZgO/IA4MkVEPMdsZvtLEpj/af519n4symKD 7TG9WDjfXlqn7d0k3wMKylJWYKG1WQj0biSgFIXn6uY49pPP9AoeKh8vFGpmyDUK9bX7 Ag07jCKWB11ZYYUAcp1/hD2YNqO31pAB4QCF5jSDbuVLQDxzKz48JVFmq/VJ3Guo92Rg yrVFLUUDUiPM3zHr2kwVKshREWgPhiC2VbXc5dp0crFAQWxjE+0XxJf8D1SSwy5B2tD8 ri1RLp2bHu6sqCnVqSkt8KYu2mbliqMrfuRRBhMZv8s9skZbz9NZ/+sl8annOkywaurH 6IHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TpfYAznv; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u9si2906741oia.62.2020.03.12.08.14.15; Thu, 12 Mar 2020 08:14:27 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TpfYAznv; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727803AbgCLPNK (ORCPT + 99 others); Thu, 12 Mar 2020 11:13:10 -0400 Received: from mail-qk1-f195.google.com ([209.85.222.195]:46070 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727505AbgCLPNJ (ORCPT ); Thu, 12 Mar 2020 11:13:09 -0400 Received: by mail-qk1-f195.google.com with SMTP id c145so6720026qke.12; Thu, 12 Mar 2020 08:13:08 -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:mime-version :content-transfer-encoding; bh=TLdhe5zz/3gMVJTRHKdPZxN/mknp2/3uH9yjLxovQmo=; b=TpfYAznvfSUfGwL3ajY9TE8po62ymtGjKLjesgAayCDAuwnLR3erM29TwGVUirz1Ps jhCOwN31NpO9IWJR4zxb0BULG2a0b1CCEtahCXM8mOP7rQ3tas4e4f5vPPQY2US2DYYS yt1DuIMLx+P6Zyg1ajWYr1jCvLD92pvTsScOJ8ycUGVUcqX086/Wu72bQKoe2FcxidX+ YeXHiMDWTaV92geB8lDnO7WFK+rt24vNnJqLzv/eIiY6u8VBEG/Ij25m6H1iWIL+hPy1 QoWqJWEYFTkIStLmvVOgq92eH8J19VIj9JENg03shG20h+i8go/4gCcUmosxKafIsa/b fNnA== 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:mime-version :content-transfer-encoding; bh=TLdhe5zz/3gMVJTRHKdPZxN/mknp2/3uH9yjLxovQmo=; b=OWuN5ZswiXulisL8pwgsfQg1kBCYlZc1mOQXtBklL0yZnaJH9qHwBL6l6iDcLAYRNs yvHE7PHzPQlaIK8JqK4bkeaq1/O1DIaG46dG5g3RSB2QmAkWCk0pTOHfoxyACOSIHkcl 3A9IrFkNh70gqaCsVqe2WoZqi10JodNT7n8YwhTX8Y2olsfeVh9bCeovrtmVJN9ItFPL Ajh254OItV7n3a+e69Gw0LSf5rBJXgKtd5xDNfpofo6flPsiac7icOfdFIoI7/+h4nVy BNDIx+TG4QItu8JW/L+LVFUDQvp7ws4mDdRS7vRn2Hs7exSxNc/8tST6JianU9mG5s3t DBMw== X-Gm-Message-State: ANhLgQ3+Vau7iK7BKmne/BojzvKnjutqpSAvYbl2Ti6ZhJHHatGwGDiS 02FYURqiIQ5Yx7NHxIOH7aY= X-Received: by 2002:a05:620a:a0d:: with SMTP id i13mr8293097qka.333.1584025987867; Thu, 12 Mar 2020 08:13:07 -0700 (PDT) Received: from auth1-smtp.messagingengine.com (auth1-smtp.messagingengine.com. [66.111.4.227]) by smtp.gmail.com with ESMTPSA id t7sm3298089qtr.88.2020.03.12.08.13.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Mar 2020 08:13:05 -0700 (PDT) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailauth.nyi.internal (Postfix) with ESMTP id E59A122451; Thu, 12 Mar 2020 11:13:03 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Thu, 12 Mar 2020 11:13:03 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedruddvhedgjeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdluddtmdenucfjughrpefhvffufffkofgggfestdekredtredttden ucfhrhhomhepuehoqhhunhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrd gtohhmqeenucfkphephedvrdduheehrdduuddurdejudenucevlhhushhtvghrufhiiigv pedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegsohhquhhnodhmvghsmhhtphgruhhthh hpvghrshhonhgrlhhithihqdeiledvgeehtdeigedqudejjeekheehhedvqdgsohhquhhn rdhfvghngheppehgmhgrihhlrdgtohhmsehfihigmhgvrdhnrghmvg X-ME-Proxy: Received: from localhost (unknown [52.155.111.71]) by mail.messagingengine.com (Postfix) with ESMTPA id F360830615B2; Thu, 12 Mar 2020 11:13:02 -0400 (EDT) From: Boqun Feng To: linux-kernel@vger.kernel.org, rcu@vger.kernel.org Cc: "Joel Fernandes (Google)" , "Paul E. McKenney" , Madhuparna Bhowmik , Boqun Feng , Qian Cai , Peter Zijlstra , Ingo Molnar , Will Deacon Subject: [PATCH] locking/lockdep: Avoid recursion in lockdep_count_{for,back}ward_deps() Date: Thu, 12 Mar 2020 23:12:55 +0800 Message-Id: <20200312151258.128036-1-boqun.feng@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Qian Cai reported a bug when PROVE_RCU_LIST=y, and read on /proc/lockdep triggered a warning: [26405.676199][ T3548] DEBUG_LOCKS_WARN_ON(current->hardirqs_enabled) ... [26406.402408][ T3548] Call Trace: [26406.416739][ T3548] lock_is_held_type+0x5d/0x150 [26406.438262][ T3548] ? rcu_lockdep_current_cpu_online+0x64/0x80 [26406.466463][ T3548] rcu_read_lock_any_held+0xac/0x100 [26406.490105][ T3548] ? rcu_read_lock_held+0xc0/0xc0 [26406.513258][ T3548] ? __slab_free+0x421/0x540 [26406.535012][ T3548] ? kasan_kmalloc+0x9/0x10 [26406.555901][ T3548] ? __kmalloc_node+0x1d7/0x320 [26406.578668][ T3548] ? kvmalloc_node+0x6f/0x80 [26406.599872][ T3548] __bfs+0x28a/0x3c0 [26406.617075][ T3548] ? class_equal+0x30/0x30 [26406.637524][ T3548] 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 --- kernel/locking/lockdep.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 32406ef0d6a2..5142a6b11bf5 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.25.1