From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) (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 C538370810; Fri, 11 Jul 2025 13:22:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752240174; cv=none; b=IitN+ehx1VdiAv2G6aoIcVuDrVcKRg8zuOeJ2I5ZnrkVWkF9aAabkeU6RUofglDf/8ZKmsp7Vq+hCQkIoENk9e3midoZsRVInOovSYhaWSh8WrgBSHGD9/LattpbE7A2Evp1tR3iT+fioJO4j2KoYMFSf8z0EkeEmhKucC8XvO4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752240174; c=relaxed/simple; bh=Z8xQn+iT3A5r4r5jVPej3tH0r1ytgXiZ3ITRDRty50c=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=YojsqugFBv5Qlb0lx75zaTcMwKfenmiiLmBga4SjDU4aSs/7OVauEla+8bgu+Pifh76NB2AutLndjsOCMl6mkgbrgX6lNlb2fVKMmZdtttKWhOVjvZyaMNSwrwUN7IMW6Q5e0Mv72ATDTIYZmgE0n2gDLgBmZVj9orD+q3QToN4= 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=cGubWbc6; arc=none smtp.client-ip=209.85.160.177 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="cGubWbc6" Received: by mail-qt1-f177.google.com with SMTP id d75a77b69052e-4a76ea97cefso21639361cf.2; Fri, 11 Jul 2025 06:22:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752240171; x=1752844971; darn=vger.kernel.org; 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=sYtOPsEZ+CQsVOIfnHqDEBe70N1WUVtu0akdEwqTHbE=; b=cGubWbc6CYl7O6Qeo3KH7lOWQHRqKX2+Aq8HT2m8nrugAdWdDKWhbVWLYvs77uiy5B bKG+Ab89I/nZcizvUnIU4BkTlDBquqb8/GSHx5rKenf8OSEuGdJgFXL78GK/T+FlHRF+ F0kkzYK/4nOPsSClMu5adMI9MECDuXERqoU3HMOx40WwebAZQ26hdML80ZxNkgD5afCF ghyamKfVChZp/FwE434uyp77+gZE9Vn1zsjSxlP8TmxCcEWjvnMHWGrq/9QG2uiFSQmR bJgIbYCeSiDDaRnFD/9iSGdvrFVXEIXjKLZOK8KxlP1qEdCPLvPD6youNFjwN2Y075LX PBFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752240171; x=1752844971; 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=sYtOPsEZ+CQsVOIfnHqDEBe70N1WUVtu0akdEwqTHbE=; b=nMODfdKj1JRZybMYM06SeQpi+VOKx3RBixnzmc1xteyVumXqkHAz7lsNezc1ugmCwB Wv+kuSvTqnEsmrz2i1aoDsYJr7qnfh7v267AwuxKiON0Nv2ZvBgcYW12sdmF5iTzMjTf GfGo68wuL/9BChjuOcoHrk5EM6L6WFK8SUqi3nrUHMG7ouU2Gpoc+An81RjRUJZcYEbE vfJoB33qDhEjeBtN4/pEcPRml5/yDt4V5hqUX00Jv+NmRSdizPa5OU1O73L+HqJ9yhqk UF2VCVDRpQoMabSXYGif8sfnWxbdFIMNvmw9dTIR1wwuUg8plNF6HA8HR6P7zzbzym3a gj4Q== X-Forwarded-Encrypted: i=1; AJvYcCUmJtbSSQYegij3bFAaNoGsgbaLJ41f4wesePZbPRpRIrG/urBHYf3e0u4A4WuAqXDK4f3TP375N7Ij@vger.kernel.org, AJvYcCV1/PcTeVTTqHg3f6kXXy35NcFi39hfQhNmY9FYowwuh0WuN80ZYrRsZ/074ySSw6wyRf0av52ZUMFtdKYIt+A=@vger.kernel.org X-Gm-Message-State: AOJu0Yy+kDFKftNy1HhPyPNrcyvZuZNCV9SM7YGbH9UZYiiCyBPw/sFS mvtxHqfp6cwDwYrLSRVU/RlfloNGf/22AYTBf2PBrsdCa0ZYMVmEsTgj X-Gm-Gg: ASbGnctWcxiDPnhb69544G58kWH1e/5TFW8CRGE2vg0PtN4NMic3tdW39YmGHcLqvaG un5Fus1gReT1POgDBUjk2uWn/pjiUuKJnOsJ/F3/FaHN0JLFk1Giw2ccOVJ+jyZZtGvCfQQIZ6+ ACzl779cc0CzOtc26EL8uIQ1v27Cbo/085kVMrNcXheICThp5EcmPhVZDOnxPFUMWHAW+FRvny1 k6GXvaf9Rek+uJAE4vnpBPm1YXXMNND13wWHmsvldVSybw+n803tC04JbqBWP2trE0KVHFPUqTK A3PVnX7CxXqVy0Hg91e5sSx6UqTXsHW4hUAqcZYX8cRoQ94RySqBigjhFjZmapJrYL/2DBHCI4R Sqgt+GscrOjgjEGTr+qIcHk6lSWhN/5cTO03cmqSYrm1lhDz1FC8/MMZsoH3Q/MYpVcJAvXLtkY mnMOf2WP9/fSH8 X-Google-Smtp-Source: AGHT+IGmUHLQtt4/Ao6E8L4tLE0MefjpXF7XEULDetINGFZ/Jy/Bf0GiAFzHKLdLVH4nwoSXYOFI1w== X-Received: by 2002:ac8:5d47:0:b0:4a7:6215:37f5 with SMTP id d75a77b69052e-4aa4158b43cmr37499891cf.48.1752240171472; Fri, 11 Jul 2025 06:22:51 -0700 (PDT) Received: from fauth-a2-smtp.messagingengine.com (fauth-a2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a9edea8e66sm21040151cf.54.2025.07.11.06.22.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jul 2025 06:22:50 -0700 (PDT) Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfauth.phl.internal (Postfix) with ESMTP id 2C2E8F40066; Fri, 11 Jul 2025 09:22:50 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-09.internal (MEProxy); Fri, 11 Jul 2025 09:22:50 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdegfeegfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpeffhffvvefukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeeuohhquhhnucfh vghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrfgrthhtvg hrnhepjeeihfdtuedvgedvtddufffggeefhefgtdeivdevveelvefhkeehffdtkeeihedv necuffhomhgrihhnpehruhhsthdqlhgrnhhgrdhorhhgnecuvehluhhsthgvrhfuihiivg eptdenucfrrghrrghmpehmrghilhhfrhhomhepsghoqhhunhdomhgvshhmthhprghuthhh phgvrhhsohhnrghlihhthidqieelvdeghedtieegqddujeejkeehheehvddqsghoqhhunh drfhgvnhhgpeepghhmrghilhdrtghomhesfhhigihmvgdrnhgrmhgvpdhnsggprhgtphht thhopedvjedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheplhhoshhsihhnsehkvg hrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhk vghrnhgvlhdrohhrghdprhgtphhtthhopehruhhsthdqfhhorhdqlhhinhhugiesvhhgvg hrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlkhhmmheslhhishhtshdrlhhinhhu gidruggvvhdprhgtphhtthhopehlihhnuhigqdgrrhgthhesvhhgvghrrdhkvghrnhgvlh drohhrghdprhgtphhtthhopehojhgvuggrsehkvghrnhgvlhdrohhrghdprhgtphhtthho pegrlhgvgidrghgrhihnohhrsehgmhgrihhlrdgtohhmpdhrtghpthhtohepghgrrhihse hgrghrhihguhhordhnvghtpdhrtghpthhtohepsghjohhrnhefpghghhesphhrohhtohhn mhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 11 Jul 2025 09:22:49 -0400 (EDT) Date: Fri, 11 Jul 2025 06:22:48 -0700 From: Boqun Feng To: Benno Lossin Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, lkmm@lists.linux.dev, linux-arch@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Will Deacon , Peter Zijlstra , Mark Rutland , Wedson Almeida Filho , Viresh Kumar , Lyude Paul , Ingo Molnar , Mitchell Levy , "Paul E. McKenney" , Greg Kroah-Hartman , Linus Torvalds , Thomas Gleixner , Alan Stern Subject: Re: [PATCH v6 4/9] rust: sync: atomic: Add generic atomics Message-ID: References: <20250710060052.11955-1-boqun.feng@gmail.com> <20250710060052.11955-5-boqun.feng@gmail.com> Precedence: bulk X-Mailing-List: rust-for-linux@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 Fri, Jul 11, 2025 at 10:03:07AM +0200, Benno Lossin wrote: [...] > > + > > + /// Returns a pointer to the underlying atomic variable. > > + /// > > + /// Extra safety requirement on using the return pointer: the operations done via the pointer > > + /// cannot cause data races defined by [`LKMM`]. > > I don't think this is correct. I could create an atomic and then share > it with the C side via this function, since I have exclusive access, the > writes to this pointer don't need to be atomic. > that's why it says "the operations done via the pointer cannot cause data races .." instead of saying "it must be atomic". > We also don't document additional postconditions like this... If you Please see how Rust std document their `as_ptr()`: https://doc.rust-lang.org/std/sync/atomic/struct.AtomicI32.html#method.as_ptr It mentions that "Doing non-atomic reads and writes on the resulting integer can be a data race." (although the document is a bit out of date, since non-atomic read and atomic read are no longer data race now, see [1]) I think we can use the similar document structure here: providing more safety requirement on the returning pointers, and... > really would have to do it like this (which you shouldn't given the > example above), you would have to make this function `unsafe`, otherwise > there is no way to ensure that people adhere to it (since it isn't part > of the safety docs). > ...since dereferencing pointers is always `unsafe`, users need to avoid data races anyway, hence this is just additional information that helps reasoning. Regards, Boqun > > + /// > > + /// [`LKMM`]: srctree/tools/memory-model > > + pub const fn as_ptr(&self) -> *mut T { > > + self.0.get() > > + } [...]