From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oo1-f51.google.com (mail-oo1-f51.google.com [209.85.161.51]) (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 9A50344DB79 for ; Tue, 20 Jan 2026 15:48:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768924106; cv=none; b=JeWmFUq5Zg5QPWpaPt/J4+2ioH02R29++dxUWcbrCcvDtsBEGkaMp1rUD2yX6hw4Q9qK7DWRqJov6q+VcLkiEvxfH/596JKNW3HjTgzK6Ti9RNVsTHxy7BghPUp+DBssTw8K3DLDyuEWQnE1OLUyIjQYu9Kp5Zvzkha56cXMcTw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768924106; c=relaxed/simple; bh=KEgCwIHV91V/HRggN5GK/V4JBaIXW7US9kJ8q/CbBhY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=b25wYoha/wVPOVd/ob0LPKKZmZYXS9l+JJ8PRBgPOxDjJHQT76REW//vt0VKaHqTdsf1BBuoEDE1cx6LOemn7QDGJqJ415sg2IEAKR3+NRCVpybv3QiqAUD2f3O3h0msrsOY/dtg5J3cP5RCHpRS31A+P+4stfA2/AhfpuNpjwA= 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=g0kcIHVn; arc=none smtp.client-ip=209.85.161.51 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="g0kcIHVn" Received: by mail-oo1-f51.google.com with SMTP id 006d021491bc7-6610e72112bso2505594eaf.1 for ; Tue, 20 Jan 2026 07:48:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768924103; x=1769528903; 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=cyXouSFdgGvsNJv0Rfk+0bxHd/9nuw4emSyLP3jbzKo=; b=g0kcIHVnFcGrQtSpkNj5xmSRRvUbb3Fd7T30wGbD1fp1ezNkAVGBqJ3diq07cTFeY6 IeqDA0Tt67z2R90ZBGpZMXPuTGfS9fbjC8lZA4cW/g48BDi/lV6o+7NvcChpG/E2RKUQ iMdJJZw/+huX++UHt4hERO9VpcUMcKoEsB16xPfOJte5cx4+McLhUTS9fYlvOQDb089c TU6JyB727Mb1fMXp3PhiZGrGbQXN1ZM+1QiqAXOwesRgloJc4xhIv/CptQCBBbsnnhLw Ti+T9mjPgumRgGUtN7JQ4u6bRZZuNOCw/QiG8OVQZec0Nl2EXMU8ixJOjv2GPOlBjLar 1PKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768924103; x=1769528903; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=cyXouSFdgGvsNJv0Rfk+0bxHd/9nuw4emSyLP3jbzKo=; b=YTrIoqySnsDTft5nIqgzncjjG6z6xDh+eET5j2OR99bEvjCX5F9q1UldSueCPozcI6 S4sp00qyFVf83T0cYNvBY3N+zrRMYqOirVYmJHyB68Te0U0uXOov6wgaJ/Y/6j/jmhFc PG9wH33B1D9fPwHSJa4TcLgUP2dhIb6cjBCMQ1pGkpVPqoeiMhEMgBBbJHrY6haoXOK7 BNRDUyfYpN9+dp0vAN0+1aYRZhwcrnEWAj8Eayr6lujaheyXltMcJUWqwTdck75XXPJj u2JQS9dNxIDyEEDp2iqaDBil0NY1G1vJfqDbHYeTE9lUO1VQdW6EiOBgoC0AWx9jUoaE jThQ== X-Forwarded-Encrypted: i=1; AJvYcCVm7eE5qMPdjqq8VnoTskABsByUJW72PxTUBUyULsrdrb7A4/g5FuBulusINlOD/QvAP9p+N2mfsAWyLz4=@vger.kernel.org X-Gm-Message-State: AOJu0Yy340Pbbc7uLZ4WU1y7q4BTQtanYduIMq8cSyU8tDkgQZWVNCtI 0amcPMxDjYC6XR0y3YWS++2GaYDb0wDHt5W0CAtKrxA4s71Z25svGIXA X-Gm-Gg: AY/fxX4XRXyBl4jiRdH7y7F/F93AOpoaEZftDTeb2rhy5Lw5IEdp4D+93JDdIAfgpUS uxwowzUZ/OfEgbpfXBYlwVTeDNHuRedCibyfuezqKzmckRe26Pb98uR6mX2wCVMGqVXrDd1jZmh 8hHHA6fBnbrPt/CYvUnQrHZspeIt03Yieqp8l7Im4czrswUpyoFyuSK/YFiJUu58ocK4D86bIGP sv+47DdtjTihXWiDH4HAAfVCEvj8InyIFqGz09ZQzI/r7k9u9tncnfYoBjVaVV7RdfH6PuzSHi0 CymIxXZHDsU/krfI0+lCs+ltlLgfbeEniXy7Hhb3TcjrE/v1d/51AXNDbL146e//p1BASpb01II rJbRrh3HIKTbvpYFJcvi6Zpv91gxTBamCQS528jVKk6bKmYFXTq8rZdTKIvnr7ENjAJhAYXqRCu spf+1Wo4eLjWHaJjjZdrBfEa/rkQ3xoAXfTnBcXGCZ2LnUg4ZJuG+bnhNPTn4TBV+oNOgcDjqL6 zYNWisLcNdBbA4= X-Received: by 2002:a05:6830:6a12:b0:7c9:5bef:e9b with SMTP id 46e09a7af769-7cfdfe21e9dmr7501113a34.3.1768918029463; Tue, 20 Jan 2026 06:07:09 -0800 (PST) Received: from fauth-a1-smtp.messagingengine.com (fauth-a1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7cfdf000b80sm8639228a34.0.2026.01.20.06.07.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jan 2026 06:07:09 -0800 (PST) Received: from phl-compute-10.internal (phl-compute-10.internal [10.202.2.50]) by mailfauth.phl.internal (Postfix) with ESMTP id C6219F40069; Tue, 20 Jan 2026 09:07:06 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-10.internal (MEProxy); Tue, 20 Jan 2026 09:07:06 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddugedtieduucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepuehoqhhunhcu hfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrghtth gvrhhnpefhtedvgfdtueekvdekieetieetjeeihedvteehuddujedvkedtkeefgedvvdeh tdenucffohhmrghinhepkhgvrhhnvghlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomhepsghoqhhunhdomhgvshhmthhprghuthhhphgv rhhsohhnrghlihhthidqieelvdeghedtieegqddujeejkeehheehvddqsghoqhhunhdrfh gvnhhgpeepghhmrghilhdrtghomhesfhhigihmvgdrnhgrmhgvpdhnsggprhgtphhtthho pedviedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheprghlihgtvghrhihhlhesgh hoohhglhgvrdgtohhmpdhrtghpthhtohepghgrrhihsehgrghrhihguhhordhnvghtpdhr tghpthhtoheprhhushhtqdhfohhrqdhlihhnuhigsehvghgvrhdrkhgvrhhnvghlrdhorh hgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdho rhhgpdhrtghpthhtoheprhgtuhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtth hopehojhgvuggrsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegsjhhorhhnfegpghhh sehprhhothhonhhmrghilhdrtghomhdprhgtphhtthhopehlohhsshhinheskhgvrhhnvg hlrdhorhhgpdhrtghpthhtoheprgdrhhhinhgusghorhhgsehkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 20 Jan 2026 09:07:06 -0500 (EST) Date: Tue, 20 Jan 2026 22:07:04 +0800 From: Boqun Feng To: Alice Ryhl Cc: Gary Guo , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, rcu@vger.kernel.org, Miguel Ojeda , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , Will Deacon , Peter Zijlstra , Mark Rutland , "Paul E. McKenney" , Frederic Weisbecker , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Uladzislau Rezki , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , FUJITA Tomonori Subject: Re: [PATCH 4/5] rust: sync: atomic: Add Atomic<*mut T> support Message-ID: References: <20260117122243.24404-1-boqun.feng@gmail.com> <20260117122243.24404-5-boqun.feng@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: On Tue, Jan 20, 2026 at 12:37:03PM +0000, Alice Ryhl wrote: > On Sun, Jan 18, 2026 at 12:19:35PM +0800, Boqun Feng wrote: > > On Sat, Jan 17, 2026 at 05:03:15PM +0000, Gary Guo wrote: > > > On Sat Jan 17, 2026 at 12:22 PM GMT, Boqun Feng wrote: > > > > +// SAFETY: > > > > +// > > > > +// - `*mut T` has the same size and alignment with `*const c_void`, and is round-trip > > > > +// transmutable to `*const c_void`. > > > > +// - `*mut T` is safe to transfer between execution contexts. See the safety requirement of > > > > +// [`AtomicType`]. > > > > +unsafe impl super::AtomicType for *mut T { > > > > + type Repr = *const c_void; > > > > +} > > > > > > How about *const T? > > > > > > > In general I want to avoid const raw pointers since it provides very > > little extra compared to mut raw pointers. For compiler optimization, > > provenenace is more important than "const vs mut" modifier, for > > dereference, it's unsafe anyway and users need to provide reasoning > > (including knowing the provenance and other accesses may happen to the > > same address), so I feel the type difference of "*const T" vs "*mut T" > > doesn't do anything extra either. > > > > Think about it, in Rust std, there are two pointer types only maps to > > "*mut T": NonNull (as_ptr() returns a `*mut T`) and AtomicPtr > > (as_ptr() returns a `*mut *mut T`). And there is no type like > > NonNullConst and AtomicConstPtr. This is a lint to me that we may > > not need to support `*const T` in most cases. > > > > But maybe I'm missing something? If you have a good reason, we can > > obviously add the support for `*const T`. > > It was pretty inconvenient in: > https://lore.kernel.org/all/20260117-upgrade-poll-v1-1-179437b7bd49@google.com/ > since I had to cast_mut() a bunch of places. > Let's add it then ;-) https://lore.kernel.org/rust-for-linux/20260120140503.62804-1-boqun.feng@gmail.com/ Regards, Boqun > Alice