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 2562913A3EF for ; Wed, 5 Jun 2024 19:12:07 +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=1717614728; cv=none; b=JUyaJeYbbgZl8/r76UJwvhipdn/yRPV5GILNLUhRpkM5GIOoFcw1QCQtETSroj+z1CYokC6nldmJ9oLyO7ldkka70eiqREsz3DvkUh/o0xmGHht+h8Y3sY8gZ0T3l2MPukDZtYRa8AYEd1L4L0GQJ0H4f+5JKqy9d2P3/Xw9VUA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717614728; c=relaxed/simple; bh=Bo2eM0e9oDIL5UYkxH1iFXlhk/Qui/4X3UDepCR4OSE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HFnTl8Huh4hz3COLCXCecvYNFvoJern++csEJRTZJDrrBJmOw87Yj+TUZHsE2kxYHmuHK3bfUohE4bx41V2v3loZbFp6Q4wKiOCx9svA1SUid5SFX2BzDYdnGZqQF1CqRI8IfumFPcYzpTZJ8lrmlQp4Hs/0aJaY12NcNpE2FTw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kFwaaifx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kFwaaifx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83231C2BD11; Wed, 5 Jun 2024 19:12:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717614727; bh=Bo2eM0e9oDIL5UYkxH1iFXlhk/Qui/4X3UDepCR4OSE=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=kFwaaifxKRPTSvieQyuSh4tRWTa4XfqEARwNvfWlhKVCnRxzrATUDOuTpUMVh5IcL pvQpjstMIiyknZjceD2hQ31djgQ+UT4Zd8IZlM75cOeLI4TmN1Al69FXYAAvS5LoUC e3RFug9Vs91HRuQYLKc9Oa1z6z5hM+7VhL0yyY4NVSxd0kK3/ShOS9JhMkc96knJ2l A+AiiDjIXuFYfAptl2UTWfI7GovB3z0QnXdImBJvD/JGrsb9SNRfj52R5ItsNTWMBP RtqCe7zghmditXQQdn44EEJlexuMYubraaYIrMxPUzRLXLowb9ExHtx37UkVMYpS13 NF6dJbe9x/7iA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 21D97CE0A73; Wed, 5 Jun 2024 12:12:07 -0700 (PDT) Date: Wed, 5 Jun 2024 12:12:07 -0700 From: "Paul E. McKenney" To: Linus Torvalds Cc: linux-toolchains@vger.kernel.org, peterz@infradead.org, hpa@zytor.com, rostedt@goodmis.org, gregkh@linuxfoundation.org, keescook@chromium.org Subject: Re: A few proposals, this time from the C++ standards committee Message-ID: <168a4d68-256e-45ea-b65f-06ed59f02e31@paulmck-laptop> Reply-To: paulmck@kernel.org References: <83f5e119-6e32-415a-a1c8-8e6b0bd11a75@paulmck-laptop> Precedence: bulk X-Mailing-List: linux-toolchains@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 Wed, Jun 05, 2024 at 11:08:40AM -0700, Linus Torvalds wrote: > On Wed, 5 Jun 2024 at 06:52, Paul E. McKenney wrote: > > > > n3243 A Memory model with Synchronization based type aliasing V1, > > Eskil Steenberg Hald > > https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3243.pdf > > I love the part that admits that the type-based aliasing is broken. > > I don't think the "cast-based barriers" are a sufficient improvement. > > Note the "sufficient". I do think a cast-based barrier would have been > a huge improvement *originally*, in that it would avoid two absolutely > huge issues: > > - "char *" being special > > - the insane model of "use a union to tell the compiler type-base > aliasing can happen" > > Both of the above things are disgusting and wrong, but they are mostly > disgusting and wrong simply because type-based aliasing is entirely > and utterly wrong to begin with. > > Saying "pointer casts are an aliasing barrier" is a much better and > more logical model for the type-based thing. No question about that. > They help make the insanity that is type-based aliasing much more > manageable. > > However, I don't see that it would be sufficient for us to ever stop > using the "-fno-strict-aliasing" thing. Because type-based aliasing > continues to be insane, and even with pointer casting acting as a > barrier, has real problems. > > The paper points out one such problem: the cast may have been done > long long before the accesses are done. In fact, unions continue to be > one very real case of such a situation, where the pointer cast > basically comes from the type system itself. > > But even with explicit casts, those casts may very naturally be before > the accesses (the examples in the paper are simplistic, but we have > the "prepare casts" pattern in the kernel in places like this: > > static long do_fcntl(int fd, unsigned int cmd, unsigned long arg, > struct file *filp) > { > void __user *argp = (void __user *)arg; > int argi = (int)arg; > ... > > which admittedly isn't about two pointers that can alias, but is very > much an example of "it's more convenient to 'prep' the casts before > use", when the 'arg' argument is then used in multiple different ways > - sometimes as a pointer, sometimes as an integer, and sometimes as > the original 'unsigned long'. > > I personally think that the whole type-based aliasing is fundamentally > unfixable, and that the C standards committee should just admit that. > It doesn't even *work*, because often the types are the same anyway, > even when you really really want to say "these accesses can't alias". All good points! > The whole type-based aliasing is literally designed for - and by - HPC > people who (a) had no taste, (b) didn't understand language design and > just hacked sh*t together and (c) were working with clearly distinct > types because their workloads are trivial. To your point, my feeling back in the day was that all of this was designed to allow FORTRAN programs to be more easily ported to C and C++. > The HPC people literally tried to solve the issue of "counters are > integers, but our data is FP, and the two have obviously different > types, so let's use that information for alias analysis". > > Anybody who doesn't understand how broken and hacky that is SHOULD NOT > BE ON A LANGUAGE COMMITTEE. > > Seriously. I think it should be a fundamental filter for any C > language committee member: "Do you think type-based aliasing makes > sense?". If you get anything but an immediate "No!", you pull the > lever that opens the trap-door to the crocodile-infested waters below. > > Or sharks. Sharks are good too. ;-) ;-) ;-) > And no, "restrict" isn't great, but at least it's a better concept. > > I would suggest that people look at improving 'restrict' and making it > more useful, and just admit that the type-based thing was a mistake. One of the complaints was that people don't use "restrict" often enough to allow all the optimizations that compiler writers would like to do. Fortunately, there seems to be increasing levels of understanding that the generated code needs to do something useful. Here is hoping, anyway! Thanx, Paul