From patchwork Thu Jan 30 18:53:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paul E. McKenney" X-Patchwork-Id: 13954858 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9928B1BEF84; Thu, 30 Jan 2025 18:53:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738263202; cv=none; b=iCJV7PWkC2o+E+ZHiWcZqLekgBHeFyzq7aND/LmDcLyasdhgEXnDtXYrPsrvZGMQSlqsP47rwQhiHQSYcT4C4G9pRKkHyfXbRaOKc7VHkb/OqQubijkozRa0sBGdFP9iLBopqFm/XzPo6lqOke7Idiu9nnK9hqFQq7jWcWY4cXI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738263202; c=relaxed/simple; bh=hv+tT3Rau97o2i5iHirH4zRSdtx++OeCZ+6fHSofWJ0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tQj5giCL//JpNaoMxnnwwsWxHoDccrsh7GkBupBO/4kGhhpqNK3qGHva+O8o0sIqy5Il79rxkjszEyw0je9OYxFMhphFY/NBZd6jTESkpdII8X37iElBwAJrbmd1OetDBoQ5L/1eJjjqUgKogJfn13SA7eh1AIkwF4UBxcB2Jwc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MRZ91qxg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MRZ91qxg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2E7DAC4CED3; Thu, 30 Jan 2025 18:53:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738263202; bh=hv+tT3Rau97o2i5iHirH4zRSdtx++OeCZ+6fHSofWJ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MRZ91qxgh/vh5XJN9KmguuZiLH0GJprOO7gT6jo+rcVPj4omNPhclnz+Q6I5BUc30 UzCO0FyJII9bY6byYdlIwlksAm1dTvLJwis3r/vi82XJAN1FRaVBItLEeMRcviphYs ORzx/IUnl/1HjcJ1Mp/iWNh2frUKRj2i79cY6FcV3YCW96FUm1Kl4U6P1VSheZH2ZH 0Tq+sSoQ1qnvT7g+AWzQ/que103Z2Umr30VROU2lz1nBO1tYr/VpwsCzRp/cKfxR4a 5Mxz/mo5GCvckcp9MeK5KZfhkJgcB0m02PE0nb57qhFI+ArTdK7km8A/tBDvRidZTw DzPerxBj9NaRg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id CF4BACE37DA; Thu, 30 Jan 2025 10:53:21 -0800 (PST) From: "Paul E. McKenney" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, Zilin Guan , "Paul E . McKenney" Subject: [PATCH rcu v2] 2/5] rcu: Remove READ_ONCE() for rdp->gpwrap access in __note_gp_changes() Date: Thu, 30 Jan 2025 10:53:17 -0800 Message-Id: <20250130185320.1651910-2-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <43f70961-1884-42bf-b303-1d33665d99d2@paulmck-laptop> References: <43f70961-1884-42bf-b303-1d33665d99d2@paulmck-laptop> Precedence: bulk X-Mailing-List: rcu@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Zilin Guan There is one access to the per-CPU rdp->gpwrap field in the __note_gp_changes() function that does not use READ_ONCE(), but all other accesses do use READ_ONCE(). When using the 8*TREE03 and CONFIG_NR_CPUS=8 configuration, KCSAN found no data races at that point. This is because all calls to __note_gp_changes() hold rnp->lock, which excludes writes to the rdp->gpwrap fields for all CPUs associated with that same leaf rcu_node structure. This commit therefore removes READ_ONCE() from rdp->gpwrap accesses within the __note_gp_changes() function. Signed-off-by: Zilin Guan Signed-off-by: Paul E. McKenney --- kernel/rcu/tree.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index 229f427b8c82..e49bcb86b6d3 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -1275,7 +1275,7 @@ static bool __note_gp_changes(struct rcu_node *rnp, struct rcu_data *rdp) /* Handle the ends of any preceding grace periods first. */ if (rcu_seq_completed_gp(rdp->gp_seq, rnp->gp_seq) || - unlikely(READ_ONCE(rdp->gpwrap))) { + unlikely(rdp->gpwrap)) { if (!offloaded) ret = rcu_advance_cbs(rnp, rdp); /* Advance CBs. */ rdp->core_needs_qs = false; @@ -1289,7 +1289,7 @@ static bool __note_gp_changes(struct rcu_node *rnp, struct rcu_data *rdp) /* Now handle the beginnings of any new-to-this-CPU grace periods. */ if (rcu_seq_new_gp(rdp->gp_seq, rnp->gp_seq) || - unlikely(READ_ONCE(rdp->gpwrap))) { + unlikely(rdp->gpwrap)) { /* * If the current grace period is waiting for this CPU, * set up to detect a quiescent state, otherwise don't @@ -1304,7 +1304,7 @@ static bool __note_gp_changes(struct rcu_node *rnp, struct rcu_data *rdp) rdp->gp_seq = rnp->gp_seq; /* Remember new grace-period state. */ if (ULONG_CMP_LT(rdp->gp_seq_needed, rnp->gp_seq_needed) || rdp->gpwrap) WRITE_ONCE(rdp->gp_seq_needed, rnp->gp_seq_needed); - if (IS_ENABLED(CONFIG_PROVE_RCU) && READ_ONCE(rdp->gpwrap)) + if (IS_ENABLED(CONFIG_PROVE_RCU) && rdp->gpwrap) WRITE_ONCE(rdp->last_sched_clock, jiffies); WRITE_ONCE(rdp->gpwrap, false); rcu_gpnum_ovf(rnp, rdp); From patchwork Thu Feb 6 10:15:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paul E. McKenney" X-Patchwork-Id: 13962772 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C7AB214A95; Thu, 6 Feb 2025 10:15:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738836911; cv=none; b=IUXLyR/gpn4WbqbVOzCTvYG/0ibSr9ugcc+r4me1jyeTBffpQmSVsmxnFSXBfHeDFSi7sSZR0ccXlLgTOBFrv57A2TucbCDr6WWGj7EemWGkZUkV0wfoyKsYTO9dh/m6jQDjNB0dil43z2kk+RjYrhp8kyu3mRKn7vPlE0sLQbM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738836911; c=relaxed/simple; bh=VG5HSHinGwYbVMpv2rQoOJ5GIadUMJ807SdOz+nKolY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Jgj2jXyCea1O52LVEzDsOEWL+sE7npvpCEGGvtKhcJa2ENXL1QmylFmYpIYjIJQH32a0YF+TpNeHiLKWC97LgEUBlZg91clDFdgXGnnZEr290JJMAapYURuWJ0lAcPnjXXyX21ROvD5+AFZ16omtHdwkI3rvVwnoPhdtHgQM4IA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lVQ8L++7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lVQ8L++7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66D1FC4CEDD; Thu, 6 Feb 2025 10:15:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738836910; bh=VG5HSHinGwYbVMpv2rQoOJ5GIadUMJ807SdOz+nKolY=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=lVQ8L++7Zvk75gXGftG4dn6oirX8L1BVfGsyYr/MtJ1+xNjeGoDW2Lhf/9+BK7eYM hmvDoeR5qWrUStzzWsiNMBu4iIf1ruI6abOfAXBAmHenvcqBTXWjBoa25ipUrLwTBF MQCdcgqJrHyxg/wvBGx2l3JWbwUOx5USE5B8+OQWYQ1AJ9rBYnUCYvDYiNfsos5Kcw x31tuvlg0c9cbY7v8S2SwpgMrKHmK5TSBLxF61oNur4WhEKrvVjPSl8er24KI2+nmV yOBJj9507ol+6A3yCx61mOd16AP++vCD3hrpLyPpIENomCqdxoatSCduHdtkKPDXE3 nJWsrO/gV3wrg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 03193CE0B74; Thu, 6 Feb 2025 02:15:10 -0800 (PST) Date: Thu, 6 Feb 2025 02:15:09 -0800 From: "Paul E. McKenney" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, leitao@debian.org, vschneid@redhat.com, frederic@kernel.org, boqun.feng@gmail.com Subject: [PATCH rcu 6/5] Make RCU watch ct_kernel_exit_state() warning Message-ID: Reply-To: paulmck@kernel.org References: <7b24a850-7d56-4386-8544-be5e643b6b9f@paulmck-laptop> <43f70961-1884-42bf-b303-1d33665d99d2@paulmck-laptop> Precedence: bulk X-Mailing-List: rcu@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <43f70961-1884-42bf-b303-1d33665d99d2@paulmck-laptop> The WARN_ON_ONCE() in ct_kernel_exit_state() follows the call to ct_state_inc(), which means that RCU is not watching this WARN_ON_ONCE(). This can (and does) result in extraneous lockdep warnings when this WARN_ON_ONCE() triggers. These extraneous warnings are the opposite of helpful. Therefore, invert the WARN_ON_ONCE() condition and move it before the call to ct_state_inc(). This does mean that the ct_state_inc() return value can no longer be used in the WARN_ON_ONCE() condition, so discard this return value and instead use a call to rcu_is_watching_curr_cpu(). This call is executed only in CONFIG_RCU_EQS_DEBUG=y kernels, so there is no added overhead in production use. Reported-by: Breno Leitao Signed-off-by: Paul E. McKenney Reviewed-by: Valentin Schneider Reviewed-by: Frederic Weisbecker diff --git a/kernel/context_tracking.c b/kernel/context_tracking.c index 938c48952d26..fb5be6e9b423 100644 --- a/kernel/context_tracking.c +++ b/kernel/context_tracking.c @@ -80,17 +80,16 @@ static __always_inline void rcu_task_trace_heavyweight_exit(void) */ static noinstr void ct_kernel_exit_state(int offset) { - int seq; - /* * CPUs seeing atomic_add_return() must see prior RCU read-side * critical sections, and we also must force ordering with the * next idle sojourn. */ rcu_task_trace_heavyweight_enter(); // Before CT state update! - seq = ct_state_inc(offset); - // RCU is no longer watching. Better be in extended quiescent state! - WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) && (seq & CT_RCU_WATCHING)); + // RCU is still watching. Better not be in extended quiescent state! + WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) && !rcu_is_watching_curr_cpu()); + (void)ct_state_inc(offset); + // RCU is no longer watching. } /*