Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp7601955rwr; Wed, 10 May 2023 10:06:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7uxhKsG6GDMdgnk1eO3z+7IEIe0qpO12J0K9Xy1ukhp9OAJEaLYfpRaqUJUroUl3IIerKO X-Received: by 2002:a05:6a00:198a:b0:643:791b:892d with SMTP id d10-20020a056a00198a00b00643791b892dmr23204636pfl.18.1683738406368; Wed, 10 May 2023 10:06:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683738406; cv=none; d=google.com; s=arc-20160816; b=l+Ib2odqypVo2jau6UGRblqZaG7LlS7uhe7qz7DmFjy56SaiT+WK5MIQaXXjbuS1Yy aD95YoUredkbRLgLZEXxudoOMvw1BH7gvemzIBKNAsI2uvFSCiKpig/ZfDNk03Fl1JSG +c3DWa5jtBI1oilg2Dw14XVy0eqz3r7j9TP6+pJHfdGbZMzmYCDUI29SOpKpNfSTmoxl djkf7b2JujeIsnSyq2L9Mb2hvn72D6CIWe7wlmT719nP9biyd2z01jvdT+mnG2oiV+N7 fpD3k65Ix/Gp2zrx8u2HfWwW5vKeqpWCk4FHYq9yCcjDjSXjaC4xqxZU9LJRSdZcAxPs lwKQ== 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=/jwXgnzyg3TI5PNypIg91qZ7S7n9963pg09DyiCtpEE=; b=0nUSj2yhxESlp/utYNtNx1jNXzm9kPy42Nmcn/fwnTMsXGH97B350fFTs6AzvnSSDt o2S2UK8ewMjkwQw3evYES7Xk7GRDDDNb0s96NgOXRT8OkIkSk0QwYIhLQArPgL9UHaTL Mpv+D9iQ8s56sA4bpTFn0QTPdUAcB0MNRGLmRjJnVqLaJU7mecD6r1AJGe6rwTw7KRyU kqpVtk/0H5jtmLvEXDJ4hbcd/syec+XHbQ+DWb2XKEI90Dpy0Cl0SWB7wkKt+rRQ1Ws1 g8CdpRdKGns89kOBobceLeKy0oOB3nku52tTfOX1MTvrIq+BaJTErt5cTadbJbZzWKhU C8CA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aOByI0GY; 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 a24-20020aa794b8000000b006439b23e8b7si5461633pfl.9.2023.05.10.10.06.32; Wed, 10 May 2023 10:06:46 -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=aOByI0GY; 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 S229617AbjEJQ6t (ORCPT + 99 others); Wed, 10 May 2023 12:58:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236049AbjEJQ6g (ORCPT ); Wed, 10 May 2023 12:58:36 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35D4519BA; Wed, 10 May 2023 09:58: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 dfw.source.kernel.org (Postfix) with ESMTPS id A9CD963F43; Wed, 10 May 2023 16:58:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B00DC4339C; Wed, 10 May 2023 16:58:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1683737914; bh=cpG57oSoRSWjavlSva8U9oIMQoMhIp2jDOdopl67PsU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aOByI0GYtGVbtiPinrjCJ4tmQ1TKhAgSY4hoTekZ4hTBOsW35VcSF8+31FJpaXVnj kImZ4LqpeYPCqnq/PAVFdxCL6yejhG7ooWhMNToJJJ+J5urMT4lo32GCGxxd+rlFmv stCglK78OegDBJmt8JUN4AtOxSPAmib3SOP0edoMI6fejv5lh5B+ef84g6X1WMtUKu NJD+GhCDfPV6IhGUF19XD4ayOUUnhHoMHz5k3B6mk4TufPicFarG+ovemXnvQ8lsVM IR3RorwH48ToCKMCn6Zdm93MTkG6xmC1KRXTlYjx7gZl/i6CcFoJvlmzJjrKHqvQM7 D5G0/kSg11S2g== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 91EEDCE12D5; Wed, 10 May 2023 09:58:33 -0700 (PDT) From: "Paul E. McKenney" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, "Paul E. McKenney" Subject: [PATCH rcu 5/8] rcu: Mark additional concurrent load from ->cpu_no_qs.b.exp Date: Wed, 10 May 2023 09:58:29 -0700 Message-Id: <20230510165832.2187453-5-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: 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_PASS,T_SCC_BODY_TEXT_LINE 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 The per-CPU rcu_data structure's ->cpu_no_qs.b.exp field is updated only on the instance corresponding to the current CPU, but can be read more widely. Unmarked accesses are OK from the corresponding CPU, but only if interrupts are disabled, given that interrupt handlers can and do modify this field. Unfortunately, although the load from rcu_preempt_deferred_qs() is always carried out from the corresponding CPU, interrupts are not necessarily disabled. This commit therefore upgrades this load to READ_ONCE. Similarly, the diagnostic access from synchronize_rcu_expedited_wait() might run with interrupts disabled and from some other CPU. This commit therefore marks this load with data_race(). Finally, the C-language access in rcu_preempt_ctxt_queue() is OK as is because interrupts are disabled and this load is always from the corresponding CPU. This commit adds a comment giving the rationale for this access being safe. This data race was reported by KCSAN. Not appropriate for backporting due to failure being unlikely. Signed-off-by: Paul E. McKenney --- kernel/rcu/tree_exp.h | 2 +- kernel/rcu/tree_plugin.h | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/kernel/rcu/tree_exp.h b/kernel/rcu/tree_exp.h index 3b7abb58157d..8239b39d945b 100644 --- a/kernel/rcu/tree_exp.h +++ b/kernel/rcu/tree_exp.h @@ -643,7 +643,7 @@ static void synchronize_rcu_expedited_wait(void) "O."[!!cpu_online(cpu)], "o."[!!(rdp->grpmask & rnp->expmaskinit)], "N."[!!(rdp->grpmask & rnp->expmaskinitnext)], - "D."[!!(rdp->cpu_no_qs.b.exp)]); + "D."[!!data_race(rdp->cpu_no_qs.b.exp)]); } } pr_cont(" } %lu jiffies s: %lu root: %#lx/%c\n", diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h index 7b0fe741a088..41021080ad25 100644 --- a/kernel/rcu/tree_plugin.h +++ b/kernel/rcu/tree_plugin.h @@ -257,6 +257,8 @@ static void rcu_preempt_ctxt_queue(struct rcu_node *rnp, struct rcu_data *rdp) * GP should not be able to end until we report, so there should be * no need to check for a subsequent expedited GP. (Though we are * still in a quiescent state in any case.) + * + * Interrupts are disabled, so ->cpu_no_qs.b.exp cannot change. */ if (blkd_state & RCU_EXP_BLKD && rdp->cpu_no_qs.b.exp) rcu_report_exp_rdp(rdp); @@ -941,7 +943,7 @@ notrace void rcu_preempt_deferred_qs(struct task_struct *t) { struct rcu_data *rdp = this_cpu_ptr(&rcu_data); - if (rdp->cpu_no_qs.b.exp) + if (READ_ONCE(rdp->cpu_no_qs.b.exp)) rcu_report_exp_rdp(rdp); } -- 2.40.1