Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp230660pxu; Tue, 5 Jan 2021 09:19:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJxiuRmWVAJp7a2xozq3J6vmfBNsd+Qc/PTRzrCjRXU0gbTJchvzgDe5rY+vDMZP/BAojSwU X-Received: by 2002:a17:906:6606:: with SMTP id b6mr141857ejp.151.1609867192081; Tue, 05 Jan 2021 09:19:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609867192; cv=none; d=google.com; s=arc-20160816; b=OODKvz1ZNoKxn2pgH4eCWByeVngdWf0e0yPXs0Df39pU7V9/NywH07XuVEUSJ25oKr h9EmiuuTfuIjQZVecLVmBi3C3+cnCWeO4LBcLzV8U0xyc2Sgm6xG5Rn/K6vaVkz6tD4O Q68G5jIwAtjhXwO+GWHPPXbfKmr/2lubGGvuRNOtP2U5HhgWxxkpI85ZlTx0GOEeVHzP UFcd24H0KVx3WLyXbqkidWWUG3AVkHhZjyUyPxCJm9YkVbLGXQV5O2AVTnAR+lrT1JRM Gb2tZIUt85DN5K4A43xh5GfZVjMtStYFDHnLFToyBgsa4NAHTdADyWq7brI1nCqiWFCr O7UA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=MJfm+HzHXj4JQcPn3t4VzL24nV+8FDSjFkMXbGgKZMY=; b=T0yZcOm0186AJMSij31VJGLws8JYxKgUGz+hNmSQ4FUDjLVye+st0w/Q8Qg8+zk5lq wzy+FmygwvNdFYBr0dVwnCOTNqrXXBGIQchgxMKT8q2AtQU95yQr8EFnMu0CGRd1Y1Fr 45c3pKu7Jkh35ecKAGeXA6uc+nuvCkSMehif8p8n1UOsfzcT7h8TrFUyem53OjRg/OZQ qq8OA9qnAftdo5HNN3rHZ6ftILWY0w8E8knoFrw8UIq0vbh3bAGsuud8QYBoK2RwDkM1 NU4yY7wPSK54BvtAkBaiUSw/8+Eac0vO3OdXikCAkHVgFpKZhgHTl410h9cZqWgO6c+6 joFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WGOaQyq6; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ce20si125828edb.138.2021.01.05.09.19.27; Tue, 05 Jan 2021 09:19:52 -0800 (PST) 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=k20201202 header.b=WGOaQyq6; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728044AbhAERPc (ORCPT + 99 others); Tue, 5 Jan 2021 12:15:32 -0500 Received: from mail.kernel.org ([198.145.29.99]:48100 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725838AbhAERPc (ORCPT ); Tue, 5 Jan 2021 12:15:32 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1237E22CBE; Tue, 5 Jan 2021 17:14:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1609866891; bh=ZBm+Do+2kpIYllhXGeLT1fi8UQ0K47P8KRqerz8BmBc=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=WGOaQyq6Gxu8cF+0m1fEt4Zq/BlRhG/B6xkErjztRNnP2Nae/r9fPIA3jWymFm1P0 d0A6UpJ+1LF7fJxDWvXDfHVz6FP1mpe20RqgpOCvF3BVOVLqc6LG0c9P+Lw9dFGxld GLddJQIpGAJrQfLoqtTEdJbT65HFYmOogzX4IrFtmPtYow5XjiqHA5fu+0v+wNZHmt 5PjB7JUR4AXf3254LiS0SBSABhUD4Q4ZvaZWA56Q0+PW/HK1/JVp+jvHVRUehy6gIj 9oYs7Atp7/dCJCNf8QRn2nVL/eRZeANfffKJNZbp+/p23WYE4V7KBCV/H/6CuP4tIw bMg/harw4paFw== Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id C76BD3521C49; Tue, 5 Jan 2021 09:14:50 -0800 (PST) Date: Tue, 5 Jan 2021 09:14:50 -0800 From: "Paul E. McKenney" To: Peter Zijlstra Cc: Neeraj Upadhyay , 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 Subject: Re: [PATCH] rcu: Fix dynticks_nmi_nesting underflow check in rcu_is_cpu_rrupt_from_idle Message-ID: <20210105171450.GF17086@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: <1608712777-1769-1-git-send-email-neeraju@codeaurora.org> <20201223151231.GC2657@paulmck-ThinkPad-P72> <20210105134232.GI3040@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210105134232.GI3040@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 05, 2021 at 02:42:32PM +0100, Peter Zijlstra wrote: > On Wed, Dec 23, 2020 at 07:12:31AM -0800, Paul E. McKenney wrote: > > On Wed, Dec 23, 2020 at 02:09:37PM +0530, Neeraj Upadhyay wrote: > > > For the smp_call_function() optimization, where callbacks can run from > > > idle context, in commit 806f04e9fd2c ("rcu: Allow for smp_call_function() > > > running callbacks from idle"), an additional check is added in > > > rcu_is_cpu_rrupt_from_idle(), for dynticks_nmi_nesting value being 0, > > > for these smp_call_function() callbacks running from idle loop. > > > However, this commit missed updating a preexisting underflow check > > > of dynticks_nmi_nesting, which checks for a non zero positive value. > > > Fix this warning and while at it, read the counter only once. > > > > > > Signed-off-by: Neeraj Upadhyay > > > --- > > > > > > Hi, > > > > > > I was not able to get this warning, with scftorture. > > > > > > RCU_LOCKDEP_WARN(__this_cpu_read(rcu_data.dynticks_nmi_nesting) <= 0, > > > "RCU dynticks_nmi_nesting counter underflow/zero!"); > > > > > > Not sure if idle loop smp_call_function() optimization is already present > > > in mainline? > > > > Now that you mention it, I don't see it. > > kernel/sched/idle.c:do_idle() calls flush_smp_call_function_from_idle(). > > (nothing x86 specific about it) Got it, thank you! The reason Neeraj was unable to trigger the problematic warning from scftorture is that its smp_call_function() handlers do not invoke rcu_is_cpu_rrupt_from_idle(). Without adding this to those handlers (which would be a good change to make), the only way to trigger this is for an expedited RCU grace period to IPI a CPU that goes idle while the IPI is in flight, which is not the easiest thing to make happen. > > > Another thing, which I am not sure of is, maybe lockdep gets disabled > > > in the idle loop contexts, where rcu_is_cpu_rrupt_from_idle() is called? > > > Was this the original intention, to keep the lockdep based > > > RCU_LOCKDEP_WARN(__this_cpu_read(rcu_data.dynticks_nmi_nesting) <= 0 > > > check separate from idle task context nesting value > > > WARN_ON_ONCE(!nesting && !is_idle_task(current)) check? > > > > An easy way to test lockdep is to create a pair of locks, acquire them > > in one order then release them both, and finally acquire them in the > > other order and then release them both. If lockdep is configured and > > enabled, it will complain. > > IIRC (and this is after not staring at the computer for 2 weeks) lockdep > should work just fine in idle, except of course that RCU will be stopped > so actually taking locks will scream bloody murder due to tracing etc.. Fair enough... And I hope that the time off went well for you and yours! > > The only reason I used RCU_LOCKDEP_WARN() was that people were complaining > > to me about idle-entry overhead back at that time. So without lockdep, > > there is zero overhead. Maybe people have become more tolerant of idle > > delays, or perhaps they are not so worried about an extra check of a > > cache-hot quantity. > > Not having checks also saves on $I and branches, in general I think > having checks depend on DEBUG features, esp. those we don't really > expect to trigger is still sane. OK, so should we convert the WARN_ON_ONCE() to RCU_LOCKDEP_WARN() while we are in the area? > > I am tempted to pull this in as is, given the current logical > > inconsistency in the checks. Thoughts? > > Patch looks ok, although I've seen compilers do CSE on > __this_cpu_read() (on x86). True, but the compilers might might have a harder time of this on other architectures. Thanx, Paul