Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp1085715rwb; Fri, 13 Jan 2023 07:46:43 -0800 (PST) X-Google-Smtp-Source: AMrXdXt+zjD5JZCzvy/F5zW7hP3wKWSV4qLMps3pzjFaed4igqZtba3BT6kLIwT/AX2r0lVqsh0N X-Received: by 2002:a05:6a20:438e:b0:a5:7700:2a1a with SMTP id i14-20020a056a20438e00b000a577002a1amr105833203pzl.1.1673624803157; Fri, 13 Jan 2023 07:46:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673624803; cv=none; d=google.com; s=arc-20160816; b=CGYUkL+mSXnmXg1wfvkcDHsbj1hwSXMCuokehi09Yo0rrclehj0qBbZk0DIU5pyEIz jacFPQuZ71iGNq6wvV6h5aw4xypcRjAd3nw6qs91v0w33ek3ZGa9YaSdRmSgl0YylqH6 LZcMDI7GOkqHWSlI+cmljfUABPey+4R2rFWa6PvnTVKxZLQ1N1dbJwtriDZlF5dWQ0Gj 7zJ+0xqhGKBp1nsfiueXj0yOHY6RG2LnLu9sUBk3PaCkCU1mHlDITFcbF3VgrsKPlZNs 5KdSJG+9AoU5QEEEMZJ/SAUzw1KBu/ccwefBLsuJy3XWp0kq48srfkV65LrKRS/lzwOQ +j9Q== 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-transfer-encoding :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=7ZmF6Gk8ewcEk1VexYnWVj5Oy/DZbk1buX6N1lExTKk=; b=ZxvUI+Y6jreBcxfrI5FT3sRYk5rBKpx/6EGTeUwrr+T8IzCjxv8OAdSrx6KohKNpVZ TLUOwzZbpdTLe61XV6fLSBIpbTEKIHDw9ztqhPy024W/BFCLgAmn+FHYNQgZGFFtHehc t/VkTHwdrHv8FRAQioPjd0Jb1StWiONOM6XH3Zyh6ZPMuQbuCUFZE9XzYu4S47PnlwNB wSkxruYZrkr9qdoouPa1+PpzMBwwMPh9Ci8cnoBIYy7vehnCQlxQfllpnXuafb79Htsv T5u+RUzgZuigcaG0Gkxbvnm4RGp4V8hjZ2o41A2aDnMWi4JWiMhnXn8GkL3ehxmcAtVN TKHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZOy91bzf; 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 mv11-20020a17090b198b00b00219f068d241si20166068pjb.130.2023.01.13.07.46.36; Fri, 13 Jan 2023 07:46:43 -0800 (PST) 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=ZOy91bzf; 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 S230292AbjAMPek (ORCPT + 51 others); Fri, 13 Jan 2023 10:34:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230267AbjAMPeI (ORCPT ); Fri, 13 Jan 2023 10:34:08 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08EB39B281; Fri, 13 Jan 2023 07:27:36 -0800 (PST) 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 ams.source.kernel.org (Postfix) with ESMTPS id EBD12B8212E; Fri, 13 Jan 2023 15:27:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7CA7AC433EF; Fri, 13 Jan 2023 15:27:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673623653; bh=mdjjde/kpGhKz7LWQy4Ha4KJulKpEmB/IfM4LXUBeF8=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=ZOy91bzf8j+p7kuD/QdLpI/BRf8Ov+HaJmoNbgd1BIPqdKVYjAyqpFdKsBjx660nS 894QZSriFopWyVtoQxIDNcKuaNdDLXwpAY8LJP/H1CUqs9lDjDnvtCrBxV0EKdHa1l Xh9GQhh83MYfUCioCwHdlsybkUKDVZY5rLusl6CtXAuRDHNW9vxOXzVzt1poxbM+kN BeevhEBmWFEaQJCjDw6J6Afv/1y0/fEE1M4yoM1A+YCmG/NAmLOEUJbegY56WUMgRY mcgQai03dVt7lr/PfaPfCHBiV07HqIp0oIitFEpZU4lYDM+IOGc8wrrhModu/RzUBd Dw8q47b8VF2fw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 1FF1B5C0964; Fri, 13 Jan 2023 07:27:33 -0800 (PST) Date: Fri, 13 Jan 2023 07:27:33 -0800 From: "Paul E. McKenney" To: "Zhang, Qiang1" Cc: "frederic@kernel.org" , "quic_neeraju@quicinc.com" , "joel@joelfernandes.org" , "rcu@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v2] rcu: Fix the start_poll_synchronize_rcu_expedited() be invoked very early Message-ID: <20230113152733.GZ4028633@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <20230112075629.1661429-1-qiang1.zhang@intel.com> <20230112190656.GR4028633@paulmck-ThinkPad-P17-Gen-1> <20230113144919.GY4028633@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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 Fri, Jan 13, 2023 at 03:02:54PM +0000, Zhang, Qiang1 wrote: > On Fri, Jan 13, 2023 at 12:10:47PM +0000, Zhang, Qiang1 wrote: > > > > > Currently, the start_poll_synchronize_rcu_expedited() can be invoked > > > very early. before rcu_init(), the rcu_data structure's->mynode is not > > > initialized, if invoke start_poll_synchronize_rcu_expedited() before > > > rcu_init(), will trigger a null rcu_node structure's->exp_seq_poll access. > > > > > > This commit add boot_exp_seq_poll_rq member to rcu_state structure to > > > store seq number return by invoke start_poll_synchronize_rcu_expedited() > > > very early. > > > > > > Fixes: d96c52fe4907 ("rcu: Add polled expedited grace-period primitives") > > > Signed-off-by: Zqiang > > > > > >First off, excellent catch, Zqiang!!! > > > > > >And thank you for Frederic and Joel for your reviews. > > > > > >But I believe that this can be simplified, for example, as shown in > > >the (untested) patch below. > > > > > >Thoughts? > > > > > >Agree, thanks for wordsmithed ????. > > > > > > > > >And yes, I did presumptuously add Frederic's and Joel's reviews. > > >Please let me know if you disagree, and if so what different approach > > >you would prefer. (Though of course simple disagreement is sufficient > > >for me to remove your tag. Not holding you hostage for improvements, > > >not yet, anyway!) > > > > > > Thanx, Paul > > > > > >------------------------------------------------------------------------ > > > > > >commit e05af5cb3858e669c9e6b70e0aca708cc70457da > > >Author: Zqiang > > >Date: Thu Jan 12 10:48:29 2023 -0800 > > > > > > rcu: Permit start_poll_synchronize_rcu_expedited() to be invoked early > > > > > > According to the commit log of the patch that added it to the kernel, > > > start_poll_synchronize_rcu_expedited() can be invoked very early, as > > > in long before rcu_init() has been invoked. But before rcu_init(), > > > the rcu_data structure's ->mynode field has not yet been initialized. > > > This means that the start_poll_synchronize_rcu_expedited() function's > > > attempt to set the CPU's leaf rcu_node structure's ->exp_seq_poll_rq > > > field will result in a segmentation fault. > > > > > > This commit therefore causes start_poll_synchronize_rcu_expedited() to > > > set ->exp_seq_poll_rq only after rcu_init() has initialized all CPUs' > > > rcu_data structures' ->mynode fields. It also removes the check from > > > the rcu_init() function so that start_poll_synchronize_rcu_expedited( > > > is unconditionally invoked. Yes, this might result in an unnecessary > > > boot-time grace period, but this is down in the noise. Besides, there > > > only has to be one call_rcu() invoked prior to scheduler initialization > > > to make this boot-time grace period necessary. > > > > A little confused, why call_rcu() invoked prior to scheduler initialization to make this boot-time > > grace period necessary ????? > > > >Because then there will be a callback queued that will require a grace > >period to run anyway. > > > >Or maybe you are asking if those callbacks will really be able to use > >that first grace period? > > Yes, because even if we queue work to rcu_gp_wq workqueue, this also requires us to wait until > the workqueue_init() is invoked, our work can be execute. and also need to wait for the > rcu_gp kthread to be created, after this, our first grace period can begin, the callbacks has the > opportunity to be called. the call_rcu() require a grace period, but we require is expedited grace period. Good catch, thank you! I will update the commit log accordingly. Thanx, Paul > Thanks > Zqiang > > > > > Thanx, Paul > > > Thanks > > Zqiang > > > > > > > > > > Signed-off-by: Zqiang > > > Reviewed-by: Frederic Weisbecker > > > Reviewed-by: Joel Fernandes (Google) > > > Signed-off-by: Paul E. McKenney > > > > > >diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c > > >index 63545d79da51c..f2e3a23778c06 100644 > > >--- a/kernel/rcu/tree.c > > >+++ b/kernel/rcu/tree.c > > >@@ -4937,9 +4937,8 @@ void __init rcu_init(void) > > > else > > > qovld_calc = qovld; > > > > > >- // Kick-start any polled grace periods that started early. > > >- if (!(per_cpu_ptr(&rcu_data, cpu)->mynode->exp_seq_poll_rq & 0x1)) > > >- (void)start_poll_synchronize_rcu_expedited(); > > >+ // Kick-start in case any polled grace periods started early. > > >+ (void)start_poll_synchronize_rcu_expedited(); > > > > > > rcu_test_sync_prims(); > > > } > > >diff --git a/kernel/rcu/tree_exp.h b/kernel/rcu/tree_exp.h > > >index 956cd459ba7f3..3b7abb58157df 100644 > > >--- a/kernel/rcu/tree_exp.h > > >+++ b/kernel/rcu/tree_exp.h > > >@@ -1068,9 +1068,10 @@ unsigned long start_poll_synchronize_rcu_expedited(void) > > > if (rcu_init_invoked()) > > > raw_spin_lock_irqsave(&rnp->exp_poll_lock, flags); > > > if (!poll_state_synchronize_rcu(s)) { > > >- rnp->exp_seq_poll_rq = s; > > >- if (rcu_init_invoked()) > > >+ if (rcu_init_invoked()) { > > >+ rnp->exp_seq_poll_rq = s; > > > queue_work(rcu_gp_wq, &rnp->exp_poll_wq); > > >+ } > > > } > > > if (rcu_init_invoked()) > > > raw_spin_unlock_irqrestore(&rnp->exp_poll_lock, flags);