Received: by 2002:ab2:788f:0:b0:1ee:8f2e:70ae with SMTP id b15csp58106lqi; Wed, 6 Mar 2024 09:59:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVjn9t6uFzBcJPaNzWket0BwN5ixMlD7tWU/8gwqutoTw8mRNllZDQHL2k+QRmNxNsS6xkDoGOHMjgG6pXh2JYqCm4AUFOlJol8UPVOIg== X-Google-Smtp-Source: AGHT+IGgHVzVsUSebUTbewYx0QPVUQHBJBChQyAUzc/Fxyqvf/FSQRAEbTHy+5QlkdJHXWfBYp3s X-Received: by 2002:a05:620a:40d0:b0:788:2ee8:5e2e with SMTP id g16-20020a05620a40d000b007882ee85e2emr7970675qko.66.1709747959927; Wed, 06 Mar 2024 09:59:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709747959; cv=pass; d=google.com; s=arc-20160816; b=Ct5F0kRtdrZ2BxCJrZyGTtZEZuTT2bdbEbbUvsTZNjd2sMuFXYijdPYQHggbGIWccu kzl+pu9BTHzOLMwkX4nld48/tRwQgzllQgpAvPxzAptDjLdk/aRiTxpT/s7AcOB0loLv NP6Yzk7YT/HF7UUOrpUUO/JjWHFF6Nwk3RYwCD7axsrRt1zVGlbEdalPI1awcr1t8uwo LDDaohnuHtPPovW0eVTLpGl+rYf4ZYpMJyiaSp2cDpUCDV1oZvJ8Q6OYzjtpBHW+QQPD GPQJgiyutKBUXvV8UFQFt/pb9HIHX+rxpvak7l+nYCa+1Hmb20DMlfwmxT9NQeLKhYPE yD/w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date; bh=+yRuLrTjTEzAZcvlbf8c4DBFSldQi2cj/eRoF2SIeo4=; fh=bT0fkHMRZlAr8keL1aEGpNy8fIqi4SNxy901/eiobW0=; b=gSXxAs+TlW/GqmD05e6h6NRvbv6fE+xu94LTHcu435HjtuGRrHIiCyxL7+80rYcGCy eLv1Zx0aqq+I8JpYuQMPPq5q8Rqee2bhEJoJH2DSlBGO8+Z2J3IXFDpa+sT7O3WirxfU NeAkKuWcsJhnsbyZs88o+GR7HKkBdqKridKtiUE47diEt18k3I8TlcsJiBfI7u4xwUHm y4WojCyR0ligcmNPncR7Fixl4PF9Y/0XxEyT5PYT7urlLe2LyTRgbOKqfQJGsxBX/HLQ FgwhifMybYELmzBtOtAJHjnM7V9qzjlH42E/ngTpYnU32bm+VHzw8J2fyfkkisSJw5V7 pFCA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-94357-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94357-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id oq17-20020a05620a611100b0078819cf3e53si10135298qkn.229.2024.03.06.09.59.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 09:59:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-94357-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-94357-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94357-linux.lists.archive=gmail.com@vger.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id A40691C217B5 for ; Wed, 6 Mar 2024 17:59:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5AA4A13C9CA; Wed, 6 Mar 2024 17:59:14 +0000 (UTC) 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 CC36013BAE8; Wed, 6 Mar 2024 17:59:13 +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=1709747953; cv=none; b=cSxOgyjkcIMAgJ1WXMudwcYOWp/ulDSK+FiJwXByuD2e/uJxyBXHM6DNaDfYln9km7S7q9D4bLTMdCLS3RdCQnTglPmugzabZbGt/FZjayaZiGfmLVGuen9yra4AE0xAyWM3bQFgXcfpAmgt8YmaX4fWVR3AMavwtA7kN73bfOM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709747953; c=relaxed/simple; bh=HDO+XgS2uhz8t0fGGsGDxAX/o5QGbVirBj1RmpOGOKM=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SoZ9BaEGAb51wyuHZHMubB5f+scq0VGGV3eAlD5LWNuAyDw36sm8wZZQp21asXbSveIk3pSGcoohlwhzqXljJfLrZ4s5VDM8IyDADlHRz7R7DHEYJEq8Wh+Vt9SVLnmj+6gjsJfsMjbLWD7Ha/5bTlXmh9QnK77Cht9ESULnX/A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id EE63EC433F1; Wed, 6 Mar 2024 17:59:11 +0000 (UTC) Date: Wed, 6 Mar 2024 13:01:03 -0500 From: Steven Rostedt To: "Paul E. McKenney" Cc: 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, mathieu.desnoyers@efficios.com, qiang.zhang1211@gmail.com, quic_neeraju@quicinc.com, rcu@vger.kernel.org, Linus Torvalds Subject: Re: [PATCH] rcutorture: Fix rcu_torture_pipe_update_one()/rcu_torture_writer() data race and concurrency bug Message-ID: <20240306130103.6da71ddf@gandalf.local.home> In-Reply-To: <27665890-8314-4252-8622-1e019fee27e4@paulmck-laptop> References: <20240306103719.1d241b93@gandalf.local.home> <27665890-8314-4252-8622-1e019fee27e4@paulmck-laptop> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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-Transfer-Encoding: 7bit On Wed, 6 Mar 2024 09:36:16 -0800 "Paul E. McKenney" wrote: > > If we take the policy of handling a compiler that can tear reads and writes > > of any size word, then we should have proper macros to handle it. > > Those are in fact READ_ONCE() and WRITE_ONCE() when given machine-word > sized/aligned variables. IIRC, the original purpose of READ_ONCE() and WRITE_ONCE() was to make sure that the compiler only reads or writes the variable "once". Hence the name. That way after a load, you don't need to worry that the content of the variable you read isn't going to be read again from the original location because the compiler decided to save stack space and registers. But that macro has now been extended for other purposes. > > > Perhaps READ_SHARED(), WRITE_SHARED(), ADD_SHARED(), SUB_SHARED(). The ONCE > > has nothing to do with the reasons for these changes. But at least "SHARED" > > can be considered "this variable is shared between different contexts". > > Note, this is different than "atomic". It's just to document that this > > variable must be loaded or stored in one transaction. > > We already have READ_ONCE() and WRITE_ONCE(). An ADD_SHARED() might > be useful, though compilers are starting to learn how to emit good code > for things like WRITE_ONCE(a, READ_ONCE(a) + 1). Well, if we keep the _ONCE() naming, it should be ADD_ONCE(). Because WRITE_ONCE(a, READ_ONCE(a) + 1) is an abomination and should only be present in obfuscation contests. > > But such things should also be documented and added to LKMM. > > > I don't know if Linus even cares about fixing "read/write tearing" which is > > why I Cc'd him. > > I am sure that whatever his views, he will not suffer in silence. ;-) > > > But I'm not going to take any patches that add these macros to fix > > compilers that tear words on load and store until we have a set policy on > > what to do with them. > > Maintainer's choice! > > For RCU, I want the code to just work with future compiler optimizations > as well as with current ones. This stuff is fun enough without giving > the compiler opportunities for more mischief! I'm not against the changes. I'm against the ugliness of the changes. Should we just create a ADD_ONCE() macro? If the approach is now to find all places that access a variable between different contexts, and create READ_ONCE()/WRITE_ONCE() around them, I'm fine with it. Perhaps we need a way to annotate them, like we have with __rcu. "__shared"? Then all accesses to that variable must be wrapped with a READ_ONCE() or WRITE_ONCE()? I mean, if this can cause legitimate bugs, we should probably address it like we do with locking and RCU. -- Steve