Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2757834rwb; Mon, 3 Oct 2022 05:18:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM55UfexQg19yStmf/Jp8MAzmByLSvcV8nGADraAn+jAb9EN+2MS6FQq31amZ+FvjbYli2sv X-Received: by 2002:a62:1c8f:0:b0:537:2284:bd00 with SMTP id c137-20020a621c8f000000b005372284bd00mr22125067pfc.78.1664799483613; Mon, 03 Oct 2022 05:18:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664799483; cv=none; d=google.com; s=arc-20160816; b=d+S0cL0XVGmMGMjubRuHbEh4/wrELyYfHoaoyOVdYAninDAZxQST3JpZdaPvyTlEwo GEkphzpggh2o/igbD2j0S5PyIBRoIbAOoujQC723xGEhuhRNbBwq+eFTou4fW7ykZ8Td U4Nr45o1O1fXqu+IgWpbzpEK42y/Nqh+EqlNNWmXvngfD8Anpap1nd26q6uX4S+g7XMX 9sevUW/Tqj7FZj995daLPoJ2Bv63q36/mZd4PwBKwY45iD9+Q6yPc7CEpA8mTtygBlKe WfC/1YUZoq5Y7DxaVv060rNNSDwuhY+bFV1bvC0W9nG+OjRfEmn/2egckBMeoiBMj7js jIVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=5W9/gl3u0l+wSmueKI+gLzfFxqgFeEbqONL33PkHsAo=; b=OKIQ1PJP5DMy6sksghpEIKFafN+IrYkuERsNCQ+0mKE/al2JFuhSTxrAVvoUVQmgep 0VuZzl1Udnkw8rCgUzwPIGvqaZXl5KkYhu3QP7IqWeDc0n0sZQHD/i+3JE2xUSB2grW6 7y/NhpzgzaT8eGZo9MS5qWPHPrx88B3mdqnHTyFNvjpUYEc+6jXnTl+PY6Mt3TFebrOf B6IH9zVdDJzF6e1qVhMSTjGovvlThwHiggmbQWaFH110fRPFJvV/xlllgKVG6Sx3EqbX vhHFxOtV/FUl/+qVR8VvnC94rLEHAWKuLXjrbVQFbbf4hsmEFWzRe98fY8tbmZsrLMdX Dafw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=i7N0VlfP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kb10-20020a17090ae7ca00b0020a7f8f8afbsi5278329pjb.49.2022.10.03.05.17.51; Mon, 03 Oct 2022 05:18:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=i7N0VlfP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S229690AbiJCLwm (ORCPT + 99 others); Mon, 3 Oct 2022 07:52:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229589AbiJCLwk (ORCPT ); Mon, 3 Oct 2022 07:52:40 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF9BA33A2E; Mon, 3 Oct 2022 04:52:35 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 96018CE0B9B; Mon, 3 Oct 2022 11:52:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9A91FC433D7; Mon, 3 Oct 2022 11:52:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664797951; bh=qZ/gyhhra5msYs9vZ80bZK2vWJ31ANToo6dRtYSNDD8=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=i7N0VlfPl9BL44b2w4yt3E9SzdcJrNYBoS1Td46bikS/RrVgRDUe3mchTSE3W9hWN 04Tn5Rh5u6b0/+Ma9UxzppSCtMlQsWz0VDKitm+HeHYabCoHA3BJsqMvhTz0EQTUJw UGVy5HO9Ci8O0mf9LJZWWTATQDmFPSKy1e1n/4j4P/qd1vSUmsAGG8Smf1KI0ygVCA OnwjgVcUP+7vKhLlmfUxhumewT+1qH7ObatFhEYOJOygGiiFXE8XifB1P5iLQAMkkz ZbT8iPUyJeVwnomaSmay+D4BqxJxa4AwrntUj4EfsPqac4gvspOBDtzDC7vPiPfyv1 sZ2P5WGbG1wBA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 36BA85C0641; Mon, 3 Oct 2022 04:52:31 -0700 (PDT) Date: Mon, 3 Oct 2022 04:52:31 -0700 From: "Paul E. McKenney" To: Frederic Weisbecker Cc: rcu@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, rostedt@goodmis.org, Randy Dunlap , Thomas Gleixner , John Ogness , Petr Mladek Subject: Re: [PATCH RFC v2 rcu 2/8] srcu: Create an srcu_read_lock_nmisafe() and srcu_read_unlock_nmisafe() Message-ID: <20221003115231.GX4196@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <20220929180714.GA2874192@paulmck-ThinkPad-P17-Gen-1> <20220929180731.2875722-2-paulmck@kernel.org> <20221002155516.GB292620@lothringen> <20221002160957.GP4196@paulmck-ThinkPad-P17-Gen-1> <20221002214710.GA297965@lothringen> <20221002234655.GV4196@paulmck-ThinkPad-P17-Gen-1> <20221003095535.GA298829@lothringen> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221003095535.GA298829@lothringen> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 03, 2022 at 11:55:35AM +0200, Frederic Weisbecker wrote: > On Sun, Oct 02, 2022 at 04:46:55PM -0700, Paul E. McKenney wrote: > > On Sun, Oct 02, 2022 at 11:47:10PM +0200, Frederic Weisbecker wrote: > > > On Sun, Oct 02, 2022 at 09:09:57AM -0700, Paul E. McKenney wrote: > > > > On Sun, Oct 02, 2022 at 05:55:16PM +0200, Frederic Weisbecker wrote: > > > > > On Thu, Sep 29, 2022 at 11:07:25AM -0700, Paul E. McKenney wrote: > > > > > > @@ -1090,7 +1121,7 @@ static unsigned long srcu_gp_start_if_needed(struct srcu_struct *ssp, > > > > > > int ss_state; > > > > > > > > > > > > check_init_srcu_struct(ssp); > > > > > > - idx = srcu_read_lock(ssp); > > > > > > + idx = __srcu_read_lock_nmisafe(ssp); > > > > > > > > > > Why do we need to force the atomic based version here (even if CONFIG_NEED_SRCU_NMI_SAFE=y)? > > > > > > > > In kernels built with CONFIG_NEED_SRCU_NMI_SAFE=n, we of course need it. > > > > As you say, in kernels built with CONFIG_NEED_SRCU_NMI_SAFE=y, we don't. > > > > But it doesn't hurt to always use __srcu_read_lock_nmisafe() here, and > > > > this is nowhere near a fastpath, so there is little benefit to using > > > > __srcu_read_lock() when it is safe to do so. > > > > > > > > In addition, note that it is possible that a given srcu_struct structure's > > > > first grace period is executed before its first reader. In that > > > > case, we have no way of knowing which of __srcu_read_lock_nmisafe() > > > > or __srcu_read_lock() to choose. > > > > > > > > So this code always does it the slow(ish) safe way. > > > > > > But then srcu_read_lock_nmisafe() would work as well, right? > > > > Almost. > > > > The problem is that without the leading "__", this would convince SRCU > > that this is an NMI-safe srcu_struct. Which it might not be. Worse yet, > > if this srcu_struct had already done an srcu_read_lock(), it would splat. > > Ah ok, now that makes sense. > > > > > > > > > ss_state = smp_load_acquire(&ssp->srcu_size_state); > > > > > > if (ss_state < SRCU_SIZE_WAIT_CALL) > > > > > > sdp = per_cpu_ptr(ssp->sda, 0); > > > > > > @@ -1123,7 +1154,7 @@ static unsigned long srcu_gp_start_if_needed(struct srcu_struct *ssp, > > > > > > srcu_funnel_gp_start(ssp, sdp, s, do_norm); > > > > > > else if (needexp) > > > > > > srcu_funnel_exp_start(ssp, sdp_mynode, s); > > > > > > - srcu_read_unlock(ssp, idx); > > > > > > + __srcu_read_unlock_nmisafe(ssp, idx); > > > > > > return s; > > > > > > } > > > > > > > > > > > > @@ -1427,13 +1458,13 @@ void srcu_barrier(struct srcu_struct *ssp) > > > > > > /* Initial count prevents reaching zero until all CBs are posted. */ > > > > > > atomic_set(&ssp->srcu_barrier_cpu_cnt, 1); > > > > > > > > > > > > - idx = srcu_read_lock(ssp); > > > > > > + idx = __srcu_read_lock_nmisafe(ssp); > > > > > > > > > > And same here? > > > > > > > > Yes, same here. ;-) > > > > > > Now bonus question: why do SRCU grace period starting/tracking > > > need to be in an SRCU read side critical section? :o) > > > > Because I am lazy and like to keep things simple? ;-) > > > > More seriously, take a look at srcu_gp_start_if_needed() and the functions > > it calls and ask yourself what bad things could happen if they were > > preempted for an arbitrarily long period of time. > > I can see a risk for ssp->srcu_gp_seq to overflow. Can't say that was obvious > though, at least for me. Am I missing something else? That is what I recall. There might also be something else, of course. ;-) Thanx, Paul