Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5298602pxj; Tue, 22 Jun 2021 20:59:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwChQf+cYul03QgWaMZtDdQ2QVzPZWaOChRWu98RIoVuiFH/li5liGEztAtsui4NA/MjPgr X-Received: by 2002:a17:906:2b85:: with SMTP id m5mr7826045ejg.141.1624420759890; Tue, 22 Jun 2021 20:59:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624420759; cv=none; d=google.com; s=arc-20160816; b=MVghZUu7f/ZGaiMrpqrxYGN/CZAPm4V3gHMwiZVxmv/4d4TmMXqHUuvkhZteTwusrf JADqIXKDFziUUXS3Z05gL3+EvLRULmokllIUMdnEJKhd1kuTup5L2N8ohjagYWpAcVmb ZFNi6VbmE7sqbx46MOrzD7VDjLSBiimgiW2RGpd6Zn1UTyOPn3p4+41Gt/X1lUYPLfGr Gh/fJoWirn4Oso1cTUvpGtWzxb7evP2B4SV+gm3UXIfwqagEVIrV/9dHO011Atyjm+zp wZ7Wl9VQfOAtV6pB3X7yREc/+KqcGlHZ7912MJPG9H/6KqVsuWSMQ2axVI5x/l7iNl6u E7gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dmarc-filter:sender:dkim-signature; bh=wW6o3uBZEysjylk8SPrMOuZ7g4T1yfR4JhqBnE4nj0s=; b=uM5mGY7TZGydwyK5M+rGlCP0VvvhJr65+E7kEu6tzIRN9ISd/ny/BzhJ1xVdJi8+kQ wxn/LtO0vRhGA3q1SqP0RS+F3WKtXosA7RRk6kTKF9f6W6gMbBXjx0p5m+TI0j89bkFP nRtNCIT++vhZjtBypZTbRq6odJx+dYHg0li2e9CJxNEOrUbOjhM2qT49tzGq7kng5eCg oD9kxlV0CKu0+QYC2m48wJJOm8gZ7JhMXGQQb8AXaf2QMr8eXQK5xlTwS3LgCOChymGg KhHue/rOHAiYFjL8FGh27+uBm7n7DXSoIvrwMqwL5eDU978VnFrwcOSxaUyaGkfpbwAe AYeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b="V/ppx2JW"; 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 hg15si3395725ejc.285.2021.06.22.20.58.33; Tue, 22 Jun 2021 20:59:19 -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=@mg.codeaurora.org header.s=smtp header.b="V/ppx2JW"; 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 S229774AbhFWD7w (ORCPT + 99 others); Tue, 22 Jun 2021 23:59:52 -0400 Received: from so254-9.mailgun.net ([198.61.254.9]:11371 "EHLO so254-9.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229907AbhFWD7v (ORCPT ); Tue, 22 Jun 2021 23:59:51 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1624420655; h=Content-Transfer-Encoding: Content-Type: In-Reply-To: MIME-Version: Date: Message-ID: From: References: Cc: To: Subject: Sender; bh=wW6o3uBZEysjylk8SPrMOuZ7g4T1yfR4JhqBnE4nj0s=; b=V/ppx2JWdsXcLJxcvMEG/fPb9oHcdRKXl+CTbSZxbmRr+On5BYs3c8b42leez/msCNFt69XB GlUoR2woxFCD9gyQGCZXn46nkvPtyXA7QTFk226nKZeve33f89WysOJtCWPKEaW7A40rvgrO 2D1fdEy1wWpsqW5w952SNWLBNhE= X-Mailgun-Sending-Ip: 198.61.254.9 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n03.prod.us-west-2.postgun.com with SMTP id 60d2b11f638039e997cd4851 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Wed, 23 Jun 2021 03:57:19 GMT Sender: neeraju=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 39B3DC43217; Wed, 23 Jun 2021 03:57:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=ALL_TRUSTED,BAYES_00, NICE_REPLY_A,SPF_FAIL autolearn=no autolearn_force=no version=3.4.0 Received: from [192.168.0.104] (unknown [103.199.158.142]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: neeraju) by smtp.codeaurora.org (Postfix) with ESMTPSA id 57CADC433F1; Wed, 23 Jun 2021 03:57:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 57CADC433F1 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=fail smtp.mailfrom=neeraju@codeaurora.org Subject: Re: [PATCH] rcu: update: Check rcu_bh_lock_map state in rcu_read_lock_bh_held To: paulmck@kernel.org Cc: josh@joshtriplett.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, jiangshanlai@gmail.com, joel@joelfernandes.org, rcu@vger.kernel.org, linux-kernel@vger.kernel.org, urezki@gmail.com, frederic@kernel.org References: <1624363521-19702-1-git-send-email-neeraju@codeaurora.org> <20210622175855.GE4397@paulmck-ThinkPad-P17-Gen-1> <61bed875-5ebf-03d8-58ea-e9263c534201@codeaurora.org> <20210622234652.GL4397@paulmck-ThinkPad-P17-Gen-1> From: Neeraj Upadhyay Message-ID: Date: Wed, 23 Jun 2021 09:27:11 +0530 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210622234652.GL4397@paulmck-ThinkPad-P17-Gen-1> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/23/2021 5:16 AM, Paul E. McKenney wrote: > On Wed, Jun 23, 2021 at 12:38:09AM +0530, Neeraj Upadhyay wrote: >> >> >> On 6/22/2021 11:28 PM, Paul E. McKenney wrote: >>> On Tue, Jun 22, 2021 at 05:35:21PM +0530, Neeraj Upadhyay wrote: >>>> In addition to irq and softirq state, check rcu_bh_lock_map >>>> state, to decide whether RCU bh lock is held. >>>> >>>> Signed-off-by: Neeraj Upadhyay >>> >>> My initial reaction was that "in_softirq() || irqs_disabled()" covers >>> it because rcu_read_lock_bh() disables BH. But you are right that it >>> does seem a bit silly to ignore lockdep. >>> >>> So would it also make sense to have a WARN_ON_ONCE() if lockdep claims >>> we are under rcu_read_lock_bh() protection, but "in_softirq() || >>> irqs_disabled()" think otherwise? >> >> After thinking more on this, looks like one intention of not >> having lockdep check here was to catch scenarios where some code enables bh >> after doing rcu_read_lock_bh(), as is mentioned in the comment above >> rcu_read_lock_bh_held(): >> >> Note that if someone uses >> rcu_read_lock_bh(), but then later enables BH, lockdep (if enabled) >> will show the situation. This is useful for debug checks in functions >> that require that they be called within an RCU read-side critical >> section. >> >> Client users seem to be doing lockdep checks on returned value: >> drivers/net/wireguard/peer.c >> RCU_LOCKDEP_WARN(!rcu_read_lock_bh_held(), >> >> Similarly, any rcu_dereference_check(..., rcu_read_lock_bh_held()) usage >> also triggers warning, if bh is enabled, inside rcu_read_lock_bh() >> section. >> >> So, using 'in_softirq() || irqs_disabled()' condition looks to be sufficient >> condition, to mark all read lock bh regions and adding '|| >> lock_is_held(&rcu_bh_lock_map)' to this condition does not seem to fit >> well with the RCU_LOCKDEP_WARN(!rcu_read_lock_bh_held()) and >> rcu_dereference_check(..., rcu_read_lock_bh_held()) calls, if we hit >> the scenario, where bh lockmap state (shows bh lock acquired) conflicts with >> the softirq/irq state . > > That makes sense to me! > > But should there be checks somewhere for something like > "lock_is_held(&rcu_bh_lock_map) && !in_softirq() && !irqs_disabled()"? > > Thanx, Paul > I think this check is good to have inside rcu_read_lock_bh_held(), to highlight this scenario explicitly; I am thinking, if it makes sense to have lock_is_held(&rcu_bh_lock_map) check in rcu_softirq_qs() ? Also, I think this check is more important for rcu_read_lock_sched_held(), where lockdep state is used as a sufficient condition, for marking a RCU sched region. One more api is rcu_read_lock_any_held(), where we can warn on conflicting cases. int rcu_read_lock_sched_held(void) { bool ret; if (rcu_read_lock_held_common(&ret)) return ret; return lock_is_held(&rcu_sched_lock_map) || !preemptible(); } Thanks Neeraj >> Thanks >> Neeraj >> >>>> --- >>>> kernel/rcu/update.c | 2 +- >>>> 1 file changed, 1 insertion(+), 1 deletion(-) >>>> >>>> diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c >>>> index c21b38c..d416f1c 100644 >>>> --- a/kernel/rcu/update.c >>>> +++ b/kernel/rcu/update.c >>>> @@ -333,7 +333,7 @@ int rcu_read_lock_bh_held(void) >>>> if (rcu_read_lock_held_common(&ret)) >>>> return ret; >>>> - return in_softirq() || irqs_disabled(); >>>> + return lock_is_held(&rcu_bh_lock_map) || in_softirq() || irqs_disabled(); >>>> } >>>> EXPORT_SYMBOL_GPL(rcu_read_lock_bh_held); >>>> -- >>>> QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, >>>> hosted by The Linux Foundation >>>> >> >> -- >> QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of >> the Code Aurora Forum, hosted by The Linux Foundation -- QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation