Received: by 2002:ab2:788f:0:b0:1ee:8f2e:70ae with SMTP id b15csp120349lqi; Wed, 6 Mar 2024 11:45:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUCUaxE3iHD5o5CnSDRWgQOQ+V6CKPRoy9M3glAFInhRYE5N57cSw/RDDVw+ElZ7wGIQwzQCVWIU9d/0m2hHQKNpplH8SM7XuUzWAU2sg== X-Google-Smtp-Source: AGHT+IGnlL/zY6SoMT9gctdrM9EP7a9gODzWpeVzfeC9kbubkziF54fzz107d5Yc3iNEey+imFB0 X-Received: by 2002:a50:8d85:0:b0:564:4211:faa3 with SMTP id r5-20020a508d85000000b005644211faa3mr6748547edh.1.1709754330561; Wed, 06 Mar 2024 11:45:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709754330; cv=pass; d=google.com; s=arc-20160816; b=uZDV1MTApORbjGT7W/NOQSGse27/vXg8r5ZNMf8z0yXfsfqdSOfFpi3p7yk8wj3RYv kHLxZ8FfwqFjuFCsvx5JkBygxXByeWOcSUTUEi+NYkG7AuWldVgMiDfbKT4/Zv2wJNJ7 Bynis878Uk7Rmjp0e3L8GQqM2kTJnq/sqT+d0XTrJ8Wd8n6KvjXDV4SuTg0VkTMf0t0n mzo5iWyKfMp0kRy/wqiFHiMa6p7P/y7lA3BD9lqBJ9Xx4Q++FIO1KDPN+FyP06/5wO0t vkrwWHw8To3envNsCoOO8MJu+sty8DIQ+9V+WSR/qahqmnCCFzotOdy6SIfxeHlQfMEs kYyw== 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=rJyJcXo2TOpX7gPRzzUO2jr3g1f5TrvUgSBGU1dDFY0=; fh=4dU+JhieUHr/RI05mehfCLNhp2+1Zi8phVAoV5qYL6U=; b=hNpMB3PR5/kTRAp1tOXv9zsp5UR8i5aBxsXT+JI98o9VO37KdkVYV1rfWDJbIJL/hr oXEhXtEsimZydMQP+MYV+bLy9AL2Skrm7d5EFBQX3NJiH5ok6eHly9T9CDkwXYk96lYv BZmPqyIdtQ7mK7jD5TcmVlSX34RkeZqrpJ35QcckYOZ0CoiwK+y0i5IMp2TyR2SYefG9 lDllLQcWmj4uY9zT847kiy6Y9NuSKoLdLF3JUAe1xrXN2wuGTTzDCPCBl0Urynhhy29v y0uxVGogI0rcaXL5B/80pUz3m+7Vg+NEc6/vJg/5ABm7sKrhiTtGrS/UM2Zo+CWB05th ro7w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-94500-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94500-linux.lists.archive=gmail.com@vger.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 o15-20020a509b0f000000b005674099f558si3420636edi.645.2024.03.06.11.45.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 11:45:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-94500-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; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-94500-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94500-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 3B0C51F214C4 for ; Wed, 6 Mar 2024 19:45:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CB38D140384; Wed, 6 Mar 2024 19:45:22 +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 5223113F00A; Wed, 6 Mar 2024 19:45:21 +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=1709754322; cv=none; b=GJq3WUJg40WP4u1d4ctzMuOnJp5echoUzidsBu91VHyHeQuko2B2n8suXKTDv3/xrXrUOgNrAYPBEpHg8xTZwZT3voElf08wjSmdzKTZyiiyDrAvJ/CZnVmzf6G1dtT7hzsj37tSxoH2OOYkOeuxqvLofrcO63tR0N2dLkBfi4I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709754322; c=relaxed/simple; bh=GoeNgILuYzw3RIt3lassJRpXKSoD4VrJVLzn63ESTBE=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ARprUo6dFrxlMTxAzX3+UBQLVLg82YLAaA+TE4yVOjNUabWcXonOInQjOLCZWYxSyhaU3nB8u7Nvx/WGlijnkKj6KT3EsKQ8MS4+zJWx262WSfrSfVyuZPXtECs52+vjKMX5XvCuAit/uWesIa5yLu53Xrnua2uCyr3IFuKrOdQ= 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 5201BC433C7; Wed, 6 Mar 2024 19:45:20 +0000 (UTC) Date: Wed, 6 Mar 2024 14:47:13 -0500 From: Steven Rostedt To: Linus Torvalds Cc: "Paul E. McKenney" , 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 Subject: Re: [PATCH] rcutorture: Fix rcu_torture_pipe_update_one()/rcu_torture_writer() data race and concurrency bug Message-ID: <20240306144713.2e1709ad@gandalf.local.home> In-Reply-To: References: <20240306103719.1d241b93@gandalf.local.home> <27665890-8314-4252-8622-1e019fee27e4@paulmck-laptop> <20240306130103.6da71ddf@gandalf.local.home> <20240306135504.2b3872ef@gandalf.local.home> 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 11:27:04 -0800 Linus Torvalds wrote: > On Wed, 6 Mar 2024 at 11:01, Linus Torvalds > wrote: > > > > In some individual tracing C file where it has a comment above it how > > it's braindamaged and unsafe and talking about why it's ok in that > > particular context? Go wild. > > Actually, I take that back. > > Even in a random C file, the naming makes no sense. There's no "once" about it. > > So if you want to do something like > > #define UNSAFE_INCREMENTISH(x) (WRITE_ONCE(a, READ_ONCE(a) + 1)) > > then that's fine, I guess. Because that's what the operation is. > > It's not safe, and it's not an increment, but it _approximates_ an > increment most of the time. So UNSAFE_INCREMENTISH() pretty much > perfectly describes what it is doing. > > Note that you'll also almost certainly end up with worse code > generation, ie don't expect to see a single "inc" instruction (or "add > $1") for the above. > > Because at least for gcc, the volatiles involved with those "ONCE" > operations end up often generating much worse code, so rather than an > "inc" instruction, you'll almost certainly get "load+add+store" and > the inevitable code expansion and extra register use. > > I really don't know what you want to do, but it smells bad. A big > comment about why you'd want that "incrementish" operation will be > needed. > > To me, this smells like "Steven did something fundamentally wrong > again, some tool is now complaining about it, and Steven doesn't want > to fix the problem but instead paper over it again". > > Not a good look. > > But I don't have a link to the original report, and I'm not thrilled > enough about this to go looking for it. Well, it's not the above, and I was afraid you would even think that. Here's the back story. I received the following patch: https://lore.kernel.org/all/tencent_BA1473492BC618B473864561EA3AB1418908@qq.com/ I didn't like it. My reply was: > - rbwork->wait_index++; > + WRITE_ONCE(rbwork->wait_index, READ_ONCE(rbwork->wait_index) + 1); I mean the above is really ugly. If this is the new thing to do, we need better macros. If anything, just convert it to an atomic_t. Then because I'm a reviewer of RCU patches, I saw the same fix for RCU (this thread): https://lore.kernel.org/all/tencent_B51A9DA220288A95A435E3435A0443BEB007@qq.com/ Where it was recommended to do the same WRITE_ONCE(a, READ_ONCE(a) + 1), and this is when I Cc'd you into the conversation to get your view of the situation. Sounds like my original gut feeling that this is a non-issue is proving to be correct. I even argued against using the _ONCE() macros. If WRITE_ONCE(a, READ_ONCE(a) + 1) is a valid operation, I sure as hell don't want it in my code, but I would be OK if it had a macro wrapper. Which you seem to be against, so I'm against it too. -- Steve