Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp767977rwl; Sat, 25 Mar 2023 10:35:16 -0700 (PDT) X-Google-Smtp-Source: AKy350ZiF4Ma/90LSTZph5TolsusQ1VAzAAfyoCb8aUN4RMQpiuziBP+KQ0XL/pwij66OL1t+9dZ X-Received: by 2002:aa7:9ace:0:b0:626:248d:4ece with SMTP id x14-20020aa79ace000000b00626248d4ecemr6361893pfp.30.1679765716611; Sat, 25 Mar 2023 10:35:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679765716; cv=none; d=google.com; s=arc-20160816; b=RReH9iEn5/BivupTvHCF02wvSpEPClbPgiWe8r4WzfLenyd1XRj2N5gEsXZFOAF9kO OxL/D38p5dLHMLsNrw78F8WugIGag3DBgw04ueCHi8Fnu9QbyqnUZGDKuj1bIoFTRvzd p2FmCAkw4h8CyWexOBM4rYBgqw69mrK0DsRPg1GnVWO5ePCAq5zORPi+nypHJhQvbC3U 5DNCije9lG068OcMKmaZwRgDxX4zgYAyTvY9RQ6slQqZut8/jRkbbETdWhp0tC6eh4Af Rk/X1lylXfQkJ1EXvEwm7fYDh+7Fk9rr/SPbab9IYknHiIT0mYmIw2w77/BPnmyXOUCj /ljQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Q6C53sn27NuA32AX3ykr9qVTka3YNyXyLo2FHjcHAPk=; b=eoprdJSxunX5++bdhOtISTMz24oKDigg+af/WHVnVJy7iHSgBLy07wdTno48zS5/0B 0Ss8RzzrRF4d/jLvon9ozBu8wP7NkQ3FSKSpd92r7orSfhcd/lNl9EFAKCnHnisjDZEN Ld+MzRB1ZPBPJSxPQs9eOK8nE2ThWqdHH4zUz8UI4BFTYVB/LMaY6oWcraGOX2bAexM8 oFO41MYuHcHXDIErvnAo/akKlnRHCkPO3J/XZnCtQeLaXCwlH2QO7LqZBqQdAWqmCmni MV/5P610yBwT43D23o1IhxMgm8kGdgC/n+tT7+5L67Le8H29x749zAZFafL/TWMSysb7 hjcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=yhQE5Jit; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 201-20020a6303d2000000b00502d794102asi12846264pgd.588.2023.03.25.10.35.05; Sat, 25 Mar 2023 10:35:16 -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=@joelfernandes.org header.s=google header.b=yhQE5Jit; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232050AbjCYRef (ORCPT + 99 others); Sat, 25 Mar 2023 13:34:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231825AbjCYReK (ORCPT ); Sat, 25 Mar 2023 13:34:10 -0400 Received: from mail-qt1-x82c.google.com (mail-qt1-x82c.google.com [IPv6:2607:f8b0:4864:20::82c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4E71DBE6 for ; Sat, 25 Mar 2023 10:34:04 -0700 (PDT) Received: by mail-qt1-x82c.google.com with SMTP id hf2so4509967qtb.3 for ; Sat, 25 Mar 2023 10:34:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; t=1679765643; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Q6C53sn27NuA32AX3ykr9qVTka3YNyXyLo2FHjcHAPk=; b=yhQE5JitzdBNkzY0TYfTzuvOS/VKmMwn5KP2dPiUdYcgdHLPrmvZZ6Np/lG32lNBAd lt9VxOLDD0Yxnj/P9thYO1M/R2JLG12ggb55LdZcQNrb8ZOv8E4OD9ybmGmBVQE7U7t4 vwfVjwDCDMeJ7G6L/7UIbp5+MZFMuw6ebBtYE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679765643; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Q6C53sn27NuA32AX3ykr9qVTka3YNyXyLo2FHjcHAPk=; b=7WwpDyrLFOfMLgWrQAQlGTo1rw2TUDwi38VlDwa518KblppmfGfe89W7ADL0VrRlfn InKrXwjINnjLNfaIiujwGVu76Ghg9JREVZjKZL7kDnyVPPPs4evSLVTS2VW0PIpRu7YD DaiiKSe+7LAmYluh8PGehrpyonJ72bJz6uXRpfZlL5R5YSYic++RKZ682LKGqQzngoVp eVtH94aFfgqwFHLi3fABlvF4bTygDk5/hLVr2V/kmAovPGFqey/CO/uzfm5cAcK9c3gv EH0WLE/71ZUlPEZ0d5wctPQzE/7nCPENEsYNHkpqmZM07pg6y0T1IYKdi5E/zDuDBApA t03Q== X-Gm-Message-State: AO0yUKUh42FFaj0pHOuF7KpBk2cUED/zde7f5MVvmFnJV/0xglbhhIR/ mTyUKinMilASvDZQ/TXjuEiw9g/DtltplRi9TlI= X-Received: by 2002:ac8:5787:0:b0:3e3:98af:5de9 with SMTP id v7-20020ac85787000000b003e398af5de9mr12140109qta.63.1679765643455; Sat, 25 Mar 2023 10:34:03 -0700 (PDT) Received: from joelboxx.c.googlers.com.com (129.239.188.35.bc.googleusercontent.com. [35.188.239.129]) by smtp.gmail.com with ESMTPSA id m4-20020ac84444000000b003e37ee54b5dsm6762764qtn.90.2023.03.25.10.34.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Mar 2023 10:34:03 -0700 (PDT) From: "Joel Fernandes (Google)" To: linux-kernel@vger.kernel.org, "Paul E. McKenney" , Frederic Weisbecker , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang Cc: rcu@vger.kernel.org Subject: [PATCH v2 10/13] rcu: Permit start_poll_synchronize_rcu_expedited() to be invoked early Date: Sat, 25 Mar 2023 17:33:13 +0000 Message-Id: <20230325173316.3118674-11-joel@joelfernandes.org> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog In-Reply-To: <20230325173316.3118674-1-joel@joelfernandes.org> References: <20230325173316.3118674-1-joel@joelfernandes.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 From: Zqiang 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. Signed-off-by: Zqiang Reviewed-by: Frederic Weisbecker Reviewed-by: Joel Fernandes (Google) Signed-off-by: Paul E. McKenney Signed-off-by: Joel Fernandes (Google) --- kernel/rcu/tree.c | 5 ++--- kernel/rcu/tree_exp.h | 5 +++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index e80e8f128c57..90d54571126a 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -4942,9 +4942,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 7cc4856da081..5343f32e7d67 100644 --- a/kernel/rcu/tree_exp.h +++ b/kernel/rcu/tree_exp.h @@ -1066,9 +1066,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); -- 2.40.0.348.gf938b09366-goog