All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] rust: sync: add SetOnce::try_get_or_populate()
@ 2026-07-22  9:16 Alice Ryhl
  2026-07-22  9:16 ` [PATCH 1/3] rust: sync: return `Result<&T, T>` from `SetOnce::populate()` Alice Ryhl
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Alice Ryhl @ 2026-07-22  9:16 UTC (permalink / raw)
  To: Boqun Feng, Gary Guo, Lyude Paul, Daniel Almeida, Onur Özkan,
	Greg Kroah-Hartman, Carlos Llamas
  Cc: Luis Chamberlain, Petr Pavlu, Daniel Gomez, Sami Tolvanen,
	Aaron Tomlin, Miguel Ojeda, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Trevor Gross, Danilo Krummrich,
	Tamir Duberstein, Alexandre Courbot, linux-modules, linux-kernel,
	rust-for-linux, Alice Ryhl

The SetOnce::populate() method does not internally synchronize callers
that fail to populate the value with the successful call. This means
that naive loops using as_ref() and populate() can lead to spinning on
the initialization, which is best avoided. Thus, provide a helper that
avoids this issue using a user-provided lock.

One potential alternative is to change populate() so that the failing
caller actually does synchronize with the successful call to populate().
However, this is somewhat tricky:

* There are users of SetOnce that construct it in const context, and we
  currently don't have the ability to do that for most locks, so we
  cannot easily add a lock to SetOnce.
* Just spinning on the atomic is undesirable unless we disable
  preemption in the success path. If we do disable preemption, then that
  raises complications for handling the PREEMPT_RT case.
* It also raises questions about deadlocks if populate() is called from
  irqs.

By using a user-provided lock, we do not have to worry about these
issues inside SetOnce.

This series is based on char-misc-next.

Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
Alice Ryhl (3):
      rust: sync: return `Result<&T, T>` from `SetOnce::populate()`
      rust: sync: add SetOnce::try_get_or_populate()
      rust_binder: use SetOnce::try_get_or_populate()

 drivers/android/binder/process.rs | 16 +++--------
 rust/kernel/module_param.rs       |  8 +++---
 rust/kernel/sync/set_once.rs      | 58 ++++++++++++++++++++++++++++++++-------
 3 files changed, 56 insertions(+), 26 deletions(-)
---
base-commit: 2cedf2272f1bb42471e646868ac572cc5752bd91
change-id: 20260721-setonce-populate-f2a9b61aeb1d

Best regards,
-- 
Alice Ryhl <aliceryhl@google.com>


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-07-22  9:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-22  9:16 [PATCH 0/3] rust: sync: add SetOnce::try_get_or_populate() Alice Ryhl
2026-07-22  9:16 ` [PATCH 1/3] rust: sync: return `Result<&T, T>` from `SetOnce::populate()` Alice Ryhl
2026-07-22  9:23   ` sashiko-bot
2026-07-22  9:16 ` [PATCH 2/3] rust: sync: add SetOnce::try_get_or_populate() Alice Ryhl
2026-07-22  9:27   ` sashiko-bot
2026-07-22  9:16 ` [PATCH 3/3] rust_binder: use SetOnce::try_get_or_populate() Alice Ryhl

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.