Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp58130lqh; Wed, 27 Mar 2024 14:50:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW1ceJbhVkGdghn58YfTrj6IjC8MpgvkM0CISwPx0hDiEDqAS0r305Qo33pyYCkvhRkeamnixi7yXON+zDvt8Na3M9k/SKU4wNopdH4gw== X-Google-Smtp-Source: AGHT+IEACjqeo5dItjRg6Sjbq7+nnhPjevRrL3oYHnDRNK/ykQAy+U0SOPpbGIVILax2PPCuoB8h X-Received: by 2002:a05:6a20:6a12:b0:1a5:6bfd:6bdd with SMTP id p18-20020a056a206a1200b001a56bfd6bddmr459431pzk.50.1711576209361; Wed, 27 Mar 2024 14:50:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711576209; cv=pass; d=google.com; s=arc-20160816; b=yPCDwcXeQasxH00fQ/fHnGOSE2q2dfJplTnjrypoTN2yAqGdEDCxxN63Ikef+T80+Y JLmpzQhTC8makuRBzXvqcH5gmDA9Mt5kLI0pjg7FXceZ32QnE96GdLhK5D0n7h4a7Oaz bRS0Nzbz/ZleOWYHiBU5n0Y98VixON4jgNyy/lCHF6MpClR1PCfV4VNZ2OLUYcB+RbH2 gJspgCA8wEdC15IEXC8M+vtvLAM3kbd6uJBtzfCEOCi0+PjpAh9YKfKfAz85ptQWaIWN QGZgiRLLUMO0LwY1WXHTpttVjE+MRMBJaQ+lmiaCQT4U1CrjOOkbrBRxyatBgL4IUmPl LISg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:dkim-signature:date; bh=9fq3QMnxkMVCH8b0951Wxyyz2XZrmXpoRDVmVHWK2mo=; fh=xU/4pTHPpfQdpkQNU8gtOBw67UXmKiuhv9E55QXyl3k=; b=wSGCe4VVBeXyW5318kiUFz9PoA3SX02SpJ3VaVxXumrAhyNbBOdOKUU+FzcnWvE+MR Mi5YY/Y9gaixgssXCGQ6RJBsOaoORgydmdNPuw4vGBYhZbRA4dDy1b+BY2mTRyqKlU9G WKy629SgU4dfekSPVUs+7OGAd9mg8HBuaON5CS4AAiGkSGyFqna0HhGBVq8dErui1rPA IenARYzq8wOZQ2fG6TUcnr3vBI1DgYeCfJPY224uy6ANNhsojrzClEEWnSmBHP9kBccz FlmA/A2A1YTWRCMdJV/Cwn6urSJHly9jgtgpWPhR+Y7JvEtqS6CDvmCDIxtXXnPF6gey bysA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=mtf5vAQM; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-122059-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122059-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id s1-20020a63ff41000000b005dbed76d0afsi12213777pgk.667.2024.03.27.14.50.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 14:50:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-122059-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=mtf5vAQM; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-122059-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122059-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 6FFD82A25A2 for ; Wed, 27 Mar 2024 21:50:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9A13B15382F; Wed, 27 Mar 2024 21:49:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="mtf5vAQM" Received: from out-170.mta1.migadu.com (out-170.mta1.migadu.com [95.215.58.170]) (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 BA61415356E for ; Wed, 27 Mar 2024 21:49:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711576192; cv=none; b=NvK7i5Va+SlnQmEy2hteo32BQvwlkKBm6q30HOBZ5aUoOSJhpvlBaPWXummDPCPYRFfcaRTRFZi/AujyIXKPKuYaGw2+LtUGBUg0iIcyNphepKSHBoMnUGaZw0gbacTrukkfuWCakoVHsqkmnJTGw+cGvGElYfi/lwsLx6gKF3I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711576192; c=relaxed/simple; bh=9Zl+I9A453cdMrWhPhzO+VutQ/fMadKGy8JNLSWoVfs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JhBCKDWHQ23p1G1VTmjZb6k8h1F7qD8KAx5zD38uF/JESK7SuqGUckLQ8CQba3UYdHncCVuActJWizUisMGdqqPIFzMfEE9bVFqj8RDjmm0Xa5582gYb9KNZNq7LaKtS3IYpGSCeXVjVdK8h8AbPeaL1fGVn85QWOeVUHe1YcLw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=mtf5vAQM; arc=none smtp.client-ip=95.215.58.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Date: Wed, 27 Mar 2024 17:49:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1711576188; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=9fq3QMnxkMVCH8b0951Wxyyz2XZrmXpoRDVmVHWK2mo=; b=mtf5vAQMnc/zscKPRaqv0R+DY2HacdeTfyNhobDQF4X1GygrV58z9wRqsYUMbpUE1AM1WW EY70Rs8bjoRdXGG3IC948oIoowv/mvLSvihXACjQ1fBoFdTTikz2CcI+DCTj9l8x7pZlRq 32ud8GjxancHf9QZsNGCSK39S7YCrFU= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kent Overstreet To: Boqun Feng Cc: Linus Torvalds , comex , "Dr. David Alan Gilbert" , Philipp Stanner , rust-for-linux , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, llvm@lists.linux.dev, Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Gary Guo , =?utf-8?B?QmrDtnJu?= Roy Baron , Benno Lossin , Andreas Hindborg , Alice Ryhl , Alan Stern , Andrea Parri , Will Deacon , Peter Zijlstra , Nicholas Piggin , David Howells , Jade Alglave , Luc Maranget , "Paul E. McKenney" , Akira Yokosawa , Daniel Lustig , Joel Fernandes , Nathan Chancellor , Nick Desaulniers , kent.overstreet@gmail.com, Greg Kroah-Hartman , Marco Elver , Mark Rutland , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Catalin Marinas , linux-arm-kernel@lists.infradead.org, linux-fsdevel@vger.kernel.org Subject: Re: [WIP 0/3] Memory model and atomic API in Rust Message-ID: References: <160DB953-1588-418E-A490-381009CD8DE0@gmail.com> 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-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT On Wed, Mar 27, 2024 at 02:21:03PM -0700, Boqun Feng wrote: > On Wed, Mar 27, 2024 at 03:41:16PM -0400, Kent Overstreet wrote: > > On Wed, Mar 27, 2024 at 12:07:26PM -0700, Linus Torvalds wrote: > > > On Wed, 27 Mar 2024 at 11:51, Kent Overstreet wrote: > > > > > > > > On Wed, Mar 27, 2024 at 09:16:09AM -0700, comex wrote: > > > > > Meanwhile, Rust intentionally lacks strict aliasing. > > > > > > > > I wasn't aware of this. Given that unrestricted pointers are a real > > > > impediment to compiler optimization, I thought that with Rust we were > > > > finally starting to nail down a concrete enough memory model to tackle > > > > this safely. But I guess not? > > > > > > Strict aliasing is a *horrible* mistake. > > > > > > It's not even *remotely* "tackle this safely". It's the exact > > > opposite. It's completely broken. > > > > > > Anybody who thinks strict aliasing is a good idea either > > > > > > (a) doesn't understand what it means > > > > > > (b) has been brainwashed by incompetent compiler people. > > > > > > it's a horrendous crock that was introduced by people who thought it > > > was too complicated to write out "restrict" keywords, and that thought > > > that "let's break old working programs and make it harder to write new > > > programs" was a good idea. > > > > Strict aliasing is crap in C and C++ because we started out with > > unrestricetd pointers, and it just doesn't work in C and C++ with the > > realities of the kind of code we have to write, and we never got any > > kind of a model that would have made it workable. Never mind trying to > > graft that onto existing codebases... > > > > (Restrict was crap too... no scoping, nothing but a single f*cking > > keyword? Who ever thought _that_ was going to work?) > > > > _But_: the lack of any aliasing guarantees means that writing through > > any pointer can invalidate practically anything, and this is a real > > I don't know whether I'm 100% correct on this, but Rust has references, > so things like "you have a unique reference to a part of memory, no one > would touch it in the meanwhile" are represented by `&mut`, to get a > `&mut` from a raw pointer, you need unsafe, where programmers can > provide the reasoning of the safety of the accesses. More like "pointers > can alias anyone but references cannot" to me. That's not really a workable rule because in practice every data structure has unsafe Rust underneath. Strict aliasing would mean that unsafe Rust very much has to follow the aliasing rules too.