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 387E31E5B6A; Wed, 9 Jul 2025 20:22:10 +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=1752092530; cv=none; b=p5W2FTIT6VQBxfMN3o1Z+JPd3Xk0F7qLDnlgCVvBV/l3ZYc82Jzx9lczlnEDBltLzVw5QClK5VohRoillOMPbn+ArGjxLkJkzCrYOYw8OEWrg1J7TxM5xRER3+9YlnB55+E+6mOpHfve/PqdmR+butvmP0YlkjYN+ttVcoOJlPs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752092530; c=relaxed/simple; bh=r4ykqC1BMysn26mbzqOJLBLUnrVxJa0A43xHGpGB23s=; h=Mime-Version:Content-Type:Date:Message-Id:To:Cc:Subject:From: References:In-Reply-To; b=k/r/oAXIdLc9z358zA1bznpImpYB525kU4DNaBdIJkL/KMuo2qnNWRicM0enwxSUH0QDCCzLY3kwt9BrYdCxdc7sMuRNkFAUTEYlsCBoJomkn9nVjJP7v3jul0kEw3cwqUEbpy1rd8moccTZ5Q///WvQgi32+rdHY63EfCcsJKg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nOXlium6; 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="nOXlium6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A3226C4CEEF; Wed, 9 Jul 2025 20:22:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1752092530; bh=r4ykqC1BMysn26mbzqOJLBLUnrVxJa0A43xHGpGB23s=; h=Date:To:Cc:Subject:From:References:In-Reply-To:From; b=nOXlium6yxzsnqoZeyAjnDBVr/+4EAnUE+lmZvPg5Z+OM32PXPh/cRQ+GaGFder7y y8n9ZPKr0LOMuYcKxURkwr57y50XEx6hDVrmZ96SyOxk44EBOcJt82SYetvZDSCFmD 7WiYT/+YnKR2UQ7a6GOD9WBibY3MoKQnHmPOnqG13O2NX/7lxZ2ocRLBqyLez2iFUd 3rBDMJ3Ws0xLrcckEEwddXVJpz/zYcNINhNAAaXPGWhYjGxJRIy0oa85+FkGWB5WIk lKEeh13grD6hLkoemvRumEeWOMS0fc+q9BxUNcDFXMyhSIGtp5ii9DO7ciJVVvwwjz YEv3+Ne4s9Cdw== Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Wed, 09 Jul 2025 22:22:04 +0200 Message-Id: To: "Boqun Feng" Cc: "Andreas Hindborg" , "Alice Ryhl" , "Miguel Ojeda" , "Alex Gaynor" , "Gary Guo" , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , "Masahiro Yamada" , "Nathan Chancellor" , "Luis Chamberlain" , "Danilo Krummrich" , "Nicolas Schier" , "Trevor Gross" , "Adam Bratschi-Kaye" , , , , "Petr Pavlu" , "Sami Tolvanen" , "Daniel Gomez" , "Simona Vetter" , "Greg KH" , "Fiona Behrens" , "Daniel Almeida" , Subject: Re: [PATCH v15 1/7] rust: sync: add `SetOnce` From: "Benno Lossin" X-Mailer: aerc 0.20.1 References: <20250707-module-params-v3-v15-0-c1f4269a57b9@kernel.org> <20250707-module-params-v3-v15-1-c1f4269a57b9@kernel.org> <877c0joyfo.fsf@kernel.org> <87ple9lkjr.fsf@kernel.org> In-Reply-To: On Wed Jul 9, 2025 at 10:12 PM CEST, Boqun Feng wrote: > On Wed, Jul 09, 2025 at 08:22:16PM +0200, Benno Lossin wrote: >> On Wed Jul 9, 2025 at 12:34 PM CEST, Andreas Hindborg wrote: >> > "Benno Lossin" writes: >> >> On Tue Jul 8, 2025 at 10:54 AM CEST, Andreas Hindborg wrote: >> >>> "Boqun Feng" writes: >> >>>> On Mon, Jul 07, 2025 at 03:38:58PM +0200, Alice Ryhl wrote: >> >>>>> On Mon, Jul 7, 2025 at 3:32=E2=80=AFPM Andreas Hindborg wrote: >> >>>>> > >> >>>>> > Introduce the `SetOnce` type, a container that can only be writt= en once. >> >>>>> > The container uses an internal atomic to synchronize writes to t= he internal >> >>>>> > value. >> >>>>> > >> >>>>> > Signed-off-by: Andreas Hindborg >> >>>>> >> >>>>> LGTM: >> >>>>> Reviewed-by: Alice Ryhl >> >>>>> >> >>>>> > +impl Drop for SetOnce { >> >>>>> > + fn drop(&mut self) { >> >>>>> > + if self.init.load(Acquire) =3D=3D 2 { >> >>>>> > + // SAFETY: By the type invariants of `Self`, `self.= init =3D=3D 2` means that `self.value` >> >>>>> > + // contains a valid value. We have exclusive access= , as we hold a `mut` reference to >> >>>>> > + // `self`. >> >>>>> > + unsafe { drop_in_place(self.value.get()) }; >> >>>>> >> >>>>> This load does not need to be Acquire. It can be a Relaxed load or >> >>>>> even an unsynchronized one since the access is exclusive. >> >>>> >> >>>> Right, I think we can do the similar as Revocable here: >> >>>> >> >>>> if *self.init.get_mut() =3D=3D 2 { } >> > >> > Ok, now I got it. You are saying I don't need to use the atomic load >> > method, because I have mutable access. Sounds good. >> > >> > But I guess a relaxed load and access through a mutable reference shou= ld >> > result in the same code generation on most (all?) platforms? >>=20 >> AFAIK it is not the same on arm. >>=20 > > Right, when LTO=3Dy, arm64 use acquire load to implement > READ_ONCE()/atomic_read(). But Andreas was talking about relaxed load vs mutable reference (=3D normal unsynchronized write)? --- Cheers, Benno