Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp1146982lqs; Wed, 6 Mar 2024 07:36:34 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXQuWAmXmhPxFZXQqi37S+Yi1Iv0619MDbn0QJ8g7XDs3iTXt3CHNCB9PjcxstMopEcP+QU9ceGxFYBC2sWR/R+tejzQh8eWLQusE8p0A== X-Google-Smtp-Source: AGHT+IFo/wiph06e5cBrA+kVgSoy3mJQCaFb98+wJogImsv0ptzyz7wjxOVt0MbEELcFG1qeC8wT X-Received: by 2002:a05:6830:18f6:b0:6e4:f680:647 with SMTP id d22-20020a05683018f600b006e4f6800647mr5508004otf.27.1709739393954; Wed, 06 Mar 2024 07:36:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709739393; cv=pass; d=google.com; s=arc-20160816; b=xsOk7HdB9fjNmUN7UKGDkyYjHq2Lv5l5TWrNT1bHaCGImJSsyGu9dRFsVRL5FgZ3KX 4R1qNl9zxLUr99mzupnppKzKmmb1mDH7mzyis8b/teGowDT8PiI3j96vUYABeQ4Ye9SE r9hdr3EhRMzJcfovkGs0jgKLhV1gE+A3aSalKrQNXFVv8VUkNOVsUc/fMU+dDx6C2rRP YrzpIaYePwDrUBBMAbQMxqIoeQeGb/H+UOOlnYQG962k7+RWb/Ih9lEp1dDKP8/BUKZ7 +I2aWNlthZxDze/BZq1tK5g8BgsO5bgxifNGvpHl+mjbdyAK8crFLi1bIw2fUaDqDhND 2HbA== 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=WUhCgvTTEVDsu2CeBcnd29rlaUz100qtwLsRCGnPuCM=; fh=tOW6QjEaw7TTMyCf303QFg8gmTdGZN6NGNhNziGpN5Y=; b=YSDZGaAuvmO0sXaSKVxZqika124titxcY6nPaV2yTbM5MCWJL4gGAiMeosH4DB25Mp zk7/EiXFjK5uGt16reypGYXzbKna4cf5ZFe8qeeeh6JXS/3dDJDeQHTxZFOKaH/kHXLT QnHD+RiYf2HazIHVdzpsCxzEn6rshKtSAjzSezrcde/7XSh0RmAIEPJm+H6gm3Q2YFUW u3xNb4gothBy5udAkI5rGVG3OeArKiJjtHUDAwA3QPDG8xwICs14xiSTnIcOzL486ccM FrgBkfWO3S1Ywk3YToTPCkfu3ALRwsFlEcqIhyHJ6ERRp0o25A8C95HpSvZObZb4Zrdl tOdw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-94163-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94163-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id o23-20020a63fb17000000b005dbefa1fb3asi12327974pgh.578.2024.03.06.07.36.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 07:36:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-94163-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-94163-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94163-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 9A34428616C for ; Wed, 6 Mar 2024 15:36:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 78D3B137C4E; Wed, 6 Mar 2024 15:35:30 +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 DF8DE13792E; Wed, 6 Mar 2024 15:35:28 +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=1709739329; cv=none; b=FbzCANx5bZNeKxO6BZUeJq1vSWB3zUF3siTjfcWnhMlR9iFVf3xDds3gfo1hrobfZ1rIvwSjJ2jChYwdQVD+Y4LrZ65NQpYPc7fBIL2RMGwp37TLd7xxdKV9H2L2ELwefrdfItUIrcMxNff9k2Z+LYZDvRFf/lmPhZ2EugPr68c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709739329; c=relaxed/simple; bh=XzHQ63q+wO8yRhMAcPLJwguwCBW5R4lx0MMXE87Ck+Y=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=c7mDYKm+4cQlQoPqJ1Wehwm3MjOsrq6FYkY32Nar7PT2v7y5rRP6Q2SHf21hICiKKiShdcuYMk59q7TOCZItjRz+AtOGY+TqXRwkiquBViM9DkrRFv/NS8lRihjycCBya1fs0GhOruU6JUwHhkFDiq+zp+QU/TirjPLCqmLpJyY= 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 E408BC43390; Wed, 6 Mar 2024 15:35:26 +0000 (UTC) Date: Wed, 6 Mar 2024 10:37:19 -0500 From: Steven Rostedt To: linke li Cc: 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, paulmck@kernel.org, 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: <20240306103719.1d241b93@gandalf.local.home> In-Reply-To: References: 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 Tue, 5 Mar 2024 14:24:20 +0800 linke li wrote: > > Anyway, a slightly related/different question: > > > > Should that: > > WRITE_ONCE(rp->rtort_pipe_count, rp->rtort_pipe_count + 1); > > > > Be: > > WRITE_ONCE(rp->rtort_pipe_count, READ_ONCE(rp->rtort_pipe_count) + 1); > > > > ? > > Hi, Joel. Sorry, I am not very sure about this. I do a little research on > it. > > I looked through all code in kernel that looks like this, both kinds are > used. I also try to compile this file with and without the READ_ONCE in > WRITE_ONCE using gcc-9. Their binary is just the same. > > Thus I think in the current compiler version, they do not have a big > difference, but if the compiler wants to optimize more, maybe the latter > one is better. I'm sorry but all these READ_ONCE/WRITE_ONCE() additions that are being added because there's a fear of the compiler tearing long words, is going to make the code really ugly and hard to read. 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. 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. I don't know if Linus even cares about fixing "read/write tearing" which is why I Cc'd him. 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. -- Steve