From mboxrd@z Thu Jan 1 00:00:00 1970 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 86104224226; Wed, 26 Feb 2025 22:34:55 +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=1740609295; cv=none; b=WCVMaFdrw+fPJwLnPfV1DgDmc97h4DozEXrScbavGTfhaO7f1Qwy/+isOdOyV+Jskm8HTO9Jh6NqrvOXXpKReK+AmjPN7w1wQ1+MNW1dSfyb7DNzXHX5siHCxm5qBtSxsxAIFNr7nC7Z+j/N44riSZTSBQGBOpUcYkMJNapAn14= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740609295; c=relaxed/simple; bh=LRRBLPCsYoX3dO8xAVoUsyACiIYHxjJxSc3w0yS6vWo=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JdiiA6Z+NPDOXCgYV27OZnkCHYQXoInGqiPc4yXIkMCXKmNEV0EJlQ0CwLBLTWl94sReDHoJtyW7k/nc30BWtErldaDwg5EwMhlfErlxpbwf3y6U83LklLWyApbuqRcHTgAZ4E5ECCjIwnPUUFt7vaxjYUc2gDLapz5cagVbtEo= 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 F3658C4CED6; Wed, 26 Feb 2025 22:34:52 +0000 (UTC) Date: Wed, 26 Feb 2025 17:35:34 -0500 From: Steven Rostedt To: Linus Torvalds Cc: Martin Uecker , Ralf Jung , "Paul E. McKenney" , Alice Ryhl , Ventura Jack , Kent Overstreet , Gary Guo , airlied@gmail.com, boqun.feng@gmail.com, david.laight.linux@gmail.com, ej@inai.de, gregkh@linuxfoundation.org, hch@infradead.org, hpa@zytor.com, ksummit@lists.linux.dev, linux-kernel@vger.kernel.org, miguel.ojeda.sandonis@gmail.com, rust-for-linux@vger.kernel.org Subject: Re: C aggregate passing (Rust kernel policy) Message-ID: <20250226173534.44b42190@gandalf.local.home> In-Reply-To: References: <6pwjvkejyw2wjxobu6ffeyolkk2fppuuvyrzqpigchqzhclnhm@v5zhfpmirk2c> <5d7363b0-785c-4101-8047-27cb7afb0364@ralfj.de> <20250226162655.65ba4b51@gandalf.local.home> <20250226165619.64998576@gandalf.local.home> <20250226171321.714f3b75@gandalf.local.home> X-Mailer: Claws Mail 3.20.0git84 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: ksummit@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Wed, 26 Feb 2025 14:22:26 -0800 Linus Torvalds wrote: > > But if I used: > > > > if (global > 1000) > > goto out; > > x = global; > > which can have the TUCTOU issue because 'global' is read twice. Correct, but if the variable had some other protection, like a lock held when this function was called, it is fine to do and the compiler may optimize it or not and still have the same result. I guess you can sum this up to: The compiler should never assume it's safe to read a global more than the code specifies, but if the code reads a global more than once, it's fine to cache the multiple reads. Same for writes, but I find WRITE_ONCE() used less often than READ_ONCE(). And when I do use it, it is more to prevent write tearing as you mentioned. -- Steve