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 23E6F234994; Fri, 27 Jun 2025 08:23:22 +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=1751012603; cv=none; b=kI9jVb8KJN5Ls3brucPMnT0I0If+LUdGsMqeH5qjS2SZdgWeHruYNMuNCeWDipHGeLlej8PvV/0jiTdvK2VIywrvFUQ1owS16aQVYjzchqI405n7Sl0vpZdXB8RZJpy5kC5nF5Ys8wmuOovb1YISPR4kMdM4P01Ysslkg6QFTcM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751012603; c=relaxed/simple; bh=uN/D8dqiB5VYUFly92uE7+enUWgNCKOFbWJkaVmg9qA=; h=Mime-Version:Content-Type:Date:Message-Id:Subject:From:To:Cc: References:In-Reply-To; b=pB5fCV0SBhNpvMOlOuyXHiSQuIxbJV0vs/ZMudiB1xNybjJV5kP+NHoPAgN8eCVZiZF1gAYoWPry09+VqyB8lXQjHCj5kk0edUwBddxUhKlwMb6ETWMVr/IngYQiN/i94T6Y7EtuUvXxCtwBn7fj9aJcfQqZzczwfdxfLlJHwfE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XgDlZYlR; 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="XgDlZYlR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F4B1C4CEF0; Fri, 27 Jun 2025 08:23:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751012602; bh=uN/D8dqiB5VYUFly92uE7+enUWgNCKOFbWJkaVmg9qA=; h=Date:Subject:From:To:Cc:References:In-Reply-To:From; b=XgDlZYlRR03OoCIqDOBeRU4oLrgs71elLSS/qGk/G2DlO88AvkkDIqF6F/Ns5XYFr bBTvujelzy6neisx4LvhnKPgCQxrq/M5odUoba+UGq0x+dLDMZVqprpeaOw4D6xqhA fTeYWukLLqRHBwnnKzQbq8tlPX0H/4PYfiTaDCfkSjG97GFpCMXEq/kFQ3Cx7ghiia bsQrXnY+3aCP0fd5tlZ4lZCkncR+PcebFVPzEqTuXcm7Csp5ivhgDTJARZ4hKwbsmi B8I9D83riALQ8iY+dptih3ew7XOw+0G8YGoW3pgRWb9TI6ZbCH0qd5bJ39OsGqIKhP SaSLksICej/iQ== Precedence: bulk X-Mailing-List: linux-kbuild@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: Fri, 27 Jun 2025 10:23:16 +0200 Message-Id: Subject: Re: [PATCH v13 2/6] rust: introduce module_param module From: "Benno Lossin" To: "Andreas Hindborg" Cc: "Miguel Ojeda" , "Alex Gaynor" , "Boqun Feng" , "Gary Guo" , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , "Alice Ryhl" , "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" , X-Mailer: aerc 0.20.1 References: <20250612-module-params-v3-v13-0-bc219cd1a3f8@kernel.org> <20250612-module-params-v3-v13-2-bc219cd1a3f8@kernel.org> <87ikkq648o.fsf@kernel.org> <877c126bce.fsf@kernel.org> <87v7om4jhq.fsf@kernel.org> <878qlh4aj1.fsf@kernel.org> <87plepzke5.fsf@kernel.org> In-Reply-To: <87plepzke5.fsf@kernel.org> On Fri Jun 27, 2025 at 9:57 AM CEST, Andreas Hindborg wrote: > Andreas Hindborg writes: >> "Benno Lossin" writes: >>> That's good to know, then let's try to go for something simple. >>> >>> I don't think that we can just use a `Mutex`, because we don't have = a >>> way to create it at const time... I guess we could have >>> >>> impl Mutex >>> /// # Safety >>> /// >>> /// The returned value needs to be pinned and then `init` needs >>> /// to be called before any other methods are called on this. >>> pub unsafe const fn const_new() -> Self; >>> >>> pub unsafe fn init(&self); >>> } >>> >>> But that seems like a bad idea, because where would we call the `init` >>> function? That also needs to be synchronized... >> >> Ah, that is unfortunate. The init function will not run before this, so >> we would need a `Once` or an atomic anyway to initialize the lock. >> >> I am not sure if we are allowed to sleep during this, I would have to >> check. But then we could use a spin lock. >> >> We will need the locking anyway, when we want to enable sysfs write >> access to the parameters. >> >>> >>> Maybe we can just like you said use an atomic bool? >> >> Sigh, I will have to check how far that series has come. >> > > I think I am going to build some kind of `Once` feature on top of > Boqun's atomic series [1], so that we can initialize a lock in these > statics. We can't use `global_lock!`, because that depends on module > init to initialize the lock before first use. Sounds good, though we probably don't want to name it `Once`. Since it is something that will be populated in the future, but not by some random accessor, but rather a specific populator. So maybe: pub struct Delayed { dummy: T, real: Opaque, populated: Atomic, // or Atomic writing: Atomic, // or Atomic } impl Delayed { pub fn new(dummy: T) -> Self { Self { dummy, real: Opaque::uninit(), populated: Atomic::new(false), writing: Atomic::new(false), } } pub fn get(&self) -> &T { if self.populated.load(Acquire) { unsafe { &*self.real.get() } } else { // maybe print a warning here? // or maybe let the user configure this in `new()`? &self.dummy } } pub fn populate(&self, value: T) { if self.writing.cmpxchg(false, true, Release) { unsafe { *self.real.get() =3D value }; self.populated.store(true, Release); } else { pr_warn!("`Delayed<{}>` written to twice!\n", core::any::ty= pe_name::()); } } } (no idea if the orderings are correct, I always have to think way to much about that... especially since our atomics seem to only take one ordering in compare_exchange?) > As far as I can tell, atomics may not land in v6.17, so this series > will probably not be ready for merge until v6.18 at the earliest. Yeah, sorry about that :( > Thanks for the input, Benno! My pleasure! --- Cheers, Benno