Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp9404275rwl; Wed, 11 Jan 2023 05:25:24 -0800 (PST) X-Google-Smtp-Source: AMrXdXvJy2JL+rm9B4PgeotVneutraGe+Vo0aOjjcOpKNz036Ucg/w/bG7x+p4NGNWqFwMtcFbbI X-Received: by 2002:a17:902:8688:b0:189:9dca:65e1 with SMTP id g8-20020a170902868800b001899dca65e1mr65755226plo.21.1673443524670; Wed, 11 Jan 2023 05:25:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673443524; cv=none; d=google.com; s=arc-20160816; b=BikPm/r4JDeeT78IR7VK8SqajQZInoL8NhdtlafWGCioQwAfWfhbOS5X5mbGbKDIDI OksUn+lrxuVilOYMkMZQG9dLEdMJzlVQYA58Akqy4R+W1CTRa9F50X5X6wJCnkkghdAi dQB4eOgdFu6eHOgVHmTi0PSGAnu66yinRb7Nzme6iOSczw2RWORW5ui5I4K/AlJRqI3K I2ji6wN7QG42zVJ3z6oNHERxGzzofvrPNmjErQTBQFjMerr+6hOaNl2WMzw92NrB4yG7 mNxr22daQToA1iiIdlM0zN04NqjycpDQot7hfbZaM3tzrj/CmAl8r36DokUiK3VoPIPH kufw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=jgRYqEQ6eGQc6oAk37Xb9DqAdLuh5RsFY5nyIa+oFMw=; b=EiaiAYSH0DCi1xr4WCrvT+sWBCChhJ4i5BTAXQTfkQHlbKxeC178AfbZZt4zoDKhR2 FpJtoEjWDUggEr5XrcVK3oNK4UEKMrvxqhXoxvI7HRsHQAlCe7CAF3ia3RS68QiFZa91 uzY2dmpAxx2EVA2EeO4G0ONwJk4En71tpLnV/SylYg6G5/hNurJxHAAh0ei2vSr7pbgM WQ2nAkOx50ImLtsnlbAdiEB6KCn7z2Ha9JBSni2yHLVwaYYZwjgvyF9pz5l89cbrOV2H acfuqXEteHPi3WumBHqhb1FAHxv+0fUy4yg2od8Wlmp8CkY1i8Ob8t6Cghlnjn+uYHzN CEFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=msv4S96Q; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i11-20020a17090332cb00b00189d0fa14desi14603545plr.620.2023.01.11.05.25.16; Wed, 11 Jan 2023 05:25:24 -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=@intel.com header.s=Intel header.b=msv4S96Q; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232216AbjAKNLY (ORCPT + 55 others); Wed, 11 Jan 2023 08:11:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232027AbjAKNLT (ORCPT ); Wed, 11 Jan 2023 08:11:19 -0500 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5008E39; Wed, 11 Jan 2023 05:11:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673442674; x=1704978674; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=tPgiAxXLY4gShdjl9d7GsMDyiml/2QFNArrDwpdyHfc=; b=msv4S96QkMlQX3+6eDtKfocmPauL1J9o4wfTiDOzv3cr4G7lI3JD7Pdf f4zXFJwFJIPbS064SfD6R8LcTd9uM6Dedwdz5TP8GX4a9yFjXObXjlMdX O2o7svmvrs4FPMFwJr4b168BpAajE4GJJud+Wu/mWQwRoajgwd6j5DIQP 0jRNAFV8HwIOaG5zrasTDoweWrVV9fi2FPQnJt9MMR7lBNgX+ikHQMlHx 7qryoZwsZszYRJmYsTHCOPKCu0bOtiAThZt8B55KmbLjy34DD7xV3FNdt BdJQZbVTchfYPV9QQbiTHQSH64M9m8r1QBlRLmjTo13FBeETXusbs3iJu g==; X-IronPort-AV: E=McAfee;i="6500,9779,10586"; a="409651827" X-IronPort-AV: E=Sophos;i="5.96,317,1665471600"; d="scan'208";a="409651827" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jan 2023 05:09:44 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10586"; a="650746989" X-IronPort-AV: E=Sophos;i="5.96,317,1665471600"; d="scan'208";a="650746989" Received: from zq-optiplex-7090.bj.intel.com ([10.238.156.129]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jan 2023 05:09:33 -0800 From: Zqiang To: paulmck@kernel.org, frederic@kernel.org, quic_neeraju@quicinc.com, joel@joelfernandes.org Cc: rcu@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] rcu: Fix the start_poll_synchronize_rcu_expedited() be invoked very early Date: Wed, 11 Jan 2023 21:14:53 +0800 Message-Id: <20230111131453.1626214-1-qiang1.zhang@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 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 access to NULL mynode pointer. This commit therefore add exp_seq_poll_rq member to rcu_state structure to store snap seq number Signed-off-by: Zqiang --- kernel/rcu/tree.c | 3 ++- kernel/rcu/tree.h | 1 + kernel/rcu/tree_exp.h | 6 ++++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index 63545d79da51..34b13d6bd8c4 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -92,6 +92,7 @@ static struct rcu_state rcu_state = { .exp_mutex = __MUTEX_INITIALIZER(rcu_state.exp_mutex), .exp_wake_mutex = __MUTEX_INITIALIZER(rcu_state.exp_wake_mutex), .ofl_lock = __ARCH_SPIN_LOCK_UNLOCKED, + .exp_seq_poll_rq = RCU_GET_STATE_COMPLETED, }; /* Dump rcu_node combining tree at boot to verify correct setup. */ @@ -4938,7 +4939,7 @@ void __init rcu_init(void) 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)) + if (!(rcu_state.exp_seq_poll_rq & 0x1)) (void)start_poll_synchronize_rcu_expedited(); rcu_test_sync_prims(); diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h index 192536916f9a..dbc7c7484a7e 100644 --- a/kernel/rcu/tree.h +++ b/kernel/rcu/tree.h @@ -397,6 +397,7 @@ struct rcu_state { /* Synchronize offline with */ /* GP pre-initialization. */ int nocb_is_setup; /* nocb is setup from boot */ + unsigned long exp_seq_poll_rq; }; /* Values for rcu_state structure's gp_flags field. */ diff --git a/kernel/rcu/tree_exp.h b/kernel/rcu/tree_exp.h index 956cd459ba7f..5964d1cccab1 100644 --- a/kernel/rcu/tree_exp.h +++ b/kernel/rcu/tree_exp.h @@ -1068,9 +1068,11 @@ 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); + } else + rcu_state.exp_seq_poll_rq = s; } if (rcu_init_invoked()) raw_spin_unlock_irqrestore(&rnp->exp_poll_lock, flags); -- 2.25.1