From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f169.google.com (mail-oi1-f169.google.com [209.85.167.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A50C215250D for ; Wed, 27 Mar 2024 22:26:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711578411; cv=none; b=FyH/udic2e7vj/8T3nG0sF7j6vs32CUK0y+b5jup2XCrLvZaBzUl38zfAbCYjJV9Ry1uERhvAnPSE2ISNm9QJ6AK6Cc7FW9U4NdNbR04/KwaukkMumMsUjh4tMDSM+KBwL4rskRLNPXyCUQCjxlQYORXUpkF3T540gskDd2S8GI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711578411; c=relaxed/simple; bh=0Eet4ylxwVn8zzff8qm5Ev6iikG6meyrEjfL2p8QNSI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jR90pNOd9w34PZd5F2D+rWHUlAVm2ijV6t1KGrabB1jDwngge7fhVaNdU/sUigLLzg7GMLnoQdDxVdkJ9OjstobuTDrEsv4r4Ult/VWsOrfAQQaIvJLVE3mkPu28I+2T0UabxxAGq1Pg9Fa54t8gHCXemWchHhI16ynKELRBSQ0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jKGJ3ufX; arc=none smtp.client-ip=209.85.167.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jKGJ3ufX" Received: by mail-oi1-f169.google.com with SMTP id 5614622812f47-3c3ae53f662so198270b6e.3 for ; Wed, 27 Mar 2024 15:26:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711578409; x=1712183209; darn=lists.linux.dev; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:from:to:cc:subject:date :message-id:reply-to; bh=wwkzJWECmlG16QHW6cdxBA+RFUUXDB2JZzSWnyJ9i9M=; b=jKGJ3ufX0W/Z1Bxtta/x/xcV6wONgtNNIOoYm9S9SgeFTC4P37VijtLAmPU19jIM2z sV22JTdeKfw3U9diMa7g47Od8Ac9I5xFjbf7PONKyrxqQvn8Qh5vVqy2TamE6QEKjEV/ Dqk13e9vrs/Qk8dnVL5oWMAB9Cx3O/6gU80lAaOHYai7SdZ1SzsXRtkOH0cZMJQlKtZB +M4wus0i2CDZRXQDRMXPL6CShNqHshJH8y8Tgs+w6tfrp2fKagHEGTrO18sRMW7vMDjs 0S4MLKGE1Jj5vnMl640ac0ww3JavkJc5U4yU+ui6TY7ImRqXHFCb0bkXSa/EhYNDMfCf p3ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711578409; x=1712183209; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wwkzJWECmlG16QHW6cdxBA+RFUUXDB2JZzSWnyJ9i9M=; b=M89GKPxx+Ajw2fXwq3gAMx3jUuauOS74ynJQ/6vJg6eL1F3hhjxRfGbk9fi/MKiVFe KxL7Q0hfGiSdqZ3e77HWCtDneDaWDYEqvWD+RA3CjOnNKWUeUELXXLLZbp6m0p6ZNfw/ 7Z4WiXhZkD0/pyRDD8tQ5E6FgFt1UygB8kBDvEyjOyQTf3qpJ2F6zOLWseYvJw6msCxl pXbp1o1IcA6DyU54Jm7hUKqaLzP5mSAXCDt6Y0TwE7HLx6qw+QxNJeJ3Dt8EUZYNxmfP XPrcn2Q55yxiRkgTrmbhIV4o1xYGFsdVR+w1SraL+7oR3hMwGgkbgYaLcQs3IazIB6FJ X8aA== X-Forwarded-Encrypted: i=1; AJvYcCUOuAiU39Nl3IJodU3I0IaqvUFNMFlxTrbStAYxUOfJ6NdDKK3PM4YOOnU26jrQ+lu2X+NrClOO+uwf/nbcRloOYaAQFA== X-Gm-Message-State: AOJu0YzPIxJgogf85AHvPTRHUdxUE2nkaNgQzMIcb4eHVVXxysbAlVkF pp4fu1+vgFhfkRINhOP24U+aOf3X0fZGszCpKG+qKUqV0OzO8C8Z X-Google-Smtp-Source: AGHT+IHGjWRkib9W0zZ7sBiv2+oNDjTn8vPgkUQXGuUBpsO88nnHMrIhshfeJQFgUjASDsrFPq59RQ== X-Received: by 2002:a05:6808:1920:b0:3c3:bc13:2ef6 with SMTP id bf32-20020a056808192000b003c3bc132ef6mr1745797oib.43.1711578408539; Wed, 27 Mar 2024 15:26:48 -0700 (PDT) Received: from fauth1-smtp.messagingengine.com (fauth1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id cb9-20020a05622a1f8900b00430b907c234sm44446qtb.26.2024.03.27.15.26.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 15:26:47 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfauth.nyi.internal (Postfix) with ESMTP id BFF2F1200032; Wed, 27 Mar 2024 18:26:46 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 27 Mar 2024 18:26:46 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudduiedgudefiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeeuohhq uhhnucfhvghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrf grthhtvghrnhephedugfduffffteeutddvheeuveelvdfhleelieevtdeguefhgeeuveei udffiedvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh epsghoqhhunhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedt ieegqddujeejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfh higihmvgdrnhgrmhgv X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 27 Mar 2024 18:26:44 -0400 (EDT) Date: Wed, 27 Mar 2024 15:26:07 -0700 From: Boqun Feng To: Kent Overstreet 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 , =?iso-8859-1?Q?Bj=F6rn?= 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: llvm@lists.linux.dev 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, Mar 27, 2024 at 05:49:41PM -0400, Kent Overstreet wrote: [...] > > > 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 I don't follow, a plain data structure like: struct Point { x: i64, y: i64 } doesn't have any unsafe Rust underneath I think. > unsafe Rust very much has to follow the aliasing rules too. > The point I was trying to say, the aliasing rule on Rust raw pointers is relatively relaxed compared to strict aliasing in C since Rust has references which should have more accurate informatio on aliasing. (but not a language expert). Regards, Boqun