Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp146989lqc; Thu, 7 Mar 2024 12:57:31 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVzfvI5t5mBFGjWDOyK0KrpfwsQqY7DYDzuOsxMiishxvlygwR7pmYFOXmlLNYUYFr1r9qlmo4/Y+i5Na5i70YJ1EjsjtT/gK9dnh3m5w== X-Google-Smtp-Source: AGHT+IEET2E6fbbgNTYrc8BHhuFd76zjrh2F9d6C94PdeI0IcqI994RPS45gsAZ+UUl5tE8KZLgh X-Received: by 2002:a17:906:1b45:b0:a45:c708:1a8a with SMTP id p5-20020a1709061b4500b00a45c7081a8amr2850776ejg.25.1709845051283; Thu, 07 Mar 2024 12:57:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709845051; cv=pass; d=google.com; s=arc-20160816; b=kIbtPhhmeLFL7ausu8uIj0wCDBeovk32wJ3cQhB4kGkyjbaevounW+9BZzE7UqLxms y+hOpgHhu90gfm9YBWs1fnUZtz8nooDG4+j2w4pulelK0+FXAk4jCRlJS0Gilt8F1SHA nqeKFkRd3sSFQDI0tw1YztTpf/yFbvrvYipVfXIrhG2J4kbh3YT7MaHTYKk+gtwWBaQ6 MRXRcxhLxL197ya4MOPekdgMdh73k5yNHRAFoDImx/tvQN6Aeb5fC5mDSaQV3B95kH86 uVQ3M6FfX1zXgX64I2wfShZnYypaomRbjMGxQ/PRZja+MwvK+ekHXVwgAQCt1OxYhyoD 2sAw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=Tdd5SdHEIxFFoRnSCRoJfC4Rml+ZZuTysLmEXsNMlJg=; fh=5CcX+ASYjsUAgXPfgiwfiKNrkguJlSLdpMxhXeAvr4w=; b=vCF4lcC+iTyuILldWkmHlV0HnyvX0GJlEP6Vg3q70+fGMftGvc9OtQi14tBpXmQpaO a84NadUCoiEsc/xd+469FjX/FDrtyRnuFeKJ7FPptMDGtvrgCGS3HQNcMRDZTA73SeJP puBjgzwH+vxAMPQnKCByZjQJFbTMaq2dHIjPqqPGRB+z9qr9l5xkq9zzlVHzgBzFiP5G C20flslFZxBHbc4mqmOHcVkCS1Jb4Ag0bJNAE76ACWwcbeeMbwEq9ugeXr/8VDPKMJCp HHSp+6p0/JWEPNxG5gVzEtBc0UJcv+uY65YRG2XWaZ3PfVMRoBRAKWFQd2meN0WvYACe qqNQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UK6Ajthk; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-96226-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96226-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id cs17-20020a170906dc9100b00a45bfa91e83si1571239ejc.465.2024.03.07.12.57.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 12:57:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-96226-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UK6Ajthk; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-96226-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96226-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id BAA711F22903 for ; Thu, 7 Mar 2024 20:57:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4889A13A267; Thu, 7 Mar 2024 20:57:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UK6Ajthk" 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 5F57B2134A; Thu, 7 Mar 2024 20:57:25 +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=1709845045; cv=none; b=fYDv3VVAPmvepxWbbVC6byw+a93+hBx5lt7hbSUDJT/0MY0nGd3H0typReinkXP5CEAaKL+LYVrleytDggLa02raSsvYaUuWYSbxmUHTPxKP1u++pDlaD/wnhzRJr487ccpDLjIQANTukLne7sIpzrc1Swa+Nh/UPlNd5BP0iJk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709845045; c=relaxed/simple; bh=GHlOXflCckEb7a2smpqIMk5VjW3f7iYXLbVZau1BSGo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Z3xpHjoudHS8YgLS9vP5LygNQbeuW0mJQ/QXWQ1R0icSLws0xqnJK7dBzoGqWT6CP7I3icxBLQQGToRCQZR+KCRp8JYcMEx4nF1jz5MD/HBykQtyG9jc8cVv9Y4/2VYqVuZePgltHStmqCMjt1AThaZGefLpTeRhiBfdiTIkUdk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UK6Ajthk; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8F3AC433F1; Thu, 7 Mar 2024 20:57:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709845044; bh=GHlOXflCckEb7a2smpqIMk5VjW3f7iYXLbVZau1BSGo=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=UK6AjthkxtHvtCV4WN+Wu7P67QEflIWMmTBvMAE6l/UfWzQBdVOwj+qb/PTlBhMHq 7T51TRlPLk4R8cN2nBeMTGx7yclPKeGVbsyUvEATWoiwtpHvpiGE1v6zIMc6owMGAj mWCz90e87TYAw54bmmZM5DPX7EBTi9WLc/or/0rrXwObVeMvx7du90+DKgwn44sNTU 360wLwK0/92NFKhkepIS6UQ4V1Z1bWZz8ktRm22DtRfFDfG3BsYLqker3TvmSEyJW4 gbP33dNfkEROafzb/7jF35SjYp9qBeluDaqum3W4VbKAo5qwDNtfW4hX14RniwXHLx Q/vjqH56wW5/g== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 61A8CCE0716; Thu, 7 Mar 2024 12:57:24 -0800 (PST) Date: Thu, 7 Mar 2024 12:57:24 -0800 From: "Paul E. McKenney" To: Linus Torvalds Cc: Mathieu Desnoyers , Steven Rostedt , linke li , joel@joelfernandes.org, boqun.feng@gmail.com, dave@stgolabs.net, frederic@kernel.org, jiangshanlai@gmail.com, josh@joshtriplett.org, linux-kernel@vger.kernel.org, qiang.zhang1211@gmail.com, quic_neeraju@quicinc.com, rcu@vger.kernel.org, julia.lawall@inria.fr Subject: Re: [PATCH] rcutorture: Fix rcu_torture_pipe_update_one()/rcu_torture_writer() data race and concurrency bug Message-ID: <65a9665e-22d4-4f21-a1cb-7ef1c82ed078@paulmck-laptop> Reply-To: paulmck@kernel.org References: <20240306142738.7b66a716@rorschach.local.home> <83b47424-e5e0-46de-aa63-d413a5aa6cec@paulmck-laptop> <851dc594-d2ea-4050-b7c6-e33a1cddf3a1@efficios.com> <72b14322-78c1-4479-9c4e-b0e11c1f0d53@paulmck-laptop> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Thu, Mar 07, 2024 at 12:00:44PM -0800, Linus Torvalds wrote: > On Thu, 7 Mar 2024 at 11:47, Paul E. McKenney wrote: > > > > > - The per-thread counter (Thread-Local Storage) incremented by a single > > > thread, read by various threads concurrently, is a good target > > > for WRITE_ONCE()/READ_ONCE() pairing. This is actually what we do in > > > various liburcu implementations which track read-side critical sections > > > per-thread. > > > > Agreed, but do any of these use WRITE_ONCE(x, READ_ONCE(x) + 1) or > > similar? > > Absolutely not. > > The READ_ONCE->WRITE_ONCE pattern is almost certainly a bug. > > The valid reason to have a WRITE_ONCE() is that there's a _later_ > READ_ONCE() on another CPU. > > So WRITE_ONCE->READ_ONCE (across threads) is very valid. But > READ_ONCE->WRITE_ONCE (inside a thread) simply is not a valid > operation. > > We do have things like "local_t", which allows for non-smp-safe local > thread atomic accesses, but they explicitly are *NOT* about some kind > of READ_ONCE -> WRITE_ONCE sequence that by definition cannot be > atomic unless you disable interrupts and disable preemption (at which > point they become pointless and only generate worse code). > > But the point of "local_t" is that you can do things that aresafe if > there is no SMP issues. They are kind of an extension of the > percpu_add() kind of operations. > > In fact, I think it might be interesting to catch those > READ_ONCE->WRITE_ONCE chains (perhaps with coccinelle?) because they > are a sign of bugs. Good point, adding Julia Lawall on CC. A really stupid version of this pattern (WRITE_ONCE.*READ_ONCE) found four more in RCU, so I will take a look at those and either fix or add comments as appropriate. > Now, there's certainly some possibility of "I really don't care about > some stats, I'm willing to do non-smp-safe and non-thread safe > operations if they are faster". So I'm not saying a > READ_ONCE->WRITE_ONCE data dependency is _always_ a bug, but I do > think it's a pattern that is very very close to being one. I agree that valid use cases should be quite rare. Thanx, Paul